Book Image

Ghidra Software Reverse Engineering for Beginners

By : A. P. David
Book Image

Ghidra Software Reverse Engineering for Beginners

By: A. P. David

Overview of this book

Ghidra, an open source software reverse engineering (SRE) framework created by the NSA research directorate, enables users to analyze compiled code on any platform, whether Linux, Windows, or macOS. This book is a starting point for developers interested in leveraging Ghidra to create patches and extend tool capabilities to meet their cybersecurity needs. You'll begin by installing Ghidra and exploring its features, and gradually learn how to automate reverse engineering tasks using Ghidra plug-ins. You’ll then see how to set up an environment to perform malware analysis using Ghidra and how to use it in the headless mode. As you progress, you’ll use Ghidra scripting to automate the task of identifying vulnerabilities in executable binaries. The book also covers advanced topics such as developing Ghidra plug-ins, developing your own GUI, incorporating new process architectures if needed, and contributing to the Ghidra project. By the end of this Ghidra book, you’ll have developed the skills you need to harness the power of Ghidra for analyzing and avoiding potential vulnerabilities in code and networks.
Table of Contents (20 chapters)
1
Section 1: Introduction to Ghidra
6
Section 2: Reverse Engineering
12
Section 3: Extending Ghidra

Looking for vulnerable functions

If you remember from the previous chapter, when looking for vulnerabilities, we started by looking for unsafe C/C++ functions listed in the symbols table. Unsafe C/C++ functions are likely to introduce vulnerabilities because it's up to the developer to check the parameters passed to the function. Therefore, they have the opportunity to commit a programming error with safety implications.

In this case, we will analyze a script that looks for the use of variables expected to be initialized by sscanf without validating the proper initialization:

00  int main() {
01 	char* data = "";
02 	char name[20];
03 	int age;
04 	int return_value = sscanf(data, "%s %i", name, &age);
05 	printf("I'm %s.\n", name);
06 	printf("I'm %i years old.", age);
07 }

When compiling this code and executing it, the result is unpredictable. Since the data variable is initialized to an empty string in...