0%

[[NUSTCTF 2022 新生赛]Eztxt] Writeup

2026-01-18 15:38By
daochunhan
MISClnk文件攻击RSA共模攻击

Problem: [NUSTCTF 2022 新生赛]Eztxt

Misc

#LNK文件分析 #CAB提取 #RSA共模攻击

解题步骤

flag.cab → flag.txt.lnk → 隐藏的CAB文件 → 损坏的ZIP文件修复 → RSA共模攻击

1.附件分析(Cabinet压缩文件)

补充(.cab文件)

1.文件头标识 4D 53 43 46 MSCF base64TVNDRgAAAA

2.Linux文件提取cabextrsct file.cab

3.Win可打开或WinRAR解压

仅提供了一个 flag.cab 文件,解压

cabextract flag.cab

得到lnk文件 flag.txt.lnk

在win尝试打开会得到指向tmp文件的fakeflag的base64加密 说明真正的flag需要分析lnk文件内部

2.LNK文件分析

使用 strings搜索LNK文件中的字符串

845858b18c.jpg注意到TVNDRgAAAA(Cabinet文件头)

cab文件以base64在lnk文件中 寻找隐藏的cab文件的偏移量

文件头TVNDRgAAAA文本在整个文本文件中的偏移量 -abo

grep -abo "TVNDRgAAAA" flag.txt.lnk

得到偏移量1957 后面是base64的cab文件数据

3.CAB提取

从1957提取数据 base64解码

从1958字节将文件数据读入hidden.cab

base64解码hidden.cab->hidden_decoded.cab 再次解压

dd if=flag.txt.lnk of=hidden.cab bs=1 skip=1957 base64 -d hidden.cab > hidden_decoded.cab cabextract hidden_decoded.cab

得到三个文件:

daifei.exe(GUI程序)

farenfeqwr.vbs(纯文本脚本)

temp 损坏的 ZIP 压缩包

ad31ba6845.jpg

4.ZIP(temp)修复

寻找文件中的zip文件头

grep -abo $'PK\x03\x04' temp

cd84bdeffb.jpg

将偏移163之后的文件数据提取到fixed.zip

dd if=temp of=fixed.zip bs=1 skip=163

文件可被识别为zip文件 尝试解压

f36d59ae26.jpg

unzip fixed_fixed.zip

得到三个文件:

user1_rsa.pub

user2_rsa.pub

encrypted.flag

两个RSA公钥(.pub)和加密的flag

5.RSA共模攻击

标志:两个公钥 flag文件加密两次

两个公钥模数 n 相同,指数 e1e2 不同,且有两个分别用这两个公钥加密的密文 c1c2

cat encrypted.flag cat user1_rsa.pub cat user2_rsa.pub

b8c8b21186.jpg

共模攻击:(gmpy2)

python3 -c " import sys sys.path.insert(0, '.') try: import gmpy2 from Crypto.PublicKey import RSA from Crypto.Util.number import long_to_bytes with open('user1_rsa.pub', 'rb') as f: key1 = RSA.importKey(f.read()) with open('user2_rsa.pub', 'rb') as f: key2 = RSA.importKey(f.read()) with open('encrypted.flag', 'r') as f: data = f.read() lines = data.splitlines() c1 = int(lines[0].split(':')[1].strip()) c2 = int(lines[1].split(':')[1].strip()) n1, n2 = key1.n, key2.n e1, e2 = key1.e, key2.e if n1 != n2: print('error: n1 != n2') sys.exit(1) s, s1, s2 = gmpy2.gcdext(e1, e2) m = (pow(c1, s1, n1) * pow(c2, s2, n2)) % n1 print(long_to_bytes(int(m)).decode('utf-8', errors='ignore')) except Exception as e: sys.exit(1) "

f920f3812d.jpg

6.得到flag

NSSCTF{c3da-bfca-dc68-cbf9}
还没有人赞赏,快来当第一个赞赏的人吧!
  
© 著作权归作者所有
加载失败
广告
×
评论区
添加新评论