diff --git a/lib/msf/ui/console/command_dispatcher/core.rb b/lib/msf/ui/console/command_dispatcher/core.rb index 8ae36d1a4f0d7..ee7db4e1da851 100644 --- a/lib/msf/ui/console/command_dispatcher/core.rb +++ b/lib/msf/ui/console/command_dispatcher/core.rb @@ -1548,9 +1548,23 @@ def cmd_sessions(*args) print_error("No command specified!") return false end + if search_term + matching_sessions = [] + terms = search_term.split + terms.each do |term| + matching_session = filter_sessions_by_search(term) + matching_sessions << matching_session.to_i if matching_session + end + if matching_sessions == [] + print_error("No matching sessions.") + return + end + end cmds.each do |cmd| if sid sessions = session_list + elsif matching_sessions + sessions = matching_sessions else sessions = framework.sessions.keys.sort end @@ -1664,7 +1678,12 @@ def cmd_sessions(*args) matching_sessions = [] terms = search_term.split terms.each do |term| - matching_sessions << filter_sessions_by_search(term) if filter_sessions_by_search(term) + matching_session = filter_sessions_by_search(term) + matching_sessions << matching_session if matching_session + end + if matching_sessions == [] + print_status("No matching sessions.") + return end end print_status("Killing all sessions...") @@ -1862,18 +1881,24 @@ def evaluate_search_criteria(session, search_term) end def parse_duration(duration) - case duration - when /(\d+)d/ - return $1.to_i * 86400 - when /(\d+)h/ - return $1.to_i * 3600 - when /(\d+)m/ - return $1.to_i * 60 - when /(\d+)s/ - return $1.to_i - else - return 0 + total_time = 0 + time_tokens = duration.scan(/\d+/).zip(duration.scan(/[a-zA-Z]+/)) + time_tokens.each do |pair| + raise "Please specify both time units and amounts" if pair[1].nil? + case pair[1] + when "d" + total_time = total_time + pair[0].to_i * 86400 + when "h" + total_time = total_time + pair[0].to_i * 3600 + when "m" + total_time = total_time + pair[0].to_i * 60 + when "s" + total_time = total_time + pair[0].to_i + else + raise "Unrecognized time format" + end end + return total_time end #