Local and remote file inclusion
Local file inclusion (LFI) vulnerabilities allow an attacker to read local files on the web server using malicious web requests, such as:
Web configuration files
Log files
Password files
Other sensitive system data
LFI can also be used for remote code execution (RCE). In most cases, this is due to poor or missing input sanitization.
Remote file inclusions are similar, but the attacker is taking advantage of the web server's ability to call local files, and using it to upload files from remote servers. These remote files can be malicious code that executes in the context of the web server user (e.g. www-data).
Techniques
Basic
Assuming you are on a Linux system, test if you can display /etc/passwd
by moving back 5 directory levels:
Even if this doesn't work, it doesn't mean that the website is immune to path traversal. When filtering input, developers will often prevent the use of forward slashes, but not backslashes or encoded characters.
wget
Sometimes browsers mess around with basic directory traversal sequences, but wget
may work:
Nesting traversal sequences
If the application is attempting to sanitize user input by removing traversal sequences, but does not apply this filter recursively, then it may be possible to bypass the filter by placing one sequence within another:
URL-encoded
Encoding all the slashes and dots in your path traversal could bypass input filters:
Example:
Double URL-encoded
Another encoding method:
Example:
Overlong UTF-8 encoding
You can also use the illegal Unicode payload type in Burp Intruder for this technique:
Null-byte injection
Some applications check whether the user-supplied file name ends in a particular file type or set of file types, and reject attempts to access anything else. A null byte terminator (%00
or 0x00
in hex) added to the LFI/RFI parameter will stop processing immediately, so that any bytes following it are ignored.
In the following code example, the extension .php
added to the file request variable $file
:
Requesting /etc/passwd
in this case will not work because the request becomes passwd.php
resulting in a 404 error. However, if we add a null byte to the passwd file name it will terminate at the end of passwd
and discard the remaining bytes:
proc/self/environ method
If you're able to request /proc/self/environ
using LFI, you might be able to get a shell by downloading a remote file with reverse shellcode and run it on the system (e.g. php reverse shell). You'll need to intercept the /proc/self/environ
request and replace HTTP request header User Agent
with the following:
Then execute the shell by calling the URL where it was uploaded:
Interesting files
If an LFI vulnerability exists, look for these files:
Linux
Linux system and user files:
Log files
Potentially interesting logfiles:
CMS configuration files
If there is a web server, always check /var/www/html
for interesting files, including robots.txt
in the root web folder.
Content management system configuration files:
Windows
Files that may exist on Windows systems:
The system and SAM files might be in different locations. As well, the path might be case-sensitive, even though it's Windows.
Further reading
Last updated