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
What Spring Developers Should Know About Jakarta EE
ivargrimstad
0
370
Webサーバーサイド言語としてのRustについて
kouyuume
0
3.3k
アメ車でサンノゼを走ってきたよ!
s_shimotori
0
230
『毎日の移動』を支えるGoバックエンド内製開発
yutautsugi
2
270
The Past, Present, and Future of Enterprise Java
ivargrimstad
0
360
大規模アプリのDIフレームワーク刷新戦略 ~過去最大規模の並行開発を止めずにアプリ全体に導入するまで~
mot_techtalk
1
470
ALL CODE BASE ARE BELONG TO STUDY
uzulla
26
6.6k
Developer Joy - The New Paradigm
hollycummins
1
320
iOSでSVG画像を扱う
kishikawakatsumi
0
150
CSC509 Lecture 06
javiergs
PRO
0
260
Le côté obscur des IA génératives
pascallemerrer
0
150
Foundation Modelsを実装日本語学習アプリを作ってみた!
hypebeans
0
120
Featured
See All Featured
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
31
9.7k
Agile that works and the tools we love
rasmusluckow
331
21k
Context Engineering - Making Every Token Count
addyosmani
7
280
Writing Fast Ruby
sferik
629
62k
Building Better People: How to give real-time feedback that sticks.
wjessup
369
20k
Docker and Python
trallard
46
3.6k
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
30
2.9k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
162
15k
The Cult of Friendly URLs
andyhume
79
6.6k
Keith and Marios Guide to Fast Websites
keithpitt
411
23k
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
115
20k
Site-Speed That Sticks
csswizardry
13
920
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 ご清聴ありがとうございました