Skip to content
RCE Write-up Advanced

$18,000 for a Serialized String in a Cookie: PHP Object Injection to Remote Code Execution

The application deserialized an attacker-controlled cookie using PHP's unserialize(), allowing reconstruction of arbitrary classes. A third-party logging library's destructor wrote attacker-chosen content to an attacker-chosen file path, enabling remote code execution.

T4nv1 Follow

Published on medium.com

I’d found Java deserialization bugs before, and my instinct going into this target was that the same mental model would transfer directly. It mostly did — the core idea of “an attacker-supplied object graph gets reconstructed and something dangerous happens during that reconstruction” holds across languages.

T4nv1, on medium.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 application called unserialize() on untrusted cookie data without restricting which classes could be reconstructed, and a dependency had a destructor that wrote to an unvalidated file path.

Impact

Full remote code execution on the application server, exploitable by anyone able to set a cookie value on an authenticated request, requiring no other vulnerability and no prior foothold beyond discovering the dependency manifest.

What the attacker needed

Authenticated request with a cookie; publicly accessible composer.lock; vulnerable logging library version

The fix

The application stopped deserializing the cookie with unserialize(), used an allowed_classes allowlist as a stopgap, migrated to a signed token format, and blocked public access to composer.lock.

How it was found

  1. Decode the rememberMe cookie from base64 to see PHP serialized object notation.
  2. Fetch the publicly accessible composer.lock file to list dependencies and versions.
  3. Read the public source of a logging library to find a destructor that writes to a property-controlled path.
  4. Hand-build a serialized object of that class with logPath set to a web-accessible .php file and logContent set to a PHP payload.
  5. Base64-encode the serialized string and replace the rememberMe cookie, then send an authenticated request.
  6. Request the written file with an inert command to confirm execution.

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 website stored a 'remember me' cookie that it decoded back into a PHP object. Because it trusted whatever object was in the cookie, an attacker could craft a cookie that made a logging library write a malicious PHP file to the server. Visiting that file then ran commands on the server.

What is RCE?

Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.

More by T4nv1

View all

113 more disclosed reports, best first.

Similar reports

View all

Same bug class and techniques, clearest first.

Remote code execution

The lesson behind this report.

Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.