File Inclusion Vulnerabilities (LFI and RFI)
Difference between File Inclusion and Directory Traversal
Directory Traversal can obtain the contents of a file outside of the web server's web root. But not code execute
File Inclusion vulnerability allow to include a file in the application's running code
This means we can use file inclusion vulnerabilities to execute local or remote files, while directory traversal only allows us to read the contents of a file
LFI + Log Poisoning to get initial access (E.g.; THM- Dogcat Room)
1. Find the vulnerable parameter:
2. Modify the url with payload
3. Reading index.php file using php://filter warpper and decode the base64 string
Normally index.php is executed and not show output, So we use base 64 encode method to look PHP code on index page.
So here there are a couple of interesting things to note. First, there is a $ext variable which kept on appending a .php extension to our input accounting for the previous errors. Also as long as our input to view contains the string dog or cat , we are good to go. So now that we know a bit more about the source code at play , lets try some path traversal.
Finally I can read /etc/passwd
There were a lot of way to get RCE but most famous two are php wrapper and log poisoning technique
4. Log Poisoning
access apache2 log form LFI Vulnerable parameter check user agent parameter included in the log entry
Modify user agent parameter to inject PHP one liner and add cmd parameter in request
Add cmd parameter with command
Finally we got RCE
5. Getting Reverse shell using nc
Choose
/usr/share/webshell/php/php-reverse-shll.php
. Change IP and Port tonc
listenerBuild python http server
Type curl request in cmd parameter using RCE
Check nc listener and get reverse shell
PHP wrapper for LFI to RCE Transformation
please read the detail about PHP wrapper at following link
php://filter (case insensitive)
data://
expect://
input:// (Most Popular)
zip://, phar:// and any other wrapper are present
Last updated