Skip to content

Commit 8bf6a34

Browse files
committed
Fix empty session ID and cleanup
- Fixed handling of empty session IDs for those commands that required them - Added help text for ranges with examples
1 parent 2bec646 commit 8bf6a34

File tree

1 file changed

+14
-5
lines changed
  • lib/msf/ui/console/command_dispatcher

1 file changed

+14
-5
lines changed

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

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1569,6 +1569,10 @@ def cmd_sessions_help
15691569
print_line
15701570
print_line "Active session manipulation and interaction."
15711571
print(@@sessions_opts.usage)
1572+
print_line
1573+
print_line "Many options allow specifying session ranges using commas and dashes."
1574+
print_line "For example: sessions -s checkvm -i 1,3-5 or sessions -k 1-2,5,6"
1575+
print_line
15721576
end
15731577

15741578
#
@@ -1608,12 +1612,12 @@ def cmd_sessions(*args)
16081612
method = 'list'
16091613
when "-k"
16101614
method = 'kill'
1611-
sid = val if val
1615+
sid = val || false
16121616
when "-K"
16131617
method = 'killall'
16141618
when "-d"
16151619
method = 'detach'
1616-
sid = val
1620+
sid = val || false
16171621
# Run a script on all meterpreter sessions
16181622
when "-s"
16191623
unless script
@@ -1623,7 +1627,7 @@ def cmd_sessions(*args)
16231627
# Upload and exec to the specific command session
16241628
when "-u"
16251629
method = 'upexec'
1626-
sid = val
1630+
sid = val || false
16271631
# Reset the ring buffer read pointer
16281632
when "-r"
16291633
reset_ring = true
@@ -1641,7 +1645,7 @@ def cmd_sessions(*args)
16411645
method = 'interact'
16421646
end
16431647

1644-
unless sid.blank? || method == 'interact'
1648+
unless sid.nil? || method == 'interact'
16451649
session_list = build_range_array(sid)
16461650
if session_list.blank?
16471651
print_error("Please specify valid session identifier(s)")
@@ -1662,8 +1666,13 @@ def cmd_sessions(*args)
16621666
else
16631667
sessions = framework.sessions.keys.sort
16641668
end
1669+
if sessions.blank?
1670+
print_error("Please specify valid session identifier(s) using -i")
1671+
return false
1672+
end
16651673
sessions.each do |s|
1666-
session = framework.sessions.get(s)
1674+
session = verify_session(s)
1675+
next unless session
16671676
print_status("Running '#{cmd}' on #{session.type} session #{s} (#{session.session_host})")
16681677

16691678
if session.type == 'meterpreter'

0 commit comments

Comments
 (0)