Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the ability to use numerics with info command #14053

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 41 additions & 30 deletions lib/msf/ui/console/command_dispatcher/modules.rb
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,22 @@ def cmd_info_help
print_line
end

def print_module_info(mod, dump_json: false, show_doc: false)
if dump_json
print(Serializer::Json.dump_module(mod) + "\n")
elsif show_doc
f = Tempfile.new(["#{mod.shortname}_doc", '.html'])
begin
print_status("Generating documentation for #{mod.shortname}, then opening #{f.path} in a browser...")
Msf::Util::DocumentGenerator.spawn_module_document(mod, f)
ensure
f.close if f
end
else
print(Serializer::ReadableText.dump_module(mod))
end
end

#
# Displays information about one or more module.
#
Expand All @@ -128,49 +144,41 @@ def cmd_info(*args)
end

if (args.length == 0)
if (active_module)
if dump_json
print(Serializer::Json.dump_module(active_module) + "\n")
elsif show_doc
f = Tempfile.new(["#{active_module.shortname}_doc", '.html'])
begin
print_status("Generating documentation for #{active_module.shortname}, then opening #{f.path} in a browser...")
Msf::Util::DocumentGenerator.spawn_module_document(active_module, f)
ensure
f.close if f
end
else
print(Serializer::ReadableText.dump_module(active_module))
end
if active_module
print_module_info(active_module, dump_json: dump_json, show_doc: show_doc)
return true
else
cmd_info_help
return false
end
elsif args.include? "-h"
elsif args.include? '-h'
cmd_info_help
return false
end

args.each do |arg|
mod_name = arg

args.each { |name|
# Use a module by search index
index_from_list(@module_search_results, mod_name) do |mod|
next unless mod && mod.respond_to?(:fullname)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just wondering if we could have the same error message that has been added to the use command when an index is invalid?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, sorry, I didn't see it happens later, when checking the return value of framework.modules.create(name).


# Module cache object from @module_search_results
mod_name = mod.fullname
end

# Ensure we have a reference name and not a path
name = trim_path(mod_name, 'modules')

# Creates an instance of the module
mod = framework.modules.create(name)

if (mod == nil)
if mod.nil?
print_error("Invalid module: #{name}")
elsif dump_json
print(Serializer::Json.dump_module(mod) + "\n")
elsif show_doc
f = Tempfile.new(["#{mod.shortname}_doc", '.html'])
begin
print_status("Generating documentation for #{mod.shortname}, then opening #{f.path} in a browser...")
Msf::Util::DocumentGenerator.spawn_module_document(mod, f)
ensure
f.close if f
end
else
print(Serializer::ReadableText.dump_module(mod))
print_module_info(mod, dump_json: dump_json, show_doc: show_doc)
end
}
end
end

def cmd_options_help
Expand Down Expand Up @@ -649,7 +657,10 @@ def cmd_use(*args)

# Use a module by search index
index_from_list(@module_search_results, mod_name) do |mod|
return false unless mod && mod.respond_to?(:fullname)
unless mod && mod.respond_to?(:fullname)
print_error("Invalid module index: #{mod_name}")
return false
end
Comment on lines +660 to +663
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before

Before when an invalid number was used with the use command it didn't return anything
image

After

Now when an invalid number is used with the use command it will return [-] Invalid module index: 99999
image

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what happens if you do info on an invalid number/multiple invalid numbers?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dwelch-r7, you beat me on this: #14053 (comment)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry forgot to add this in!

When an invalid number is used with the info command it will return [-] Invalid module index: 9999
image

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great usability change!


# Module cache object from @module_search_results
mod_name = mod.fullname
Expand Down