Skip to content

Commit

Permalink
initial functionality, testing/cleanup still needed
Browse files Browse the repository at this point in the history
  • Loading branch information
zgoldman-r7 committed Oct 13, 2023
1 parent 5b2c583 commit fd80f91
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 4 deletions.
1 change: 1 addition & 0 deletions lib/msf/core/session_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ module Msf
###
class SessionManager < Hash

attr_accessor :on_error_proc
include Framework::Offspring

LAST_SEEN_INTERVAL = 60 * 2.5
Expand Down
14 changes: 13 additions & 1 deletion lib/msf/ui/console/command_dispatcher/core.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@


require 'msf/core/opt_condition'

require 'optparse'

module Msf
Expand Down Expand Up @@ -957,6 +956,14 @@ def cmd_load_help
print_line
end

def log_on_timeout_error(message)
proc do |e|
next unless e.is_a?(Rex::TimeoutError)
elog(e)
puts message
end
end

def list_plugins
plugin_directories = {
'Framework' => Msf::Config.plugin_directory,
Expand Down Expand Up @@ -1555,6 +1562,7 @@ def cmd_sessions(*args)
if session.respond_to?(:response_timeout)
last_known_timeout = session.response_timeout
session.response_timeout = response_timeout
session.on_error_proc = log_on_timeout_error("Send timed out. Timeout currently #{session.response_timeout} seconds, you can configure this with sessions --cmd <id> --timeout <value>") #TODO: is this actually the command?
end

begin
Expand Down Expand Up @@ -1678,6 +1686,9 @@ def cmd_sessions(*args)
print_status("Starting interaction with #{session.name}...\n") unless quiet
begin
self.active_session = session

session.on_error_proc = log_on_timeout_error("Send timed out. Timeout currently #{session.response_timeout} seconds, you can configure this with sessions --interact <id> --timeout <value>")

sid = session.interact(driver.input.dup, driver.output)
self.active_session = nil
driver.input.reset_tab_completion if driver.input.supports_readline
Expand Down Expand Up @@ -1708,6 +1719,7 @@ def cmd_sessions(*args)
if session.respond_to?(:response_timeout)
last_known_timeout = session.response_timeout
session.response_timeout = response_timeout
session.on_error_proc = log_on_timeout_error("Send timed out. Timeout currently #{session.response_timeout} seconds, you can configure this with sessions --script --timeout <value>")
end
begin
print_status("Session #{sess_id} (#{session.session_host}):")
Expand Down
4 changes: 2 additions & 2 deletions lib/rex/post/meterpreter/packet_dispatcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,8 @@ def send_request(packet, timeout = self.response_timeout)

if timeout.nil?
return nil
elsif response.nil?
raise Rex::TimeoutError.new("Send timed out. Timeout currently #{timeout} seconds, you can configure this with %grnsessions --interact <id> --timeout <value>%clr")
elsif response.nil?
raise Rex::TimeoutError.new("Send timed out.")
elsif (response.result != 0)
einfo = lookup_error(response.result)
e = RequestError.new(packet.method, einfo, response.result)
Expand Down
8 changes: 7 additions & 1 deletion lib/rex/post/meterpreter/ui/console.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,13 @@ def queue_cmd(cmd)
#
def run_command(dispatcher, method, arguments)
begin
super
super
rescue Rex::TimeoutError => e
if self.client.on_error_proc
self.client.on_error_proc.call(e)
else
log_error(e.message)
end
rescue Timeout::Error
log_error("Operation timed out.")
rescue RequestError => info
Expand Down

0 comments on commit fd80f91

Please sign in to comment.