Skip to content

PHP filter chain RCE (code execution with no writable file)

PHP filter chain RCE abuses php://filter's ability to apply many conversion filters in sequence: by chaining iconv character-set conversions, an attacker makes the wrapper generate arbitrary bytes — a full PHP payload — entirely in memory, so include executes it with no writable file or log needed. It is the modern, config-light path from LFI to remote code execution.

Any OSRemote code executionPHP wrapper

How it works

php://filter can apply a list of filters to a resource. Certain iconv conversions both transform and prepend predictable bytes. By stacking hundreds of carefully ordered conversions, the output can be coerced to begin with attacker-chosen bytes.

A tool (the public php_filter_chain_generator) computes the exact sequence of convert.iconv.* steps that, applied to a trivial base resource, produce a chosen string such as <?php system($_GET[0]);?>. include then executes that generated content.

The key advantage over log poisoning or session inclusion: it needs no file the attacker can write, no known path, and no allow_url_include — only that user input reaches include/require and the iconv filters are available. The payloads are very long chains of convert.iconv.XXX.YYY steps.

When it works and when it fails

Works when

  • User input reaches include/require and the php://filter wrapper with convert.iconv.* filters is available.
  • iconv support is compiled in (the common default).
  • No allowlist constrains the include target.

Fails when

  • The php:// wrapper or convert.iconv filters are disabled.
  • Input is resolved through an allowlist so no filter string reaches include.
  • iconv is unavailable, or the include context is tightly sandboxed.

Representative payloads

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

  • php://filter/convert.iconv.UTF8.CSISO2022KR|convert.base64-encode|convert.iconv.UTF8.UTF7|…/resource=php://temp
    Any OSPHP wrapper

    Shape of a filter chain: dozens-to-hundreds of convert.iconv.* steps feeding a base resource. The full chain is machine-generated to emit a chosen PHP string.

    Note: Generate the complete chain with the public php_filter_chain_generator against your authorized target; it is too long to list verbatim.

  • resource=php://temp
    Any OSPHP wrapper

    The trivial base resource the chain operates on; the generated iconv steps build the payload bytes from it.

  • <?php system($_GET[0]);?>
    Any OSPHP wrapper

    The PHP string a chain is typically built to produce; once include runs it, ?0=id executes commands.

Detection

In logs

  • Very long php://filter parameters containing many convert.iconv.* segments separated by |.
  • resource=php://temp or resource=data:// at the end of a long filter chain.
  • Unusually large request URLs/parameters directed at a page/file endpoint.

In code

  • User input reaching include/require at all — the precondition for the whole class.
  • No allowlist between the request and the included path.
  • php://filter reachable for include contexts with iconv filters enabled.

Detection rule: Alert on php://filter parameters containing multiple convert.iconv. segments or exceeding a length threshold; the filter-chain signature is distinctive.

Remediation

  • Never pass user input to include/require; map a request key through an allowlist to a fixed local file. This defeats filter chains along with every other wrapper trick.
  • Disable the php:// wrapper (or at least convert.iconv/convert.* filters) for code paths that must take dynamic input.
  • Reject any input containing a URL scheme or the pipe character used to chain filters.
  • Keep least-privilege execution and disable_functions so that even successful code execution is contained.

Vulnerable (php)

include($_GET['page']); // php://filter/convert.iconv...|...

Fixed

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

Because the chain must reach include, an allowlist that never passes user input to include removes it.

FAQ

Why is filter-chain RCE so powerful compared with log poisoning?
It needs no writable file, no known file path, and not even allow_url_include — only that user input reaches include and iconv filters exist. The payload is generated entirely in memory by the conversion chain.

References