Skip to content

Commit 210bd33

Browse files
committed
Land rapid7#16774, Suggest a correct datastore option
2 parents c4a2456 + c388499 commit 210bd33

File tree

2 files changed

+15
-2
lines changed
  • lib/msf/ui/console/command_dispatcher
  • spec/lib/msf/ui/console/command_dispatcher

2 files changed

+15
-2
lines changed

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

+13-2
Original file line numberDiff line numberDiff line change
@@ -1834,6 +1834,7 @@ def cmd_set(*args)
18341834
global = true
18351835
datastore = self.framework.datastore
18361836
end
1837+
valid_options = tab_complete_option_names(active_module, '', [])
18371838

18381839
# Dump the contents of the active datastore if no args were supplied
18391840
if (args.length == 0)
@@ -1852,11 +1853,14 @@ def cmd_set(*args)
18521853
datastore) + "\n")
18531854
return true
18541855
elsif (args.length == 1)
1855-
if (not datastore[args[0]].nil?)
1856+
if valid_options.any? { |vo| vo.casecmp?(args[0]) }
18561857
print_line("#{args[0]} => #{datastore[args[0]]}")
18571858
return true
18581859
else
1859-
print_error("Unknown variable")
1860+
message = "Unknown datastore option: #{args[0]}."
1861+
suggestion = DidYouMean::SpellChecker.new(dictionary: valid_options).correct(args[0]).first
1862+
message << " Did you mean #{suggestion}?" if suggestion
1863+
print_error(message)
18601864
cmd_set_help
18611865
return false
18621866
end
@@ -1881,7 +1885,14 @@ def cmd_set(*args)
18811885
# [name, class] from payload_show_results
18821886
value = mod.first
18831887
end
1888+
end
18841889

1890+
unless valid_options.any? { |vo| vo.casecmp?(name) }
1891+
message = "Unknown datastore option: #{name}."
1892+
suggestion = DidYouMean::SpellChecker.new(dictionary: valid_options).correct(name).first
1893+
message << " Did you mean #{suggestion}?" if suggestion
1894+
print_error(message)
1895+
return false
18851896
end
18861897

18871898
# If the driver indicates that the value is not valid, bust out.

spec/lib/msf/ui/console/command_dispatcher/core_spec.rb

+2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
def set_and_test_variable(name, framework_value, module_value, framework_re, module_re)
1919
# set the current module
2020
allow(core).to receive(:active_module).and_return(mod)
21+
# always assume the variable is valid
22+
allow(core).to receive(:tab_complete_option_names).and_return([ name ])
2123
# always assume set variables validate (largely irrelevant because ours are random)
2224
allow(driver).to receive(:on_variable_set).and_return(true)
2325
# the specified global value

0 commit comments

Comments
 (0)