本文为看雪论坛精华文章
看雪论坛作者ID:Hedione
一
前言
二
FISRT GLANCE
int __cdecl sub_401D10(_BYTE *a1, char a2)
{
int result; // eax
do
{
*a1++ ^= a2;
result = (unsigned __int8)*a1;
}
while ( *a1 );
return result;
}
dword_426388初始值为9
程序里同时存在需要调试器和不需要调试器的两段代码
有一个未知的函数sub_4011F0接收魔数,似乎输出函数地址
sub_4011F0内含一个结构体变量
sub_4011F0内含SM3常量,可能是加密
sub_401320函数内存在异常常量
其中含有可能的迷宫结构
输入将被处理成十六进制,不能为偶数;输入长度为50字节,存储在Str1里
以及其他
三
地址转换机构:sub_4011F0
.text:004011BD 58 pop eax
.text:004011BE 58 pop eax
.text:004011BF 33 C0 xor eax, eax
.text:004011C1 83 F0 03 xor eax, 3
.text:004011C4 E8 00 00 00 00 call $+5
.text:004011C9 F7 E0 mul eax
.text:004011CB 83 F8 51 cmp eax, 51h ; 'Q'
.text:004011CE 74 01 jz short loc_4011D1
.text:004011D0 C3 retn
.text:004011D1 ; ---------------------------------------------------------------------------
.text:004011D1
.text:004011D1 loc_4011D1: ; CODE XREF: sub_401170+5E↑j
.text:004011D1 83 E8 21 sub eax, 21h ; '!'
.text:004011D4 64 8B 00 mov eax, fs:[eax]
.text:004011D7 8B 40 0C mov eax, [eax+0Ch]
.text:004011DA 8B 40 0C mov eax, [eax+0Ch]
.text:004011DD 8B 00 mov eax, [eax]
.text:004011DF 8B 00 mov eax, [eax]
.text:004011E1 8B 40 18 mov eax, [eax+18h]
.text:004011E4 5D pop ebp
.text:004011E5 C3 retn
四
子母进程调试及异常处理
.text:00D31A38 60 pusha
.text:00D31A39 B9 01 00 00 00 mov ecx, 1
.text:00D31A3E C1 E1 03 shl ecx, 3
.text:00D31A41 B8 02 00 00 00 mov eax, 2
.text:00D31A46 BB 09 00 00 00 mov ebx, 9
.text:00D31A4B 33 D2 xor edx, edx
.text:00D31A4D 8B 12 mov edx, [edx]
.text:00D31A4F B9 01 00 00 00 mov ecx, 1
.text:00D31A54 D1 E1 shl ecx, 1
.text:00D31A56 B8 04 00 00 00 mov eax, 4
.text:00D31A5B CC int 3 ; Trap to Debugger
.text:00D31A5C B9 01 00 00 00 mov ecx, 1
.text:00D31A61 C1 E1 02 shl ecx, 2
.text:00D31A64 B8 00 00 00 00 mov eax, 0
.text:00D31A69 CC int 3 ; Trap to Debugger
.text:00D31A6A B9 01 00 00 00 mov ecx, 1
.text:00D31A6F D1 E1 shl ecx, 1
.text:00D31A71 B8 00 00 00 00 mov eax, 0
.text:00D31A76 BB FF FF FF FF mov ebx, 0FFFFFFFFh
.text:00D31A7B 33 D2 xor edx, edx
.text:00D31A7D 8B 12 mov edx, [edx]
.text:00D31A7F B9 01 00 00 00 mov ecx, 1
.text:00D31A84 C1 E1 04 shl ecx, 4
.text:00D31A87 B8 00 00 00 00 mov eax, 0
.text:00D31A8C BB 06 00 00 00 mov ebx, 6
.text:00D31A91 CC int 3 ; Trap to Debugger
.text:00D31A92 B9 01 00 00 00 mov ecx, 1
.text:00D31A97 B8 00 00 00 00 mov eax, 0
.text:00D31A9C BB 05 00 00 00 mov ebx, 5
.text:00D31AA1 33 D2 xor edx, edx
.text:00D31AA3 8B 12 mov edx, [edx]
.text:00D31AA5 B9 01 00 00 00 mov ecx, 1
.text:00D31AAA C1 E1 03 shl ecx, 3
.text:00D31AAD B8 01 00 00 00 mov eax, 1
.text:00D31AB2 BB 00 00 00 00 mov ebx, 0
.text:00D31AB7 33 D2 xor edx, edx
.text:00D31AB9 8B 12 mov edx, [edx]
.text:00D31ABB B9 01 00 00 00 mov ecx, 1
.text:00D31AC0 C1 E1 04 shl ecx, 4
.text:00D31AC3 B8 01 00 00 00 mov eax, 1
.text:00D31AC8 BB 02 00 00 00 mov ebx, 2
.text:00D31ACD 33 D2 xor edx, edx
.text:00D31ACF 8B 12 mov edx, [edx]
.text:00D31AD1 B9 01 00 00 00 mov ecx, 1
.text:00D31AD6 B8 02 00 00 00 mov eax, 2
.text:00D31ADB CC int 3 ; Trap to Debugger
.text:00D31ADC B9 01 00 00 00 mov ecx, 1
.text:00D31AE1 D1 E1 shl ecx, 1
.text:00D31AE3 B8 04 00 00 00 mov eax, 4
.text:00D31AE8 BB FF FF FF FF mov ebx, 0FFFFFFFFh
.text:00D31AED 33 D2 xor edx, edx
.text:00D31AEF 8B 12 mov edx, [edx]
.text:00D31AF1 B9 01 00 00 00 mov ecx, 1
.text:00D31AF6 C1 E1 05 shl ecx, 5
.text:00D31AF9 B8 0F 00 00 00 mov eax, 0Fh
.text:00D31AFE 33 D2 xor edx, edx
.text:00D31B00 8B 12 mov edx, [edx]
.text:00D31B02 B9 01 00 00 00 mov ecx, 1
.text:00D31B07 B8 00 00 00 00 mov eax, 0
.text:00D31B0C BB 06 00 00 00 mov ebx, 6
.text:00D31B11 33 D2 xor edx, edx
.text:00D31B13 8B 12 mov edx, [edx]
.text:00D31B15 B9 01 00 00 00 mov ecx, 1
.text:00D31B1A D1 E1 shl ecx, 1
.text:00D31B1C B8 00 00 00 00 mov eax, 0
.text:00D31B21 BB 01 00 00 00 mov ebx, 1
.text:00D31B26 33 D2 xor edx, edx
.text:00D31B28 8B 12 mov edx, [edx]
.text:00D31B2A B9 01 00 00 00 mov ecx, 1
.text:00D31B2F C1 E1 03 shl ecx, 3
.text:00D31B32 B8 01 00 00 00 mov eax, 1
.text:00D31B37 BB 00 00 00 00 mov ebx, 0
.text:00D31B3C 33 D2 xor edx, edx
.text:00D31B3E 8B 12 mov edx, [edx]
.text:00D31B40 B9 01 00 00 00 mov ecx, 1
.text:00D31B45 C1 E1 04 shl ecx, 4
.text:00D31B48 B8 01 00 00 00 mov eax, 1
.text:00D31B4D BB 02 00 00 00 mov ebx, 2
.text:00D31B52 33 D2 xor edx, edx
.text:00D31B54 8B 12 mov edx, [edx]
.text:00D31B56 B9 01 00 00 00 mov ecx, 1
.text:00D31B5B B8 02 00 00 00 mov eax, 2
.text:00D31B60 CC int 3 ; Trap to Debugger
.text:00D31B61 B9 01 00 00 00 mov ecx, 1
.text:00D31B66 D1 E1 shl ecx, 1
.text:00D31B68 B8 05 00 00 00 mov eax, 5
.text:00D31B6D BB 01 00 00 00 mov ebx, 1
.text:00D31B72 33 D2 xor edx, edx
.text:00D31B74 8B 12 mov edx, [edx]
.text:00D31B76 B9 01 00 00 00 mov ecx, 1
.text:00D31B7B C1 E1 05 shl ecx, 5
.text:00D31B7E B8 08 00 00 00 mov eax, 8
.text:00D31B83 33 D2 xor edx, edx
.text:00D31B85 8B 12 mov edx, [edx]
.text:00D31B87 B9 01 00 00 00 mov ecx, 1
.text:00D31B8C B8 00 00 00 00 mov eax, 0
.text:00D31B91 BB 06 00 00 00 mov ebx, 6
.text:00D31B96 33 D2 xor edx, edx
.text:00D31B98 8B 12 mov edx, [edx]
.text:00D31B9A B9 01 00 00 00 mov ecx, 1
.text:00D31B9F D1 E1 shl ecx, 1
.text:00D31BA1 B8 00 00 00 00 mov eax, 0
.text:00D31BA6 BB FF FF FF FF mov ebx, 0FFFFFFFFh
.text:00D31BAB 33 D2 xor edx, edx
.text:00D31BAD 8B 12 mov edx, [edx]
.text:00D31BAF B9 01 00 00 00 mov ecx, 1
.text:00D31BB4 C1 E1 03 shl ecx, 3
.text:00D31BB7 B8 01 00 00 00 mov eax, 1
.text:00D31BBC BB 00 00 00 00 mov ebx, 0
.text:00D31BC1 33 D2 xor edx, edx
.text:00D31BC3 8B 12 mov edx, [edx]
.text:00D31BC5 B9 01 00 00 00 mov ecx, 1
.text:00D31BCA C1 E1 04 shl ecx, 4
.text:00D31BCD B8 01 00 00 00 mov eax, 1
.text:00D31BD2 BB 02 00 00 00 mov ebx, 2
.text:00D31BD7 33 D2 xor edx, edx
.text:00D31BD9 8B 12 mov edx, [edx]
.text:00D31BDB B9 01 00 00 00 mov ecx, 1
.text:00D31BE0 B8 02 00 00 00 mov eax, 2
.text:00D31BE5 CC int 3 ; Trap to Debugger
.text:00D31BE6 B9 01 00 00 00 mov ecx, 1
.text:00D31BEB D1 E1 shl ecx, 1
.text:00D31BED B8 04 00 00 00 mov eax, 4
.text:00D31BF2 BB 01 00 00 00 mov ebx, 1
.text:00D31BF7 33 D2 xor edx, edx
.text:00D31BF9 8B 12 mov edx, [edx]
.text:00D31BFB B9 01 00 00 00 mov ecx, 1
.text:00D31C00 C1 E1 05 shl ecx, 5
.text:00D31C03 B8 01 00 00 00 mov eax, 1
.text:00D31C08 33 D2 xor edx, edx
.text:00D31C0A 8B 12 mov edx, [edx]
.text:00D31C0C B9 01 00 00 00 mov ecx, 1
.text:00D31C11 C1 E1 05 shl ecx, 5
.text:00D31C14 CC int 3 ; Trap to Debugger
.text:00D31C15 B9 01 00 00 00 mov ecx, 1
.text:00D31C1A D1 E1 shl ecx, 1
.text:00D31C1C B8 09 00 00 00 mov eax, 9
.text:00D31C21 BB 01 00 00 00 mov ebx, 1
.text:00D31C26 33 D2 xor edx, edx
.text:00D31C28 8B 12 mov edx, [edx]
.text:00D31C2A B9 01 00 00 00 mov ecx, 1
.text:00D31C2F C1 E1 03 shl ecx, 3
.text:00D31C32 CC int 3 ; Trap to Debugger
.text:00D31C33 61 popa
ins=[
'mov','ecx','1',
'shl','ecx','3',
'mov','eax','2',
'mov','ebx','9',
'xor','edx','edx',
'mov','edx','[edx]',
'mov','ecx','1',
'shl','ecx','1',
'mov','eax','4',
'int','3',
'mov','ecx','1',
'shl','ecx','2',
'mov','eax','0',
'int','3',
'mov','ecx','1',
'shl','ecx','1',
'mov','eax','0',
'mov','ebx','-1',
'xor','edx','edx',
'mov','edx','[edx]',
'mov','ecx','1',
'shl','ecx','4',
'mov','eax','0',
'mov','ebx','6',
'int','3',
'mov','ecx','1',
'mov','eax','0',
'mov','ebx','5',
'xor','edx','edx',
'mov','edx','[edx]',
'mov','ecx','1',
'shl','ecx','3',
'mov','eax','1',
'mov','ebx','0',
'xor','edx','edx',
'mov','edx','[edx]',
'mov','ecx','1',
'shl','ecx','4',
'mov','eax','1',
'mov','ebx','2',
'xor','edx','edx',
'mov','edx','[edx]',
'mov','ecx','1',
'mov','eax','2',
'int','3',
'mov','ecx','1',
'shl','ecx','1',
'mov','eax','4',
'mov','ebx','-1',
'xor','edx','edx',
'mov','edx','[edx]',
'mov','ecx','1',
'shl','ecx','5',
'mov','eax','15',
'xor','edx','edx',
'mov','edx','[edx]',
'mov','ecx','1',
'mov','eax','0',
'mov','ebx','6',
'xor','edx','edx',
'mov','edx','[edx]',
'mov','ecx','1',
'shl','ecx','1',
'mov','eax','0',
'mov','ebx','1',
'xor','edx','edx',
'mov','edx','[edx]',
'mov','ecx','1',
'shl','ecx','3',
'mov','eax','1',
'mov','ebx','0',
'xor','edx','edx',
'mov','edx','[edx]',
'mov','ecx','1',
'shl','ecx','4',
'mov','eax','1',
'mov','ebx','2',
'xor','edx','edx',
'mov','edx','[edx]',
'mov','ecx','1',
'mov','eax','2',
'int','3',
'mov','ecx','1',
'shl','ecx','1',
'mov','eax','5',
'mov','ebx','1',
'xor','edx','edx',
'mov','edx','[edx]',
'mov','ecx','1',
'shl','ecx','5',
'mov','eax','8',
'xor','edx','edx',
'mov','edx','[edx]',
'mov','ecx','1',
'mov','eax','0',
'mov','ebx','6',
'xor','edx','edx',
'mov','edx','[edx]',
'mov','ecx','1',
'shl','ecx','1',
'mov','eax','0',
'mov','ebx','-1',
'xor','edx','edx',
'mov','edx','[edx]',
'mov','ecx','1',
'shl','ecx','3',
'mov','eax','1',
'mov','ebx','0',
'xor','edx','edx',
'mov','edx','[edx]',
'mov','ecx','1',
'shl','ecx','4',
'mov','eax','1',
'mov','ebx','2',
'xor','edx','edx',
'mov','edx','[edx]',
'mov','ecx','1',
'mov','eax','2',
'int','3',
'mov','ecx','1',
'shl','ecx','1',
'mov','eax','4',
'mov','ebx','1',
'xor','edx','edx',
'mov','edx','[edx]',
'mov','ecx','1',
'shl','ecx','5',
'mov','eax','1',
'xor','edx','edx',
'mov','edx','[edx]',
'mov','ecx','1',
'shl','ecx','5',
'int','3',
'mov','ecx','1',
'shl','ecx','1',
'mov','eax','9',
'mov','ebx','1',
'xor','edx','edx',
'mov','edx','[edx]',
'mov','ecx','1',
'shl','ecx','3',
'int','3',
'popa',
]
def ROL(i,index):
tmp = bin(i)[2:].rjust(8, "0")
for _ in range(index):
tmp = tmp[1:] + tmp[0]
return int(tmp, 2)
CONTEXT = {
'eax' : 0,
'ebx' : 0,
'ecx' : 0,
'edx' : 0
}
round = 0
eip = 0
while True:
#print(str(CONTEXT['eax']) +','+ str(CONTEXT['ebx']) +','+ str(CONTEXT['ecx']) +','+ str(CONTEXT['edx'] ))
if(ins[eip] == 'mov'):
if(ins[eip+2][0] =='['):
#print('0xC0000005' +','+ str(CONTEXT['eax']) +','+ str(CONTEXT['ebx']) +','+ str(CONTEXT['ecx']) +','+ str(CONTEXT['edx'] )+ ',' )
if(CONTEXT['ecx'] == 1):
print('sub_D33570('+str(CONTEXT['eax'])+', '+str(CONTEXT['ebx'])+');')
#do 1
elif(CONTEXT['ecx'] == 2):
print('sub_D335B0('+str(CONTEXT['eax'])+', '+str(CONTEXT['ebx'])+');')
#do 2
elif(CONTEXT['ecx'] == 4):
print('sub_D335E0('+str(CONTEXT['eax'])+', '+str(CONTEXT['ebx'])+');')
#do 2
elif(CONTEXT['ecx'] == 8):
print('sub_D33610('+str(CONTEXT['eax'])+', '+str(CONTEXT['ebx'])+');')
#do 2
elif(CONTEXT['ecx'] == 16):
print('sub_D33640('+str(CONTEXT['eax'])+', '+str(CONTEXT['ebx'])+');')
#do 2
elif(CONTEXT['ecx'] == 32):
print('sub_D33680('+str(CONTEXT['eax'])+');')
#do 2
else:
#if(ins[eip+1] == 'eax' or ins[eip+1] == 'ebx' or ins[eip+1] == 'ecx' or ins[eip+1] == 'edx')
CONTEXT[ins[eip+1]] = int(ins[eip+2])
elif(ins[eip] == 'shl'):
CONTEXT[ins[eip+1]] = CONTEXT[ins[eip+1]] << int(ins[eip+2])
elif(ins[eip] == 'xor'):
CONTEXT[ins[eip+1]] = CONTEXT[ins[eip+1]] ^ CONTEXT[ins[eip+2]]
elif(ins[eip] == 'int'):
eip = eip -1
#print('0x80000003' +','+ str(CONTEXT['eax']) +','+ str(CONTEXT['ebx']) +','+ str(CONTEXT['ecx']) +','+ str(CONTEXT['edx'] )+ ',' )
if(CONTEXT['ecx'] == 1):
print('sub_D336A0('+str(CONTEXT['eax'])+');')
elif(CONTEXT['ecx'] == 2):
print('sub_D336D0('+str(CONTEXT['eax'])+');')
elif(CONTEXT['ecx'] == 4):
print('sub_D33720('+str(CONTEXT['eax'])+');')
elif(CONTEXT['ecx'] == 8):
print('CorrectOutput();')
elif(CONTEXT['ecx'] == 16):
print('sub_D33800('+str(CONTEXT['eax'])+', '+str(CONTEXT['ebx'])+');')
elif(CONTEXT['ecx'] == 32):
print('WrongOutput();')
#do
elif(ins[eip] == 'popa'):
eip = -3
round = round + 1
if(round == 19):break
#break
#do
eip = eip + 3
sub_D33610(2, 9);
sub_D336D0(4);
sub_D33720(0);
sub_D335B0(0, -1);
sub_D33800(0, 6);
sub_D33570(0, 5);
sub_D33610(1, 0);
sub_D33640(1, 2);
sub_D336A0(2);
sub_D335B0(4, -1);
sub_D33680(15);
sub_D33570(0, 6);
sub_D335B0(0, 1);
sub_D33610(1, 0);
sub_D33640(1, 2);
sub_D336A0(2);
sub_D335B0(5, 1);
sub_D33680(8);
sub_D33570(0, 6);
sub_D335B0(0, -1);
sub_D33610(1, 0);
sub_D33640(1, 2);
sub_D336A0(2);
sub_D335B0(4, 1);
sub_D33680(1);
WrongOutput();
sub_D335B0(9, 1);
CorrectOutput();
五
VM
EXCEPTION_BREAKPOINT
case 1u:sub_D336A0(_eax);
case 2u:sub_D336D0(_eax);
case 4u:sub_D33720(_eax);
case 8u:_CorrectOutput();
case 0x10u:sub_D33800(_eax, _ebx);
case 0x20u:_WrongOutput();
EXCEPTION_ACCESS_VIOLATION
case 1u:sub_D33570(_eax, _ebx);
case 2u:sub_D335B0(_eax, _ebx);
case 4u:sub_D335E0(_eax, _ebx);
case 8u:sub_D33610(_eax, _ebx);
case 0x10u:cmp(_eax, _ebx);
case 0x20u:sub_D33680(_eax);
EXCEPTION_BREAKPOINT
case 1u:jnz(_eax);
case 2u:push(_eax);
case 4u:pop(_eax);
case 8u:_CorrectOutput();
case 0x10u:mul(_eax, _ebx);
case 0x20u:_WrongOutput();
EXCEPTION_ACCESS_VIOLATION
case 1u:add(_eax, _ebx);
case 2u:addn(_eax, _ebx); //直接访存
case 4u:store(_eax, _ebx);
case 8u:load(_eax, _ebx);
case 0x10u:cmp(_eax, _ebx);
case 0x20u:jmp(_eax);
load(2, 9);
push(4);
pop(0);
addn(0, -1);
mul(0, 6);
add(0, 5);
load(1, 0);
cmp(1, 2);
jnz(2);
addn(4, -1);
jmp(15);
add(0, 6);
addn(0, 1);
load(1, 0);
cmp(1, 2);
jnz(2);
addn(5, 1);
jmp(8);
add(0, 6);
addn(0, -1);
load(1, 0);
cmp(1, 2);
jnz(2);
addn(4, 1);
jmp(1);
WrongOutput();
addn(9, 1);
CorrectOutput();
六
SOLVE!
看雪ID:Hedione
https://bbs.pediy.com/user-home-923183.htm
# 往期推荐
球分享
球点赞
球在看
点击“阅读原文”,了解更多!