File Inclusion
This happens when a user can control the file that is being loaded on the server.
Local File Inclusion (LFI)
The server loads a local file.
Basic LFI and bypasses
URL encoding
One can try to URL encode the path either once or numerous times.
Filter bypasses
Remote File Inclusion (RFI)
The server loads a file which is hosted on another server.
RFI can only take place if allow_url_include
is turned on.
Basic RFI and bypasses
PHP wrappers
php://filter
PHP filters allow one to perform modification on data before it's being read by the server. Some of the techniques below can be used to bypass restrictions and filters set by the server.
data://
phar:// and phar deserialisation
A .phar
file is a PHP archive. One can upload such file and execute code when it is being loaded.
It contains metadata in a serialised format. When parsed on the server said metadata gets deserialised.
Even if the source code on the server is not using the eval
function, the following other methods will still invoke the vulnerability. file_get_contents()
,fopen()
,file()
,file_exists()
,md5_file()
,filemtime()
,filesize()
Exploitation
Pretend that this is the source code of the server.
This is the code that will make the phar file.
Magic bytes of JPG \xff\xd8\xff
have been added to the phar file to bypass file upload restrictions
Compile
pwned.phar
with:
References
Last updated