Finding A Pop Chain On A Common Symfony Bundle: Part 2
The article builds a PHP object injection (POP) chain against the widely used doctrine/doctrine-bundle package, chaining a file write through MockFileSessionStorage with a file inclusion through PhpArrayAdapter to achieve remote code execution. An attacker who can pass a crafted serialised string to unserialize() could write a PHP file and then include it, running arbitrary code on the server.
Published on synacktiv.com
Rédigé par Rémi Matasse - 11/10/2023 - dans Pentest - Téléchargement
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 the application unserialises attacker-controlled data while the installed doctrine/doctrine-bundle and Symfony classes contain magic methods (__destruct) that call file-writing and file-including code with attacker-controlled properties.
Impact
An attacker able to control data passed to unserialize could achieve arbitrary code execution on the server; the chain works on all doctrine/doctrine-bundle versions since 1.5.1, though the payload must be adapted to the target PHP version.
What the attacker needed
Attacker controls data passed to unserialize; vulnerable bundle installed; payload matched to PHP version
How it was found
- Create a CacheAdapter object with a non-empty deferredItems array so its destructor reaches commit.
- Set the cache property to a MockFileSessionStorage with started, savePath, id, data and a MetadataBag so save writes a .mocksess file containing PHP code.
- Create a second CacheAdapter whose cache is a PhpArrayAdapter with file pointing at the written file and an expired item so delete triggers inclusion.
- Combine both objects in one serialised array and use fast destruct so both destructors run.
- Unserialise the payload and observe the injected PHP code executing.
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.
Some PHP applications turn untrusted text back into objects using a function called unserialize. If the classes loaded in the app have dangerous methods that run automatically when an object is destroyed, an attacker can chain them together so that simply supplying crafted text leads to code running on the server. This article shows such a chain in a very common Symfony package.
What is RCE?
Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.