下载文件发现是图片,直接用kali binwalk隐写,分离出隐藏文件
打开分离文件
发现最后的文件要密码,用随波逐流暴力破解成功,密码是123456
打开密码文件,文件给了一大串数字
自己不怎么会脚本所以用了下DeepSeek写的脚本
import re
from tkinter import filedialog
image_path = filedialog.askopenfilename(filetypes=[("JPEG文件", "*.jpg")])
from tqdm import tqdm # 进度条库
def read_file(filepath):
"""读取文件内容"""
with open(filepath, 'r', encoding='utf-8') as fp:
return fp.read()
def write_file(filepath, content):
"""写入内容到文件"""
with open(filepath, 'w', encoding='utf-8') as f:
f.write(content)
def main():
# 建议使用原始字符串(r前缀)处理Windows路径
input_file = r'C:\python代码\thienc.txt' # 输入文件路径
output_file = r'C:\python代码\thienc_output.txt' # 输出文件路径(避免覆盖原文件)
# 1. 读取原始文件
hex_content = read_file(input_file)
# 2. 提取所有两位十六进制组合
hex_pairs = re.findall(r'.{2}', hex_content)
# 3. 十六进制转字符
decoded_str = ''
for pair in tqdm(hex_pairs, total=len(hex_pairs), desc="转换十六进制"):
try:
# 将十六进制转为字节后解码为字符
decoded_str += bytes.fromhex(pair).decode('latin-1') # 使用latin-1编码确保兼容性
except ValueError:
decoded_str += '�' # 无效十六进制时显示替换字符
# 4. 处理特殊格式(按0x分割后补零)
formatted_str = ''
for segment in decoded_str.split('0x'):
if segment: # 跳过空字符串
formatted_str += segment if len(segment) > 1 else '0' + segment
# 5. 写入结果文件
write_file(output_file, formatted_str)
print(f"处理完成,结果已保存至:{output_file}")
if __name__ == "__main__":
main()
把解出来的结果导入到编辑器中保存,发现是7Z头
但是解压需要密码,我们分离出来的还有个图片,010查看末尾发现
base64+32解码得到KEY{Lazy_Man}
打开文件又是一串字符串
发现base64 base32解码发现不行
后来发现是个base64+32循环解码。
运用脚本
import base64
import re
def decode_data(input_file='secenc.txt', output_file='result.txt'):
"""自动解码 Base32 或 Base64 编码的多层嵌套数据"""
try:
with open(input_file, 'rb') as file:
f = file.read() # 直接读取二进制数据,避免 encode/decode 重复转换
while True:
try:
decoded_str = f.decode('utf-8')
if re.fullmatch(r'^[2-7A-Z=]+$', decoded_str):
f = base64.b32decode(f)
elif re.fullmatch(r'^[0-9a-zA-Z+/=]+$', decoded_str):
f = base64.b64decode(f)
else:
break
except (UnicodeDecodeError, ValueError):
break # 解码失败时退出循环
result = f.decode('utf-8', errors='replace') # 替换无法解码的字符
with open(output_file, 'w', encoding='utf-8') as file:
file.write(result)
print("解密完成!最终结果已保存至", output_file)
return result
except FileNotFoundError:
print(f"错误:文件 {input_file} 不存在!")
return None
if __name__ == "__main__":
decode_data()
得到flag:flag{Welc0me_tO_cTf_3how!}