160 - 41 defiler.1.exe

环境:
Windows xp sp3

工具:
Ollydbg
stud_PE
LoadPE

先分析一下。
这次的程序要求更改了,变成了这个:

defiler's reversme no.1
-----------------------

The task of this little, lame reverseme is to add some code to it.
The code you have to add will be triggered by the 'Exit' menu and should
look like this:

A messagebox should appear asking the user "Do you fickbirne really want to quit?".
Its buttons should be 'Yes' and 'No'. If the user clicks 'Yes', simply exit the
program in a clean way, if the user clicks 'No' just do NOT exit the program
(it's up to you what will happen when the user clicks 'No').

Valid solutions are solutions with a tutorial explaining what you did,
explaining the code you added and the modified binaries.

Mail your solution to [email protected]
Valid solutions will be published on http://immortaldescendants.org,
the first solution will be on http://defiler.cjb.net

thats it.. i hope i didn't forget any more unimportant stuff ;)

best regards,
    defiler

其实就是程序的菜单栏的Exit选项没有功能,让我们把加个messagebox下去,实现这个Exit选项。

OD载入,直接运行,点击菜单栏,选About选项,弹出messagebox,F12站厅,Alt+F9,点击确定。断下来到这里:

0043CCE2  |.  64:FF31       push dword ptr fs:[ecx]
0043CCE5  |.  64:8921       mov dword ptr fs:[ecx],esp
0043CCE8  |.  53            push ebx                                 ; /Style
0043CCE9  |.  57            push edi                                 ; |Title
0043CCEA  |.  56            push esi                                 ; |Text
0043CCEB  |.  8B45 FC       mov eax,[local.1]                        ; |
0043CCEE  |.  8B40 24       mov eax,dword ptr ds:[eax+0x24]          ; |  这个是messageBox所属的hwnd
0043CCF1  |.  50            push eax                                 ; |hOwner
0043CCF2  |.  E8 C998FCFF   call <jmp.&user32.MessageBoxA>           ; \MessageBoxA
0043CCF7  |.  8945 F8       mov [local.2],eax                        ;程序暂停后的位置

单步F8往下走:

00430528  /$  53            push ebx
00430529  |.  33DB          xor ebx,ebx
0043052B  |.  0FB7D2        movzx edx,dx
0043052E  |.  33C9          xor ecx,ecx
00430530  |.  E8 53FFFFFF   call defiler_.00430488                   ;  获取点击后的位置
00430535  |.  85C0          test eax,eax                             ;  确认点击的是哪个东西
00430537  |.  74 07         je Xdefiler_.00430540                    ;  
00430539  |.  8B10          mov edx,dword ptr ds:[eax]               ;  
0043053B  |.  FF52 40       call dword ptr ds:[edx+0x40]
0043053E  |.  B3 01         mov bl,0x1
00430540  |>  8BC3          mov eax,ebx
00430542  |.  5B            pop ebx
00430543  \.  C3            retn

在00430535下断点,重新运行程序,点击菜单栏,选About,程序断下。观察EAX的值:

数据窗口跟随:
显示方式改为:长型 -> 地址

可以猜测上一个call是用来确定菜单栏的选项的。
让程序重新运行,这次点Exit

看出这两个的值是不同的,于是可以用eax的值来判断点击的内容。

现在可以开始添加代码了。
首先先用LoadPE删除重定位信息。
打开LOadPE后用PE编辑器加载程序。

设置为0

然后就保存

再用stud_PE打开,添加section

大小设置为0x1000,用NULL填充

点击Add添加,完成后双击新建的section

设置一下Characteristics flags为0xE00000E0
顺便记一下VirtualOff:4E000
save一下。

OD载入这个修改过的程序,跳转到44E000处,然后就可以开始添加代码了。

思路是这样的:
在00430530处的call后获取了点击的内容,然后就直接跳转到44E000处进行判断,根据内容来确定接下来的程序。如果是“About”的值就直接返回去源代码处,否则就是exit的值了,就可以弹出消息框,根据用户点击来确定点击内容从而判断接下来的行为。

0044E000    85C0            test eax,eax
0044E002  - 0F84 3825FEFF   je 复件_def.00430540                     ;这里就和原代码相同,如果为空就跳过
0044E008    60              pushad
0044E009    8B0D D0FB4300   mov ecx,dword ptr ds:[0x43FBD0]          ; 复件_def.004407C8
0044E00F    8B09            mov ecx,dword ptr ds:[ecx]
0044E011    90              nop
0044E012    90              nop
0044E013    90              nop
0044E014    81C1 04230000   add ecx,0x2304                            ;这个值会有所改变,在xp上是0x2304,在Win8.1的话则是0x22A0,具体原因能力有限
0044E01A    3BC1            cmp eax,ecx                               ;这里就判断eax的值是"ABout"还是"Exit"的
0044E01C    61              popad
0044E01D    8B10            mov edx,dword ptr ds:[eax]
0044E01F    75 05           jnz X复件_def.0044E026
0044E021  - E9 1525FEFF     jmp 复件_def.0043053B
0044E026    A1 D0FB4300     mov eax,dword ptr ds:[0x43FBD0]
0044E02B    8B00            mov eax,dword ptr ds:[eax]
0044E02D    83C0 24         add eax,0x24                               ;这里是获取handle,具体的原因可以看一开始程序断下时的messagebox
0044E030    6A 24           push 0x24
0044E032    68 58E04400     push 复件_def.0044E058                     ; ASCII "Quit"
0044E037    68 60E04400     push 复件_def.0044E060                     ; ASCII "Are you sure quit?"
0044E03C    FF30            push dword ptr ds:[eax]
0044E03E    E8 7D85FBFF     call <jmp.&user32.MessageBoxA>
0044E043    83F8 06         cmp eax,0x6                                ;0x6为“Yes”,0x7为“No”
0044E046    74 05           je X复件_def.0044E04D
0044E048  - E9 F124FEFF     jmp 复件_def.0043053E                       ;如果是“No”就跳回去原来的位置
0044E04D    6A 00           push 0x0
0044E04F    E8 D831FBFF     call <jmp.&kernel32.ExitProcess>
0044E054    0000            add byte ptr ds:[eax],al
0044E056    0000            add byte ptr ds:[eax],al
0044E058    51              push ecx                                    ;这里开始往下就是字符串的值了
0044E059    75 69           jnz X复件_def.0044E0C4
0044E05B    74 00           je X复件_def.0044E05D
0044E05D    0000            add byte ptr ds:[eax],al
0044E05F    0041 72         add byte ptr ds:[ecx+0x72],al
0044E062    65:2079 6F      and byte ptr gs:[ecx+0x6F],bh
0044E066    75 20           jnz X复件_def.0044E088
0044E068    73 75           jnb X复件_def.0044E0DF
0044E06A    72 65           jb X复件_def.0044E0D1
0044E06C    2071 75         and byte ptr ds:[ecx+0x75],dh
0044E06F    69743F 00 00000>imul esi,dword ptr ds:[edi+edi],0x0

修改完44E000的代码后,再修改一下 00430530后面的内容

0043052B   .  0FB7D2        movzx edx,dx
0043052E   .  33C9          xor ecx,ecx
00430530   .  E8 53FFFFFF   call 复件_def.00430488
00430535   .- E9 C6DA0100   jmp 复件_def.0044E000                      ;  改了这里
0043053A      90            nop
0043053B   .  FF52 40       call dword ptr ds:[edx+0x40]
0043053E   .  B3 01         mov bl,0x1

修改完后保存一下就好了

完成 O(∩_∩)O

参考:
https://www.52pojie.cn/thread-654237-1-1.html

猜你喜欢

转载自blog.csdn.net/goodnameused/article/details/80722574
41
今日推荐