Skip to content

Commit 63c66f6

Browse files
author
Tod Beardsley
committed
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 rapid7#4549, but better solutions are welcome!
1 parent 2cc44cc commit 63c66f6

File tree

1 file changed

+9
-3
lines changed
  • lib/msf/ui/console/command_dispatcher

1 file changed

+9
-3
lines changed

lib/msf/ui/console/command_dispatcher/core.rb

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2418,9 +2418,15 @@ def cmd_use(*args)
24182418
mod_name = args[0]
24192419

24202420
begin
2421-
if ((mod = framework.modules.create(mod_name)) == nil)
2422-
print_error("Failed to load module: #{mod_name}")
2423-
return false
2421+
mod = framework.modules.create(mod_name)
2422+
if mod.nil?
2423+
# Try one more time; see #4549
2424+
sleep 3
2425+
mod = framework.modules.create(mod_name)
2426+
if mod.nil?
2427+
print_error("Failed to load module: #{mod_name}")
2428+
return false
2429+
end
24242430
end
24252431
rescue Rex::AmbiguousArgumentError => info
24262432
print_error(info.to_s)

0 commit comments

Comments
 (0)