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

Also check the IO.console is not nil before wrapping based on its width #34

Merged
merged 1 commit into from
Jan 18, 2021

Conversation

zeroSteiner
Copy link
Contributor

This fixes a stack trace where if IO.console is nil, the WrappedTable will fail to generate leading to stacktraces instead of output within msfconsole. I came across this when debugging Metasploit with RubyMine and running the jobs command. The proposed solution is to check if ::IO.console is nil before wrapping tables based on its width. If the width isn't available from the console, then there's probably no point in automatically wrapping tables.

Example stack trace:

msf6 exploit(windows/smb/psexec) > jobs
[-] Error while running command jobs: undefined method `winsize' for nil:NilClass

Call stack:
/home/smcintyre/.rvm/gems/ruby-2.7.2@metasploit-framework/gems/rex-text-0.2.28/lib/rex/text/wrapped_table.rb:74:in `initialize'
/home/smcintyre/.rvm/gems/ruby-2.7.2@metasploit-framework/gems/rex-text-0.2.28/lib/rex/text/table.rb:26:in `new'
/home/smcintyre/.rvm/gems/ruby-2.7.2@metasploit-framework/gems/rex-text-0.2.28/lib/rex/text/table.rb:26:in `new'
/home/smcintyre/Repositories/metasploit-framework/lib/msf/base/serializer/readable_text.rb:964:in `dump_jobs'
/home/smcintyre/Repositories/metasploit-framework/lib/msf/ui/console/command_dispatcher/jobs.rb:172:in `cmd_jobs'
/home/smcintyre/Repositories/metasploit-framework/lib/rex/ui/text/dispatcher_shell.rb:525:in `run_command'
/home/smcintyre/Repositories/metasploit-framework/lib/rex/ui/text/dispatcher_shell.rb:476:in `block in run_single'
/home/smcintyre/Repositories/metasploit-framework/lib/rex/ui/text/dispatcher_shell.rb:470:in `each'
/home/smcintyre/Repositories/metasploit-framework/lib/rex/ui/text/dispatcher_shell.rb:470:in `run_single'
/home/smcintyre/Repositories/metasploit-framework/lib/rex/ui/text/shell.rb:158:in `run'
/home/smcintyre/Repositories/metasploit-framework/lib/metasploit/framework/command/console.rb:48:in `start'
/home/smcintyre/Repositories/metasploit-framework/lib/metasploit/framework/command/base.rb:82:in `start'
/home/smcintyre/Repositories/metasploit-framework/msfconsole:23:in `<top (required)>'
/home/smcintyre/.rvm/gems/ruby-2.7.2@metasploit-framework/gems/ruby-debug-ide-2.3.0/lib/ruby-debug-ide.rb:100:in `debug_load'
/home/smcintyre/.rvm/gems/ruby-2.7.2@metasploit-framework/gems/ruby-debug-ide-2.3.0/lib/ruby-debug-ide.rb:100:in `debug_program'
/home/smcintyre/.rvm/gems/ruby-2.7.2@metasploit-framework/gems/ruby-debug-ide-2.3.0/bin/rdebug-ide:204:in `<main>'
msf6 exploit(windows/smb/psexec) > 

I'm not sure under what other conditions ::IO.console will be nil, so your best bet might be to reproduce this using RubyMine and the console within the debugger.

@zeroSteiner
Copy link
Contributor Author

I forgot to mention that this is related to the wrapped tables feature which must be enabled.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants