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
print("Hello, World")
eddie
2
530
MCPでVibe Working。そして、結局はContext Eng(略)/ Working with Vibe on MCP And Context Eng
rkaga
5
2.3k
意外と簡単!?フロントエンドでパスキー認証を実現する WebAuthn
teamlab
PRO
2
780
The Past, Present, and Future of Enterprise Java
ivargrimstad
0
430
もうちょっといいRubyプロファイラを作りたい (2025)
osyoyu
1
460
Tool Catalog Agent for Bedrock AgentCore Gateway
licux
7
2.6k
API Platform 4.2: Redefining API Development
soyuka
0
240
Namespace and Its Future
tagomoris
6
710
Testing Trophyは叫ばない
toms74209200
0
890
旅行プランAIエージェント開発の裏側
ippo012
2
930
テストコードはもう書かない:JetBrains AI Assistantに委ねる非同期処理のテスト自動設計・生成
makun
0
570
JSONataを使ってみよう Step Functionsが楽しくなる実践テクニック #devio2025
dafujii
1
650
Featured
See All Featured
Chrome DevTools: State of the Union 2024 - Debugging React & Beyond
addyosmani
7
850
Learning to Love Humans: Emotional Interface Design
aarron
273
40k
GraphQLの誤解/rethinking-graphql
sonatard
72
11k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
139
34k
The Cost Of JavaScript in 2023
addyosmani
53
8.9k
Done Done
chrislema
185
16k
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
127
53k
The Invisible Side of Design
smashingmag
301
51k
Mobile First: as difficult as doing things right
swwweet
224
9.9k
Testing 201, or: Great Expectations
jmmastey
45
7.7k
Build The Right Thing And Hit Your Dates
maggiecrowley
37
2.9k
XXLCSS - How to scale CSS and keep your sanity
sugarenia
248
1.3M
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 ご清聴ありがとうございました