CTF 网安之路 2026年郑州大学“奇安信杯”网络空间安全竞赛 Koyanrush 2026-11-14 2026-11-22 前言 非常好奇安信👍👍👍使我的ctf爆零👍👍👍
什么年代了还在搞禁止ai禁止本地题库这一块,网安界的满清遗老吗?
来让我好好欣赏一下都什么题目
决赛-工控网关密钥泄露 附件结构
决赛-工控网关密钥泄露.zip └─ 附件/ ├─ firmware.bin 577 B └─ flag.enc 48 B
解压附件拿到两个文件:firmware.bin和flag.enc,其中flag.enc只有48字节,猜测是加密后的flag,而firmware.bin中隐藏着加密方法。
使用010 Editor打开firmware.bin,看到文件头是1F 8B 08 ,说明是个gzip压缩文件,其中的原始文件名为 firmware.squashfs。
工具:7-zip
1 2 winget install --id 7 zip.7 zip -e --silent --accept-package-agreements --accept-source-agreements
安装后在用户变量里的Path添加 C:\Program Files\7-Zip。
用7-zip提取:
1 7 z x .\firmware.bin "-o$PWD \fw" -y
成功拿到.squashfs文件,看一眼文件头:68 73 71 73 ,标准的小端squashfs。
继续用7-zip展开squashfs文件系统:
1 7 z x .\fw\firmware.squashfs "-o$PWD \root" -y
在config.json中找到AES-128 密钥:
1 A1B2C3D4E5F67890ABCDEF1234567890
接着分析flag.enc的48字节:
1 2 3 28 07 80 BF 37 E1 FC 7B 70 BE 36 E8 A5 E5 BF 4B 7D 7E BD 59 27 B7 ED 4F E4 3F 9A 4D AD 83 25 20 B9 F6 B2 7A 6F 6C 0F 06 77 1C AC 95 64 F6 59 CC
是AES加密的话,有这几种可能:
1 2 3 4 5 IV ‖ CT CT ‖ IV 全 48 都是密文 GCM openssl 格式
优先测试可能性最大的切法:前16字节是IV,后36字节是密文。写解密脚本decrypt_iv_prefix.py:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 import argparseimport jsonimport osimport sysHERE = os.path.dirname(os.path.abspath(__file__)) def load_key (text, key_from ): if not text and key_from: with open (key_from, 'r' , encoding='utf-8' ) as fh: cfg = json.load(fh) text = (cfg.get('crypto' ) or {}).get('aes_key_hex' ) if not text: raise SystemExit('[!] %s 里没有 crypto.aes_key_hex' % key_from) if not text: raise SystemExit('[!] 需要 --key 或 --key-from' ) clean = '' .join(ch for ch in text if ch not in ' :-\t\r\n' ) if len (clean) not in (32 , 48 , 64 ) or any (c not in '0123456789abcdefABCDEF' for c in clean): raise SystemExit('[!] key 不是 32/48/64 位十六进制' ) return bytes .fromhex(clean) def aes_cbc_decrypt (key, iv, ct ): """优先 pycryptodome,退到同目录 pure_aes.py(纯标准库)""" try : from Crypto.Cipher import AES return AES.new(key, AES.MODE_CBC, iv).decrypt(ct), 'pycryptodome' except ImportError: pass sys.path.insert(0 , HERE) from pure_aes import cbc_decrypt return cbc_decrypt(key, iv, ct), 'pure_aes' def pkcs7_unpad (data ): n = data[-1 ] if data else 0 if 1 <= n <= 16 and data[-n:] == bytes ([n]) * n: return data[:-n] raise SystemExit('[!] PKCS#7 校验不过 -> key 不对(或这题不是 IV‖CT 结构)' ) def main (): ap = argparse.ArgumentParser() ap.add_argument('enc' ) ap.add_argument('--key' ) ap.add_argument('--key-from' ) args = ap.parse_args() key = load_key(args.key, args.key_from) blob = open (args.enc, 'rb' ).read() if len (blob) <= 16 or (len (blob) - 16 ) % 16 != 0 : raise SystemExit('[!] 长度 %d 不符合 IV(16)+CT(16的倍数)' % len (blob)) iv, ct = blob[:16 ], blob[16 :] raw, backend = aes_cbc_decrypt(key, iv, ct) text = pkcs7_unpad(raw).decode('utf-8' , 'replace' ) print ('[*] AES-%d / CBC / PKCS#7 (AES 来自: %s)' % (len (key) * 8 , backend)) print ('[*] IV = ' + iv.hex ().upper()) print ('[*] 密文 = %d 字节' % len (ct)) print () print (text) import re m = re.search(r'(?i)(flag|ctf)\{[^}]*\}' , text) if m: print ('\nFLAG: ' + m.group(0 )) if __name__ == '__main__' : main()
运行脚本后得到flag。
1 python decrypt_iv_prefix.py .\flag.enc --key-from .\root\config.json
最终flag:
flag{APUISC_2026}
转轮机加密 附件结构
转轮机加密.zip └─ crypto5.txt 544 B
题目描述:flag格式flag{}。
只有一个txt文件,简单粗暴的crypto。内容如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 1: < ZWAXJGDLUBVIQHKYPNTCRMOSFE < 2: < KPBELNACZDTRXMJQOYHGVSFUWI < 3: < BDMAIZVRNSJUWFHTEQGYXPLOCK < 4: < RPLNDVHGFCUKTEBSXQYIZMJWAO < 5: < IHFRLABEUOTSGJVDKCPMNZQWXY < 6: < AMKGHIWPNYCJBFZDRUSLOQXVET < 7: < GWTHSPYBXIZULVKMRAFDCEONJQ < 8: < NOZUTWDCVRJLXKISEFAPMYGHBQ < 9: < XPLTDSRFHENYVUBMCQWAOIKZGJ < 10: < UDNAJFBOWTGVRSCZQKELMXYIHP < 11: < MNBVCXZQWERTPOIUYALSKDJFHG < 12: < LVNCMXZPQOWEIURYTASBKJDFHG < 13: < JZQAWSXCDERFVBGTYHNUMKILOP < 密钥为:2,3,7,5,13,12,9,1,8,10,4,11,6 密文为:NFQKSEVOQOFNP
前十三行是转子,每行是 A-Z 的一个置换;密钥也是十三位,指定了每个字母用哪个转子;最后去解密密文。
加密是已知某个位置查输出字母;解密则需要反过来,已知输出字母找回输入位置。所以必须求逆置换。
比如密文的第一位是“N”,对应第一位密钥是“2”,所以查转子2,也就是第二行。对应关系如下
1 2 位置: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 字母: K P B E L N A C Z D T R X M J Q O Y H G V S F U W I
这里N在第五个,所以密文N要从第五位开始走一定的偏移量到一个新的字母,那就是解出的明文。
但是本题中我们不知道偏移量是多少,好在一共只有26个字母,所以可以写脚本批量尝试,看看哪种偏移能解出人话。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 import reimport sysdef parse (path ): """解析附件:13 个转子 / 密钥 / 密文。兼容半角 : 与全角 :""" with open (path, 'r' , encoding='utf-8' , errors='replace' ) as fh: text = fh.read() rotors = {} for line in text.splitlines(): m = re.match (r'\s*(\d+)\s*[::]\s*<\s*([A-Za-z]+)\s*<' , line) if m: rotors[int (m.group(1 ))] = m.group(2 ).upper() if not rotors: sys.exit('[!] 没解析出转子,检查附件是不是 < 26个字母 < 这种格式' ) for idx, row in rotors.items(): if len (row) != 26 or len (set (row)) != 26 : sys.exit('[!] 转子 %d 不是 A-Z 的完整排列(长度 %d)' % (idx, len (row))) m = re.search(r'密钥为?\s*[::]\s*([\d,\s,]+)' , text) if not m: sys.exit('[!] 没找到“密钥为:”这一行' ) key = [int (x) for x in re.split(r'[,,\s]+' , m.group(1 ).strip()) if x] m = re.search(r'密文为?\s*[::]\s*([A-Za-z]+)' , text) if not m: sys.exit('[!] 没找到“密文为:”这一行' ) ct = m.group(1 ).upper() if len (key) != len (ct): sys.exit('[!] 密钥 %d 位、密文 %d 位,长度对不上' % (len (key), len (ct))) for k in key: if k not in rotors: sys.exit('[!] 密钥引用了不存在的转子 %d' % k) return rotors, key, ct def decrypt (rotors, key, ct, offset ): out = [] for k, ch in zip (key, ct): row = rotors[k] out.append(row[(row.index(ch) + offset) % 26 ]) return '' .join(out) def main (): path = sys.argv[1 ] if len (sys.argv) > 1 else 'crypto5.txt' rotors, key, ct = parse(path) print ('[*] 转子 %d 个 | 密钥 %d 位 | 密文 %s' % (len (rotors), len (key), ct)) print () print ('偏移 明文' ) print ('---- --------------' ) for offset in range (26 ): print ('%+4d %s' % (offset, decrypt(rotors, key, ct, offset))) if __name__ == '__main__' : main()
解出的26种明文中,只有+17偏移对应的FIREINTHEHOLE可读,所以这是答案。
最终flag:
flag{FIREINTHEHOLE}
决赛-GhostPlatoon 附件结构
决赛-GhostPlatoon.zip └─ 附件/ ├─ output.txt 35.2 KB └─ task.sage 5.4 KB
题目描述:你截获了一段编队行驶期间的认证流量,以及一份封装着机密的密文。Flag格式为flag{}
注意到有sage文件,直接用记事本打开,里面是出题人的源代码。搜索“flag”字样,在149行发现以下内容
1 2 3 4 5 6 d3 = int((d0 + 3 * alpha + 9 * beta) % n) secret = i2b(d0) + i2b(alpha) + i2b(beta) + i2b(d3) flag = "flag{" + md5(secret).hex()[:16] + "}" aes_key = sha256(b"platoon-seal-v2" + secret) enc_nonce = sha256(b"nonce" + secret)[:16] ciphertext = stream_crypt(aes_key, enc_nonce, flag.encode())
这一段代码直接告诉我们:flag以secret的md5形式出现,而secret由四个i2b拼接而成:d0,alpha,beta和d3。其中d3可以由另外三个计算得出。
在sage中继续搜索其他i2b,在第113行找到:
1 privs = [int((d0 + i * alpha + (i * i) * beta) % n) for i in range(3)]
这里揭示了privs和d0,alpha和beta间的关系。可以发现,这里有一个跑了三次的range循环,每跑一次计算出一个privs。分别带入i=0,1,2,得到三个等式:
1 2 3 privs[0] = d0 + 0 + 0 privs[1] = d0 + α + β privs[2] = d0 + 2α + 4β
其中privs代表”privates”(私钥),与之相对的,还有pubs = “publics”(公钥)。也就是说只要找到三个私钥,再拿到d0便能计算出最终flag。
接下来查看output.txt。发现大多数内容都是这样的一段数据
1 2 3 4 5 6 7 8 { "veh": 0, "gps_time": 1725000000, "counter": 40960, "msg_hex": "42534d7c69643d307c743d313732353030303030307c633d34303936307c7370643d32307c6864673d30", "r": "0xd63cb44ce06033679a3e0b2e5174d252057ef640ad99c83fcde9c42ce5cf59de", "s": "0xdef50c7cc6b015990b29eaf417b5aa2cd56d454dc7f2e49e91980e9819d256d8" }
联系到题目背景,可知这是车联网里的广播消息(BSM),内容包括:veh(车辆编号),gps_time(GPS 时间戳),counter(计数器),msg_hex(被签名的消息原文)以及r,s两个签名值。
遍历整个txt文件,总计99条这样的记录,veh只有0,1,2三种,各占33条。所有的99条都包含在“signatures”中,说明这些是由三辆车签发的签名,每辆有33条。到这里可以推断出,三个私钥应该分别隐藏在三辆车对应的33条签名中,且私钥编号对应车辆编号。先看veh=0的33条签名,里面的私钥privs[0]就等于d0。
回到sage的95行找d0如何与签名产生联系:
1 2 3 4 5 6 7 8 9 10 11 12 def ecdsa_sign(d, msg: bytes, gps_time: int, counter: int, veh: int, poisoned: bool): h = b2i(sha256(msg)) % n while True: k = gen_k(gps_time, counter, veh, poisoned) R = k * G r = int(R.xy()[0]) % n if r == 0: continue s = (inverse_mod(k, n) * (h + r * d)) % n if s == 0: continue return int(r), int(s)
这是一个标准的 ECDSA 签名算法,签名中的r只依赖于随机数k和基点G,与消息、私钥无关;而s的生成公式满足s = k⁻¹ (h + r·d) mod n。这里出现了d,也就是说我们要求的d0就是这0号车33条签名对应的那个d。
而k是个随机数,对s的生成公式进行变形表示k:k = (r·s⁻¹)·d + (h·s⁻¹) ,记 t = r·s⁻¹, u = h·s⁻¹,mod n。
另外根据sage中生成k的函数gen_k,还能得到k = H·2¹⁰⁸ + low。其中H为k的高位部分,能通过签名里的veh、gps_time、counter算出,具体方法见函数public_nonce_material;low是k的低108位,由 HSM(硬件安全模块)随机生成,是未知量。
两个式子联立消k得到方程组
t₁·d + u₁ ≡ low₁ (mod n), 0 ≤ low₁ < 2¹⁰⁸ t₂·d + u₂ ≡ low₂ (mod n), 0 ≤ low₂ < 2¹⁰⁸、
t,u,n都是已知量(n明写在 output.txt 里),问题转换为求low。但low和d都是未知量,只能用LLL算法把 (low₁, low₂, d) 作为一组联立解出。
同样的办法,在veh=1,veh=2的签名中分别解出d1和d0,代入到私钥的三个等式中求出α和β,再求d3,最后取MD5得到flag。
完整脚本如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 import hashlibimport jsonimport osimport randomimport sysimport timefrom fractions import FractionL = 108 B = 1 << L MASK = (1 << (256 - L)) - 1 def find_output (argv ): if len (argv) > 1 : return argv[1 ] for cand in ('output.txt' , os.path.join('附件' , '附件' , 'output.txt' ), os.path.join('附件' , 'output.txt' )): if os.path.isfile(cand): return cand sys.exit('[!] 找不到 output.txt,请显式传路径' ) path = find_output(sys.argv) with open (path, encoding='utf-8' ) as fh: data = json.load(fh) n = int (data['n' ], 16 ) print ('[*] 曲线 %s,模数 n = 0x%064x' % (data.get('curve' , '?' ), n))print ('[*] 签名 %d 条,车辆 %d 辆' % (len (data['signatures' ]), len (data['vehicles' ])))def H_of (gps, counter, veh ): """与 task.sage 的 public_nonce_material 完全一致;注意末尾那个按车号异或的 limb。""" dg = hashlib.sha256(b'\x01\x60\x9e\x02' + gps.to_bytes(8 , 'big' ) + counter.to_bytes(4 , 'big' ) + bytes ([veh & 0xFF ])).digest() return (int .from_bytes(dg, 'big' ) >> L) ^ ((veh * 0x9E3779B1 ) & MASK) sigs = [] for s in data['signatures' ]: msg = bytes .fromhex(s['msg_hex' ]) h = int .from_bytes(hashlib.sha256(msg).digest(), 'big' ) % n sigs.append(dict (veh=s['veh' ], h=h, r=int (s['r' ], 16 ), s=int (s['s' ], 16 ), H=H_of(s['gps_time' ], s['counter' ], s['veh' ]))) groups = {0 : [], 1 : [], 2 : []} for s in sigs: groups[s['veh' ]].append(s) print ('[*] 分车:' + ', ' .join('veh%d=%d条' % (v, len (g)) for v, g in groups.items()))def dot (u, v ): return sum (a * b for a, b in zip (u, v)) def rnd (x ): if x >= 0 : return (2 * x.numerator + x.denominator) // (2 * x.denominator) return -((-2 * x.numerator + x.denominator) // (2 * x.denominator)) def gs (M ): nvec = len (M) Bs = [] mu = [[Fraction(0 ) for _ in range (nvec)] for _ in range (nvec)] for i in range (nvec): v = [Fraction(x) for x in M[i]] for j in range (i): mu[i][j] = dot([Fraction(x) for x in M[i]], Bs[j]) / dot(Bs[j], Bs[j]) v = [a - mu[i][j] * b for a, b in zip (v, Bs[j])] Bs.append(v) return Bs, mu def lll (M, delta=Fraction(99 , 100 ) ): M = [[Fraction(x) for x in row] for row in M] k = 1 Bs, mu = gs(M) while k < len (M): for j in range (k - 1 , -1 , -1 ): if abs (mu[k][j]) > Fraction(1 , 2 ): q = rnd(mu[k][j]) M[k] = [a - q * b for a, b in zip (M[k], M[j])] Bs, mu = gs(M) if dot(Bs[k], Bs[k]) >= (delta - mu[k][k - 1 ] ** 2 ) * dot(Bs[k - 1 ], Bs[k - 1 ]): k += 1 else : M[k], M[k - 1 ] = M[k - 1 ], M[k] Bs, mu = gs(M) k = max (k - 1 , 1 ) return M def build (sub ): """ 对每条签名:s^-1(h + r d) = k = H*2^L + low,|low| < B -> t_i * d + u_i ≡ low_i (mod n),其中 t_i = r_i s_i^-1,u_i = (h_i s_i^-1 - H_i 2^L) 格基(t+2 维): 前 t 行:n * I (消掉模 n 的整数倍) 第 t 行:t_i 分量 + B/n (d 的系数) 第 t+1 行:u_i 分量 + B (常数项) 短向量即 (low_1..low_t, d*B/n, B),从倒数第二个分量反解 d。 """ t = len (sub) M = [[Fraction(0 ) for _ in range (t + 2 )] for _ in range (t + 2 )] for i in range (t): M[i][i] = Fraction(n) for i, s in enumerate (sub): inv_s = pow (s['s' ], -1 , n) ti = (s['r' ] * inv_s) % n ui = (s['h' ] * inv_s - (s['H' ] << L)) % n M[t][i] = Fraction(ti) M[t + 1 ][i] = Fraction(ui) M[t][t] = Fraction(B, n) M[t + 1 ][t + 1 ] = Fraction(B) return M def candidates (red, t ): out = [] for row in red: if row[t + 1 ] == 0 : continue d = row[t] * n / B if d.denominator == 1 : out.append(int (d) % n) return out def verify (group, d ): """用整组签名验证:真 d 能让绝大多数签名满足 k>>L == H;毒签名是随机 k,必然不过。""" ok = 0 for s in group: inv_s = pow (s['s' ], -1 , n) k = (((s['h' ] + s['r' ] * d) % n) * inv_s) % n if (k >> L) == s['H' ] and k < n: ok += 1 return ok random.seed(7 ) found = {} t0 = time.time() for veh, group in groups.items(): best = None for attempt in range (120 ): t = random.choice((2 , 3 , 3 , 4 )) sub = random.sample(group, t) red = lll(build(sub)) for d in candidates(red, t): sc = verify(group, d) if best is None or sc > best[1 ]: best = (d, sc) if sc >= len (group) * 0.85 : break if best and best[1 ] >= len (group) * 0.85 : break if best: found[veh] = best[0 ] print ('[+] veh %d d = 0x%064x 通过 %d/%d 条' % (veh, best[0 ], best[1 ], len (group))) else : print ('[!] veh %d 恢复失败' % veh) if len (found) != 3 : sys.exit('[!] 没恢复出全部 3 个私钥' ) d0, d1, d2 = found[0 ], found[1 ], found[2 ] beta = ((d2 - 2 * d1 + d0) % n) * pow (2 , -1 , n) % n alpha = (d1 - d0 - beta) % n d3 = (d0 + 3 * alpha + 9 * beta) % n print ()print ('[*] d0 = 0x%064x' % d0)print ('[*] alpha = 0x%064x' % alpha)print ('[*] beta = 0x%064x' % beta)print ('[*] d3 = 0x%064x' % d3)secret = b'' .join(x.to_bytes(32 , 'big' ) for x in (d0, alpha, beta, d3)) flag = 'flag{' + hashlib.md5(secret).hexdigest()[:16 ] + '}' aes_key = hashlib.sha256(b'platoon-seal-v2' + secret).digest() iv = hashlib.sha256(b'nonce' + secret).digest()[:16 ] ct = bytes .fromhex(data['ciphertext_hex' ]) ks = b'' ctr = 0 while len (ks) < len (ct): ks += hashlib.sha256(aes_key + iv + ctr.to_bytes(4 , 'big' )).digest() ctr += 1 plain = bytes (a ^ b for a, b in zip (ct, ks)).decode('utf-8' , 'replace' ) print ()print ('[+] 由 md5(secret)[:16] 得到: %s' % flag)print ('[+] 用 stream_crypt 解密密文得到: %s' % plain)print ('[+] 两者一致: %s' % ('是' if plain == flag else '否' ))print ('[+] 用时 %.1f 秒' % (time.time() - t0))print ()print ('FLAG: %s' % flag)
经过实测发现本题99条签名中混入了若干条“毒签名”,导致每辆车33条签名验证时只能通过31~32条。
最终flag:
flag{204d453a575f94cd}
决赛-mapmap 附件结构
mapmap-.zip └─ mapmap 2.3 MB
题目描述:map
什么玩意给个map就没了()
先扔进010 Editor验明真身:文件头是7F 45 4C 46,是Linux x86-64 可执行文件,相当于Windows的exe。
那这里就需要Linux环境进行操作了,我使用的是WSL2挂载的Ubuntu 24.04.3 LTS。
先运行一下看看效果
回车之后没有回显内容,光标闪烁说明在等待输入。随便输点东西提交,返回“wrong”,接着程序结束。
很好,什么都没弄明白就结束了。这下得换IDA 查看它的内部结构。
在IDA中打开附件,自动定位到entry(0x404a30),IDA将其标注为start。代码块如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 ; Attributes: noreturn fuzzy-sp public start start proc near ; __unwind { endbr64 xor ebp, ebp mov r9, rdx pop rsi mov rdx, rsp and rsp, 0FFFFFFFFFFFFFFF0h push rax push rsp xor r8d, r8d xor ecx, ecx mov rdi, offset sub_404340 db 67h call sub_515C30 hlt ; } // starts at 404A30 start endp
在Linux x86_64架构的函数调用约定中,rdi寄存器用来传递函数的第一个参数,而传给rdi的地址就是 main 函数的地址。所以sub_404340是main函数。双击进入,反编译看逻辑。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 __int64 sub_404340() { unsigned __int64 v0; // rsi unsigned __int64 v1; // rdx __int64 v2; // rcx __int64 v3; // r12 unsigned __int64 v4; // r14 int v5; // ebx int v6; // r13d char v7; // al __int64 v8; // rbp __int64 v9; // r15 __int64 v10; // rax __int64 v11; // rax __int64 v12; // rdx _BOOL8 v13; // rdi unsigned __int64 v14; // rdi __int64 *v15; // rax unsigned __int64 v16; // r12 __int64 v17; // rax __int64 v19; // [rsp+0h] [rbp-78h] __int64 v20; // [rsp+0h] [rbp-78h] _QWORD *v21; // [rsp+10h] [rbp-68h] BYREF unsigned __int64 v22; // [rsp+18h] [rbp-60h] _QWORD v23[3]; // [rsp+20h] [rbp-58h] BYREF unsigned __int64 v24; // [rsp+38h] [rbp-40h] v24 = __readfsqword(0x28u); sub_404C00(); v0 = (unsigned __int64)&v21; v22 = 0; v21 = v23; LOBYTE(v23[0]) = 0; sub_471A90(&unk_648560, &v21); v3 = qword_647530; if ( v22 != 140 ) sub_404BD0(); v4 = 0; v5 = 0; v6 = 0; do { v7 = *((_BYTE *)v21 + v4); if ( v7 == 119 ) { v8 = *(_QWORD *)(v3 + 16); --v5; v9 = v3 + 8; if ( !v8 ) goto LABEL_40; } else { switch ( v7 ) { case 's': ++v5; break; case 'a': --v6; break; case 'd': ++v6; break; default: sub_404BD0(); } v8 = *(_QWORD *)(v3 + 16); v9 = v3 + 8; if ( !v8 ) { LABEL_40: v8 = v9; LABEL_18: v19 = v8; v8 = sub_470DE0(96, v0, v1, v2); *(_DWORD *)(v8 + 32) = v5; *(_OWORD *)(v8 + 56) = 0; *(_OWORD *)(v8 + 72) = 0; *(_QWORD *)(v8 + 88) = 0; *(_QWORD *)(v8 + 40) = v8 + 88; *(_QWORD *)(v8 + 48) = 1; *(_DWORD *)(v8 + 72) = 1065353216; v11 = sub_46F910(v3, v19, v8 + 32); if ( v12 ) { v13 = v11 || v9 == v12 || v5 < *(_DWORD *)(v12 + 32); v0 = v8; sub_479520(v13, v8, v12, v9); ++*(_QWORD *)(v3 + 40); } else { v0 = 96; v20 = v11; sub_46FF40(v8, 96); v8 = v20; } goto LABEL_23; } } v2 = v9; while ( 1 ) { v1 = *(_QWORD *)(v8 + 16); v10 = *(_QWORD *)(v8 + 24); if ( v5 > *(_DWORD *)(v8 + 32) ) break; LABEL_13: if ( !v1 ) goto LABEL_16; v2 = v8; v8 = v1; } while ( v10 ) { v8 = v10; v1 = *(_QWORD *)(v10 + 16); v10 = *(_QWORD *)(v10 + 24); if ( v5 <= *(_DWORD *)(v8 + 32) ) goto LABEL_13; } v8 = v2; LABEL_16: if ( v8 == v9 || v5 < *(_DWORD *)(v8 + 32) ) goto LABEL_18; LABEL_23: v14 = *(_QWORD *)(v8 + 48); v1 = v6 % v14; v15 = *(__int64 **)(*(_QWORD *)(v8 + 40) + 8 * v1); v16 = v1; if ( v15 ) { v2 = *v15; v0 = *(unsigned int *)(*v15 + 8); while ( v6 != (_DWORD)v0 ) { v2 = *(_QWORD *)v2; if ( v2 ) { v0 = *(int *)(v2 + 8); v1 = v0 % v14; if ( v16 == v0 % v14 ) continue; } goto LABEL_28; } v2 += 16; } else { LABEL_28: v17 = sub_470DE0(24, v0, v1, v2); *(_QWORD *)v17 = 0; v0 = v6 % v14; *(_DWORD *)(v17 + 8) = v6; *(_QWORD *)(v17 + 16) = 0; v2 = sub_46FD80(v8 + 40, v16, v6, v17, 1) + 16; } v3 = *(_QWORD *)v2; if ( !*(_QWORD *)v2 ) sub_404BD0(); ++v4; } while ( v22 > v4 ); if ( v6 == 38 && v5 == 38 ) sub_4DA410(&unk_648440, "flag{md5(your input)}", 21); else sub_4DA410(&unk_648440, "wrong", 5); sub_404B60(&unk_648440); if ( v21 != v23 ) sub_46FF40(v21, v23[0] + 1LL); if ( v24 != __readfsqword(0x28u) ) sub_59B4A0(); return 0; }
审计整个函数可知,只有当v6和v5都为38时程序打印flag{md5(your input)},此时只需要把输入转为md5即可拿到flag。
至于对输入的要求,回到开头部分:
1 2 if ( v22 != 140 ) sub_404BD0();
其中sub_404BD0是个失败出口函数,结合上下代码段不难猜出v22代表输入长度,所以输入必须是140字符。
接下来是这一段:
1 2 3 4 5 6 7 8 9 v7 = *((_BYTE *)v21 + v4); if ( v7 == 119 ) { v8 = *(_QWORD *)(v3 + 16); --v5; v9 = v3 + 8; if ( !v8 ) goto LABEL_40; }
取出输入字符串中第 v4 个字符并判断这个字符的 ASCII 值是否为 119。ASCII值为119的字符就是’w’。执行--v5说明遇到 w 时,v5 减一。
后面这一段更是演都不演了
1 2 3 4 5 6 7 8 9 10 11 12 13 14 switch ( v7 ) { case 's': ++v5; break; case 'a': --v6; break; case 'd': ++v6; break; default: sub_404BD0(); }
经常玩电脑的应该已经意识到了,这不就是wasd控制上下左右吗,v5就是y轴,v6就是x轴。v5和v6一开始都初始化为0,所以这个程序实际上是让用户通过wasd控制坐标变化,操作140次后使横纵坐标均为38。
可是真有这么简单吗?注意到下面这段代码:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 else { LABEL_28: v17 = sub_470DE0(24, v0, v1, v2); *(_QWORD *)v17 = 0; v0 = v6 % v14; *(_DWORD *)(v17 + 8) = v6; *(_QWORD *)(v17 + 16) = 0; v2 = sub_46FD80(v8 + 40, v16, v6, v17, 1) + 16; } v3 = *(_QWORD *)v2; if ( !*(_QWORD *)v2 ) sub_404BD0(); ++v4;
程序开始时,main函数调用sub_404C00() 建哈希表。这表还会变,走一步换一张,每走一步,程序用移动后的绝对坐标 (y,x) 去当前格子自己的表里查value,只有查到的结点有非零value,程序才继续;找到value为零的已有结点或者不存在的节点都会失败。所以我们没法只靠静态文件找出可行路径,只能开启程序一步步试出来。
回到WSL写gdb脚本,测试oracle。原理就是对一条候选路径,若在“第 len(prefix) 个字符”处命中 0x404667(失败分支),说明这一步撞墙;否则该方向可走。测试通过后用 gdb Python 从 (0,0) 做 全量BFS,每次把 prefix + 方向 用w补齐到 140 字符送入程序,读 $r14(当前字符下标)判断是否撞墙。涉及到的脚本如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 import osimport subprocessBIN = os.path.expanduser('~/mapmap/mapmap' ) IN = '/tmp/mapmap_in.txt' SCRIPT = '/tmp/mapmap_oracle.gdb' NEED = 140 BPS = [(0x404667 , 'WALL' , True ), (0x40466c , 'BADCHAR' , True ), (0x404676 , 'LENGTH' , False ), (0x40456a , 'END' , False ), (0x404647 , 'PASS' , False )] def _script (): lines = ['set style enabled off' , 'set pagination off' , 'set confirm off' ] for addr, name, has_idx in BPS: lines += ['b *0x%x' % addr, 'commands' , 'silent' ] if has_idx: lines.append('printf "%s@%%ld\\n", $r14' % name) else : lines.append('printf "%s\\n"' % name) lines += ['quit' , 'end' ] lines += ['run < %s' % IN, 'printf "EXIT\\n"' ] with open (SCRIPT, 'w' ) as f: f.write('\n' .join(lines) + '\n' ) def check (s ): with open (IN, 'w' ) as f: f.write(s + '\n' ) _script() out = subprocess.run(['gdb' , '-q' , '-nx' , '-batch' , '-x' , SCRIPT, BIN], capture_output=True , text=True ).stdout for line in out.splitlines(): line = line.strip() if line.startswith(('WALL@' , 'BADCHAR@' )) or line in ('LENGTH' , 'END' , 'PASS' , 'EXIT' ): return line return 'UNKNOWN' def probe (prefix, d ): path = prefix + d r = check(path + 'w' * (NEED - len (path))) if r == 'PASS' : return 'goal' if r.startswith('WALL@' ): return 'wall' if int (r.split('@' )[1 ]) == len (prefix) else 'valid' if r == 'END' : return 'valid' return 'error:' + r if __name__ == '__main__' : import sys if len (sys.argv) == 2 : print (check(sys.argv[1 ])) else : print (probe(sys.argv[1 ], sys.argv[2 ]))
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 from collections import dequeimport sysfrom oracle import probeNEED = 140 GOAL = (38 , 38 ) DIRS = [('w' , 0 , -1 ), ('s' , 0 , 1 ), ('a' , -1 , 0 ), ('d' , 1 , 0 )] def find_path (): start = (0 , 0 ) parent = {start: None } q = deque([(start, '' )]) probes = 0 while q: (x, y), p = q.popleft() if len (p) >= NEED: continue for d, dx, dy in DIRS: r = probe(p, d) probes += 1 if probes % 500 == 0 : print ('probes=%d cells=%d depth=%d' % (probes, len (parent), len (p)), file=sys.stderr) if r == 'wall' : continue if r == 'goal' : return p + d, probes nxt = (x + dx, y + dy) if nxt not in parent: parent[nxt] = (p, d) q.append((nxt, p + d)) return None , probes if __name__ == '__main__' : path, probes = find_path() print ('probes =' , probes) print ('PATH =' , path)
运行后得到路径(有效输入)为
1 ssssddwwwwddddssaassssssaassddssaassddssddssssssddssaassddssddwwddssssddwwddddssssssssssddddddddddwwddssddddddwwaawwddwwaaaawwddddddssssssss
求MD5得到最终flag
flag{f205f28a97000b7a21a5df3f9264d796}
决赛-ColdChain 附件结构
决赛-ColdChain.zip └─ Challenge/ └─ ColdChain.exe 7.6 MB
题目描述:ColdChain
依旧无效提示。附件只有一个exe,先双击运行,显示要输入flag,先随便输入内容提交,程序显示wrong并退出。
用特征字符串探一下打包方式
1 2 3 4 foreach($k in @("PyInstaller","_MEIPASS","python313.dll","Input flag: ","Correct")){ $r = cmd /c "findstr /m /c:`"$k`" ColdChain.exe" 2>$null if($r){"[$k] 命中"}else{"[$k] 没有"} }
前三个都命中,说明它是 PyInstaller 打包的 Python 程序,但题目自己的字符串不在exe里面。
接下来用PyInstaller解包器pyinstxtractor.py解开归档
工具:pyinstxtractor.py
1 2 Invoke-WebRequest -Uri "https://raw.githubusercontent.com/extremecoders-re/pyinstxtractor/master/pyinstxtractor.py" -OutFile pyinstxtractor.py
1 py pyinstxtractor.py ColdChain.exe
提取成功后,得到 PyInstaller 归档中的文件,包括: main.pyc,PYZ.pyz,python313.dll等。
对main.pyc进行反序列化和反汇编,暂且认为16字节的pyc头存在。
1 py -c 'import marshal,dis;co=marshal.loads(open("main.pyc","rb").read()[16:]);dis.dis(co)'
得到结果
1 2 3 4 5 6 7 8 9 10 11 12 13 14 0 RESUME 0 1 LOAD_CONST 0 (0) LOAD_CONST 1 (None) IMPORT_NAME 0 (sys) STORE_NAME 0 (sys) 2 LOAD_NAME 0 (sys) LOAD_ATTR 2 (exit) PUSH_NULL LOAD_CONST 0 (0) CALL 1 POP_TOP RETURN_CONST 1 (None)
对应python源码
所以这是个空壳。提取PYZ.pyz统计内部模块,内容也基本都是Python标准库,没有明显的自定义业务模块。
所以检查的重点落在了python313.dll。在其中搜索程序提示语:
1 2 3 4 $p = "D:\Desktop\奇安信\work\决赛-ColdChain\附件\Challenge\ColdChain.exe_extracted\python313.dll" $b = [IO.File]::ReadAllBytes($p) $s = [Text.Encoding]::Latin1.GetString($b) foreach($k in @("Input flag: ","Correct","Wrong")){ "{0,-14} -> 0x{1:X}" -f $k, $s.IndexOf($k) }
全部命中
1 2 3 Input flag: -> 0x4A791C Correct -> 0x4A792C Wrong -> 0x4A7935
接着查看命中位置附近的二进制数据
1 Format-Hex python313.dll -Offset 0x4A7800 -Count 400
发现除了程序提示语外,还出现了EOFError、KeyboardInterrupt、print、_runtime_entry等类似Python代码对象的数据结构。既然 DLL可能包含Python代码对象,那么可以尝试直接启动DLL自带的Python运行时,让解释器帮我们执行其中的代码。
用python交互模式执行
1 2 3 4 5 6 7 8 import os, ctypes d = r"D:\Desktop\奇安信\work\决赛-ColdChain\附件\Challenge\ColdChain.exe_extracted" os.add_dll_directory(d) lib = ctypes.CDLL(os.path.join(d, "python313.dll")) lib.Py_InitializeEx.argtypes = [ctypes.c_int] lib.Py_InitializeEx(0) lib.PyRun_SimpleString.argtypes = [ctypes.c_char_p] lib.PyRun_SimpleString(b"import sys; print(sys.version)")
输出3.13.1和0,说明解释器拉起来了。现在检查 os 模块,根据前面的分析,合理怀疑题目作者修改了Python运行时,在os模块中植入了隐藏函数。
1 lib.PyRun_SimpleString(b"import os; print([n for n in dir(os) if n.startswith('_runtime')])")
输出[‘_runtime_check’, ‘_runtime_entry’, ‘_runtime_size’, ‘_runtime_width’]和0。继续查看:
1 2 lib.PyRun_SimpleString(b"import os; print(os._runtime_size, os._runtime_width)") lib.PyRun_SimpleString(b"import os; print(type(os._runtime_check), os._runtime_check('x'*38))")
第一条指令的输出表明flag必须是38字节,而算法会将输入补齐到48字节;第二个指令验证了这一点。
最后反汇编_runtime_check看校验算法。转化为接近python源码的形式方便理解:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 raw = text.encode("ascii") keys = stat._mode_keys(ntpath._volume_salt) padding = 48 - len(raw) data = raw + bytes([padding]) * padding data = stat._mode_mix(data, keys) data = genericpath._path_fold( data, keys, ntpath._volume_salt ) data = ntpath._volume_mix(data, keys) parts = ( stat._mode_tag, genericpath._path_tag, ntpath._volume_tag ) for i, value in enumerate(data): expected = ( parts[i % 3][i // 3] ^ keys[(i * 9 + 5) % 64] ^ ((i * 13 + 66) & 0xFF) ) if value != expected: return False return True
从这里可以确定,校验函数执行的是三层连续变换:_runtime_check(text)首先检查输入是否为38个ASCII字符,然后在末尾填充10个0x0A字节,使数据达到48字节。接着通过_mode_keys()生成密钥,依次调用_mode_mix()、_path_fold()和_volume_mix()进行三层变换。最后结合三个模块的标签、密钥及位置常数计算预期字节,将变换结果与预期数据逐字节比较,并通过diff累积差异。全部48字节匹配则返回True,否则返回False。这38字节的输入就是flag,所以现在获取校验函数中的预期结果expected,再做逆变换即可还原flag。
在拉起解释器的环境中依次运行下列指令:
1 lib.PyRun_SimpleString(b"import stat,genericpath,ntpath; print(stat._mode_seed.hex()); print(stat._mode_tag.hex()); print(genericpath._path_tag.hex()); print(ntpath._volume_salt.hex()); print(ntpath._volume_tag.hex()); print(genericpath._path_rounds)")
1 lib.PyRun_SimpleString(b"import stat,ntpath; print(stat._mode_keys(ntpath._volume_salt).hex())")
1 lib.PyRun_SimpleString(b"import stat,genericpath,ntpath; k=stat._mode_keys(ntpath._volume_salt); p=(stat._mode_tag,genericpath._path_tag,ntpath._volume_tag); e=bytes(p[i%3][i//3]^k[(i*9+5)%64]^((i*13+66)&255) for i in range(48)); print(e.hex(), len(e))")
拿到48字节校验数据
1 d1c417243dc59c0039334a367a7e21dded0cdd58d9ade04e2e23f783262a4c307a3a7bf34a18fff4fb6e3dd39f962469
最后写还原脚本:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 EXPECTED = bytes .fromhex( "d1c417243dc59c0039334a367a7e21dded0cdd58d9ade04e2e23f783262a4c307a3a7bf34a18fff4fb6e3dd39f962469" ) MODE_SEED = bytes .fromhex("759877262c9ef26dfd11801cf03acba0" ) VOL_SALT = bytes .fromhex("d3fd2ef337bb956a36ff4813" ) SIZE = 38 ROUNDS = 10 def ror8 (v, r ): return ((v >> r) | (v << (8 - r))) & 0xFF def mode_keys (salt ): out = bytearray (64 ) x = 3222520030 for i in range (64 ): x ^= (x << 13 ) & 0xFFFFFFFF x ^= x >> 17 x ^= (x << 5 ) & 0xFFFFFFFF out[i] = ((x >> (8 * (i & 3 ))) ^ MODE_SEED[i % 16 ] ^ salt[(i * 5 + 3 ) % 12 ] ^ (i * 61 )) & 0xFF return bytes (out) def volume_order (n, keys ): p = list (range (n)) x = 2447445413 for i in range (n - 1 , 0 , -1 ): x = (1664525 * x + 1013904223 + VOL_SALT[i % 12 ] + keys[i % 64 ]) & 0xFFFFFFFF j = x % (i + 1 ) p[i], p[j] = p[j], p[i] return p def path_round (v, keys, r ): n = len (v) out = bytearray (n) carry = keys[(r * 5 + 1 ) % 64 ] ^ ((r * 29 + 99 ) & 0xFF ) for i in range (n): a, b, c = v[i], v[(i + 1 ) % n], v[(i + 7 ) % n] t = (a + keys[(r * 7 + i) % 64 ] + carry) & 0xFF t = ((t << (1 + (i + r) % 7 )) | (t >> (7 - (i + r) % 7 ))) & 0xFF t ^= (b * (keys[(i + 11 ) % 64 ] | 1 ) + c + i + r) & 0xFF out[i] = t carry = (carry + t + a + i) & 0xFF return bytes (out) def volume_unmix (data, keys ): out = bytearray (len (data)) for i, j in enumerate (volume_order(len (data), keys)): v = (data[i] - VOL_SALT[i % 12 ] - 23 * i) & 0xFF out[j] = ror8(v, i % 7 + 1 ) ^ keys[(i * 11 + 3 ) % 64 ] return bytes (out) def path_unfold (data, keys ): n = len (data) // 2 left, right = data[:n], data[n:] for r in reversed (range (ROUNDS)): prev_right = left prev_left = bytes ( a ^ b for a, b in zip (right, path_round(prev_right, keys, r)) ) left, right = prev_left, prev_right return left + right def mode_unmix (data, keys ): out = bytearray (len (data)) prev = 167 for i, q in enumerate (data): v = ror8(q ^ prev ^ keys[(7 * i + 11 ) % 64 ], i % 7 + 1 ) out[i] = (v - keys[i % 64 ] - 17 * i) & 0xFF prev = q return bytes (out) def main (): keys = mode_keys(VOL_SALT) data = volume_unmix(EXPECTED, keys) data = path_unfold(data, keys) data = mode_unmix(data, keys) print ("flag =" , data[:SIZE].decode("ascii" )) if __name__ == "__main__" : main()
运行后得到最终flag
flag{810d096ba783da4eb5956cf8ed82d114}
Pm-android 附件结构
Pm-android.zip └─ app.apk 2.3 MB
题目描述:android
apk题目,先7z解压看有没有壳
1 7z l "Pm-android\app.apk"
浏览一遍输出,APK就是zip,无lib\,无assets\,classes.dex只有 1 个。这是好事,可以放心静态反编译。
工具:jadx
1 2 winget install -e --id Skylot.jadx
用jadx反编译
1 2 3 $jar = (Get-ChildItem "$env:LOCALAPPDATA\Microsoft\WinGet\Packages\Skylot.jadx_*\lib\jadx-gui-*-all.jar" | Select-Object -First 1).FullName java -cp "$jar" jadx.cli.JadxCLI -d .\jadx_out --show-bad-code .\app.apk
读Manifest,也就是resources下的AndroidManifest.xml
1 2 3 4 5 6 7 8 9 10 11 <manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="1" android:versionName="1.0" android:compileSdkVersion="30" android:compileSdkVersionCodename="11" package="com.example.ilililililil" platformBuildVersionCode="30" platformBuildVersionName="11"> <uses-sdk android:minSdkVersion="23" android:targetSdkVersion="30"/> <application android:theme="@style/Theme.IlIlIlIlIlIl" android:label="@string/app_name" android:icon="@mipmap/ic_launcher" android:allowBackup="true" android:supportsRtl="true" android:extractNativeLibs="false" android:roundIcon="@mipmap/ic_launcher_round" android:appComponentFactory="androidx.core.app.CoreComponentFactory"> <activity android:name="com.example.ilililililil.MainActivity"> <intent-filter> <action android:name="android.intent.action.MAIN"/> <category android:name="android.intent.category.LAUNCHER"/> </intent-filter> </activity> </application> </manifest>
可以看到package都在com.example.ilililililil;此外,标有LAUNCHER的类在MainActivity这个activity下。
所以先去查看”\com\example\ilililililil”下的MainActivity.java。有这一段
1 2 3 4 5 6 7 8 public /* synthetic */ void lambda$onCreate$0$MainActivity(final EditText editText, View v) { System.out.println(encoder.encode(editText.getText().toString())); if (encoder.encode(editText.getText().toString()).equals("嫇嫍嫂嫈嫜媘嫅嫆媑媖媗嫇嫄媑媙嫂媘媗媒媚嫄媗媙嫂嫅媘媚嫅嫃媕媙嫇媘媑媘媚媔嫞")) { Toast.makeText(this, "YES", 0).show(); } else { Toast.makeText(this, "NO", 0).show(); } }
拿到密文
1 嫇嫍嫂嫈嫜媘嫅嫆媑媖媗嫇嫄媑媙嫂媘媗媒媚嫄媗媙嫂嫅媘媚嫅嫃媕媙嫇媘媑媘媚媔嫞
它用来跟用户输入比较,两者完全相同,看起来是flag变换后得到的结果。注意到它调用了encode,而MainActivity.java的21-22行初始化了这个类以及另一个名为MainActlvity的类。
继续查看Encoder.java和MainActlvity.java
1 2 3 4 5 6 7 8 9 10 11 12 13 14 package com.example.ilililililil; /* JADX INFO: loaded from: classes.dex */ public class Encoder { private int key = 305419896; public String encode(String str) { StringBuilder sb = new StringBuilder(); for (char c : str.toCharArray()) { sb.append((char) (c + this.key)); } return sb.toString(); } }
MainActlvity.java:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 package com.example.ilililililil; import java.lang.reflect.Field; /* JADX INFO: loaded from: classes.dex */ public class MainActlvity { public MainActlvity() { try { Field declaredField = Encoder.class.getDeclaredField("key"); declaredField.setAccessible(true); declaredField.set(MainActivity.encoder, 439048801); } catch (IllegalAccessException | NoSuchFieldException e) { e.printStackTrace(); } } }
这下看懂了:Encoder的字段初始化把key设成305419896,然后MainActlvity的构造器用反射把encoder.key改成439048801。
所以这道题的逻辑就是对用户输入做Encode,当得到的结果等于那串汉字密文时通过,此时用户输入就是flag。现在已知密文和逻辑直接逆向即可。而Encode的逻辑中涉及到的key被MainActlvity修改,所以key的值要先取439048801,再按照Encode的规定继续运算。
OK一行命令直接还原
1 py -c "t='嫇嫍嫂嫈嫜媘嫅嫆媑媖媗嫇嫄媑媙嫂媘媗媒媚嫄媗媙嫂嫅媘媚嫅嫃媕媙嫇媘媑媘媚媔嫞'; print(''.join(chr((ord(c)-439048801)&0xFFFF) for c in t))"
也就是取每一位密文提升为int再减key,保留低16位转回char,最后拼接。
最终flag
flag{7de056fc08a7619c68ad79db48f70793}
Am-时间域隐蔽通道-“扫描幽灵”.zip 附件结构
Am-时间域隐蔽通道-“扫描幽灵”.zip └─ plc_protocol_id.pcapng 18.4 KB
题目描述:某 SCADA 系统定期轮询 PLC,流量包间隔精确到毫秒——一切看起来都很正常。但仔细统计时间间隔后发现:某次轮询周期内出现了异常密集的请求窗口,响应速度远超正常值。这些额外响应包里藏着什么? flag 格式:flag{…}
总算到舒适区了()
拿到pcapng文件直接wireshark打开,先看协议分级统计
1 2 3 4 5 6 7 frame 312 raw 312 ip 312 tcp 312 mbtcp 112 modbus 112 _ws.malformed 31
该流量共312帧,其中有112条modbus,那么这是本题主要协议。
题目描述中提到让我们关注“异常密集的请求窗口”,所以要先找这个。有个方便的办法:右键列头添加一个名为“Delta”的列,类型用Delta time displayed。应用后过滤器填写modbus && ip.src == 192.168.1.10只保留modbus请求,然后检查Delta列,此时这一列显示的就是由 192.168.1.10发出的、相邻两个modbus请求包之间的时间间隔(即主站的轮询间隔时间)。
观察一下,前几个请求的间隔都是1s,属于稳定的轮询。第13条突变为0.3,之后的15,17,19,21,23全是0.125,25条变为0.345,后续恢复为1s。再往后的数据能明显分成两部分:35到61均为0.4s;63至末尾是较为抖动的数据,浮动在0.171-0.328之间。
所以符合题目描述中“异常密集”的就是那些间隔为0.125的帧了,范围在13-25之间。由于第25条的Time正好是6.0,已经落在1秒整数网格上,所以接下来仅过滤出13-24的条目继续分析。
用时间网格过滤
1 modbus && frame.time_relative >= 5.03 && frame.time_relative <= 5.67
这样就只剩下了12帧需要分析。观察Length列发现有7帧都是52,这些应该是正常的,重点看14,16,18,20,24几帧携带了什么载荷。
依次点开这五帧,看底部字节窗格的ASCII列,找到这五段数据:
1 2 3 4 5 666c61677b4d6f646275735f 3530325f323032365f41687d B16Enc ode!! Gap=125ms
Gap=125ms验证了我们的判断,有问题的就是这个间隔;B16Enc和ode!!两段拼出B16Encode!!是解密提示,剩下两个就是密文了。
按照提示,拼接密文为666c61677b4d6f646275735f3530325f323032365f41687d,按base16/hex解出最终flag
flag{Modbus_502_2026_Ah}
决赛-make_stego_great_again(未解出) 附件结构
决赛-make_stego_great_again.zip └─ make_stego_great_again/ ├─ pressure_chamber.zip 48.8 KB └─ desalination.png 4.2 KB
我嘞个MSGA。附件有一张png和一个zip,zip是加密的。先看png,既然题目提到了隐写,就先试试LSB隐写。
在R通道LSB按字节果然解出记录:LSB1.Desalination_Pressure@7。尝试用这个解压加密的pressure_chamber.zip,失败。
继续换别的png隐写寻找线索,最后发现该png每行filter类型0..4,按5进制/3 bit一字节能解出 FILT 记录:SeaWater_Filter#42。 用该密码成功解开 pressure_chamber.zip,得到 out/f5.jpg。
jpg命名提示f5隐写,末尾附加了52字节:U5 RH MLG HGZMWZIW / FHV B ZX NRWYZMW HPRK HSIRMPZTV。 Atbash 解码得到:F5 IS NOT STANDARD / USE Y AC MIDBAND SKIP SHRINKAGE。 该提示给出第 4 层的三个约束:非标准 F5、只取 Y 的 AC midband、跳过 shrinkage。
之后就卡住了,一个非标准的f5,扔给ai也只得到以下结论:
第 4 层的提示完备地描述了嵌入信道(Y / AC / zigzag 5..42 / |c|≥2 + 无 shrinkage 的修改规则),并在数据上被 77/77 验证,但它刻意不涉及访问顺序 π。而 π 是这一层唯一的载荷载体:77 次改动只给出 77 个 (位置,位值),对 π 的约束仅是”这 77 个载体必须被打乱分散”(强统计证据:秩跨 [15,11384]、行/列卡方均匀),并不唯一确定 π。
于是问题退化为:在没有密钥的情况下恢复一个未知置换。这个密钥至今也没找到,置换方式也仍未确定,比赛时本题也是0解,估计就是防止AK而设置的。
我把题目附件放这了,有感兴趣的可以来逝一下⬇️
一点没碰的 Am-老管家的画廊 决赛-ret2text Pm-秘密图书馆 Am-WebChain
这四个不是web就是pwn,没做,比赛结束后也进不去环境了。
结语 第二次线下赛,体验是糟糕的,成绩是没有的。如今已是ai agent的时代,这样连本地模型都禁止的比赛意义何在?我不明白。而且就题目的难度而言,不出网或不用ai模型辅助几乎不可能在短短两小时内解出中等及以上难度的题目。所以,见仁见智吧。