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

Switch to using mod parameter for tab completion #14564

Conversation

adfoster-r7
Copy link
Contributor

@adfoster-r7 adfoster-r7 commented Dec 28, 2020

This is a pre-requisite PR for future work. These functions will be used with an arbitrary module - not just the active_module that the implementation currently assumes. There should be no semantic changes for the end user as part of this PR.

Verification

  • Start msfconsole
  • use exploit/windows/wins/ms04_045_wins - just an example, possibly test different module types
  • type run followed by a space then hit tab
  • Verify that a list of possible tab completions displays
  • Verify that tab completion works for both flags and options in multiple different scenarios

These are the same verification steps as #14240

@jmartin-tech
Copy link
Contributor

@msjenkins-r7 test this please.

@bwatters-r7
Copy link
Contributor

I went ahead and merged this locally, doing my best to fix the conflicts, but when I retested after the merge fix, I got:

msf6 > use auxiliary/gather/jenkins_cred_recovery 
msf6 auxiliary(gather/jenkins_cred_recovery) > run Traceback (most recent call last):
	22: from ./msfconsole:23:in `<main>'
	21: from /home/tmoose/rapid7/metasploit-framework/lib/metasploit/framework/command/base.rb:82:in `start'
	20: from /home/tmoose/rapid7/metasploit-framework/lib/metasploit/framework/command/console.rb:48:in `start'
	19: from /home/tmoose/rapid7/metasploit-framework/lib/rex/ui/text/shell.rb:141:in `run'
	18: from /home/tmoose/rapid7/metasploit-framework/lib/rex/ui/text/shell.rb:321:in `get_input_line'
	17: from /home/tmoose/rapid7/metasploit-framework/lib/rex/ui/text/input/readline.rb:100:in `pgets'
	16: from /home/tmoose/rapid7/metasploit-framework/lib/rex/ui/text/input/readline.rb:162:in `readline_with_output'
	15: from /home/tmoose/.rvm/gems/ruby-2.7.2@metasploit-framework/gems/rb-readline-0.5.5/lib/rbreadline.rb:4875:in `readline'
	14: from /home/tmoose/.rvm/gems/ruby-2.7.2@metasploit-framework/gems/rb-readline-0.5.5/lib/rbreadline.rb:4853:in `readline_internal'
	13: from /home/tmoose/.rvm/gems/ruby-2.7.2@metasploit-framework/gems/rb-readline-0.5.5/lib/rbreadline.rb:4779:in `readline_internal_charloop'
	12: from /home/tmoose/.rvm/gems/ruby-2.7.2@metasploit-framework/gems/rb-readline-0.5.5/lib/rbreadline.rb:4363:in `_rl_dispatch'
	11: from /home/tmoose/.rvm/gems/ruby-2.7.2@metasploit-framework/gems/rb-readline-0.5.5/lib/rbreadline.rb:4374:in `_rl_dispatch_subseq'
	10: from /home/tmoose/.rvm/gems/ruby-2.7.2@metasploit-framework/gems/rb-readline-0.5.5/lib/rbreadline.rb:6903:in `rl_complete'
	 9: from /home/tmoose/.rvm/gems/ruby-2.7.2@metasploit-framework/gems/rb-readline-0.5.5/lib/rbreadline.rb:6813:in `rl_complete_internal'
	 8: from /home/tmoose/.rvm/gems/ruby-2.7.2@metasploit-framework/gems/rb-readline-0.5.5/lib/rbreadline.rb:6329:in `gen_completion_matches'
	 7: from /home/tmoose/.rvm/gems/ruby-2.7.2@metasploit-framework/gems/rb-readline-0.5.5/lib/readline.rb:136:in `readline_attempted_completion_function'
	 6: from /home/tmoose/rapid7/metasploit-framework/lib/rex/ui/text/shell.rb:69:in `block in init_tab_complete'
	 5: from /home/tmoose/rapid7/metasploit-framework/lib/rex/ui/text/dispatcher_shell.rb:377:in `tab_complete'
	 4: from /home/tmoose/rapid7/metasploit-framework/lib/rex/ui/text/dispatcher_shell.rb:392:in `tab_complete_stub'
	 3: from /home/tmoose/rapid7/metasploit-framework/lib/rex/ui/text/dispatcher_shell.rb:392:in `each'
	 2: from /home/tmoose/rapid7/metasploit-framework/lib/rex/ui/text/dispatcher_shell.rb:403:in `block in tab_complete_stub'
	 1: from /home/tmoose/rapid7/metasploit-framework/lib/rex/ui/text/dispatcher_shell.rb:444:in `tab_complete_helper'
/home/tmoose/rapid7/metasploit-framework/lib/msf/ui/console/command_dispatcher/auxiliary.rb:45:in `cmd_run_tabs': uninitialized class variable @@auxiliary_opts in Msf::Ui::Console::CommandDispatcher::Auxiliary (NameError)
[ruby-2.7.2@metasploit-framework](upstream-master) tmoose@ubuntu:~/rapid7/metasploit-framework$ 

I may have screwed it up in my attempts to fix the merge conflicts, though.

@adfoster-r7
Copy link
Contributor Author

@bwatters-r7 Thanks for testing this out; Looks like tab completion is broken in master after this change #14582

@adfoster-r7 adfoster-r7 force-pushed the switch-to-using-mod-parameter-for-tab-completion branch from df377c7 to ad8891d Compare January 21, 2021 22:59
@adfoster-r7
Copy link
Contributor Author

Rebased and rested with your scenario 👍

@@ -118,8 +118,8 @@ def cmd_action_help(action)
# at least 1 when tab completion has reached this stage since the command itself has been completed
#
def cmd_run_tabs(str, words)
flags = @@run_action_opts.fmt.keys
options = tab_complete_option(str, words)
flags = @@module_opts.fmt.keys
Copy link
Contributor Author

Choose a reason for hiding this comment

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

cc @zeroSteiner I'm thinking this was just a typo from #14582 👀

Master:

bundle exec ./msfconsole -q --logger Stdout
...
msf6 > use auxiliary/gather/jenkins_cred_recovery 
[01/21/2021 23:03:19] [i(2)] core: Reloading auxiliary module gather/jenkins_cred_recovery. Ambiguous module warnings are safe to ignore
msf6 auxiliary(gather/jenkins_cred_recovery) > run rh<tab_here>
bundler: failed to load command: ./msfconsole (./msfconsole)
NameError: uninitialized class variable @@run_action_opts in Msf::Ui::Console::ModuleActionCommands
  /Users/user/Documents/code/metasploit-framework/lib/msf/ui/console/module_action_commands.rb:121:in `cmd_run_tabs'
  /Users/user/Documents/code/metasploit-framework/lib/rex/ui/text/dispatcher_shell.rb:444:in `tab_complete_helper'
  /Users/user/Documents/code/metasploit-framework/lib/rex/ui/text/dispatcher_shell.rb:403:in `block in tab_complete_stub'
  /Users/user/Documents/code/metasploit-framework/lib/rex/ui/text/dispatcher_shell.rb:392:in `each'
  /Users/user/Documents/code/metasploit-framework/lib/rex/ui/text/dispatcher_shell.rb:392:in `tab_complete_stub'
  /Users/user/Documents/code/metasploit-framework/lib/rex/ui/text/dispatcher_shell.rb:377:in `tab_complete'
  /Users/user/Documents/code/metasploit-framework/lib/rex/ui/text/shell.rb:69:in `block in init_tab_complete'
  /Users/user/.rvm/gems/ruby-2.7.2@metasploit-framework/gems/rb-readline-0.5.5/lib/readline.rb:136:in `readline_attempted_completion_function'
  /Users/user/.rvm/gems/ruby-2.7.2@metasploit-framework/gems/rb-readline-0.5.5/lib/rbreadline.rb:6329:in `gen_completion_matches'
  /Users/user/.rvm/gems/ruby-2.7.2@metasploit-framework/gems/rb-readline-0.5.5/lib/rbreadline.rb:6813:in `rl_complete_internal'
  /Users/user/.rvm/gems/ruby-2.7.2@metasploit-framework/gems/rb-readline-0.5.5/lib/rbreadline.rb:6903:in `rl_complete'
  /Users/user/.rvm/gems/ruby-2.7.2@metasploit-framework/gems/rb-readline-0.5.5/lib/rbreadline.rb:4374:in `_rl_dispatch_subseq'
  /Users/user/.rvm/gems/ruby-2.7.2@metasploit-framework/gems/rb-readline-0.5.5/lib/rbreadline.rb:4363:in `_rl_dispatch'
  /Users/user/.rvm/gems/ruby-2.7.2@metasploit-framework/gems/rb-readline-0.5.5/lib/rbreadline.rb:4779:in `readline_internal_charloop'
  /Users/user/.rvm/gems/ruby-2.7.2@metasploit-framework/gems/rb-readline-0.5.5/lib/rbreadline.rb:4853:in `readline_internal'
  /Users/user/.rvm/gems/ruby-2.7.2@metasploit-framework/gems/rb-readline-0.5.5/lib/rbreadline.rb:4875:in `readline'
  /Users/user/Documents/code/metasploit-framework/lib/rex/ui/text/input/readline.rb:162:in `readline_with_output'
  /Users/user/Documents/code/metasploit-framework/lib/rex/ui/text/input/readline.rb:100:in `pgets'
  /Users/user/Documents/code/metasploit-framework/lib/rex/ui/text/shell.rb:321:in `get_input_line'
  /Users/user/Documents/code/metasploit-framework/lib/rex/ui/text/shell.rb:141:in `run'
  /Users/user/Documents/code/metasploit-framework/lib/metasploit/framework/command/console.rb:48:in `start'
  /Users/user/Documents/code/metasploit-framework/lib/metasploit/framework/command/base.rb:82:in `start'
  /Users/user/Documents/code/metasploit-framework/msfconsole:23:in `<top (required)>'

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah it looks like I made a typo there. I think that's supposed to be @@module_action_opts.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I assumed it was module_opts as it's a superset of module_action_opts? 🤔

@@module_opts = Rex::Parser::Arguments.new(@@module_action_opts.fmt.merge(
'-a' => [ true, 'The action to use. If none is specified, ACTION is used.']
))

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes if the action can be set in this context then the super set should be used. Do you want me to open a dedicated PR to fix this or roll it into these changes?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed by: #14647

@bwatters-r7 bwatters-r7 self-assigned this Jan 25, 2021
@bwatters-r7 bwatters-r7 merged commit 5dafb52 into rapid7:master Jan 25, 2021
@bwatters-r7
Copy link
Contributor

bwatters-r7 commented Jan 25, 2021

Release Notes

Updates internal Metasploit libraries to dependency inject the currently active module when performing tab completion for users

@pbarry-r7 pbarry-r7 added the rn-no-release-notes no release notes label Feb 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
rn-no-release-notes no release notes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants