DumpFromOEP.py for Immunity Debugger
2011/10/22 13:31
Windows XP에서 Immunity Debugger의 플러그인들이 충돌을 일으켜서 만들었던 스크립트입니다. OllyDump의 소스코드를 보면서 만들었습니다. 단순히 메모리를 덤프해서 PE 헤더를 고친 후 파일로 출력하는 게 전부입니다.
PyCommand 디렉토리 아래에 스크립트 파일을 저장한 후, eip가 OEP에 있을 때 커맨드라인에서 다음과 같이 입력하면 실행이 됩니다.
!dumpfromoep [a path of the output file]
OEP까지 직접 찾아가야 하고 IAT도 수동으로 고쳐줘야 합니다. UPX와 UPack으로 패킹된 바이너리는 정확히 덤프하는 걸 확인했습니다.
dumpfromoep.py
__author__ = '6l4ck3y3'
__version__ = '1.0.0'
__contact__ = '6l4ck3y3@gmail.com'
import immlib
import pefile
def main (args):
imm = immlib.Debugger ()
name = imm.getDebuggedName ()
try:
mod = imm.getModule (name)
if not mod:
raise Exception, "Couldn't find %s" % name
except Exception, msg:
return "Error: %s" % msg
pe = pefile.PE (name = mod.getPath ())
memory = imm.readMemory (pe.OPTIONAL_HEADER.ImageBase, pe.OPTIONAL_HEADER.SizeOfImage)
out = pefile.PE (data = memory)
orig_eip = imm.getRegs ()['EIP']
out.FILE_HEADER.NumberOfSections = pe.FILE_HEADER.NumberOfSections
out.OPTIONAL_HEADER.ImageBase = pe.OPTIONAL_HEADER.ImageBase
out.OPTIONAL_HEADER.SizeOfImage = pe.OPTIONAL_HEADER.SizeOfImage
out.OPTIONAL_HEADER.AddressOfEntryPoint = orig_eip - pe.OPTIONAL_HEADER.ImageBase
out.OPTIONAL_HEADER.BaseOfCode = pe.OPTIONAL_HEADER.BaseOfCode
out.OPTIONAL_HEADER.BaseOfData = pe.OPTIONAL_HEADER.BaseOfData
imm.log ("ImageBase = " + hex (out.OPTIONAL_HEADER.ImageBase))
imm.log ("SizeOfImage = " + hex (out.OPTIONAL_HEADER.SizeOfImage))
imm.log ("AddressOfEntryPoint = " + hex (out.OPTIONAL_HEADER.AddressOfEntryPoint))
imm.log ("BaseOfCode = " + hex (out.OPTIONAL_HEADER.BaseOfCode))
imm.log ("BaseOfData= " + hex (out.OPTIONAL_HEADER.BaseOfData))
imm.log ("")
for i in range (pe.FILE_HEADER.NumberOfSections):
out.sections[i].Name = pe.sections[i].Name
out.sections[i].VirtualSize = pe.sections[i].Misc_VirtualSize
out.sections[i].VirtualAddress = pe.sections[i].VirtualAddress
out.sections[i].SizeOfRawData = pe.sections[i].Misc_VirtualSize
out.sections[i].PointerToRawData = pe.sections[i].VirtualAddress
out.sections[i].Characteristics = pe.sections[i].Characteristics
imm.log ("Name = " + repr (out.sections[i].Name))
imm.log ("VirtualSize = " + hex (out.sections[i].VirtualSize))
imm.log ("VirtualAddress = " + hex (out.sections[i].VirtualAddress))
imm.log ("SizeOfRawData = " + hex (out.sections[i].SizeOfRawData))
imm.log ("PointerToRawData = " + hex (out.sections[i].PointerToRawData))
imm.log ("Characteristics = " + hex (out.sections[i].Characteristics))
imm.log ("")
out.write (args[0])"0x02 Windows RCE" 분류의 다른 글
| 게임 매크로 Inventory A+ 분석 | 2012/02/15 |
| From AppInit_DLLs To Injection | 2011/09/28 |
| Windows Debugging Intrenals: A to Z | 2011/08/28 |
| IsDebuggerPresent 그리고 패치 | 2011/07/04 |
| API Redirect on Themida | 2011/02/27 |
Trackback Address:http://hisjournal.net/blog/trackback/373