Skip to content

php://filter wrapper for source code disclosure

The php://filter wrapper source disclosure technique turns an LFI into a source-code reader: by wrapping the target in php://filter/convert.base64-encode/resource=..., the file is base64-encoded before it reaches include, so PHP returns the raw source as text instead of executing it. It is the standard way to exfiltrate server-side PHP (config, credentials, logic) through a file-inclusion bug.

Any OSSource code disclosureInformation disclosurePHP wrapper

How it works

If user input reaches include/require, pointing it at a .php file normally executes that file, revealing only its output — not its source. php:// is a PHP stream wrapper; php://filter applies conversion filters to a resource as it is read.

convert.base64-encode transforms the file's bytes to base64 while reading. Because base64 is not valid PHP, include emits it as plain text rather than running it. The attacker base64-decodes the response offline to recover the exact source, including database passwords and API keys in config files.

It reads any file the process can access, not just PHP, and chaining multiple filters (for example several iconv/convert steps) is the basis for the more advanced filter-chain RCE technique. For pure source disclosure, the base64 filter alone is enough.

When it works and when it fails

Works when

  • User input reaches include/require/file functions and the php:// wrapper is enabled (default unless restricted).
  • The target file is readable by the web-server user.
  • allow_url_include is not required — php://filter works on local resources regardless.

Fails when

  • php:// (or convert.* filters) are disabled via disable_functions / stream wrapper restrictions.
  • Input is resolved through an allowlist so no wrapper string reaches the file call.
  • open_basedir confines reads away from the target file.

Representative payloads

Adapt these to your authorized target; they are shown in canonical form. Payloads are never translated.

  • php://filter/convert.base64-encode/resource=index.php
    Any OSPHP wrapper

    Base64-encodes index.php so its source is returned instead of executed; decode offline to read the code.

  • php://filter/convert.base64-encode/resource=../config/database.php
    Any OSPHP wrapper

    Reads an application config file's source, typically exposing database credentials and secret keys.

  • php://filter/read=convert.base64-encode/resource=/etc/passwd
    Linux / UnixPHP wrapper

    The explicit read= form of the filter; also works on non-PHP files such as /etc/passwd.

  • php://filter/read=string.rot13/resource=index.php
    Any OSPHP wrapper

    ROT13 is a lighter obfuscation that likewise prevents execution; useful when base64 is filtered.

Detection

In logs

  • php://filter , convert.base64-encode , or read= strings in request parameters.
  • Responses containing long base64 blobs returned from a page/file parameter.
  • resource= pointing at source files (index.php, config, wp-config.php).

In code

  • User input reaching include/require/file_get_contents without wrapper restrictions.
  • No allowlist between the request and the included path.
  • php.ini leaving allow_url_include/wrappers permissive for include contexts.

Detection rule: Match php://filter and convert\.base64-encode in parameters; alert on outbound responses that are large base64 strings from a file endpoint.

Remediation

  • Resolve the request through an allowlist of keys to fixed includes; never pass user input to include/require.
  • Restrict stream wrappers: where dynamic includes are unavoidable, disallow the php:// wrapper for those code paths and keep allow_url_include off.
  • Reject any input containing a URL scheme (php://, data://, phar://, file://).
  • Store secrets outside the web root and outside readable config files (environment/secret manager) so a source read yields no credentials.

Vulnerable (php)

include($_GET['page']); // php://filter/.../resource=config.php

Fixed

$pages = ['home' => 'home.php', 'about' => 'about.php'];
$key = (string) ($_GET['page'] ?? 'home');
if (!isset($pages[$key])) { http_response_code(404); exit; }
include __DIR__ . '/pages/' . $pages[$key];

Mapping keys to fixed includes means a php://filter string can never reach include.

FAQ

Why does php://filter return source instead of running the file?
The convert.base64-encode filter encodes the file as it is read. Base64 text is not valid PHP, so include outputs it verbatim rather than executing it. Decoding the response reveals the original source.
Does it only work on PHP files?
No. It reads any file the process can access — /etc/passwd, logs, keys — but it is most valuable against PHP source because that is what you otherwise cannot read.

References