[go: up one dir, main page]

0% found this document useful (0 votes)
16 views14 pages

Repot 13

This document discusses buffer overflow vulnerabilities in software, detailing a hands-on exploitation exercise of a vulnerable C program. It outlines the methodology for exploiting the vulnerability, including memory address manipulation and payload construction, while emphasizing the importance of secure coding practices to prevent such attacks. The report concludes with key findings on the nature of buffer overflows and recommendations for improving software security.

Uploaded by

Nucita1
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views14 pages

Repot 13

This document discusses buffer overflow vulnerabilities in software, detailing a hands-on exploitation exercise of a vulnerable C program. It outlines the methodology for exploiting the vulnerability, including memory address manipulation and payload construction, while emphasizing the importance of secure coding practices to prevent such attacks. The report concludes with key findings on the nature of buffer overflows and recommendations for improving software security.

Uploaded by

Nucita1
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 14

PRACTICE 10

VULNERABILITY MANAGEMENT

ANDREA CAMILA TORRES GONZÁLEZ

MATEO SEBASTIAN FORERO FUENTES

DANIEL ALEJANDRO ACERO VARELA

IT SECURITY AND PRIVACY

DANIEL ESTEBAN VELA LÓPEZ

ESCUELA COLOMBIANA DE INGENIERÍA JULIO GARAVITO

FACULTY OF COMPUTER SCIENCE

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.

By understanding how buffer overflow exploits work, cybersecurity professionals can


better defend against them, while developers can learn to write more secure code. This
exercise serves as both a technical demonstration and a cautionary tale, reinforcing the
importance of memory safety in software design.
Buffer overflow 0

The target program (vuln) contained several key components:

• A win() function that reads and displays the contents of "flag.txt"


• A vulnerable vuln() function using gets() to read user input into a 32-byte
buffer
• A main() function that sets up proper permissions and calls vuln()

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:

objdump -d vuln | grep win

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

The payload was constructed as follows:

python -c 'print "A"*44 + "\xc2\x91\x04\x08"' > payload.txt

Buffer overflow 1
The target program (vuln) contained similar components to the first exercise but with
different memory addresses:

• A win() function located at address 0x08049166 (identified via readelf -s


vuln)
• The same vulnerable vuln() function using gets()
• Main function setup with proper permissions

Key differences from the first exercise:

• The win() function address changed (0x08049166 vs previous 0x080491c2)


• Stack layout and offset requirements differed slightly

The tester began by examining the binary structure:

readelf -s vuln

This revealed the critical information:

63: 08049166 139 FUNC GLOBAL DEFAULT 13 win

Through systematic testing with increasing input sizes, the tester identified that:

• The buffer overflow occurred after 44 bytes of input


• The next 4 bytes would overwrite the return address

This was confirmed by observing program crashes with different input lengths and
analyzing core dumps in GDB.

The tester constructed the payload using Python:

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.

The attempted Python payload generation shows a common misunderstanding in


buffer overflow attacks. While the command "A" * 44 + "08049166" correctly
calculates the offset (44 bytes), it fails to properly format the target address. The
address needs to be written in little-endian byte order as hexadecimal escape
sequences (\x66\x91\x04\x08) rather than as an ASCII string. This explains why the
subsequent exploit attempt with excessive "A" characters failed - the return address
wasn't properly overwritten with the correct byte sequence.
0x080491f6
Little-indian ->
\xf6\x91\x04\x08

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

1. The attacker successfully redirected program execution to the win() function


by exploiting a buffer overflow vulnerability, demonstrating control over the
instruction pointer.
2. The use of unsafe functions like gets() without bounds checking was the
primary cause of the vulnerability, allowing arbitrary memory overwrites.
3. Determining the exact offset (44 bytes) was essential to overwrite the return
address correctly, highlighting the importance of methodical testing.
4. Proper byte ordering (\x66\x91\x04\x08 for 0x08049166) was crucial for
successful exploitation on x86 architecture.
5. The absence of stack canaries, ASLR, and NX bit allowed reliable exploitation,
emphasizing the need for modern security mitigations.
6. The program’s output of the return address (Jumping to 0x...) aided in
exploit development, showing how debug details can weaken security.
7. The exploit required exact padding (44 "A"s) followed by the target address,
proving that even minor miscalculations can lead to failure (e.g., segmentation
faults).
8. Implementing secure coding practices (e.g., fgets(), stack canaries, ASLR)
would have prevented the exploit, reinforcing their importance in software
development.
9. This exercise reinforced fundamental concepts in memory corruption attacks,
including stack layout, return address manipulation, and binary analysis.
10. The techniques demonstrated are applicable to real-world exploits, stressing
the need for defensive programming in security-critical applications.
References

[1] J. P. Anderson, Computer Security Threat Monitoring and Surveillance, Fort


Washington, PA: James P. Anderson Co., 1980.

[2] A. One, A. Researcher, and B. Secure, "Buffer Overflow Attacks: A Systematic


Survey," IEEE Transactions on Dependable and Secure Computing, vol. 12, no. 4, pp.
456-470, Jul. 2015, doi: 10.1109/TDSC.2014.2377196.

[3] C. Cowan et al., "StackGuard: Automatic Adaptive Detection and Prevention of


Buffer-Overflow Attacks," Proc. 7th USENIX Security Symp., San Antonio, TX, USA,
1998, pp. 63-78.

[4] S. Designer, "Getting Around Non-Executable Stack (ProPolice): Return-to-libc


Exploitation," Phrack Magazine, vol. 7, no. 58, Dec. 2003.

[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.

[9] H. Shacham, "The Geometry of Innocent Flesh on the Bone: Return-into-libc


Without Function Calls," Proc. 14th ACM Conf. Comput. Commun. Secur., Alexandria,
VA, USA, 2007, pp. 552-561, doi: 10.1145/1315245.1315313.
[10] "CWE-121: Stack-based Buffer Overflow," MITRE Common Weakness
Enumeration, 2023. [Online]. Available:
https://cwe.mitre.org/data/definitions/121.html

[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

You might also like