@@ -1569,6 +1569,10 @@ def cmd_sessions_help
1569
1569
print_line
1570
1570
print_line "Active session manipulation and interaction."
1571
1571
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
1572
1576
end
1573
1577
1574
1578
#
@@ -1608,12 +1612,12 @@ def cmd_sessions(*args)
1608
1612
method = 'list'
1609
1613
when "-k"
1610
1614
method = 'kill'
1611
- sid = val if val
1615
+ sid = val || false
1612
1616
when "-K"
1613
1617
method = 'killall'
1614
1618
when "-d"
1615
1619
method = 'detach'
1616
- sid = val
1620
+ sid = val || false
1617
1621
# Run a script on all meterpreter sessions
1618
1622
when "-s"
1619
1623
unless script
@@ -1623,7 +1627,7 @@ def cmd_sessions(*args)
1623
1627
# Upload and exec to the specific command session
1624
1628
when "-u"
1625
1629
method = 'upexec'
1626
- sid = val
1630
+ sid = val || false
1627
1631
# Reset the ring buffer read pointer
1628
1632
when "-r"
1629
1633
reset_ring = true
@@ -1641,7 +1645,7 @@ def cmd_sessions(*args)
1641
1645
method = 'interact'
1642
1646
end
1643
1647
1644
- unless sid . blank ? || method == 'interact'
1648
+ unless sid . nil ? || method == 'interact'
1645
1649
session_list = build_range_array ( sid )
1646
1650
if session_list . blank?
1647
1651
print_error ( "Please specify valid session identifier(s)" )
@@ -1662,8 +1666,13 @@ def cmd_sessions(*args)
1662
1666
else
1663
1667
sessions = framework . sessions . keys . sort
1664
1668
end
1669
+ if sessions . blank?
1670
+ print_error ( "Please specify valid session identifier(s) using -i" )
1671
+ return false
1672
+ end
1665
1673
sessions . each do |s |
1666
- session = framework . sessions . get ( s )
1674
+ session = verify_session ( s )
1675
+ next unless session
1667
1676
print_status ( "Running '#{ cmd } ' on #{ session . type } session #{ s } (#{ session . session_host } )" )
1668
1677
1669
1678
if session . type == 'meterpreter'
0 commit comments