011 base64stego
题目描述
菜狗经过几天的学习,终于发现了如来十三掌最后一步的精髓
Solution
根据 CTF Wiki ZIP 格式 板块的介绍,我们的切入点可能是:
- 爆破:穷举所有可能的密码
- 伪加密:修改标记位
- 明文攻击:利用已知文件找加密密钥,利用密钥来解锁其它加密文件
- CRC32:不去爆破密码,而是直接去爆破源文件的内容
我们拿到题目文件,解压会被提示输入密码:
我们首先考虑是不是伪加密,如果不是再采用爆破手段。
我们用 HxD 打开压缩包,搜索十六进制504B0102
,可以看到每个加密文件的文件头字段:
然后从50
开始,第9、第10个 byte 为加密字段,将其设置为0000
即可变成无加密状态:
另一个办法是在 Kali 下使用binwalk -e
来绕过伪加密。
解压出来的文件带着大量的 base64 编码字符串。解码出来关于隐写术的介绍:
┌──(cheery㉿Laptop)-[~/Desktop]
└─$ cat stego.txt| base64 -d >> decoded.txt
┌──(cheery㉿Laptop)-[~/Desktop]
└─$ cat decoded.txt
Steganography is the art and science of writing hidden messages in such a way that no one, apart from the sender and intended recipient, suspects the existence of the message, a form of security through obscurity. The word steganography is ......
根据题目名字“base64stego”,可以猜想本题是一道 base64 隐写题目。我们编写一段 Python 脚本来处理这些 base64 编码字符串:
import re
path = './stego.txt'
b64char = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'
with open(path, 'r')as f:
cipher = [i.strip() for i in f.readlines()]
plaintext = ''
for i in cipher:
if i[-2] == '=': # There are 4-bit hidden info while end with two '='
bin_message = bin(b64char.index(i[-3]))[2:].zfill(4)
plaintext += bin_message[-4:]
elif i[-1] == '=': # There are 2-bit hidden info while end with one '='
bin_message = bin(b64char.index(i[-2]))[2:].zfill(2)
plaintext += bin_message[-2:]
plaintext = re.findall('.{8}', plaintext) # 8bits/group
plaintext = ''.join([chr(int(i, 2)) for i in plaintext])
print(plaintext)
运行结果如下:
Base_sixty_four_point_five
修改一下格式即可得到 Flag。