首页
论坛
课程
招聘
[原创]第二题WP
2022-5-14 00:47 2208

[原创]第二题WP

2022-5-14 00:47
2208

Flag分成三部分,第一部分是三字节,需要满足0^1^2=7的约束,第二部分是KCTF字符,第三部分需要满足运算后能被1-9整除,直接上脚本很快可以爆破出结果。

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
205
206
207
208
209
210
211
212
213
214
import struct
import logging
import binascii
from itertools import permutations
import string
 
gkey_tmp = [0x00,0x00,0x00,0x00,0x96,0x30,0x07,0x09,0x2C,0x61,0x0E,0x12,0xBA,0x51,0x09,0x1B,0x19,0xC4,0x6D,0xFF,0x8F,0xF4,0x6A,0xF6,0x35,0xA5,0x63,0xED,0xA3,0x95,0x64,0xE4,0x32,0x88,0xDB,0xFE,0xA4,0xB8,0xDC,0xF7,0x1E,0xE9,0xD5,0xEC,0x88,0xD9,0xD2,0xE5,0x2B,0x4C,0xB6,0x01,0xBD,0x7C,0xB1,0x08,0x07,0x2D,0xB8,0x13,0x91,0x1D,0xBF,0x1A,0x64,0x10,0xB7,0xFD,0xF2,0x20,0xB0,0xF4,0x48,0x71,0xB9,0xEF,0xDE,0x41,0xBE,0xE6,0x7D,0xD4,0xDA,0x02,0xEB,0xE4,0xDD,0x0B,0x51,0xB5,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x93,0xB3,0x0F,0xA6,0xA3,0xB4,0x06,0x05,0x36,0xD0,0xE2,0x93,0x06,0xD7,0xEB,0x29,0x57,0xDE,0xF0,0xBF,0x67,0xD9,0xF9,0x2E,0x7A,0x66,0xE3,0xB8,0x4A,0x61,0xEA,0x02,0x1B,0x68,0xF1,0x94,0x2B,0x6F,0xF8,0x37,0xBE,0x0B,0x1C,0xA1,0x8E,0x0C,0x15,0x1B,0xDF,0x05,0x0E,0x8D,0xEF,0x02,0x07]
 
# transform gkey
gkey_1 = []
for i in range(len(gkey_tmp)//4):
    b = gkey_tmp[i*4].to_bytes(1, 'little') +\
        gkey_tmp[i*4+1].to_bytes(1, 'little') +\
        gkey_tmp[i*4+2].to_bytes(1, 'little') +\
        gkey_tmp[i*4+3].to_bytes(1, 'little')
    num = struct.unpack("<I", b)[0]
    gkey_1.append(num)
 
assert len(gkey_1) == 256
 
# input should not be manipulated
 
 
def get_flag_0_7(f):
    tmp_v11 = -1;
    tmp_v11&=0xffffffff
 
    for i in range(len(f)):
 
        tmp_shift = tmp_v11
        for j in range(8):
            c = tmp_shift&0x80000000
            tmp_shift>>=1
            tmp_shift|=c
 
        # print("f[i]: {}".format(hex(ord(f[i]))))
        # print("key: {:x}".format(gkey_1[((tmp_v11&0xff) ^ ord(f[i])) & 0xff]))
        # print("sar: {}".format(hex(tmp_shift)))
        # print(hex(tmp_v11))
        # print("-----------------")
 
        tmp_v11 = gkey_1[((tmp_v11&0xff) ^ ord(f[i])) & 0xff] ^ (tmp_shift)
        tmp_v11&=0xffffffff
        #print(hex(tmp_v11))
 
 
    flag_0_7 = (~tmp_v11)&0xffffffff
    print("[-] get flag_0_7: 0x{:08X}".format(flag_0_7))
    if(not flag_0_7 == 0xF52E0765):
        print("[@] flag_0_7 should be 0xF52E0765!!!")
    return flag_0_7
 
# manipulate
 
 
def manipulate_flag(f):
    f_ = []
    for i in range(len(f)):
        c = 0x30
        if ord(f[i]) >= 0x3A:
            c = 0x37
        f_.append(ord(f[i])-c)
    return f_
 
 
def cal_whole_hash(f, l):
    v5 = 0
    v7 = 0
    l_count_1 = l
 
    while(l_count_1!=0):
        v5 ^= ord(f[v7])
        #print("v5:",hex(v5))
 
        l_count_1-=1
        v7+=1
        l_count_2 = 8
        while ( l_count_2 ):
            v9 = (2 * v5)&0xff
            #print("v9:",hex(v9))
 
            v10 = v9^7
            if ( v9 == 0 or v9<=0x7f ):
                v10 = v9
            v5 = v10&0xff
            #print("v10:",hex(v10))
            #print("v5(end):",hex(v10))
 
 
            l_count_2-=1
 
    hash_whole_arg = v10&0xff
    #print(hex(v10))
    if hash_whole_arg>0x7f:
        hash_whole_arg|=0xffffff00
 
    print("[-] hash whole flag: 0x{:02X}".format(hash_whole_arg))
    return hash_whole_arg
 
def cal_hash_3(flag, h_0):
    h = h_0
    v33 = [0,]
    for i in range(1,200):
        if (h&1)!=0:
            h = 3*h+1
            h &= 0xffffffff
        else:
            carry = h&0x80000000
            h >>=1
            h |= carry
            h &= 0xffffffff
 
        #print(hex(h))
        v33.append(h)
    print("[-] hash3 : 0x{:08X} 0x{:08X} 0x{:08X}".format(v33[198], v33[197], v33[196]))
    print("[*] hash3-> : 0x{:08X}".format(v33[198]|v33[197]|v33[196]))
    return (v33[198]|v33[197]|v33[196])
 
 
 
def run(flag_0):
    print("[*] input flag: {}".format(flag_0))
    flag_len = len(flag_0)
    print("[*] flag length: {}".format(flag_len))
    #assert flag_len==16
 
    flag_0_7 = get_flag_0_7(flag_0)
 
    if(flag_0_7 != 0xF52E0765):
        return -1
        pass
 
    hashw = cal_whole_hash(flag_0, flag_len)
 
    flag_1 = manipulate_flag(flag_0)
    print("[*] manipulated flag: ", flag_1)
 
    hash3 = cal_hash_3(flag_1, hashw)
    print("[@] {:08X} vs {:08X}".format((flag_1[2])^(flag_1[1])^(flag_1[0]), hash3))
 
    if (hash3 != (flag_1[2])^(flag_1[1])^(flag_1[0])):
        return -1
        pass
 
    #@#############
    #@#############
    #@#############
    return 0
    pass
    #@#############
    #@#############
    #@#############
 
    #assert hash3[198]^hash3[197]^hash3[196] == (flag_1[2])^(flag_1[1])^(flag_1[0])
 
    ans_0_1_2 = hash3
    v19 = ans_0_1_2+2
    flag_ = flag_len - v19 - 7
    print("[-] v19 : {:x}".format(v19))
    print("[-] flag_ : {:x}".format(flag_))
 
    assert flag_1[3] == 0x14
    assert flag_1[4] == 0xC
    assert flag_1[5] == 0x1D
    assert flag_1[6] == 0xF
 
    ## check flag [7]~[15]
    v37 = 0
    counter = 1
    for i in range(7,16):
        v23 = flag_1[i]+10*v37
        v24 = v23 - 0x37373737
        if ( v23 <= 0x4B435445 ):
            v24 = v23
        v37 = v24
        print("[_] v24({})/counter({})={}".format(v24, counter, v24%counter))
 
        if(v24%counter):
            print("[X] v24({}) should be multiple of counter({})".format(v24, counter))
            print("[X] but result is : {}".format(v24%counter))
            return -1
        counter += 1
 
    return 0
 
 
 
flag_0_2 = "016"
flag_7_ = "381654729"
flag_3_6 = "KCTF"
 
# items = ['1', '2', '3', '4', '5', '6', '7', '8', '9']
# for p in permutations(items):
#     flag_7_ = "".join(p)
#     print(flag_7_)
#     flag_0 = flag_0_2+flag_3_6+flag_7_
#     if(run(flag_0)==0):
#         print("!!!!!!!!!!!!!!! FIND !!!!!!!!!!1")
#         exit(-1)
 
 
items = list(string.digits+string.ascii_uppercase)
for p in permutations(items, 3):
    flag_0_2 = "".join(p)
    print(flag_0_2)
    flag_0 = flag_0_2+flag_3_6+flag_7_
    if(run(flag_0)==0):
        print("!!!!!!!!!!!!!!! FIND !!!!!!!!!!1")
        exit(-1)
 
 
flag_0 = flag_0_2+flag_3_6+flag_7_
flag_0 = "016KCTF381654729"
run(flag_0)

【公告】 [2022大礼包]《看雪论坛精华22期》发布!收录近1000余篇精华优秀文章!

收藏
点赞0
打赏
分享
最新回复 (0)
游客
登录 | 注册 方可回帖
返回