Phpinfo() Type Confusion Infoleak Vulnerability and SSL Private Keys
The phpinfo() function read the PHP_SELF, PHP_AUTH_TYPE, PHP_AUTH_USER and PHP_AUTH_PW variables from the symbol table and printed them as strings without checking their actual type. By setting one of these variables to an integer, a PHP script could make phpinfo() treat that integer as a string pointer and read arbitrary process memory, which on PHP 5.3 allowed leaking the server's private SSL RSA key.
sektioneins.de
Published on sektioneins.de
A vulnerability in PHP's phpinfo() function allows PHP scripts to read arbitrary strings from memory.
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 type confusion: php_print_info() fetched variables from the symbol table and passed them to the string-printing helper via Z_STRVAL_PP without verifying that the zval's type was actually a string.
Impact
On PHP 5.3 an attacker with the ability to run a PHP script could leak arbitrary binary memory and recover the server's private SSL RSA key; on PHP 5.4 and 5.5 the forced UTF-8 escaping stripped invalid bytes, so only valid string content could be leaked and the leak was unusable for sensitive binary data.
What the attacker needed
Ability to run a PHP script on the server; PHP 5.3 for binary key leak; guessable heap address
How it was found
- Set one of the affected variables, such as PHP_SELF, to an integer that acts as a memory address.
- Call phpinfo() with the INFO_VARIABLES flag so the variable is printed.
- Read the leaked bytes back from the generated output, decoding HTML entities and handling the 'no value' case.
- Repeat with increasing addresses to scan the Apache heap for the RSA key structure.
- Download the recovered DER-encoded private key.
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 stores every variable in a small tagged container, and the tag says whether the value is a number, a string, a list and so on. The phpinfo() page assumed certain variables were always strings and read the string pointer field even when the value was really a number, so the number was used as a memory address. A script could then walk through the web server's memory and pull out secrets such as the private key used for HTTPS.
What is Info disclosure?
Data the application should keep private (personal data, internal details, other users' records) reaches someone it should not.