西湖论剑 2024

Last updated on January 30, 2024 pm

MZ,babycpp

MZ

核心逻辑在这

输入48位flag后,利用flag作为索引,然后与取得值相比较,最后再换表

尝试爆破一下,发现符合要求的字符很少,那么可以考虑从第一个字符开始爆破,这里搓了一个idapython脚本,方便看值,然后就是不断调试程序,不断尝试输入。

由于题目所说flag有意义且爆破出的字符也比较少,所以手动爆破效率也挺高的

结合题目说flag有意义,边爆边猜会快一点

Somet1mes_ch0ice_i5_more_import@nt_tHan_effort~!

babycpp

有两处主要逻辑,先看第一处

一直跟进去会看到一个循环

跟进操作

就是一个挺标准的TEA类算法了,动调可以拿到Key和delta,不过需要对TEA加密比较熟悉,才能反应过过来哪个变量是什么

还有一处加密是最终比较的上一行

跟进去

也挺长的,不过关键在后面

可以发现就是对TEA之后的密文进行异或和加法

但有个坑,就是前面有一个swap语句

我一直以为是只是交换值,没想到还交换了地址的内容,导致我一直卡在这里,最终在赛后一个钟才发现这个问题,比较遗憾。

解密就很简单了,先打表把最后的异或哪些常量给打出来,然后就是TEA逆运算

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
from ctypes import *

key = [0x67452301, 0xEFCDAB89, 0x98BADCFE, 0x10325476]

def decrypt(v1, v2):
sum = c_uint32(0xdeadbeef * 256)
for i in range(256):
sum.value -= 0xdeadbeef
v2.value -= (((v1.value >> 3) ^ (v1.value << 6)) + v1.value) ^ (sum.value + key[(sum.value >> 0xb) & 3])
v1.value -= (((v2.value >> 7) ^ (v2.value << 2)) + v2.value) ^ (sum.value + key[sum.value & 3])

for i in range(4):
print(chr((v1.value >> (8 * i)) & 0xff), end='')
for i in range(4):
print(chr((v2.value >> (8 * i)) & 0xff), end='')
# return v1.value, v2.value

enc = [0x33, 0xb2, 0x49, 0x8c, 0x39, 0xdd, 0x60,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bf, 0x6, 0x16, 0xc3,
0x32, 0xab, 0xb2, 0x68, 0x2c, 0xf7, 0xad, 0x96, 0x9, 0x8a, 0x2a, 0xf5, 0x8b, 0x7b, 0x19, 0x8d, 0x4e, 0x93,
0xff, 0x78, 0xec, 0xd7, 0x25, 0x9d, 0xd3, 0x64, 0xca, 0xaa, 0xcb, 0xd8, 0xe0, 0x24, 0x46, 0xb5, 0xd6, 0xd9,
0xc7, 0xe, 0x98, 0xaf, 0x85, 0xfc, 0x41, 0x94, 0x91, 0xc8, 0xc4, 0x63, 0x84, 0xf6, 0xc0, 0x7, 0x69, 0x88,
0x1c, 0x11, 0x18, 0x3a, 0x72, 0x47, 0x4b, 0xf0, 0xde, 0x73, 0x66, 0xda, 0xea, 0x54, 0xf2, 0xa5, 0x3d, 0x79,
0x71, 0x1a, 0x15, 0x3f, 0x40, 0x92, 0xcd, 0xc5, 0xb9, 0x57, 0xdf, 0xac, 0xfa, 0x99, 0x95, 0x5d, 0xe1, 0x77,
0x9f, 0xdc, 0x56, 0xb8, 0x43, 0xe9, 0x12, 0x2f, 0x83, 0x2b, 0x28, 0x4f, 0xe6, 0xf3, 0xdb, 0xce, 0xb1, 0x97,
0xed, 0x67, 0xab]

xor1 = []
add = []
xor2 = []
index = 0
sum_ = 0

for i in range(48):
index = index + 1

sum_ = (sum_ + tabel1[index]) % 256

tabel1[sum_], tabel1[index] = tabel1[index], tabel1[sum_]

v15 = (tabel1[index] + tabel1[sum_]) % 256

xor1.append(tabel1[v15])
xor2.append(tabel1[sum_])
add.append(tabel1[index])

enc_2 = []
for i in range(len(enc)):
enc_2.append((c_uint8(((enc[i] ^ xor2[i]) - add[i]) ^ xor1[i])).value)

tea = []
for i in range(0, len(enc), 4):
tea.append((enc_2[i]) | (enc_2[i + 1] << 8) | (enc_2[i + 2] << 16) | (enc_2[i + 3] << 24))


for i in range(0, len(tea), 2):
decrypt(c_uint32(tea[i]), c_uint32(tea[i + 1]))

# df8d8ab87c22a396041f9bde6a40c4987c22a396041f9bde

小反思

经验还是有点不足,也可能还是存在一点畏难心理吧,在爆破完第一题后摆了一会儿,现在想来如果不摆的话应该是可以做出最后一题的。其实差不多在离比赛结束还有一个钟的时候就已经把最后一题的逻辑全部理清了,唯独就是一直没想到那个swap会把地址一起交换,一直以为是有两个表,不过还好队友nb,拿了个24名。


西湖论剑 2024
http://example.com/2024/01/30/shlj/
Author
yring
Posted on
January 30, 2024
Licensed under