File Inclusion/Path Traversal
Ability to include files and resources within the web page via parameters (not correctly programmed).
Tools
Test Local File Inclusion Vulnerabilities.
python3 liffy.py http://<DOMAIN>/?<PARAM>= <OPTIONS>
Functions
include()
/include_once()
✅
✅
✅
require()
/require_once()
✅
✅
❌
file_get_contents()
✅
❌
✅
fopen()
/file()
✅
❌
❌
Local File Inclusion (LFI)
Files to try to read:
Linux:
/etc/passwd
Windows:
C:\Windows\boot.ini
It is possible to try different payloads of SecLists, in particular LFI-Jhaddix.txt.
Bypassing Filters
....//....//....//
Regex
%2e%2e%2f%2e%2e%2f
Encoding (../../../../
)
%25%32%65%25%32%65%25%32%66
Double Encoding (../../../../
)
../../<FILE>%00.png
Null Byte (PHP <5.5)
<PATH>/../../<FILE>
Forced initial path
Read Source PHP
If you include code that is interpreted and executed, but instead want to read the source, you can use wrappers and filters.
In particular try to read the main PHP configuration file: php.ini
In this file you can see if allow_url_include
is enabled.
Is usually located in:
Apache :
/etc/php/X.Y/apache2/php.ini
Nginx:
/etc/php/X.Y/fpm/php.ini
Where X.Y
is the installed PHP version (try brute force)
RCE PHP
Require allow_url_include
.
Allows you to include external data, including php code and execute it. Possibility to pass it the code as base64.
Remote File Inclusion (RFI)
The file is loaded from a remote server.
In php this is disabled by default, require allow_url_include
.
In Windows, however, you can use SMB to enable the remote file without allowing_url_include
.
This is because Windows treats files on remote SMB servers as normal files, which can be referenced directly with a UNC path (//server/share/file
). This technique is more likely to work if we were on the same network, since access to remote SMB servers over the Internet may be disabled by default, depending on Windows server configurations.
RCE
If the included file is executed, a webshell can be created according to the language being used by the server and hosted by making it public. Then upload it via the RFI.
Possible to apply SSRF techniques , such as port scanning etc.
File Upload + LFI
If there is the presence of file uploads on the site (even non-vulnerable ones) combined with LFI with a function that executes, then it is possible to exploit the uploaded files to obtain RCE.
Insert a real image (ex. gif
) with simply a PHP piece containing the webshell inside.
Upload the file, get the path and use it in the LFI.
Log Poisoning
If the LFI functions have execution, you can try to poison the logs by injecting code (ex. php
) and then reading them through the LFI.
Cookies can contain user-specific information in the backend. Examine the log file via the LFI to see what information it contains, and whether it can be poisoned.
Linux:
/var/lib/php/sessions/sess_<PHPSESSID>
Windows:
C:\Windows\Temp\sess_<PHPSESSID>
Last updated