@@ -47,7 +47,7 @@ class Core
47
47
"-q" => [ false , "Quiet mode" ] ,
48
48
"-k" => [ true , "Terminate sessions by session ID and/or range" ] ,
49
49
"-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" ] ,
51
51
"-r" => [ false , "Reset the ring buffer for the session given with -i, or all" ] ,
52
52
"-u" => [ true , "Upgrade a shell to a meterpreter session on many platforms" ] ,
53
53
"-t" => [ true , "Set a response timeout (default: 15)" ] ,
@@ -1180,10 +1180,10 @@ def cmd_sessions(*args)
1180
1180
sid = val || false
1181
1181
when "-K"
1182
1182
method = 'killall'
1183
- # Run a script on all meterpreter sessions
1183
+ # Run a script or module on specified sessions
1184
1184
when "-s"
1185
1185
unless script
1186
- method = 'scriptall '
1186
+ method = 'script '
1187
1187
script = val
1188
1188
end
1189
1189
# Upload and exec to the specific command session
@@ -1389,15 +1389,11 @@ def cmd_sessions(*args)
1389
1389
sid = nil
1390
1390
end
1391
1391
end
1392
- when 'scriptall '
1392
+ when 'script '
1393
1393
unless script
1394
- print_error ( "No script specified!" )
1394
+ print_error ( "No script or module specified!" )
1395
1395
return false
1396
1396
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
-
1401
1397
sessions = sid ? session_list : framework . sessions . keys . sort
1402
1398
1403
1399
sessions . each do |sess_id |
@@ -1413,15 +1409,13 @@ def cmd_sessions(*args)
1413
1409
session . response_timeout = response_timeout
1414
1410
end
1415
1411
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 } " )
1425
1419
end
1426
1420
ensure
1427
1421
if session . respond_to? ( :response_timeout ) && last_known_timeout
0 commit comments