Skip to content

Commit 31042d4

Browse files
committed
Land rapid7#9324, AutoRunScript with resource scripts
2 parents 32c4860 + 3339c3b commit 31042d4

File tree

3 files changed

+15
-15
lines changed

3 files changed

+15
-15
lines changed

lib/msf/base/sessions/meterpreter.rb

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -302,11 +302,15 @@ def desc
302302
##
303303
# :category: Msf::Session::Scriptable implementors
304304
#
305-
# Runs the meterpreter script in the context of a script container
305+
# Runs the Meterpreter script or resource file
306306
#
307307
def execute_file(full_path, args)
308-
o = Rex::Script::Meterpreter.new(self, full_path)
309-
o.run(args)
308+
# Infer a Meterpreter script by it having an .rb extension
309+
if File.extname(full_path) == ".rb"
310+
Rex::Script::Meterpreter.new(self, full_path).run(args)
311+
else
312+
console.load_resource(full_path)
313+
end
310314
end
311315

312316

lib/msf/base/sessions/scriptable.rb

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -164,13 +164,17 @@ def execute_script(script_name, *args)
164164
else
165165
full_path = self.class.find_script_path(script_name)
166166

167-
# No path found? Weak.
168167
if full_path.nil?
169168
print_error("The specified script could not be found: #{script_name}")
170-
return true
169+
return
170+
end
171+
172+
begin
173+
execute_file(full_path, args)
174+
framework.events.on_session_script_run(self, full_path)
175+
rescue StandardError => e
176+
print_error("Could not execute #{script_name}: #{e.class} #{e}")
171177
end
172-
framework.events.on_session_script_run(self, full_path)
173-
execute_file(full_path, args)
174178
end
175179
end
176180

lib/msf/ui/console/driver.rb

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -313,8 +313,6 @@ def load_resource(path)
313313
return
314314
end
315315

316-
self.active_resource = resource_file
317-
318316
# Process ERB directives first
319317
print_status "Processing #{path} for ERB directives."
320318
erb = ERB.new(resource_file)
@@ -362,8 +360,6 @@ def load_resource(path)
362360
run_single(line)
363361
end
364362
end
365-
366-
self.active_resource = nil
367363
end
368364

369365
#
@@ -507,10 +503,6 @@ def on_variable_unset(glob, var)
507503
# The active session associated with the driver.
508504
#
509505
attr_accessor :active_session
510-
#
511-
# The active resource file being processed by the driver
512-
#
513-
attr_accessor :active_resource
514506

515507
def stop
516508
framework.events.on_ui_stop()

0 commit comments

Comments
 (0)