Exploiting VSFTPD v2
Exploiting VSFTPD v2
4 on Metasploitable 2
Let’s have a look at the source code of the vulnerable version of VSFTPD v2.3.4 to see what the
backdoor looks like in the source code. Surprisingly the source code has not been obfuscated in any
way so we can easily read it and see how it is working. There is a copy of the vulnerable code available
on Pastebin by using the following link: http://pastebin.com/AetT9sS5. The following code validates the
user input on the username:
0x3a = :
0x29 = )
Line 37 and 38 check for user input containing hexadecimal chars 0x3a followed by 0x29 which
represents the smiley face :) characters. When the username contains both characters the else if
statement executes the vsf_sysutil_extra function. Let’s have a look at this function.
The ‘struct sockaddr_in sa’ on line 79 is a structure containing an internet address named sa. The
structure is defined by the sin_family which is set to the constant AF_INET, sin_port (6200) and the
client address set to any on line 83, 84 and 85. The code to follow uses the structure to setup a bind
socket and a listener process to listen on the socket for incoming connections. Note that this code is
run in the server context, so the server is setting up the bind socket and listener which is used by the
remote attacker for setting up a connection. Line 94 presents a shell to anyone connecting to the server
on port 6200.
USER user:)
PASS pass
Than use the escape character ^] or wait a few seconds. When we fire up nmap and scan for port
6200 we should see that the malicious code was executed and port 6200 is open:
When we issue the id command followed by a semicolon (;) we can see that the FTP services was
running as root and we have a root shell on the box. Let’s see how we can exploit this backdoor
vulnerability by using the Metasploit Framework.
msfconsole
When msfconsole is running select the backdoor exploit using the following command:
use exploit/unix/ftp/vsftpd_234_backdoor
Type the following command to have a look at the exploit options:
Show options
As we can see we only need to supply a remote host IP and a port which we leave to default on port
21. Now we can type run or exploit to exploit the target.