Acknowledgments |
|
xix | |
Introduction |
|
xxi | |
About This Book |
|
xxii | |
Who Should Read This Book? |
|
xxii | |
What's in This Book? |
|
xxii | |
Part I Introduction |
|
xxiii | |
Part II Basic Ghidra Usage |
|
xxiii | |
Part III Making Ghidra Work for You |
|
xxiii | |
Part IV A Deeper Dive |
|
xxiv | |
Part V Real-World Application |
|
xxiv | |
|
|
1 | (38) |
|
1 Introduction To Disassembly |
|
|
3 | (12) |
|
|
4 | (1) |
|
|
5 | (1) |
|
|
6 | (1) |
|
|
6 | (1) |
|
|
6 | (1) |
|
Software Interoperability |
|
|
7 | (1) |
|
|
7 | (1) |
|
|
7 | (1) |
|
|
7 | (7) |
|
A Basic Disassembly Algorithm |
|
|
8 | (1) |
|
|
9 | (2) |
|
Recursive Descent Disassembly |
|
|
11 | (3) |
|
|
14 | (1) |
|
2 Reversing And Disassembly Tools |
|
|
15 | (18) |
|
|
15 | (5) |
|
|
16 | (2) |
|
|
18 | (1) |
|
|
19 | (1) |
|
|
20 | (7) |
|
|
20 | (2) |
|
|
22 | (2) |
|
|
24 | (1) |
|
|
25 | (1) |
|
|
25 | (1) |
|
|
26 | (1) |
|
|
27 | (4) |
|
|
28 | (1) |
|
|
29 | (2) |
|
|
31 | (2) |
|
|
33 | (6) |
|
|
34 | (1) |
|
|
34 | (1) |
|
|
34 | (1) |
|
|
35 | (1) |
|
|
35 | (3) |
|
The Ghidra Directory Layout |
|
|
36 | (1) |
|
|
37 | (1) |
|
|
38 | (1) |
|
PART II BASIC GHIDRA USAGE |
|
|
39 | (176) |
|
4 Getting Started With Ghidra |
|
|
41 | (14) |
|
|
41 | (2) |
|
|
43 | (5) |
|
|
44 | (2) |
|
Using the Raw Binary Loader |
|
|
46 | (2) |
|
Analyzing Files with Ghidra |
|
|
48 | (4) |
|
|
51 | (1) |
|
Desktop Behavior During Initial Analysis |
|
|
52 | (2) |
|
Saving Your Work and Exiting |
|
|
53 | (1) |
|
Ghidra Desktop Tips and Tricks |
|
|
54 | (1) |
|
|
54 | (1) |
|
|
55 | (34) |
|
|
56 | (2) |
|
|
58 | (20) |
|
|
61 | (3) |
|
Creating Additional Disassembly Windows |
|
|
64 | (2) |
|
Ghidra Function Graph View |
|
|
66 | (5) |
|
|
71 | (1) |
|
|
72 | (3) |
|
The Data Type Manager Window |
|
|
75 | (1) |
|
|
75 | (1) |
|
|
75 | (3) |
|
|
78 | (9) |
|
|
78 | (2) |
|
|
80 | (1) |
|
The Defined Strings Window |
|
|
81 | (1) |
|
The Symbol Table and Symbol References Windows |
|
|
82 | (3) |
|
|
85 | (1) |
|
The Function Call Graph Window |
|
|
86 | (1) |
|
|
87 | (2) |
|
6 Making Sense Of A Ghidra Disassembly |
|
|
89 | (30) |
|
|
90 | (3) |
|
|
90 | (1) |
|
|
91 | (1) |
|
|
92 | (1) |
|
|
92 | (1) |
|
|
93 | (12) |
|
|
94 | (2) |
|
|
96 | (4) |
|
Additional Stack Frame Considerations |
|
|
100 | (1) |
|
|
101 | (1) |
|
|
101 | (4) |
|
|
105 | (9) |
|
Ghidra Stack Frame Analysis |
|
|
106 | (1) |
|
Stack Frames in Listing View |
|
|
106 | (3) |
|
Decompiler-Assisted Stack Frame Analysis |
|
|
109 | (1) |
|
Local Variables as Operands |
|
|
110 | (1) |
|
The Ghidra Stack Frame Editor |
|
|
111 | (3) |
|
|
114 | (3) |
|
|
115 | (1) |
|
|
116 | (1) |
|
|
117 | (2) |
|
7 Disassembly Manipulation |
|
|
119 | (1) |
|
Manipulating Names and Labels |
|
|
120 | (1) |
|
Renaming Parameters and Local Variables |
|
|
121 | (3) |
|
|
124 | (1) |
|
|
125 | (1) |
|
|
126 | (1) |
|
|
127 | (1) |
|
|
128 | (1) |
|
|
128 | (5) |
|
|
129 | (1) |
|
|
130 | (1) |
|
|
130 | (1) |
|
|
131 | (1) |
|
Parameter and Local Variable Comments |
|
|
132 | (1) |
|
|
132 | (1) |
|
Basic Code Transformations |
|
|
133 | (7) |
|
Changing Code Display Options |
|
|
133 | (2) |
|
Formatting Instruction Operands |
|
|
135 | (2) |
|
|
137 | (2) |
|
Converting Data to Code (and Vice Versa) |
|
|
139 | (1) |
|
Basic Data Transformations |
|
|
140 | (5) |
|
|
141 | (1) |
|
|
142 | (2) |
|
|
144 | (1) |
|
|
145 | (2) |
|
8 Data Types And Data Structures |
|
|
147 | (36) |
|
|
148 | (2) |
|
Recognizing Data Structure Use |
|
|
150 | (16) |
|
|
150 | (9) |
|
|
159 | (7) |
|
Creating Structures with Ghidra |
|
|
166 | (6) |
|
|
166 | (3) |
|
Editing Structure Members |
|
|
169 | (2) |
|
Applying Structure Layouts |
|
|
171 | (1) |
|
|
172 | (10) |
|
|
173 | (1) |
|
Virtual Functions and Vftables |
|
|
173 | (4) |
|
|
177 | (2) |
|
|
179 | (1) |
|
Runtime Type Identification |
|
|
180 | (1) |
|
Inheritance Relationships |
|
|
181 | (1) |
|
C++ Reverse Engineering References |
|
|
182 | (1) |
|
|
182 | (1) |
|
|
183 | (14) |
|
|
184 | (9) |
|
Cross-References (Back References) |
|
|
185 | (3) |
|
|
188 | (5) |
|
Reference Management Windows |
|
|
193 | (3) |
|
|
193 | (1) |
|
|
194 | (1) |
|
|
194 | (1) |
|
Advanced Reference Manipulation |
|
|
195 | (1) |
|
|
196 | (1) |
|
|
197 | (18) |
|
|
198 | (1) |
|
|
198 | (10) |
|
|
208 | (6) |
|
|
214 | (1) |
|
|
214 | (1) |
|
PART III MAKING GHIDRA WORK FOR YOU |
|
|
215 | (146) |
|
|
217 | (24) |
|
|
218 | (1) |
|
|
218 | (3) |
|
|
221 | (3) |
|
Creating a Shared Project |
|
|
222 | (1) |
|
|
223 | (1) |
|
|
224 | (8) |
|
|
224 | (3) |
|
|
227 | (2) |
|
|
229 | (3) |
|
|
232 | (8) |
|
|
233 | (2) |
|
|
235 | (5) |
|
|
240 | (1) |
|
|
241 | (20) |
|
|
242 | (7) |
|
|
242 | (1) |
|
|
243 | (3) |
|
|
246 | (1) |
|
Special Tool Editing Features |
|
|
247 | (1) |
|
Saving the CodeBrowser Layout |
|
|
248 | (1) |
|
|
249 | (4) |
|
|
253 | (5) |
|
|
258 | (1) |
|
|
259 | (2) |
|
13 Extending Ghidra's Worldview |
|
|
261 | (24) |
|
|
262 | (3) |
|
|
265 | (1) |
|
|
265 | (2) |
|
|
267 | (5) |
|
Creating New Data Type Archives |
|
|
269 | (3) |
|
|
272 | (1) |
|
|
273 | (11) |
|
Function ID Plugin Example: UPX |
|
|
275 | (4) |
|
Function ID Plugin Example: Profiling a Static Library |
|
|
279 | (5) |
|
|
284 | (1) |
|
14 Basic Ghidra Scripting |
|
|
285 | (30) |
|
|
286 | (3) |
|
|
286 | (1) |
|
|
287 | (2) |
|
|
289 | (8) |
|
Writing Java Scripts (Not JavaScript!) |
|
|
289 | (1) |
|
Edit Script Example: Regex Search |
|
|
290 | (5) |
|
|
295 | (2) |
|
Support for Other Languages |
|
|
297 | (1) |
|
Introduction to the Ghidra API |
|
|
297 | (10) |
|
|
298 | (1) |
|
|
298 | (1) |
|
|
299 | (1) |
|
|
299 | (6) |
|
|
305 | (1) |
|
|
306 | (1) |
|
The Instruction Interface |
|
|
306 | (1) |
|
Ghidra Scripting Examples |
|
|
307 | (6) |
|
Example 1 Enumerating Functions |
|
|
307 | (1) |
|
Example 2 Enumerating Instructions |
|
|
308 | (1) |
|
Example 3 Enumerating Cross-References |
|
|
308 | (2) |
|
Example 4 Finding Function Calls |
|
|
310 | (1) |
|
Example 5 Emulating Assembly Language Behavior |
|
|
311 | (2) |
|
|
313 | (2) |
|
|
315 | (26) |
|
|
316 | (2) |
|
|
316 | (1) |
|
|
316 | (1) |
|
Editing Scripts with Eclipse |
|
|
317 | (1) |
|
|
318 | (11) |
|
|
319 | (5) |
|
Navigating the Package Explorer |
|
|
324 | (5) |
|
Example: Ghidra Analyzer Module Project |
|
|
329 | (11) |
|
Step 1 Define the Problem |
|
|
330 | (1) |
|
Step 2 Create the Eclipse Module |
|
|
331 | (1) |
|
Step 3 Build the Analyzer |
|
|
331 | (6) |
|
Step 4 Test the Analyzer Within Eclipse |
|
|
337 | (1) |
|
Step 5 Add the Analyzer to Our Ghidra Installation |
|
|
337 | (1) |
|
Step 6 Test the Analyzer Within Ghidra |
|
|
338 | (2) |
|
|
340 | (1) |
|
16 Ghidra In Headless Mode |
|
|
341 | (20) |
|
|
342 | (13) |
|
|
343 | (1) |
|
Steps 2 and 3: Create a New Ghidra Project in a Specified Location |
|
|
343 | (1) |
|
Step 4 Import a File to the Project |
|
|
344 | (1) |
|
Steps 5 and 6: Auto Analyze the File, Save, and Exit |
|
|
344 | (3) |
|
|
347 | (8) |
|
|
355 | (5) |
|
|
355 | (4) |
|
|
359 | (1) |
|
|
360 | (1) |
|
|
361 | (106) |
|
|
363 | (38) |
|
|
365 | (1) |
|
Manually Loading a Windows PE File |
|
|
366 | (9) |
|
Example 1 SimpleShellcode Loader Module |
|
|
375 | (12) |
|
|
377 | (2) |
|
Step 1 Define the Problem |
|
|
379 | (1) |
|
Step 2 Create the Eclipse Module |
|
|
379 | (1) |
|
|
380 | (5) |
|
Step 4 Add the Loader to Our Ghidra Installation |
|
|
385 | (1) |
|
Step 5 Test the Loader Within Ghidra |
|
|
385 | (2) |
|
Example 2 Simple Shellcode Source Loader |
|
|
387 | (4) |
|
Update 1 Modify the Response to the Importer Poll |
|
|
388 | (1) |
|
Update 2 Find the Shellcode in the Source Code |
|
|
388 | (1) |
|
Update 3 Convert Shellcode to Byte Values |
|
|
389 | (1) |
|
Update 4 Load Converted Byte Array |
|
|
389 | (1) |
|
|
389 | (2) |
|
Example 3 Simple ELF Shellcode Loader |
|
|
391 | (9) |
|
|
392 | (1) |
|
|
392 | (1) |
|
Find Supported Load Specifications |
|
|
393 | (1) |
|
Load File Content into Ghidra |
|
|
394 | (1) |
|
Format Data Bytes and Add an Entry Point |
|
|
395 | (1) |
|
Language Definition Files |
|
|
396 | (1) |
|
|
397 | (1) |
|
|
398 | (2) |
|
|
400 | (1) |
|
|
401 | (26) |
|
Understanding Ghidra Processor Modules |
|
|
403 | (4) |
|
Eclipse Processor Modules |
|
|
403 | (1) |
|
|
404 | (2) |
|
|
406 | (1) |
|
Modifying a Ghidra Processor Module |
|
|
407 | (19) |
|
|
408 | (1) |
|
Example 1 Adding an Instruction to a Processor Module |
|
|
409 | (6) |
|
Example 2 Modifying an Instruction in a Processor Module |
|
|
415 | (9) |
|
Example 3 Adding a Register to a Processor Module |
|
|
424 | (2) |
|
|
426 | (1) |
|
|
427 | (16) |
|
|
428 | (2) |
|
|
428 | (2) |
|
|
430 | (12) |
|
Example 1 Editing in the Decompiler Window |
|
|
431 | (5) |
|
Example 2 Non-Returning Functions |
|
|
436 | (1) |
|
Example 3 Automated Structure Creation |
|
|
437 | (5) |
|
|
442 | (1) |
|
|
443 | (24) |
|
|
444 | (7) |
|
|
444 | (5) |
|
Example: Comparing gcc with Microsoft C/C++ Compiler |
|
|
449 | (2) |
|
|
451 | (7) |
|
Example 1 Modulo Operator |
|
|
452 | (3) |
|
Example 2 The Ternary Operator |
|
|
455 | (2) |
|
Example 3 Function Inlining |
|
|
457 | (1) |
|
Compiler-Specific C++ Implementation |
|
|
458 | (5) |
|
|
458 | (1) |
|
|
459 | (4) |
|
Locating the main Function |
|
|
463 | (3) |
|
Example 1 _Start to main with gcc on Linux x86-64 |
|
|
464 | (1) |
|
Example 2 _Start to main with clang on FreeBSD x86-64 |
|
|
464 | (1) |
|
Example 3 _Start to main with Microsoft's C/C++ compiler |
|
|
465 | (1) |
|
|
466 | (1) |
|
PART V REAL-WORLD APPLICATIONS |
|
|
467 | (84) |
|
21 Obfuscated Code Analysis |
|
|
469 | (36) |
|
|
470 | (21) |
|
|
470 | (1) |
|
Anti-Static Analysis Techniques |
|
|
470 | (12) |
|
Imported Function Obfuscation |
|
|
482 | (5) |
|
Anti-Dynamic Analysis Techniques |
|
|
487 | (4) |
|
Static Deobfuscation of Binaries Using Ghidra |
|
|
491 | (13) |
|
Script-Oriented Deobfuscation |
|
|
491 | (5) |
|
Emulation-Oriented Deobfuscation |
|
|
496 | (2) |
|
Step 1 Define the Problem |
|
|
498 | (1) |
|
Step 2 Create the Eclipse Script Project |
|
|
498 | (1) |
|
Step 3 Build the Emulator |
|
|
499 | (3) |
|
Step 4 Add the Script to Our Ghidra Installation |
|
|
502 | (1) |
|
Step 5 Test the Script Within Ghidra |
|
|
502 | (2) |
|
|
504 | (1) |
|
|
505 | (24) |
|
|
506 | (1) |
|
|
506 | (7) |
|
|
507 | (1) |
|
Searching for Direct References |
|
|
508 | (1) |
|
Searching for Instruction Patterns |
|
|
508 | (4) |
|
Finding Specific Behaviors |
|
|
512 | (1) |
|
|
513 | (9) |
|
|
513 | (6) |
|
Making Nontrivial Changes |
|
|
519 | (3) |
|
|
522 | (3) |
|
|
522 | (1) |
|
|
523 | (1) |
|
|
523 | (2) |
|
Example: Patching a Binary |
|
|
525 | (3) |
|
|
528 | (1) |
|
23 Binary Differencing And Version Tracking |
|
|
529 | (22) |
|
|
529 | (9) |
|
|
531 | (3) |
|
Example: Merging Two Analyzed Files |
|
|
534 | (4) |
|
|
538 | (8) |
|
Function Comparison Window |
|
|
538 | (3) |
|
Example: Comparing Crypto Routines |
|
|
541 | (5) |
|
|
546 | (3) |
|
Version Tracking Concepts |
|
|
547 | (2) |
|
|
549 | (2) |
|
|
551 | (6) |
|
|
552 | (4) |
|
|
552 | (2) |
|
Basic Windows and Navigation |
|
|
554 | (2) |
|
|
556 | (1) |
|
|
556 | (1) |
Index |
|
557 | |