IDA Pro und Reverse Engineering-Techniken

0x00 starten


; {EN} entry point, do nothing, just run _main {EN}


Ein Artikel für Anfänger von „Kriegern der Dunkelheit“, die in die dunkle Seite der Macht eintauchen wollen: Reverse Engineering. Auf unserem „Operationstisch“ befindet sich ein kleiner handwerklicher Server, der über TCP / IP ausgeführt wird. Bei der Analyse des Datenaustauschprotokolls wird uns der De-facto-Standard im Bereich Reverse-IDA Pro helfen.


Es wurden bereits viele Artikel über Reverse Engineering und IDA Pro geschrieben (obwohl nicht so sehr wie über PHP), aber da der Reverse-Prozess Forschung ist, ist die Idee, wie man die Reverse-Entwicklungsaufgabe von der „anderen Seite“ aus angeht, für Anfänger nützlich. Zumindest als Autor ließ ich mich von der Idee leiten, allen Praktikanten und den ersten Paaren des Reverse Engineering-Kurses an der Universität die grundlegenden Praktiken und Techniken zu erläutern, über die ich in den frühen Tagen gesprochen habe.


Was wird nicht in dem Artikel sein?

Google Chrome Apple iPhone… CVE , , - .



"Sobald du den dunklen Pfad entlang gehst, wird er für immer dein Schicksal dominieren."


Betreff: crackme - keine Binärdateien auf dem Hauptsystem ausführen, dies ist besser auf einer virtuellen Maschine!


Systemanforderungen: Virtuelle Maschine mit installiertem Windows 7 / 0xA


0x01 mov eax, ds: __ stack_chk_guard


; {EN} Disclaimer {EN}


, , x86, , (), .. . , .



0x10 , ?


; {EN} Setups prerequisites for the consequent execution {EN}


, , :


  • C C++;
  • x86;
  • (PE, ELF);
  • , — ;
  • ;
  • ;
  • .

, — IDA Pro Hex-Rays ( , “ ” “”, , “ ”, ). , -, , : ( IDA — ) x86.


, — . ( , *.exe Windows), , . , , x86 ( x64 — ).


— , x86 (assembler language).



, x86: (mov, lea, push/pop, call, jmp, ), . , , :



, . 10 , . ().


. , , , regexp ( ) — , . , .


— 30 (, , 30 ) .


0x20 IDA Pro ?


; {EN} Whatta hell? {EN}



- ( ) — “ , - … , - — ( ), , , , - ” — Reversing: Secrets of Reverse Engineering, Eldad Eilam.

? , . , IDA? IDA — , “ “. “”. , , -, , , “ ”, . IDE — , , — .. — . IDA Pro , .


, , . - , — radare2 ( r2, Cutter , IDA Pro). , IDA Pro Python API .


-, , , 100% . , - , IDA Pro! .



0x30 IDA Pro


; {EN}
; This function is too complex.
; Perhaps it interacts with user.
; But currently I am not sure about it.
; A lot of calls to Qt-framework.
; {EN}

0x31 IDA Pro


IDA Pro. ( ), . , , — . “”.



IDA Pro


( exe- IDA, ) , IDA Pro (PE, portable execute), , , , .


- , , . , -, , , .


, . — , .


, “” ( - ). . , .


, (. ). “” , - .




0x32 IDA Pro ?


IDA Pro : , , — , . IDA Pro ( ). IDA Pro ( Python C++). IDA Meta PC — x86/x64, , Intel AMD. , , IDA, Portable Executable. , , , ( ). , ( loader- IDA, «» , IDA ).


, :


  • (analyze);
  • (emulate — , , , QEMU);
  • .

“” IDA , “” . , ( ), IDA .


, , . , , , IDA.


, IDA Pro . “” (, , ). IDA (, MongoDB) . .idb ( .i64).


, , , . , , . AU: Idle IDA Pro.


UX/UI IDA Pro

GUI IDA Pro Qt, , - , Qt, :


  • drag&drop ;
  • , . , .


main


, IDA Pro.


  • — ( , - ). , . . ( — , — ). , .

Proximity View

, Proximity View. .


. , , .


  • — , , . , ( ). ( gcc -s) -g, , . IDA Pro sub_<_ _>;
  • (Strings) — , , SHIFT+F12. IDA Pro — , . , .

0x33 “” IDA Pro


- , . ? , IDA Pro? — . - , .



IDA Pro (-, cheatsheet) . -. - IDA Pro — Hexrays. - , , , , , - .



CTRL+S CTRL+Z?

, . — (CTRL+W, ), — undo. , undo — . - , CTRL+Z. , undo 7.3 ( — 7.0), undo — . , - IDA, , . , (make code) .


, , IDA Pro. , - " ", . , IDA Pro .


IDA Pro.


0x33a


— , , IDA Pro, :


  • ;
  • , ESC CTRL+ENTER ( - — );
  • SPACE, ();
  • : ( ) X. , ( );
  • (g): ( 0x) IDA Pro — (), .

0x33b


() :


  • ( N): , ( ), . , , .
  • . : , , ;.

0x33c (data representation)


:


  • (byte);
  • (word);
  • (dword);
  • (offset);
  • (undefined);
  • (code).

, , — , (, ..). , ( ), IDA Pro undefined. , , . , ( ), , IDA Pro.


0x33d


:


  • ( IDA Pro );
  • ( , P).
    IDA Pro , . ? , (call), , , , — .

,

- , IDA Pro , , IDA Pro . , call, , "" call . , - , , , — .


0x33e


, . , mov eax, 0xFFFFFFFF , , mov eax, -1. , , , IDA Pro .


0x33f IDA Pro


Strings, Names, Functions, Hex Dump. View->Open Subviews.


0x40 ?


; {EN}
; I think I found actual protocol parsing in function sub_401D3C
;
; But this function just chases bytes from corner to corner
; before actual parsing... we need to go deeper
; {EN}

0x41 ?


, " " IDA Pro, , .


, , IDA 76 , . , , . «» 100% ( ). :


  • . , ;
  • , , , API;
  • (, );
  • - ...

, , , — . , , . , , .


0x42


; {RU}
;     ;
;    ;
;   ,     ( .1-3);
; {RU}

? , , API OpenSource-, "doxygen": API .


doxygen?

doxygen — . , , . , , , — HTML ( ).


, TCP/IP-, , “” recv, . , recvfrom, API — ( Linux — read).


: / , Socket programming in c using TCP/IP.



IDA Pro? ( , ). SHIFT+F4. (Names).


, ( , ). , , , , CTRL+F. ( ). , ( recv), , , ( ).


. ( ENTER).


: ESC.




. recv (, recv — , ).


, recv. IDA Pro ( ) . , , ( ), , X. , . . type :


  • p[rocedure] — “ ”, () call;
  • r[ead] — ; ();
  • w[rite] — ; ().

:


  1. recv ( r),
  2. recv ( p).
    , recv . :

push    0
push    1000h   ; len
push    ebx     ; buf
push    edi     ; s
call    esi     ; recv   <----   recv 

, call esi. IDA , esi, , call esi recv. IDA recv .



recv


p, IDA ( ), recv. — IDA. , recv: sub_401D3C.


? . . , , recv , - , ( — ).


0x43 “ ”: sub_401D3C


; {EN} x_vserv_protocol {EN}


x_?

x_ ( eXecutable), IDA Pro.
ax_ — (IDAPython);
v_ — ( Variable);
av_ — , (IDAPython).


sub_401D3C recv . , «».


: : . , ( ), — .


(. «debug» — ) , . , -, : -- . -, - , ,


, , , , , . , , , , , , , .



recv


“ ”. sub_401D3C, , : sub_401CF0 sub_401BFD. , puts — libc. (stdout). - , , , - !



: recv. “ ” . Strings (SHIFT+F12) , , - -. , .


, , puts. 0x00401D64 ( , g ) “Received failed", 0x00401D7A — "Client disconnected", 0x00401D9C — “VSERV protocol error…”. , VSERV ( ). :


  • 0x00401D76 RECV_SUCCESS;
  • 0x00401D8C CLIENT_NOT_DISCONNECTED.

: -. , , — . , , , , , - . . : “ ”, , .



, 0x00401D54 — , “” . “RECV_LOOP”. IDA Pro : ( ) ( ) .


0x00401D3C, , , , x_vserv_protocol. , , — , ( TCP “”). , x_vserv_protocol, , sub_401CF0 sub_401BFD, ( ESC).




0x44 “ ”: sub_401CF0


; {EN} x_vserv_parse_header {EN}

, , sub_401CF0, . , , sub_401CF0. . ( ), , :


  • (, , recv TCP-);
  • (if-else);
  • memcmp atoi;
  • 0xFFFFFFFF (-1) ;
  • .


_ sub_401CF0 x_vserv_parse_header_


, .


0x44a sub_401CF0


IDA ( , , calling convention ( ) , ). , ( x86 cdecl, , ), IDA Pro arg_.


: (calling convention). , ( , ). , , — x86- ( push), eax (, return).


. packet_buffer? , , , . x_vserv_protocol. ebx. ebx , IDA , . recv (, ) (, « »).



_ x_vserv_parse_header_


( , recv) recv. , — , recv . , , sub_401CF0 TCP- .


0x44b sub_401CF0


, IDA Pro , ( ). sub_401CF0 , sub_401CF0 .


, , IDA Pro , if-else . :


  • — , ;
  • — .

, , . sub_401CF0 , , .


: if-else ( ):


  1. ( );
  2. .

0x44c sub_401CF0 memcmp atoi


, , , . API- , , , , memcmp.


: “fear … leads to suffering”, -, , , , reboot. , , , . . reboot, : «or enables/disables the reboot keystroke». «» F8, reboot, , , … RTFM!


, memcmp , «» . , , . , 0 — , 1 — . 0, , > 0, < 0.


API- atoi , ascii-, integer. , , — .


0x44d


API- ?


-, memcmp ( , «», ). , memcmp ( ), "VMES" 4 ( VMES). , , , eax 0xFFFFFFFF (-1), atoi.


memcmp, strcmp, , - , , 4 . strcmp -. "VMES" - , , — - . - , , strcmp .


-, atoi, , - ( ). , atoiVMES ( , 0x00401D19) — . atoi eax. , eax , , -1. , x86 eax, , — -1, . , ? , :


char tmp[5] = { 0 };
if (memcmp(&buf[0], "VMES", 4) != 0)
    return -1;
*(int*) tmp = *(int*)(&buf[4]);
return atoi(tmp);

. , : 5 ? ? atoi(buf + 4)? atoi, strtol ( atoi, strtol 10). , , , . , 10- 0 9. , , , , - . ( ) . : - ascii-.


5 , ( ): buffer_length var_D ( ). 0 , . var_D -.


x_vserv_parse_header ( ).


0x45 “ ”: sub_401BFD


; {EN} x_vserv_parse_body {EN}

0x45a


, , «» , . , . x_vserv_protocol, PARSE_BODY ( , , g, ENTER). push, , , sub_401BFD ( x_vserv_protocol_body). , .



_ body_buffer?_


( lea) ( body_buffer). — , x_vserv_protocol_header ( eax push ). — atoi-, .


, body_buffer, :


  • , recv;
  • x_vserv_protocol.

, recv, . recv , , ebx recv (. RECV_LOOP). ebx , , , esp. esp ( ) , , , push/pop. esp , :


char buffer[0x1000];


: ? , , , , . , , . Wikipedia.


( ) x_vserv_protocol. IDA Pro , ( — «» ). , .




, recv ( esp ). ( — N) vmes_sign ( "VMES").


— , atoi x_vserv_parse_header. , x_vserv_parse_header ( 0x00401D19). mov [ebx+4] eax atoi. , , vmes_body_len.


, TCP-. - , , — , (), , , x_vserv_parse_header. , x_vserv_parse_body.


0x45b


( ESC) . sub_401BFD (x_vserv_protocol_body — ) — , , TCP- recv, ( , — ). – , +4 (, ) «» atoi, .


: - Stack BOF ( Stack Buffer Overflow, ) , . , . , .


x_vserv_protocol_body, .



_ x_vserv_protocol_body_


- «» , if-else-if-else-if-else (, switch). , , , “HEXDUMP”, “TALK2ME”, “B64DECO”, “DISCONN”, “STOP!!!”. , «Unknown command». , , — . . : x_vserv_hexdump, x_vserv_talk2me, x_vserv_b64deco, x_vserv_disconn, x_vserv_stop. .


0x45c vserv


, , , , . , , , 15 ( ). - , , len, , , x_vserv_hexdump. .



_ x_vserv_hexdump_


, , ebp (, , ebp ). , , , , , .


0x45d



0x50 Is this the end?


; {EN} x_vserv_parse_body {EN}

, -, . , , , , IDA Pro.


9- -, VSERV IDA Pro, RCE ( ) .



All Articles