Reveal API Redirect on Themida

2010/09/25 18:15

일주일 전에 쿠시스 영남권 세미나에서 "API Redirect on Themida"라는 주제로 발표를 했었습니다. 아래는 그때 발표자료랑 시연에서 잠시 소개했던 스크립트입니다. Immunity Debugger 용으로 python으로 작성하였습니다.

PyCommand 디렉토리 아래에 스크립트 파일을 저장한 후, eip가 call 문에 있을 때 커맨드라인에서 다음과 같이 입력하면 실행이 됩니다.

!revealapi

이 스크립트는 call 문을 직접 실행하지 않고 Themida에서 리다이렉트된 API를 찾아서 comment로 알려줍니다. 스크립트가 완성된 게 아니라서 70%의 정확도를 가집니다.

revealapi.py


# -*- coding:utf-8 -*-    

'''
* =====================================================================================
*
* Filename: revealapi.py
*
* Description: The script to reveal the redirected Windows API in the Themida.
*
* Version: 1.0
* Created: 2010.09.12. 15:58:44
* Revision: none
* Compiler: Python
*
* Author: Yeonjae Kim (http://hisjournal.net/blog), 6l4ck3y3 (at) gmail.com
* Company: CERT-IS (http://www.cert-is.com)
*
* =====================================================================================
'''

from immlib import *

def main (args):

imm = Debugger ()

eip = orig_eip = imm.getRegs ()['EIP']

if not imm.Disasm (eip).isCall ():
return "Call instruction is NOT here."

imm.Log ("", 0)
imm.Log ("", 0)
imm.Log ("==================================================================", 0)
imm.Log ("", 0)
imm.Log ("[+] Revealing the redirected Windows API of %08X" % orig_eip, 0, True)
imm.Log ("[+] This script was written by 6l4ck3y3 (@6l4ck3y3)", 0, True)
imm.Log ("", 0)
imm.Log ("==================================================================", 0)
imm.Log ("", 0)

limit = 1000

while (eip < 0x10000000 and limit):
try:
opcode = imm.Disasm (eip)
except:
imm.Log ("[*] %s" % opcode.getDisasm (), eip)
return "What is hidden? Go into."

if (opcode.isJmp () or opcode.isConditionalJmp () or opcode.isCall ()):
eip = opcode.getJmpAddr ()
elif opcode.isRet ():
return "API was NOT found. Maybe here is a local func."
else:
imm.Log ("[*] %s" % opcode.getDisasm (), eip)
eip = eip + int (opcode.getSize ())

limit = limit - 1

if not limit:
return "API was NOT found"

msg = "".join (["%s " % m for m in opcode.getDisasm ().split (' ')[1:]])

imm.Log ("[*] %s" % msg, eip)
imm.setComment (orig_eip, "%s" % msg)

return "%s was FOUND." % msg
크리에이티브 커먼즈 라이센스
Creative Commons License

6l4ck3y3 0x02 Windows RCE , , , , , , ,

Trackback Address:http://hisjournal.net/blog/trackback/342
  1. Blog Icon

    python 잘쓰시는분들 보면 참 부러워요. (특히 immunitydbg가 제공하는 정보 잘쓰시는분들..ㅋㅋ)

  2. Blog Icon
    6l4ck3y3

    하하하... 파이썬 금방 배웁니다. 쉬워요.. ^^;