Skip to content
Info disclosure Write-up Advanced

PHP FILTER CHAINS: FILE READ FROM ERRORBASED ORACLE

The PHP file() function reads a file but does not print its content, so an attacker cannot directly see the file. By using a chain of php://filter conversions that cause a memory exhaustion error only when the first character of the file is not a hexadecimal digit, an attacker can build an error-based oracle to leak the file's contents character by character.

synacktiv.com

Published on synacktiv.com

Written by Rémi Matasse - 21/03/2023 - in Pentest - Download

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

Likely the application passes user-controlled input to a PHP file-reading function that does not output the file's content, and the php://filter wrapper allows chaining iconv and dechunk filters to create an error-based oracle that reveals file contents.

Impact

An attacker could read local files that are otherwise not displayed, but the attack may be defeated by frameworks that treat warnings as errors.

What the attacker needed

User-controlled input to a file-reading function; php://filter wrapper enabled; memory_limit set (default 128MB)

How it was found

  1. Use the iconv filter with an encoding that increases data size exponentially to trigger a memory error.
  2. Use the dechunk filter to determine the first character of the file based on the previous error.
  3. Use the iconv filter again with encodings having different byte ordering to swap remaining characters with the first one.
  4. Apply the UCS-4LE encoding multiple times to overflow the memory_limit.
  5. Combine dechunk and size bomb filters to create an oracle that triggers a memory error only when the first character is not hexadecimal.
  6. Use additional filters like convert.base64-encode and string.rot13 to narrow down the character value.

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.

Normally, if a website reads a file but never shows it to you, you cannot see what is inside. This research shows a clever trick: by making the server process the file through a series of filters that cause a crash only when the first character is a certain type, you can ask yes/no questions about the file's content. Repeating this for each character lets you slowly read the whole file, even though it is never printed.

What is Info disclosure?

Data the application should keep private (personal data, internal details, other users' records) reaches someone it should not.

Similar reports

View all

Same bug class and techniques, clearest first.

Information disclosure

The lesson behind this report.

Data the application should keep private (personal data, internal details, other users' records) reaches someone it should not.