Skip to content
Memory corruption Write-up Advanced

Bypassing open_basedir and disable_functions by Using PHP Use-After-Free Vulnerability

A use-after-free in PHP's unserialize handling (CVE-2015-0231) lets an attacker forge a zval object to gain arbitrary memory read and write. The author uses this to overwrite the GOT entry of popen with the address of rename, so a call to rename executes a shell command, bypassing open_basedir and disable_functions.

blog.orange.tw

Published on blog.orange.tw

主要參考 PoC 來源

The author, on blog.orange.tw

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 a use-after-free in PHP's unserialize where a serialized reference points at an object that has already been freed, leaving a dangling zval that can be forged.

Impact

An attacker with code execution inside PHP could bypass open_basedir and disable_functions and run shell commands; on Apache with libphp the address must first be brute-forced, which floods error.log with segmentation faults.

What the attacker needed

PHP 5.6 < 5.6.5, 5.5 < 5.5.21, 5.4 < 5.4.36; ability to run PHP code on the target; for remote, brute-force the image base

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.

PHP has a feature called unserialize that rebuilds objects from text, and a bug there let a crafted input free an object while a reference to it still existed. That dangling reference could then be abused to read and write the program's memory, which the author turns into running a shell command. This defeats two common PHP restrictions meant to stop a hacked site from touching the rest of the server.

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.