将程序加载至PEiD中,发现VC6编写,无壳。随意输入aaaaaaaaaaa,目标程序弹出error错误。
将目标程序加载至Ollydbg,查看ascii字符串,找到error所在地址空间004012d6,向上追述可得到下面的判断逻辑:
0040120B . FF15 A8704000 call dword ptr ds:[<&USER32.GetDlgItemTe>; \GetDlgItemTextA 得到输入框内容
00401211 . 68 F4010000 push 1F4 ; /Timeout = 500. ms
00401216 . FF15 00704000 call dword ptr ds:[<&KERNEL32.Sleep>] ; \Sleep
0040121C . 8D45 E4 lea eax,dword ptr ss:[ebp-1C]
0040121F . 50 push eax
00401220 . E8 DB000000 call WannaLOL.00401300
00401225 . 83F8 04 cmp eax,4 ; 输入的字符个数是否为4
00401228 . 59 pop ecx
00401229 . 0F85 A0000000 jnz WannaLOL.004012CF
0040122F . 6A 30 push 30
00401231 . 59 pop ecx
00401232 . 384D E4 cmp byte ptr ss:[ebp-1C],cl ; 所有字符不能为0
00401235 . 0F84 94000000 je WannaLOL.004012CF
0040123B . 384D E5 cmp byte ptr ss:[ebp-1B],cl
0040123E . 0F84 8B000000 je WannaLOL.004012CF
00401244 . 384D E6 cmp byte ptr ss:[ebp-1A],cl
00401247 . 0F84 82000000 je WannaLOL.004012CF
0040124D . 384D E7 cmp byte ptr ss:[ebp-19],cl
00401250 . 74 7D je short WannaLOL.004012CF
00401252 . 807D E4 31 cmp byte ptr ss:[ebp-1C],31 ; 第1个字符ascii码为0x31=‘1’
00401256 . 75 77 jnz short WannaLOL.004012CF
00401258 . 807D E5 35 cmp byte ptr ss:[ebp-1B],35 ; 第2个字符ascii码为0x35=‘5’
0040125C . 75 71 jnz short WannaLOL.004012CF
0040125E . 74 03 je short WannaLOL.00401263
00401260 . 75 01 jnz short WannaLOL.00401263
00401262 E8 db E8
00401263 > 66:B8 0800 mov ax,8
00401267 . 66:35 0700 xor ax,7
0040126B . 0FBE45 E6 movsx eax,byte ptr ss:[ebp-1A] ; 从这里向后对第3个和第4个字符进行浮点运算
0040126F . 2BC1 sub eax,ecx
00401271 . 8945 FC mov dword ptr ss:[ebp-4],eax
00401274 . 0FBE45 E4 movsx eax,byte ptr ss:[ebp-1C]
00401278 . DB45 FC fild dword ptr ss:[ebp-4]
0040127B . 2BC1 sub eax,ecx
0040127D . 8945 FC mov dword ptr ss:[ebp-4],eax
00401280 . 0FBE45 E5 movsx eax,byte ptr ss:[ebp-1B]
00401284 . DB45 FC fild dword ptr ss:[ebp-4]
00401287 . 2BC1 sub eax,ecx
00401289 . 8945 FC mov dword ptr ss:[ebp-4],eax
0040128C . DA75 FC fidiv dword ptr ss:[ebp-4]
0040128F . 0FBE45 E7 movsx eax,byte ptr ss:[ebp-19]
00401293 . 2BC1 sub eax,ecx
00401295 . 8945 FC mov dword ptr ss:[ebp-4],eax
00401298 . DEE9 fsubp st(1),st
0040129A . DA4D FC fimul dword ptr ss:[ebp-4]
0040129D . D80D 1C714000 fmul dword ptr ds:[40711C]
004012A3 . D95D FC fstp dword ptr ss:[ebp-4]
004012A6 . 74 03 je short WannaLOL.004012AB
004012A8 . 75 01 jnz short WannaLOL.004012AB
004012AA E8 db E8
004012AB > 66:B8 0800 mov ax,8
004012AF . 66:35 0700 xor ax,7
004012B3 . D945 FC fld dword ptr ss:[ebp-4]
004012B6 . D81D 18714000 fcomp dword ptr ds:[407118] ; 最后判断浮点运算的结果是否等于dword ptr ds:[407118]的值:0x43C00000
004012BC . 6A 00 push 0
004012BE . 68 78804000 push WannaLOL.00408078 ; CrackMe 2017 CTF
004012C3 . DFE0 fstsw ax
004012C5 . 9E sahf
004012C6 . 75 0E jnz short WannaLOL.004012D6
004012C8 . 68 5C804000 push WannaLOL.0040805C ; Registration successful !
004012CD . EB 0C jmp short WannaLOL.004012DB
004012CF > 6A 00 push 0
004012D1 . 68 48804000 push WannaLOL.00408048 ; CrackMe 2017 CTF v2
004012D6 > 68 40804000 push WannaLOL.00408040 ; error !
004012DB > FF35 34AA4000 push dword ptr ds:[40AA34] ; |hOwner = 00050934
004012E1 . FF15 AC704000 call dword ptr ds:[<&USER32.MessageBoxA>>; \MessageBoxA
004012E7 . C9 leave
004012E8 . C3 retn
从上述代码可以判断输入的字符串长度为4,第1个为‘1’,第2个为‘5’,通过VC6编写内联汇编计算满足上述浮点运算的第3和第4个字符:
void main()
{
char d_1 = '\x31' ;
char d_2 = '\x35' ;
char d_3 = '\x01';
char d_4 = '\x01';
unsigned long m_40711c = 0x41800000 ;
unsigned long m_407118 = 0x43c00000 ;
unsigned long temp = 0x00000000;
for(d_3=0; d_3<127; d_3++){
for(d_4=0; d_4<127; d_4++){
__asm{
push 30h
pop ecx
mov ax, 8
xor ax, 7
movsx eax,d_3
sub eax,ecx
mov temp,eax
movsx eax, d_1;
fild temp
sub eax,ecx
mov temp,eax
movsx eax, d_2;
fild temp
sub eax,ecx
mov temp,eax
fidiv temp
movsx eax,d_4
sub eax,ecx
mov temp,eax
fsubp st(1),st
fimul temp
fmul m_40711c
fstp temp
mov ax,8
xor ax,7
fld temp
fcomp m_407118
fstsw ax
sahf
jz _CODE
}
continue;
_CODE:
printf("d_1=%d, d_2=%d, d_3=%d, d_4=%d\n",d_1, d_2, d_3,d_4);
}
}
}
计算结果如下:
d_1=49, d_2=53, d_3=47, d_4=28
d_1=49, d_2=53, d_3=49, d_4=78
d_1=49, d_2=53, d_3=53, d_4=53
或者char输出:
d_1=1, d_2=5, d_3=/, d_4=
d_1=1, d_2=5, d_3=1, d_4=N
d_1=1, d_2=5, d_3=5, d_4=5
可以发现答案有3组,可见字符答案为151N或1555,答题完毕。
新手小坑:
1、在内联汇编中,起初没有利用temp代替[ebp-4],导致d_4数值被篡改,循环一直不正常。
2、d_3和d_4为一个字节,但起初采用int类型。
[注意]传递专业知识、拓宽行业人脉——看雪讲师团队等你加入!