0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Reversing.kr Easy Unpack Writeup Using Ghidra

Last updated at Posted at 2021-03-15

Reversing.kr Easy Unpack は OEP(Original Entry Point)を見つける問題。
OEP の可能性がある Far Jump を抽出する Ghidra Script を作成したので,Ghidra研究の記録として残しておく。

問題配布サイト

Easy Unpack では,EXE とテキストファイルが渡され,テキストファイルには
Find the OEP
ex) 00401000
と記載されている。

まずは,IDA free
Graph overview で下の方へ行く
image.png

Graph view の最後の方にあるジャンプ先をいくつか入力したら正解だった。
image.png


ここからが本題

OEP は VirtualAlloc などで新しく割り当てられたメモリ空間にあるので遠くに jump するはず。
遠くにジャンプするとき jump to any absolute address となるはず。
Ghidra で Script を組んで Far Jump を自動的に探すことにチャレンジ。

参考サイト:ピンク先生の Ghidra Script 置き場

Ghidra API

Far Jump を抽出する Ghidra Script

far_jmp_search.py
from ghidra.program.model.listing import CodeUnit

jump_count = 0

#get all memory ranges
addr_ranges = currentProgram.getMemory().getAddressRanges()

for addr_range in addr_ranges:
    insts = currentProgram.getListing().getInstructions(addr_range.getMinAddress(), True)
    for inst in insts:
        flow_type = inst.getFlowType()
        if flow_type.isJump():            
            len = inst.getDefaultFallThroughOffset()
            # Exclude near jumps
            if len > 2:
                print("{} {} {}".format(inst.address, inst, len))
                jump_count += 1
            
print('far jump count: {}'.format(jump_count))

結果
image.png

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?