Arming The Use After Free
The article explains use-after-free vulnerabilities using a simple C program where a freed pointer is reused, and a challenge program where freeing username and password chunks without nulling pointers allows an attacker to overwrite the username with 'root' and gain a shell.
Published on infosecwriteups.com
Let’s continue with our heap exploitation series. If you are new to this please go through the previous article.
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
The program frees memory but does not set the pointers to NULL, so they still point to the freed chunks and can be reused.
Impact
An attacker could overwrite the username with 'root' and execute a shell, as demonstrated in the challenge.
What the attacker needed
Local program execution
The fix
The pointers should be set to NULL after freeing to prevent use-after-free.
How it was found
- Use option 1 to allocate a chunk for storing the username.
- Use option 2 to allocate a chunk for storing the password.
- Free the chunks using option 3.
- Use option 2 to allocate a password chunk so that it can rewrite the contents of the previously allocated username chunk.
- Use option 4 to log in and get the shell.
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.
A use-after-free bug happens when a program frees a piece of memory but keeps using it. In the challenge, the program frees the username and password but still uses the old pointers, so an attacker can make the username become 'root' and get a shell.
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.