Skip to content
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions lib/msf/ui.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ module Ui
require 'rex/ui'
require 'msf/ui/banner'
require 'msf/ui/tip'
require 'msf/ui/debug'
require 'msf/ui/driver'
require 'msf/ui/common'
require 'msf/ui/console'
57 changes: 57 additions & 0 deletions lib/msf/ui/console/command_dispatcher/core.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,14 @@ class Core
@@tip_opts = Rex::Parser::Arguments.new(
"-h" => [ false, "Help banner." ])

@@debug_opts = Rex::Parser::Arguments.new(
"-h" => [ false, "Help banner." ],
"-d" => [ false, "Display the Datastore Information." ],
"-c" => [ false, "Display command history." ],
"-e" => [ false, "Display the most recent Error and Stack Trace." ],
"-l" => [ false, "Display the most recent logs." ],
"-v" => [ false, "Display versions and install info." ])

@@connect_opts = Rex::Parser::Arguments.new(
"-h" => [ false, "Help banner." ],
"-p" => [ true, "List of proxies to use." ],
Expand Down Expand Up @@ -103,6 +111,7 @@ def commands
"cd" => "Change the current working directory",
"connect" => "Communicate with a host",
"color" => "Toggle color",
"debug" => "Display information useful for debugging",
"exit" => "Exit the console",
"get" => "Gets the value of a context-specific variable",
"getg" => "Gets the value of a global variable",
Expand Down Expand Up @@ -291,6 +300,54 @@ def cmd_tips(*args)

alias cmd_tip cmd_tips


def cmd_debug_help
print_line "Usage: debug [options]"
print_line
print_line("Print a set of information in a Markdown format to be included when opening an Issue on Github. " +
"This information helps us fix problems you encounter and should be included when you open a new issue: " +
Debug.issue_link)
print @@debug_opts.usage
end

#
# Display information useful for debugging errors.
#
def cmd_debug(*args)
if args.empty?
print_line Debug.all(framework, driver)
return
end

if args.include?("-h")
cmd_debug_help
else
output = ""
@@debug_opts.parse(args) do |opt|
case opt
when '-d'
output << Debug.datastore(framework, driver)
when '-c'
output << Debug.history(driver)
when '-e'
output << Debug.errors
when '-l'
output << Debug.logs
when '-v'
output << Debug.versions(framework)
end
end

if output.empty?
print_line("Valid argument was not given.")
cmd_debug_help
else
output = Debug.preamble + output
print_line output
Comment on lines +345 to +346

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

❔ Is this the same? 🤔

Suggested change
output = Debug.preamble + output
print_line output
print_line Debug.all(framework, driver)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

No not necessarily, if you run debug with no args then you'll get the result of Debug.all. If there are args to the debug command then the user is either looking for help (-h) or is looking to display only some parts of the debug command (Eg debug -e -l for logs & errors).

A user could pass all the flags (debug -d -H -e -l -v ) and get the same result as debug with no args, save potentially a different order of information. This is the only instance where the above lines are the same.

end
end
end

def cmd_connect_help
print_line "Usage: connect [options] <host> <port>"
print_line
Expand Down
22 changes: 18 additions & 4 deletions lib/msf/ui/console/driver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -285,9 +285,9 @@ def load_config(path=nil)
end

#
# Saves configuration for the console.
# Generate configuration for the console.
#
def save_config
def get_config
# Build out the console config group
group = {}

Expand All @@ -301,9 +301,23 @@ def save_config
end
end

# Save it
group
end

def get_config_core
ConfigCore
end

def get_config_group
ConfigGroup
end

#
# Saves configuration for the console.
#
def save_config
begin
Msf::Config.save(ConfigGroup => group)
Msf::Config.save(ConfigGroup => get_config)
rescue ::Exception
print_error("Failed to save console config: #{$!}")
end
Expand Down
Loading