for i in range(0,len(code),4): a1 = ((code[i]<<2) | (code[i+1]>>4))&0xff a2 = (((code[i+1]&0x3f)<<4) | (code[i+2]>>2))&0xff a3 = (((code[i+2]&0x3f)<<6) | code[i+3])&0xff res += [a1,a2,a3]
字符都是在0-0xff范围内的,所以最终的结果要&0xff。
1 2 3 4 5 6 7 8 9 10
for ( i = 0; i <= 50; ++i ) { if ( v12[i] != byte_602080[i] ) { puts("Wrong"); return0LL; } } puts("Good"); return0LL;
最后是一个校验,byte_602080就是校验值,ida提取下:
1 2
.data:0000000000602080 byte_602080 db 5Ah ; DATA XREF: main+177↑r .data:0000000000602081 aTzztrdFqpVvlYn db '`TzzTrD|fQP[_VVL|yneURyUmFklVJgLasJroZpHRxIUlH\vZE=',0
我们可以知道,0x5A = ‘Z’,所以字符串就出来了:
s = ‘Z`TzzTrD|fQP[_VVL|yneURyUmFklVJgLasJroZpHRxIUlH\vZE=’
这里因为\要转义,这是一个易错点。
好了,有了字符串就可以逆向了:
先解出base64那一块的密文:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
#coding=utf8 s = 'Z`TzzTrD|fQP[_VVL|yneURyUmFklVJgLasJroZpHRxIUlH\\vZE='
print len(s) code = [] for i in s: if i!=' ': code.append(ord(i) - 61) else: code.append(0) res = [] for i in range(0,len(code),4): a1 = ((code[i]<<2) | (code[i+1]>>4))&0xff a2 = (((code[i+1]&0x3f)<<4) | (code[i+2]>>2))&0xff a3 = (((code[i+2]&0x3f)<<6) | code[i+3])&0xff res += [a1,a2,a3] print res print len(res)
#coding=utf8 s = 'Z`TzzTrD|fQP[_VVL|yneURyUmFklVJgLasJroZpHRxIUlH\\vZE='
print len(s) code = [] for i in s: if i!=' ': code.append(ord(i) - 61) else: code.append(0) res = [] for i in range(0,len(code),4): a1 = ((code[i]<<2) | (code[i+1]>>4))&0xff a2 = (((code[i+1]&0x3f)<<4) | (code[i+2]>>2))&0xff a3 = (((code[i+2]&0x3f)<<6) | code[i+3])&0xff res += [a1,a2,a3] print res print len(res) c = [0x10,0x59,0x9c,0x92,0x6,0x22,0xcf,0xa5,0x72,0x1e,0x45,0x6a,0x6,0xcb,0x8,0xc3,0xe4,0x49,0x5a,0x63,0xc,0xdf,0xf6,0x5f,0x8,0x28,0xbd,0xe2,0x10,0x15,0x1f,0x6e,0xaa,0x5a,0xca,0xec,0x80,0xaf,0x9b] print len(c) m = '' for i in range(39): m += chr(c[i]^res[i]) print m
.data:0000000000601060 unk_601060 db 31h ; 1 .data:0000000000601061 db 34h ; 4 .data:0000000000601062 byte_601062 db 23h ; DATA XREF: sub_400881+F↑w .data:0000000000601063 db 32h ; 2 .data:0000000000601064 db 33h ; 3 .data:0000000000601065 db 33h ; 3 .data:0000000000601066 db 30h ; 0 .data:0000000000601067 byte_601067 db 23h ; DATA XREF: sub_400881+1D↑w .data:0000000000601068 db 31h ; 1 .data:0000000000601069 byte_601069 db 23h ; DATA XREF: sub_400881+2B↑w .data:000000000060106A db 30h ; 0 .data:000000000060106B byte_60106B db 23h ; DATA XREF: sub_400881+39↑w .data:000000000060106C db 32h ; 2 .data:000000000060106D db 33h ; 3 .data:000000000060106E byte_60106E db 23h ; DATA XREF: sub_400881+47↑w .data:000000000060106F byte_60106F db 23h ; DATA XREF: sub_400881+55↑w .data:0000000000601070 db 33h ; 3 .data:0000000000601071 byte_601071 db 23h ; DATA XREF: sub_400881+63↑w .data:0000000000601072 byte_601072 db 23h ; DATA XREF: sub_400881+71↑w .data:0000000000601073 db 30h ; 0 .data:0000000000601074 db 34h ; 4 .data:0000000000601075 db 32h ; 2 .data:0000000000601076 byte_601076 db 23h ; DATA XREF: sub_400881+7F↑w .data:0000000000601077 byte_601077 db 23h ; DATA XREF: sub_400881+8D↑w .data:0000000000601078 db 31h ; 1 .data:0000000000601078 _data ends