From 63c66f66a09f300c83330bc9f4edfbaabf97c946 Mon Sep 17 00:00:00 2001 From: Tod Beardsley Date: Tue, 20 Jan 2015 15:46:29 -0600 Subject: [PATCH] Add a second_chance on cmd_use This is a weak attempt to solve a race condition between modules loading and cmd_use being fired. Upon startup, saved configurations, running resource scripts, and running commands will sometimes jump ahead of the module loading procedure. I have not discovered where the race actually is and how to cause the race to happen. However, the timing seems to be fairly close to a second; by waiting three seconds after trying use again, we seem to be in the clear, at least according to testing. Fixes #4549, but better solutions are welcome! --- lib/msf/ui/console/command_dispatcher/core.rb | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/msf/ui/console/command_dispatcher/core.rb b/lib/msf/ui/console/command_dispatcher/core.rb index 975ec750f7..addec44079 100644 --- a/lib/msf/ui/console/command_dispatcher/core.rb +++ b/lib/msf/ui/console/command_dispatcher/core.rb @@ -2418,9 +2418,15 @@ class Core mod_name = args[0] begin - if ((mod = framework.modules.create(mod_name)) == nil) - print_error("Failed to load module: #{mod_name}") - return false + mod = framework.modules.create(mod_name) + if mod.nil? + # Try one more time; see #4549 + sleep 3 + mod = framework.modules.create(mod_name) + if mod.nil? + print_error("Failed to load module: #{mod_name}") + return false + end end rescue Rex::AmbiguousArgumentError => info print_error(info.to_s)