Skip to content
Memory corruption Write-up Intermediate

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.

Ajin Deepak Follow

Published on infosecwriteups.com

Let’s continue with our heap exploitation series. If you are new to this please go through the previous article.

Ajin Deepak (AD2001), on infosecwriteups.com

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

  1. Use option 1 to allocate a chunk for storing the username.
  2. Use option 2 to allocate a chunk for storing the password.
  3. Free the chunks using option 3.
  4. Use option 2 to allocate a password chunk so that it can rewrite the contents of the previously allocated username chunk.
  5. 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.

Similar reports

View all

Same bug class and techniques, clearest first.

Memory corruption

The lesson behind this report.

Native code reads or writes memory it should not: overflows, use-after-free, type confusion. The core of browser, kernel and parser bugs.