Skip to content

Command that can be used to generate information useful when debugging user errors - #13430

Merged
adfoster-r7 merged 1 commit into
rapid7:masterfrom
agalway-r7:report-issue
Jun 29, 2020
Merged

Command that can be used to generate information useful when debugging user errors#13430
adfoster-r7 merged 1 commit into
rapid7:masterfrom
agalway-r7:report-issue

Conversation

@agalway-r7

@agalway-r7 agalway-r7 commented May 11, 2020

Copy link
Copy Markdown
Contributor

Adds the debug command, that can be used to generate information useful when debugging errors.

Context

The purpose of this command is to generate a detailed error report that can be attached to Github issues. The debug output is split into five sections:

  • Datastore
    The variables currently in use in the given environment. This section can be copied and pasted into your ~/.msf4/config file to recreate the environment that caused the error.
[framework/database]
default_db=local-https-data-service

[framework/database/local-https-data-service]
url=https://localhost:5443
cert=/Users/agalway/.msf4/msf-ws-cert.pem
skip_verify=true
api_token=fbe48c1ee49f493b0eb9bd08567e1e6d2cb1ee6b790734a2a9efa0bdf03621393b197a267e4ea841

[framework/ui/console]
ActiveModule=exploit/windows/misc/crosschex_device_bof

[windows/misc/crosschex_device_bof]
WORKSPACE=
VERBOSE=false
WfsDelay=0
EnableContextEncoding=false
ContextInformationFile=
DisablePayloadHandler=false
CPORT=5050
CHOST=0.0.0.0
TIMEOUT=1
PAYLOAD=windows/meterpreter/reverse_https
LHOST=192.168.1.2
  • History

The last 50 commands run by a user

547    debug -e
548    reload_lib -a
549    debug -e
550    debug
551    use crosshcex
552    use crosschex
553    run
...etc...
  • Errors

The last 10 errors logged to framework.log. The stack traces for any error are also retrieved and do not count towards the error total.

[06/17/2020 15:42:13] [e(0)] error: Dependencies for windows/x64/encrypted_reverse_tcp: [Metasploit::Framework::Compiler::Mingw::X64]
[06/17/2020 15:42:13] [e(0)] error: Unable to load module /Users/Shared/Relocated_Items/Security/rapid7/metasploit-framework/modules/auxiliary/gather/office365userenum.py, unknown module type
[06/17/2020 15:43:02] [e(0)] error: [-] Error while running command debug: uninitialized constant Msf::Ui::Console::CommandDispatcher::Core::Debugtext/shell
Call stack:
/Users/Shared/Relocated_Items/Security/rapid7/metasploit-framework/lib/msf/ui/console/command_dispatcher/core.rb:318:in `cmd_debug'
/Users/Shared/Relocated_Items/Security/rapid7/metasploit-framework/lib/rex/ui/text/dispatcher_shell.rb:523:in `run_command'
/Users/Shared/Relocated_Items/Security/rapid7/metasploit-framework/lib/rex/ui/text/dispatcher_shell.rb:474:in `block in run_single'
/Users/Shared/Relocated_Items/Security/rapid7/metasploit-framework/lib/rex/ui/text/dispatcher_shell.rb:468:in `each'
/Users/Shared/Relocated_Items/Security/rapid7/metasploit-framework/lib/rex/ui/text/dispatcher_shell.rb:468:in `run_single'
/Users/Shared/Relocated_Items/Security/rapid7/metasploit-framework/lib/rex/ui/text/shell.rb:158:in `run'
/Users/Shared/Relocated_Items/Security/rapid7/metasploit-framework/lib/metasploit/framework/command/console.rb:48:in `start'
/Users/Shared/Relocated_Items/Security/rapid7/metasploit-framework/lib/metasploit/framework/command/base.rb:82:in `start'
./msfconsole:22:in `<main>'
  • Logs

The last 50 lines of framework.log. This can repeat info retrieved with the error command

/Users/Shared/Relocated_Items/Security/rapid7/metasploit-framework/modules/exploits/windows/smb/ms08_067_netapi.rb:1094: Invalid return in class/module body
        return Msf::Exploit::CheckCode::Unk...
        ^~~~~~
/Users/Shared/Relocated_Items/Security/rapid7/metasploit-framework/modules/exploits/windows/smb/ms08_067_netapi.rb:1150: syntax error, unexpected end, expecting end-of-input
  end
  ^~~
[06/23/2020 11:07:48] [e(0)] core: /Users/Shared/Relocated_Items/Security/rapid7/metasploit-framework/modules/exploits/windows/smb/ms08_067_netapi.rb failed to load - Errno::ENOENT No such file or directory
[06/23/2020 11:08:09] [e(0)] core: /Users/Shared/Relocated_Items/Security/rapid7/metasploit-framework/modules/exploits/windows/smb/ms08_067_netapi.rb failed to load - SyntaxError /Users/Shared/Relocated_Items/Security/rapid7/metasploit-framework/modules/exploits/windows/smb/ms08_067_netapi.rb:1089: Invalid return in class/module body
      return Msf::Exploit::CheckCode::Unk...
      ^~~~~~
/Users/Shared/Relocated_Items/Security/rapid7/metasploit-framework/modules/exploits/windows/smb/ms08_067_netapi.rb:1094: Invalid return in class/module body
        return Msf::Exploit::CheckCode::Unk...
        ^~~~~~
/Users/Shared/Relocated_Items/Security/rapid7/metasploit-framework/modules/exploits/windows/smb/ms08_067_netapi.rb:1150: syntax error, unexpected end, expecting end-of-input
  end
  ^~~
Call stack:
/Users/Shared/Relocated_Items/Security/rapid7/metasploit-framework/lib/msf/core/modules/loader/base.rb:51:in `module_eval'
/Users/Shared/Relocated_Items/Security/rapid7/metasploit-framework/lib/msf/core/modules/loader/base.rb:51:in `module_eval_with_lexical_scope'
/Users/Shared/Relocated_Items/Security/rapid7/metasploit-framework/lib/msf/core/modules/loader/base.rb:140:in `block in load_module'
/Users/Shared/Relocated_Items/Security/rapid7/metasploit-framework/lib/msf/core/modules/loader/base.rb:549:in `namespace_module_transaction'
/Users/Shared/Relocated_Items/Security/rapid7/metasploit-framework/lib/msf/core/modules/loader/base.rb:178:in `load_module'
/Users/Shared/Relocated_Items/Security/rapid7/metasploit-framework/lib/msf/core/module_manager/cache.rb:91:in `block in load_cached_module'
/Users/Shared/Relocated_Items/Security/rapid7/metasploit-framework/lib/msf/core/module_manager/cache.rb:86:in `each'
/Users/Shared/Relocated_Items/Security/rapid7/metasploit-framework/lib/msf/core/module_manager/cache.rb:86:in `load_cached_module'
/Users/Shared/Relocated_Items/Security/rapid7/metasploit-framework/lib/msf/core/module_set.rb:45:in `create'
/Users/Shared/Relocated_Items/Security/rapid7/metasploit-framework/lib/msf/core/module_manager.rb:90:in `create'
/Users/Shared/Relocated_Items/Security/rapid7/metasploit-framework/lib/msf/ui/console/command_dispatcher/modules.rb:707:in `cmd_use'
/Users/Shared/Relocated_Items/Security/rapid7/metasploit-framework/lib/rex/ui/text/dispatcher_shell.rb:523:in `run_command'
/Users/Shared/Relocated_Items/Security/rapid7/metasploit-framework/lib/rex/ui/text/dispatcher_shell.rb:474:in `block in run_single'
/Users/Shared/Relocated_Items/Security/rapid7/metasploit-framework/lib/rex/ui/text/dispatcher_shell.rb:468:in `each'
/Users/Shared/Relocated_Items/Security/rapid7/metasploit-framework/lib/rex/ui/text/dispatcher_shell.rb:468:in `run_single'
/Users/Shared/Relocated_Items/Security/rapid7/metasploit-framework/lib/rex/ui/text/shell.rb:158:in `run'
/Users/Shared/Relocated_Items/Security/rapid7/metasploit-framework/lib/metasploit/framework/command/console.rb:48:in `start'
/Users/Shared/Relocated_Items/Security/rapid7/metasploit-framework/lib/metasploit/framework/command/base.rb:82:in `start'
./msfconsole:23:in `<main>'
[06/23/2020 11:08:09] [e(0)] core: /Users/Shared/Relocated_Items/Security/rapid7/metasploit-framework/modules/exploits/windows/smb/ms08_067_netapi.rb failed to load - Errno::ENOENT No such file or directory
Call stack:
none
[06/23/2020 12:03:25] [i(0)] core: Default data service found. Attempting to connect...
[06/23/2020 12:03:25] [d(0)] core: Updated user based module store
[06/23/2020 12:03:29] [e(0)] core: Dependency for windows/encrypted_shell_reverse_tcp is not supported
[06/23/2020 12:03:29] [e(0)] core: Dependency for windows/x64/encrypted_shell_reverse_tcp is not supported
[06/23/2020 12:03:29] [e(0)] core: Dependency for windows/encrypted_reverse_tcp is not supported
[06/23/2020 12:03:29] [e(0)] core: Dependency for windows/x64/encrypted_reverse_tcp is not supported
[06/23/2020 12:03:30] [e(0)] core: Unable to load module /Users/Shared/Relocated_Items/Security/rapid7/metasploit-framework/modules/auxiliary/gather/office365userenum.py, unknown module type
[06/23/2020 12:06:03] [e(0)] core: Dependency for windows/encrypted_shell_reverse_tcp is not supported
[06/23/2020 12:06:03] [e(0)] core: Dependency for windows/x64/encrypted_shell_reverse_tcp is not supported
[06/23/2020 12:06:03] [e(0)] core: Dependency for windows/encrypted_reverse_tcp is not supported
[06/23/2020 12:06:03] [e(0)] core: Dependency for windows/x64/encrypted_reverse_tcp is not supported
  • Versions

The Framework version, Ruby version, Install Root, DB Connection Session Type (if any), DB Connection Name (if any), and the framework Installation method.

Framework: 5.0.95-dev-ae74d0d3a5
Ruby: ruby 2.6.6p146 (2020-03-31 revision 67876) [x86_64-darwin19]
Install Root: /Users/Shared/Relocated_Items/Security/rapid7/metasploit-framework
Session Type: Connected to remote_data_service: (https://localhost:5443). Connection type: http. Connection name: #<Metasploit::Framework::DataService::RemoteHTTPDataService:0x00007fb4369773f8>.
Install Method: Git Clone

These sections are then wrapped in Markdown, which can be copied and pasted into an Issue for easy readability:
nested-sections

@agalway-r7
agalway-r7 marked this pull request as draft May 11, 2020 09:23
@wvu

wvu commented May 11, 2020

Copy link
Copy Markdown
Contributor

Hey, can you retitle this and add some labels? Thanks!

@agalway-r7 agalway-r7 changed the title WIP Command that can be used to generate information useful when debugging user errors May 11, 2020
@agalway-r7 agalway-r7 assigned agalway-r7 and unassigned agalway-r7 May 11, 2020
@adfoster-r7 adfoster-r7 changed the title Command that can be used to generate information useful when debugging user errors WIP: Command that can be used to generate information useful when debugging user errors May 12, 2020
Comment thread lib/msf/ui/debug.rb Outdated
Comment thread lib/msf/ui/console/command_dispatcher/core.rb Outdated
Comment thread lib/msf/ui/debug.rb Outdated
Comment thread lib/msf/ui/debug.rb Outdated
@adfoster-r7 adfoster-r7 added the blocked Blocked by one or more additional tasks label May 14, 2020
Comment thread lib/msf/base/logging.rb Outdated
register_log_source(src, f)
}

register_log_source('error', error_f)

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.

I think this will lead to good questions for module hacking 👀

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.

sweat

Comment thread lib/msf/ui/debug.rb Outdated
Comment thread lib/msf/ui/debug.rb Outdated
Comment thread lib/msf/ui/debug.rb Outdated
Comment thread lib/msf/ui/debug.rb
Comment thread lib/msf/ui/debug.rb Outdated
Comment thread lib/msf/ui/debug.rb Outdated
Comment thread lib/msf/ui/debug.rb Outdated
Comment thread lib/msf/ui/debug.rb Outdated
Comment thread lib/msf/ui/debug.rb Outdated
Comment thread lib/msf/ui/debug.rb Outdated

@acammack-r7 acammack-r7 left a comment

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.

This should save us a lot of time! Some notes about logging and strings.

Comment thread lib/msf/ui/debug.rb Outdated
Comment thread lib/msf/ui/debug.rb
Comment thread lib/rex/ui/text/shell.rb
Comment thread lib/rex/ui/text/shell.rb Outdated
@agalway-r7
agalway-r7 force-pushed the report-issue branch 2 times, most recently from 4819f9b to b9def68 Compare May 20, 2020 14:11
Comment on lines +345 to +346
output = Debug.preamble + output
print_line output

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.

Comment thread lib/msf/ui/debug.rb Outdated
Comment thread lib/msf/ui/debug.rb Outdated
Comment thread lib/msf/ui/debug.rb Outdated
Comment thread lib/msf/ui/console/command_dispatcher/core.rb Outdated
Comment thread spec/lib/msf/debug_spec.rb Outdated
Comment thread spec/lib/msf/debug_spec.rb Outdated
Comment thread lib/msf/ui/debug.rb Outdated
Comment thread spec/lib/msf/debug_spec.rb Outdated
Comment thread spec/lib/msf/debug_spec.rb Outdated
@agalway-r7
agalway-r7 marked this pull request as ready for review June 23, 2020 10:57
@agalway-r7 agalway-r7 changed the title WIP: Command that can be used to generate information useful when debugging user errors Command that can be used to generate information useful when debugging user errors Jun 23, 2020
@agalway-r7 agalway-r7 removed the blocked Blocked by one or more additional tasks label Jun 23, 2020
Comment thread lib/msf/ui/debug.rb Outdated
Comment thread lib/msf/ui/debug.rb

end

def self.errors

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.

Now that we've got errors appearing as expected in the framework log, what are your thoughts on this section? Is this section now redundant if the log section now has all of the same information? 🤔

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 I don't think so, the log command is relatively dumb and just returns the last X lines of the log file. Errors will scan the log file for the last Y number of errors and extract them in their complete from, stack traces and all. That's useful functionality, and at the very least acts as a tl;dr for logs

Comment thread lib/msf/ui/console/command_dispatcher/core.rb Outdated
Comment thread lib/msf/ui/debug.rb Outdated
Comment thread lib/msf/ui/debug.rb Outdated
Comment thread lib/msf/ui/debug.rb Outdated
Comment thread lib/msf/ui/debug.rb Outdated
logs_str = concat_str_array_from_last_idx(log_lines, LOG_LINE_TOTAL)

build_section('Logs',
'The following logs were recorded before the issue occurred:',

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.

nab: It might be easier to debug this log file if there was additional information on when the shell was opened, to help cross-correlate things better

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.

As in putting messages on the log file to say "Hey, a new shell was opened here" and some identifying info?

@adfoster-r7 adfoster-r7 Jun 24, 2020

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.

Sorry, the time at which msfconsole was opened. We probably don't care about stale logs.

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.

The comment was in a similar vein to https://github.com/rapid7/metasploit-framework/pull/13430/files#r444918893 - were we probably don't care about 10 errors ago 🐛

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.

This is kind of what I was going for with the optional arguments, as it would let people choose how long the log line total and error total are. However, you're also right that there's no real reason people would care about details spanning multiple console sessions, and manually guess working that with optional log line numbers would be a pain.

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.

Would say this is more of a seperate PR to improve logging, then debug can build on said improvements

Comment thread lib/msf/ui/debug.rb Outdated
Comment thread lib/msf/ui/console/command_dispatcher/core.rb Outdated
Comment thread lib/msf/ui/debug.rb
Comment thread spec/lib/msf/debug_spec.rb Outdated
@adfoster-r7
adfoster-r7 dismissed stale reviews from acammack-r7 and themself June 29, 2020 12:56

Changes implemented

@agalway-r7
agalway-r7 force-pushed the report-issue branch 2 times, most recently from 11d9aba to d89cbb2 Compare June 29, 2020 13:15
@adfoster-r7
adfoster-r7 merged commit d127f71 into rapid7:master Jun 29, 2020
@adfoster-r7 adfoster-r7 added the rn-enhancement release notes enhancement label Jun 29, 2020
@adfoster-r7

adfoster-r7 commented Jun 29, 2020

Copy link
Copy Markdown
Contributor

Release Notes

A debug command was added that can be used directly in Metasploit console to output the current module, datastore, logs and software versions. This command will be useful to help improve the quality of bug reports raised on Github and when helping Metasploit users debug their issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants