Skip to content

Commit 73c9807

Browse files
committed
Add module support for sessions -s
1 parent 140955f commit 73c9807

File tree

1 file changed

+12
-18
lines changed
  • lib/msf/ui/console/command_dispatcher

1 file changed

+12
-18
lines changed

lib/msf/ui/console/command_dispatcher/core.rb

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class Core
4747
"-q" => [ false, "Quiet mode" ],
4848
"-k" => [ true, "Terminate sessions by session ID and/or range" ],
4949
"-K" => [ false, "Terminate all sessions" ],
50-
"-s" => [ true, "Run a script on the session given with -i, or all" ],
50+
"-s" => [ true, "Run a script or module on the session given with -i, or all" ],
5151
"-r" => [ false, "Reset the ring buffer for the session given with -i, or all" ],
5252
"-u" => [ true, "Upgrade a shell to a meterpreter session on many platforms" ],
5353
"-t" => [ true, "Set a response timeout (default: 15)" ],
@@ -1180,10 +1180,10 @@ def cmd_sessions(*args)
11801180
sid = val || false
11811181
when "-K"
11821182
method = 'killall'
1183-
# Run a script on all meterpreter sessions
1183+
# Run a script or module on specified sessions
11841184
when "-s"
11851185
unless script
1186-
method = 'scriptall'
1186+
method = 'script'
11871187
script = val
11881188
end
11891189
# Upload and exec to the specific command session
@@ -1389,15 +1389,11 @@ def cmd_sessions(*args)
13891389
sid = nil
13901390
end
13911391
end
1392-
when 'scriptall'
1392+
when 'script'
13931393
unless script
1394-
print_error("No script specified!")
1394+
print_error("No script or module specified!")
13951395
return false
13961396
end
1397-
script_paths = {}
1398-
script_paths['meterpreter'] = Msf::Sessions::Meterpreter.find_script_path(script)
1399-
script_paths['shell'] = Msf::Sessions::CommandShell.find_script_path(script)
1400-
14011397
sessions = sid ? session_list : framework.sessions.keys.sort
14021398

14031399
sessions.each do |sess_id|
@@ -1413,15 +1409,13 @@ def cmd_sessions(*args)
14131409
session.response_timeout = response_timeout
14141410
end
14151411
begin
1416-
if script_paths[session.type]
1417-
print_status("Session #{sess_id} (#{session.session_host}):")
1418-
print_status("Running script #{script} on #{session.type} session" +
1419-
" #{sess_id} (#{session.session_host})")
1420-
begin
1421-
session.execute_file(script_paths[session.type], extra)
1422-
rescue ::Exception => e
1423-
log_error("Error executing script: #{e.class} #{e}")
1424-
end
1412+
print_status("Session #{sess_id} (#{session.session_host}):")
1413+
print_status("Running #{script} on #{session.type} session" +
1414+
" #{sess_id} (#{session.session_host})")
1415+
begin
1416+
session.execute_script(script, *extra)
1417+
rescue ::Exception => e
1418+
log_error("Error executing script or module: #{e.class} #{e}")
14251419
end
14261420
ensure
14271421
if session.respond_to?(:response_timeout) && last_known_timeout

0 commit comments

Comments
 (0)