環境:
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 defiler@immortaldescendants.org
Valid solutions will be published on http://immortaldescendants.org,
the first solution will be on http://defiler.cjb.netthats 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