Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Annotate Windows API!
Search
Bigdrea6
October 17, 2021
Programming
0
67
Annotate Windows API!
seccamp2021のZ7トラックで制作したGhidraの拡張機能の説明スライドです
Bigdrea6
October 17, 2021
Tweet
Share
More Decks by Bigdrea6
See All by Bigdrea6
Bluetooth Mesh
bigdrea6
0
30
Bluetoothのあれこれ
bigdrea6
0
55
Fileless Malware !
bigdrea6
0
220
Other Decks in Programming
See All in Programming
RailsGirls IZUMO スポンサーLT
16bitidol
0
180
生成AI時代のコンポーネントライブラリの作り方
touyou
1
210
Hypervel - A Coroutine Framework for Laravel Artisans
albertcht
1
130
AI時代の『改訂新版 良いコード/悪いコードで学ぶ設計入門』 / ai-good-code-bad-code
minodriven
14
4.6k
dbt民主化とLLMによる開発ブースト ~ AI Readyな分析サイクルを目指して ~
yoshyum
3
1k
Rails Frontend Evolution: It Was a Setup All Along
skryukov
0
140
GitHub Copilot and GitHub Codespaces Hands-on
ymd65536
2
150
明示と暗黙 ー PHPとGoの インターフェイスの違いを知る
shimabox
2
510
なぜ「共通化」を考え、失敗を繰り返すのか
rinchoku
1
650
5つのアンチパターンから学ぶLT設計
narihara
1
170
Composerが「依存解決」のためにどんな工夫をしているか #phpcon
o0h
PRO
1
260
Team operations that are not burdened by SRE
kazatohiei
1
310
Featured
See All Featured
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
507
140k
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
281
13k
Code Review Best Practice
trishagee
69
18k
The Pragmatic Product Professional
lauravandoore
35
6.7k
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
32
2.4k
Imperfection Machines: The Place of Print at Facebook
scottboms
267
13k
The Art of Programming - Codeland 2020
erikaheidi
54
13k
A designer walks into a library…
pauljervisheath
207
24k
Building Flexible Design Systems
yeseniaperezcruz
328
39k
Rebuilding a faster, lazier Slack
samanthasiow
82
9.1k
Done Done
chrislema
184
16k
Bootstrapping a Software Product
garrettdimon
PRO
307
110k
Transcript
Annotate Windows API ! Z-VII リバースエンジニアリングを支えるGhidra拡張機能の開発
• 高専4年 • Cトラック + Z-VII • Twitter : @Bigdrea6_
• Github : Bigdrea6 今回発表するスクリプトは以下に上げています https://github.com/Bigdrea6/winapi-ghidra 自己紹介
Ghidraのおさらい、 Ghidra API CookBookの学習&ハンズオン Day1 Day2 Day3 Flow Ghidra Scriptの開発演習、各自の
テーマで拡張機能の実装開始 オレオレ拡張機能のお披露目会 8/22、9/19、9/26 当日ごとの感想+メモは https://scrapbox.io/bigdrea6/ の キャンプ五日目(後半)、キャンプ七日目(後半)、キャンプ八日目(後半)にあります。
As a PE Analyst I want WindowsAPIの詳細表示 So that 見やすい
+ なんとなく分かる User Story • 日頃はELFを触ることが多い(CTFとか) • 名前で予測できないWindows API。なんの意味を持つかいまいち分からない引数たち。 これを毎回調べるのは時間がかかる。
call_api_table.py api_summary.py auto_equate_setting.py (by my dictionary) 01 02 03 04
auto_equate_setting.py (by gdt) Step APIをCALLするアドレスとそのAPIを一覧表示する APIの概要をコメントもしくはAPIにかざした際に見えるようにする 一部のAPIの引数(constのみ)にequateをセットする gdtから行うことである程度のAPIに対応する キャンプ中
call_api_table.py Logic and results of this script 01 APIをCALLするアドレスとそのAPIを一覧表示する
Logic Ghidraの解析後の情報を扱う 1. すべての外部参照に対するイテレータを取る 2. 参照タイプがcallであるかのチェック 3. このイテレータからアドレス、APIの取得 4. アドレスの順番に表示
+ APIの種類数、CALL数の表示 修正していないミス -> Thunk FunctionとかができあがるAPIはこれで拾えない 1. https://ghidra.re/ghidra_docs/api/ghidra/program/model/symbol/ReferenceManager.html#getExternalReferences() 2. https://ghidra.re/ghidra_docs/api/ghidra/program/model/symbol/Reference.html#getReferenceType() 3. https://ghidra.re/ghidra_docs/api/ghidra/program/model/symbol/Reference.html#getFromAddress() 4. https://ghidra.re/ghidra_docs/api/ghidra/app/events/ExternalReferencePluginEvent.html#getExternalLocation() 5. https://ghidra.re/ghidra_docs/api/ghidra/program/database/external/ExternalLocationDB.html#getLabel() Ghidra APIの情報
Results
auto_equate_setting.py Logic and results of this script 03 一部のAPIの引数(constのみ)にequateをセットする
Logic Ghidraのデコンパイル後のPCodeを扱う PCodeとはGhidra独自の中間言語 1. APIの引数の取得 2. タイプがconstか、constであればoffsetの取得 3. equateを作成した辞書とoffsetの照らし合わせで決定する 4.
equateのセット。ここでDynamicHashを使用することでPUSHのアドレスがいらない 対応しているAPIは次の4つ。 CreateProcessA、RegCreateKeyExA、RegValueExA、SHGetSpecialFolderPathA 1. https://ghidra.re/ghidra_docs/api/ghidra/program/database/symbol/EquateManager.html#createEquate(java.lang.String,long) 2. https://ghidra.re/ghidra_docs/api/ghidra/program/model/pcode/DynamicHash.html#%3Cinit%3E(ghidra.program.model.pcode.Varnode,int) 3. https://ghidra.re/ghidra_docs/api/ghidra/program/model/symbol/Equate.html#addReference(long,ghidra.program.model.address.Address) Ghidra APIの情報
① ① ② ② ③ ③
Results ① ② ③ ④
Future • 引数のタイプに依存しない(unique, register, stack) ※ポインタはequate付の対象外 • 対応APIの増加 • 変数名の変更とか(local_210
→ pszPath) Before After
Impressions • Z7でスクリプトを2つほど制作したが、講師の方々の力が大きいのでキャンプ後も続けて 自分のスクリプトを完成させる • スクリプト開発だけでなくGhidraの仕様や豆技術も知れたのがよかった • Ghidraは拡張することで使いやすくできる。積極的に開発していくべきである • インスタ映えではなくGhidra映えを考えて生きていく
• ボタン適当に押せばおもしろい機能に出会える • PCodeとtoAddrは偉大である
CREDITS ◂ Icons by Flaticon ◂ Presentation template by Slidesgo
◂ Ghidra API information by ghidra.re ◂ Windows API information by MSDN ◂ English by DeepL ご清聴ありがとうございました