LFI via /proc/self/environ and other /proc entries
LFI via /proc/self/environ abuses the Linux proc filesystem, where /proc/self/environ exposes the including process's environment — including the attacker-controlled User-Agent on many CGI setups. Injecting PHP into that header and then including /proc/self/environ executes it; other /proc entries (cmdline, fd, status) leak information useful for escalation. It needs only a readable /proc and an LFI.
How it works
On Linux, /proc/self/ reflects the process doing the reading. /proc/self/environ lists that process's environment variables as NUL-separated KEY=value pairs.
In CGI/FastCGI configurations the request's User-Agent is placed into the HTTP_USER_AGENT environment variable. An attacker sends <?php system($_GET['c']); ?> as the User-Agent, then includes /proc/self/environ; the included content contains the PHP, which executes. This mirrors log poisoning but uses the environment instead of a log file.
Even without execution, /proc is an information-disclosure goldmine: /proc/self/cmdline reveals how the app was launched (and secrets passed as arguments), /proc/self/status and /proc/self/maps expose runtime details, and /proc/<pid>/fd/<n> can read open files including deleted ones. These aid further exploitation.
When it works and when it fails
Works when
- A Linux target with a readable /proc and user input reaching include/require.
- For RCE: a CGI/FastCGI setup that puts the User-Agent into the process environment (modern php-fpm often does not).
- The web-server user can read /proc/self/* (usually true for its own process).
Fails when
- Non-Linux targets, or hardened hosts where /proc is restricted (hidepid) / out of read scope.
- Modern php-fpm where the User-Agent does not land in /proc/self/environ, so only info disclosure remains.
- Input allowlisted so /proc paths can never be included.
Representative payloads
Adapt these to your authorized target; they are shown in canonical form. Payloads are never translated.
../../../../proc/self/environLinux / UnixNo filterIncludes the process environment; after sending PHP in the User-Agent, the injected code executes. ?c=id then runs commands.
Note: Inject via header: User-Agent: <?php system($_GET['c']); ?>
../../../../proc/self/cmdlineLinux / UnixNo filterDiscloses the exact command line that started the process — arguments sometimes contain credentials or config paths.
../../../../proc/self/fd/10Linux / UnixNo filterReads an open file descriptor of the process; iterating fd numbers can reveal logs, sockets, or deleted files still held open.
../../../../proc/self/statusLinux / UnixNo filterLeaks process UID/GID, capabilities and limits — useful reconnaissance for privilege escalation.
Detection
In logs
- Inclusion of /proc/self/* or /proc/<pid>/* paths in file parameters.
- User-Agent (or other logged headers) containing <?php when /proc/self/environ is being probed.
- Sequential reads across /proc/self/fd/<n> indicating fd enumeration.
In code
- User input reaching include/require on a Linux host with /proc readable.
- CGI/FastCGI configuration exposing request headers as environment variables.
- No allowlist between the request and the include target.
Detection rule: Alert on /proc/self/(environ|cmdline|fd|status|maps) in request parameters; correlate environ reads with PHP-laden headers for RCE intent.
Remediation
- Never pass user input to include/require; resolve a key through an allowlist to fixed local files.
- Confine the process with open_basedir, a chroot, or a container so /proc and other sensitive paths are not readable.
- Prefer php-fpm over classic CGI and avoid reflecting request headers into the environment unnecessarily.
- Run with least privilege and keep secrets out of command-line arguments and environment variables where feasible.
Vulnerable (php)
include($_GET['page']); // ../../proc/self/environFixed
// php.ini: open_basedir = /var/www/app
$pages = ['home' => 'home.php', 'status' => 'status.php'];
$key = (string) ($_GET['page'] ?? 'home');
if (!isset($pages[$key])) { http_response_code(404); exit; }
include __DIR__ . '/pages/' . $pages[$key];An allowlist keeps /proc paths out of include; open_basedir confines reads as defence in depth.
FAQ
- Does /proc/self/environ still give RCE on modern PHP?
- Often not — many php-fpm setups no longer place the User-Agent into the process environment, so execution fails. The /proc entries remain valuable for information disclosure and escalation reconnaissance.