관리 메뉴

kisoo

OllyDbg에서 DLL 파일 디버깅 하기 본문

01.About Programming /3.Debug Lab

OllyDbg에서 DLL 파일 디버깅 하기

JamesK78 2009. 12. 29. 11:29
OllyDbg에서 DLL 파일 디버깅 하기  2006.10.24 10:13  

http://tong.nate.com/rohbr/27504568    OllyDbg110.zip
  
출처 : http://dasomnetwork.com/%7Eleedw/mywiki/moin.cgi/OllyDbg_bf_a1_bc_ad_20DLL_20_c6_c4_c0_cf_20_b5_f0_b9_f6_b1_eb_c7_cf_b1_e2

Written by 이동우(leedw at ssrnet.snu.ac.kr), 2004.2.18


대부분 ollydbg에서는 로드하는 실행파일(exe)만 분석작업을 진행한다. 그러나 때론 dll을 내부로 파고들어가 리버싱해야하는 상황이 발생한다. 어플리케이션과 연결된 dll을 디버깅할 때와 dll파일만 단독으로 주어졌을 때 디버깅하는 방법으로 나누어 설명한다.



1 어플리케이션 실행 파일과 연결된 DLL을 디버깅할 때
Run the principal program (the program use the dll you can debug) and put in EVENTS the mark in STOP IN DLL LOAD.
Olly stop in the load of any dll, go to view-executables, right click FOLLOW ENTRY and you can view the entry point of the dll, you can put a BP here, or a BPM in the code section of the dll, and you can debug the dll.


1. ollydbg실행
2. Debugging Options 열기 (단축키:Alt+O)
3. Events Tab 클릭
4. [v] Break on new module (DLL) 항목에 체크 표시
5. [ OK ] 버튼 클릭해서 창닫고 작업할 프로그램(.EXE)을 로드
6. 대상 프로그램에서 새로운 모듈(DLL)을 사용할때 마다 브레이크가 걸린다.
7. Executable modules창에 디버깅하길 원하는 DLL파일이 보일때 까지 F9키를 누른다.
8. 찾았다면 원하는 모듈에 마우스를 Duble Click하면 해당 모듈로 들어간다.
9. Analyse code (Ctrl+A) 한 후 작업.



2 어플리케이션 없이 DLL 파일만 디버깅할 때
위의 방법은 DLL을 사용하는 어플리케이션이 존재할 경우에 유용한 방법이지만 DLL을 로딩하는 app가 없을경우에는 속수무책이다. 이때 DLL을 메모리에 로딩해서 olly에서 디버깅할 수 있도록 template 프로그램을 이용하면 dll을 디버깅할 수 있다.


소스출처: http://www20.brinkster.com/qweerdy
실행파일: dllload.exe


.586 .model flat,stdcall option casemap:none include include\windows.inc include include\kernel32.inc include include\user32.inc includelib lib\kernel32.lib includelib lib\user32.lib .code ; --------------------------------------------------------------------------- start: invoke GetCommandLine ; command line argument를 가져온다. mov esi,eax lodsb .if al=='"' ; NULL인지 확인 @@: lodsb cmp al,0 je Err1 cmp al,'"' jne @B lodsb .endif .if al==" " @@: lodsb cmp al,0 je Err1 cmp al," " je @B .endif mov edi,esi .if al=='"' inc edi @@: lodsb cmp al,0 je Err1 cmp al,'"' jne @B mov byte ptr [esi-1],0 .endif dec edi cmp byte ptr [edi],0 je Err1 invoke LoadLibraryEx,edi,0,DONT_RESOLVE_DLL_REFERENCES ; DLL을 로딩한다. int 3 ; Break point instruction Die: invoke ExitProcess,0 szErr1 db "Invalid arguments.",13,10,"You must pass the dll to load as a command line argument!",0 szErr2 db "Failed to load DLL. Please check the filename.",13,10,"Also, Windows Me / 9x don't support DONT_RESOLVE_DLL_REFERENCES flag.",0 Err1: invoke MessageBox,0,addr szErr1,0,MB_OK jmp Die Err2: invoke MessageBox,0,addr szErr2,0,MB_OK jmp Die end start
사용하는 방법은,
1. olly 디버거 실행
2. 위 소스를 빌드한 실행 프로그램(dllload.exe) 실행
3. Debug -> Arguments 에 디버깅하고자 하는 dll 파일명 입력
4. F9(run)
5. break point instruction에 의해 int3 다음 instruction에서 진행이 멈춘다.
6. View modules(ALT+E)로 dll이 메모리에 로딩된 것을 확인할 수 있다.

추신)

DLL 등록 할때(COM 인경우) Tools 메뉴에서 Register Control 을 쓰시면 자동 등록 되더군요...
Regsvr32 를 내부적으로 수행해 주는....

Comments