Repot 13
Repot 13
VULNERABILITY MANAGEMENT
BOGOTÁ D.C.
2025
Introduction
Buffer overflow vulnerabilities remain one of the most critical and persistent security
flaws in software development, enabling attackers to hijack program execution,
escalate privileges, and compromise systems. Despite being a well-documented issue
for decades, buffer overflows continue to appear in modern software due to improper
memory handling and the use of unsafe functions. This report documents a hands-on
exploitation exercise where a deliberately vulnerable C program was analyzed and
exploited using a classic stack-based buffer overflow attack.
The objective of this exercise was to demonstrate how an attacker can manipulate
memory corruption vulnerabilities to redirect program execution to a malicious or
unintended function—in this case, a predefined win() function designed to simulate
arbitrary code execution. The process involved reverse-engineering the binary to locate
key memory addresses, determining the precise buffer offset needed to overwrite the
return address, and crafting a payload that successfully hijacked the program’s control
flow.
This report details the methodology, tools, and techniques used, including static
analysis with readelf, dynamic testing with debuggers, and payload construction
using Python. Additionally, it discusses the security weaknesses that made the exploit
possible, such as the absence of stack protections (e.g., canaries, ASLR, NX bit) and
the use of vulnerable functions like gets(). Finally, the report provides mitigation
strategies to prevent such attacks in real-world applications, emphasizing secure
coding practices and modern compiler protections.
The critical vulnerability was in the vuln() function, which used the unsafe gets()
function to read user input without any bounds checking, making it susceptible to
buffer overflow attacks.
The tester first ran the program with normal input to observe its behavior:
This revealed that the program displayed the return address after processing input,
which would be valuable for crafting the exploit.
To determine the exact offset needed to overwrite the return address, the tester used a
pattern generation tool. The generated pattern was then fed into the program under a
debugger (GDB) to identify the exact offset where the return address was overwritten.
The tester examined the binary to find the address of the win() function:
This revealed the memory address of the win() function (for example, 0x080491c2),
which would be used to overwrite the return address.
Using the information gathered, the tester constructed an exploit string consisting of:
1. Enough characters to fill the buffer and reach the return address (determined to
be 44 bytes)
2. The address of the win() function in little-endian format
Buffer overflow 1
The target program (vuln) contained similar components to the first exercise but with
different memory addresses:
readelf -s vuln
Through systematic testing with increasing input sizes, the tester identified that:
This was confirmed by observing program crashes with different input lengths and
analyzing core dumps in GDB.
Key points:
• 44 "A" characters to fill the buffer and reach the return address
• Little-endian format of the win() function address (0x08049166 →
\x66\x91\x04\x08)
• The null byte problem was avoided as the address didn't contain any
Dmesg
file vuln
readelf -s vuln
The readelf -s vuln output reveals critical information about the binary's symbol table.
Of particular importance is entry 63, which shows the win() function located at memory
address 0x08049166. This address becomes the target for our buffer overflow attack,
as redirecting execution to this function will display the flag. The output also confirms
the binary is linked against standard C library functions (like setvbuf and fopen),
suggesting it was compiled without special hardening measures.
dentified the target address to which the execution should jump, given as 0x080491f6.
Since the machine architecture follows little-endian format, the student converted this
address into its corresponding byte sequence: \xf6\x91\x04\x08. This conversion is
crucial because little-endian systems store the least significant byte first.
To craft the payload, the student used a Python interactive shell (python3) and
generated a string composed of 44 "A" characters followed by the address bytes.
This produced the expected payload, which the student then used as input for the
vulnerable program. Next, the student executed the vulnerable binary (./vuln) and
provided the crafted string as input. Upon entering the payload, the program responded
with:
However, this jump was incorrect, resulting in a segmentation fault. The incorrect jump
indicated that the payload was either misaligned or improperly formatted.
To investigate further, the student verified the structure of the payload using a small
Python script that outputs the raw binary data. Piping the output to the xxd tool
confirmed the correct layout. The output showed a sequence of '41' bytes (representing
"A") followed by the correct address bytes f6 91 04 08, ensuring that the payload was
properly constructed. Finally, the student tested the corrected payload by piping it
directly into the vulnerable binary
This time, the output indicated that the execution correctly jumped to 0x080491f6, as
intended. The final message showed that the exploit was successful, with the program
requesting a flag.txt file to proceed further.
Conclutions
[5] M. Howard and D. LeBlanc, Writing Secure Code, 2nd ed. Redmond, WA: Microsoft
Press, 2003.
[6] P. Ször, The Art of Computer Virus Research and Defense, Upper Saddle River, NJ:
Addison-Wesley, 2005.
[7] "IEEE Standard for Secure Coding," *IEEE Std 2600.2™-2022*, 2022, doi:
10.1109/IEEESTD.2022.9719438.
[8] D. Evans and D. Larochelle, "Improving Security Using Extensible Lightweight Static
Analysis," IEEE Software, vol. 19, no. 1, pp. 42-51, Jan. 2002, doi: 10.1109/52.976940.
[11] "OWASP Top 10:2021 – A03: Injection," Open Web Application Security Project,
2021. [Online]. Available: https://owasp.org/Top10/A03_2021-Injection/
[12] NIST, Secure Software Development Framework (SSDF), NIST SP 800-218, Feb.
2022. [Online]. Available: https://csrc.nist.gov/publications/detail/sp/800-218/final