File Inclusion/Path Traversal
Last updated
Was this helpful?
Last updated
Was this helpful?
Ability to include files and resources within the web page via parameters (not correctly programmed).
Test Local File Inclusion Vulnerabilities.
python3 liffy.py http://<DOMAIN>/?<PARAM>= <OPTIONS>
include()
/include_once()
✅
✅
✅
require()
/require_once()
✅
✅
❌
file_get_contents()
✅
❌
✅
fopen()
/file()
✅
❌
❌
Files to try to read:
Linux: /etc/passwd
Windows: C:\Windows\boot.ini
It is possible to try different payloads of , in particular .
....//....//....//
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
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)
Require allow_url_include
.
Allows you to include external data, including php code and execute it. Possibility to pass it the code as base64.
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.
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.
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>
If you include code that is interpreted and executed, but instead want to read the source, you can use and .
In this case we should upload a zip. Create a webshell to wrap a zip file and upload the zip, then access it via the in LFI. However, this wrapper is not enabled by default, and may not always work.
Similar result to the case with the ZIP, but via the wrapper.
They can change, see: