Skip to content

Commit

Permalink
fix time parsing, add command support
Browse files Browse the repository at this point in the history
  • Loading branch information
zgoldman-r7 committed Oct 2, 2023
1 parent d7abe5d commit d531cab
Showing 1 changed file with 37 additions and 12 deletions.
49 changes: 37 additions & 12 deletions lib/msf/ui/console/command_dispatcher/core.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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...")
Expand Down Expand Up @@ -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

#
Expand Down

0 comments on commit d531cab

Please sign in to comment.