Skip to content
Memory corruption Write-up Advanced

Exploiting Memory Corruption Bugs in PHP Part 3: Popping Remote Shells

The post describes how to turn a PHP unserialize memory-corruption primitive into remote code execution by locating internal symbols and ROP gadgets, then writing a crafted stack layout via multipart form data. An attacker who can reach the vulnerable unserialize endpoint could execute arbitrary PHP code and pop a remote shell.

inulledmyself.com

Published on inulledmyself.com

This took longer than expected, but it's a journey worth taking! This is less descriptive than other blog posts, because I'd like to try the video format out once.

The author, on inulledmyself.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

Impact

An attacker able to reach the unserialize endpoint could execute arbitrary PHP code on the server, though the author notes the first ROP method only affects older PHP versions with the same gadgets.

What the attacker needed

Reachable unserialize endpoint; attacker controls base64 input; knowledge of target PHP binary layout

How it was found

  1. Send base64-encoded serialized data to the page so PHP unserializes it.
  2. Locate the addresses of zend_eval_string, executor_globals and the bailout JMP_BUF in the PHP binary.
  3. Use a multipart/form-data POST to place a crafted stack layout in a stack buffer that PHP does not fully overwrite.
  4. Include the required SPLObjectStorage object so the ROP gadgets work without crashing PHP.
  5. For newer PHP, crack the PTR_MANGLE-obfuscated registers in the jmp_buf and free/write memory via SPLObjectStorage to build the stack.
  6. Trigger the exploit so PHP calls zend_eval_string with attacker PHP code.

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.

The app takes data from a web request, decodes it and hands it to PHP's unserialize function, which can be tricked into corrupting memory. The author then shows how to use that corruption to redirect the program into PHP's own code-execution function, so the attacker's PHP code runs on the server. This is advanced exploitation, not a simple web bug.

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.