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
概念モデル→論理モデルで気をつけていること
sunnyone
2
260
実用的なGOCACHEPROG実装をするために / golang.tokyo #40
mazrean
1
280
2025 年のコーディングエージェントの現在地とエンジニアの仕事の変化について
azukiazusa1
24
12k
250830 IaCの選定~AWS SAMのLambdaをECSに乗り換えたときの備忘録~
east_takumi
0
390
はじめてのMaterial3 Expressive
ym223
2
750
為你自己學 Python - 冷知識篇
eddie
1
350
Introducing ReActionView: A new ActionView-compatible ERB Engine @ Rails World 2025, Amsterdam
marcoroth
0
690
rage against annotate_predecessor
junk0612
0
170
機能追加とリーダー業務の類似性
rinchoku
2
1.3k
HTMLの品質ってなんだっけ? “HTMLクライテリア”の設計と実践
unachang113
4
2.9k
アルテニア コンサル/ITエンジニア向け 採用ピッチ資料
altenir
0
110
デザイナーが Androidエンジニアに 挑戦してみた
874wokiite
0
480
Featured
See All Featured
For a Future-Friendly Web
brad_frost
180
9.9k
Reflections from 52 weeks, 52 projects
jeffersonlam
352
21k
How to Ace a Technical Interview
jacobian
279
23k
Keith and Marios Guide to Fast Websites
keithpitt
411
22k
Typedesign – Prime Four
hannesfritz
42
2.8k
Site-Speed That Sticks
csswizardry
10
820
Building a Scalable Design System with Sketch
lauravandoore
462
33k
The World Runs on Bad Software
bkeepers
PRO
70
11k
4 Signs Your Business is Dying
shpigford
184
22k
XXLCSS - How to scale CSS and keep your sanity
sugarenia
248
1.3M
Why Our Code Smells
bkeepers
PRO
339
57k
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
36
2.5k
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 ご清聴ありがとうございました