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
Composerが「依存解決」のためにどんな工夫をしているか #phpcon
o0h
PRO
1
260
チームのテスト力を総合的に鍛えて品質、スピード、レジリエンスを共立させる/Testing approach that improves quality, speed, and resilience
goyoki
5
880
AIエージェントはこう育てる - GitHub Copilot Agentとチームの共進化サイクル
koboriakira
0
590
VS Code Update for GitHub Copilot
74th
2
650
なんとなくわかった気になるブロックテーマ入門/contents.nagoya 2025 6.28
chiilog
1
270
PicoRuby on Rails
makicamel
2
130
なぜ適用するか、移行して理解するClean Architecture 〜構造を超えて設計を継承する〜 / Why Apply, Migrate and Understand Clean Architecture - Inherit Design Beyond Structure
seike460
PRO
3
770
『自分のデータだけ見せたい!』を叶える──Laravel × Casbin で複雑権限をスッキリ解きほぐす 25 分
akitotsukahara
2
640
Flutterで備える!Accessibility Nutrition Labels完全ガイド
yuukiw00w
0
160
GitHub Copilot and GitHub Codespaces Hands-on
ymd65536
2
150
脱Riverpod?fqueryで考える、TanStack Queryライクなアーキテクチャの可能性
ostk0069
0
150
ふつうの技術スタックでアート作品を作ってみる
akira888
1
860
Featured
See All Featured
GraphQLの誤解/rethinking-graphql
sonatard
71
11k
Visualization
eitanlees
146
16k
Improving Core Web Vitals using Speculation Rules API
sergeychernyshev
18
970
Six Lessons from altMBA
skipperchong
28
3.9k
Docker and Python
trallard
44
3.5k
Connecting the Dots Between Site Speed, User Experience & Your Business [WebExpo 2025]
tammyeverts
6
300
GraphQLとの向き合い方2022年版
quramy
49
14k
Intergalactic Javascript Robots from Outer Space
tanoku
271
27k
VelocityConf: Rendering Performance Case Studies
addyosmani
332
24k
What's in a price? How to price your products and services
michaelherold
246
12k
Imperfection Machines: The Place of Print at Facebook
scottboms
267
13k
Building Flexible Design Systems
yeseniaperezcruz
328
39k
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 ご清聴ありがとうございました