Reverse Engineering Function Call In C And Exploiting It
The article explains how a C function's return address on the stack can be overwritten via a pointer to skip an assignment, altering program flow. It demonstrates this with a local example, not a real-world vulnerability.
Published on infosecwriteups.com
In today’s digital age, companies are spending more and more money to secure their infrastructure from cyber attacks. But the truth is, it’s not a question of if you’ll be hacked, it’s when.
The full write-up lives on its author's site
It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the program allows a pointer to be created to the return address on the stack and its value modified, because the code does not prevent such access.
Impact
An attacker could alter the program's control flow, potentially leading to arbitrary code execution, though the article notes such attacks are usually easily detected and prevented.
What the attacker needed
Local access to compile and run the program; ability to use GDB
How it was found
- Compile the C program with stack protector disabled and debug symbols.
- Use GDB to find the memory address of buffer1 and the frame pointer (BP).
- Calculate the offset between buffer1 and BP, then add the size of BP to get the return address location.
- Disassemble main to find the byte offset to skip the assignment line.
- Modify the return address value via the pointer to jump over the assignment.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
When a program calls a function, it saves a return address on the stack so it knows where to continue afterwards. If an attacker can change that saved address, they can make the program jump to a different place. This article shows a simple example of doing that in a local C program.
What is Memory corruption?
Native code reads or writes memory it should not: overflows, use-after-free, type confusion. The core of browser, kernel and parser bugs.