0xshivaay@home:~$

GDB(GNU Debugger) Part 1

In the realm of exploit development and reverse engineering, debugging stands out as one of the most crucial phases. This blog series will offer an in-depth exploration of GDB, one of the most powerful and important debugging tools.

GDB.

I don’t know how many of you know about debugging, so I am assuming that you are all beginners in the field of debugging. In this blog, we will not take a straight dive into GDB; instead, we will look at some basic concepts of debugging.

What is Debugging?

For beginner, the first question that often arises is, “What is debugging, and what does it really mean?” Let’s break it down in simple terms:

The term debug is formed by combining two words: de and bug. In this context, bug refers to issues or problems. So, debugging essentially means identifying and addressing issues or problems, regardless of whether they’re in software, websites, Android applications, or any digital system.

Debugging is the process of not only identifying these bugs but also getting rid of them. You can think of it as the art of finding and eliminating bugs, ensuring that the software or system works properly.

If we talk about bugs, they can be divided into two different categories: functional bugs and security bugs.

  1. Functional Bugs: Functional bugs are issues that affect the correct operation of a software application, system, or website. They typically interfere with the intended functionality of the software. a. Crashes b. Incorrect Behavior c. Performance Issues

  2. Security Bugs: Security bugs, on the other hand, are issues that can be exploited by malicious actors to compromise the security of a system, application, or website. These bugs often have the potential to allow unauthorized access, data breaches, or other security-related vulnerabilities. a. SSTI b. Dependency Confusion c. Race Condition Functional bugs impact user experience, security bugs pose a more significant threat as they can lead to data breaches.

What is Debuggers?

Program or software use to analyze and debug other programs: >GDB (user mode) >WinGDB (user mode) >IDB (user mode) >SoftIce (Kernel mode)

GDB

Installation of GDB

apt-get install gdb

In this blog series, we will be using C++ code for debugging.

// Print hello world
#include <iostream>

int main() {
    std::cout << "Hello, World!" << std::endl;
    return 0;
}
  • Before delving into debugging code, it’s important to understand debugging symbols and how they are useful during the debugging process.

Debugging symbols are special kinds of symbols that provide essential information to debuggers, enabling them to investigate and analyze code effectively. These symbols are added to the symbolic table of an object file, enriching it with valuable data.

If you’re wondering what a symbolic table is, it’s a data structure used by language translators (interpreters or compilers) to manage symbols such as functions, variables, and other program elements.

Let’s back to our main topic, this of symbolic information in the object file allows the debugger to gain access to specific details within the code, including functions, variables, and more. This additional information is crucial for debugging and understanding how the program executes and behaves.

Debugging symbols can be a part of of binary(compiled with binary) or can be a separate file.

To better understand this concept, let’s make a comparison with humans: Person 1 (without debugging symbols):

  • Man
  • Young
  • Programmer

Person 2 (with debugging symbols):

  • Man (Name: Shashank)
  • Young (Age: 18)
  • Programmer (Languages: C++, Python)

This analogy illustrates how debugging symbols provide additional information about each element, making it easier for a debugger, or in this case, an observer, to comprehend the specifics.

You have to explicitly specify whether you want to include debugging symbols or not at compile time.

    # Complie without debugging symbols
    $ gcc -o hello_world hello_world.cpp

    # Complie with debugging symbols
    $ gcc -o -g hello_world hello_world.cpp

    # Compile with debugging symbols(for GDB)
    $ gcc -o -ggdb hello_world hello_world.cpp
  • Debug symbols filetype:
    • DWARF2
    • COFF
    • XCOFF
    • Stabs
  • There are many, but these are the most common ones.

This concludes the provided content. If you have any further questions or need additional information, please feel free to ask.

See you in next blog.