Gnu Debugger
Gnu Debugger
ID: F2022408046
SECTION: Y2
Testing Integer Overflow and Buffer Overflow Using GDB
Introduction
This report demonstrates how to test and mitigate integer and buffer overflow
vulnerabilities using GNU Debugger (GDB). By analyzing a vulnerable C program,
exploiting its weaknesses, and applying secure coding practices, the exercise
highlights the importance of detecting and preventing these common security
issues.
Prerequisites
A Linux system (Ubuntu recommended).
GCC (GNU Compiler Collection).
GDB (GNU Debugger).
1. Set Up Environment
Required Tools
1. Linux system:
Ubuntu is recommended for its user-friendliness, but Kali Linux
will also work effectively for security-related tasks.
2. GCC (GNU Compiler Collection):
Essential for compiling C programs.
3. GDB (GNU Debugger):
A powerful tool for debugging and analyzing programs.
Run this command
sudo apt-get install gcc gdb
2. Write a Vulnerable C Program
Create a file named vulnerable.c
Run a command
nano vulnerable.c
Now we can write the vulnerable code inside it
And write the following code in it:
Vulnerable code :
#include <stdio.h>
#include <string.h>
int main() {
int number;
printf("Enter a number: ");
scanf("%d", &number);
if (number + 1 < number) {
printf("Integer overflow detected!\n");
} else {
printf("Number is safe: %d\n", number);
}
char input[100];
printf("Enter a string: ");
scanf("%s", input);
vulnerable_function(input);
return 0;
}
Written below in the screenshot
The program has two vulnerabilities:
1. Integer Overflow: The if (number + 1 < number) condition exploits an
overflow scenario.
2. Buffer Overflow: Using strcpy in vulnerable_function causes overflow when
the input exceeds the buffer size.
9. Re-Test
Repeat the integer overflow and buffer overflow tests after fixing the
vulnerabilities.
break main
This output simply indicates that you have successfully set a breakpoint at
the main function. The debugger is notifying you about the memory
address (0x11df) where the breakpoint is set, as well as the source file
(vulnerable.c) and line number (15).
GNU: Overview and Explanation
GNU, which stands for "GNU's Not Unix," is a free software project
that was launched in 1983 by Richard Stallman. The goal of the
GNU project is to provide a complete operating system made
entirely of free software, meaning that users have the freedom to
run, study, modify, and share the software.