3
3
module Msf
4
4
module Exploit ::FileDropper
5
5
6
+ include Msf ::Post ::Common
7
+ include Msf ::Post ::File
8
+
6
9
def initialize ( info = { } )
7
10
super
8
11
@@ -22,6 +25,8 @@ def initialize(info = {})
22
25
def on_new_session ( session )
23
26
super
24
27
28
+ @session = session
29
+
25
30
if session . type == "meterpreter"
26
31
session . core . use ( "stdapi" ) unless session . ext . aliases . include? ( "stdapi" )
27
32
end
@@ -32,6 +37,8 @@ def on_new_session(session)
32
37
33
38
@dropped_files . delete_if do |file |
34
39
win_file = file . gsub ( "/" , "\\ \\ " )
40
+ exists_before = check_file ( file , win_file )
41
+
35
42
if session . type == "meterpreter"
36
43
begin
37
44
# Meterpreter should do this automatically as part of
@@ -41,10 +48,9 @@ def on_new_session(session)
41
48
session . shell_command_token ( %Q|attrib.exe -r #{ win_file } | )
42
49
end
43
50
session . fs . file . rm ( file )
44
- print_good ( "Deleted #{ file } " )
45
- true
51
+ file_deleted? ( file , win_file , exists_before )
46
52
rescue ::Rex ::Post ::Meterpreter ::RequestError
47
- false
53
+ return false
48
54
end
49
55
else
50
56
win_cmds = [
@@ -59,8 +65,7 @@ def on_new_session(session)
59
65
# succeed. Doing it this way saves us an extra round-trip.
60
66
# Trick shared by @mihi42
61
67
session . shell_command_token ( "rm -f \" #{ file } \" >/dev/null ; echo ' & #{ win_cmds . join ( " & " ) } & echo \" ' >/dev/null" )
62
- print_good ( "Deleted #{ file } " )
63
- true
68
+ file_deleted? ( file , win_file , exists_before )
64
69
end
65
70
end
66
71
end
@@ -125,6 +130,39 @@ def cleanup
125
130
print_warning ( "This exploit may require manual cleanup of '#{ f } ' on the target" )
126
131
end
127
132
133
+ private
134
+
135
+ def session
136
+ @session
137
+ end
138
+
139
+ alias :client :session
140
+
141
+ def check_file ( file , win_file )
142
+ if session . platform =~ /win/
143
+ res = file_exist? ( win_file )
144
+ else
145
+ res = file_exist? ( file )
146
+ end
147
+
148
+ res
149
+ end
150
+
151
+ def file_deleted? ( file , win_file , exists_before )
152
+ if exists_before
153
+ if check_file ( file , win_file )
154
+ print_error ( "Unable to delete #{ file } " )
155
+ false
156
+ else
157
+ print_good ( "Deleted #{ file } " )
158
+ true
159
+ end
160
+ end
161
+
162
+ print_warning ( "Tried to delete #{ file } , unknown result" )
163
+ true
164
+ end
165
+
128
166
end
129
167
end
130
168
end
0 commit comments