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

Update rhost walker to handle interrupt signal #17409

Conversation

adfoster-r7
Copy link
Contributor

Updates the rhost walker to handle interrupt signals from the user when pressing ctrl+c in msfconsole

Improves #16765

Note that the ctrl+c interrupt signal won't be handled immediately - the DNS timeout will have to finish first. This seems like a bug in Ruby itself, where the the DNS resolve is blocking and the Ruby VM won't receive the interrupt signal until the DNS resolve timeout is hit - https://bugs.ruby-lang.org/issues/16476. So if the user spams ctrl+c, the multiple excess interrupt requests will bubble up after the DNS timeout ends - then msfconsole will be killed. Therefore the user will have to press ctrl+c once and wait patiently for invalid DNS requests to fail.

Verification

Steps are in #16765

@jheysel-r7 jheysel-r7 self-assigned this Dec 23, 2022
@jheysel-r7
Copy link
Contributor

jheysel-r7 commented Dec 28, 2022

Before

msf6 exploit(windows/iis/ms01_033_idq) > rexploit set target 1
[*] Reloading module...
rex	^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C[-] rexploit: Interrupted
[-] rexploit: Interrupted
Interrupt: use the 'exit' command to quit
Interrupt: use the 'exit' command to quit
Interrupt: use the 'exit' command to quit
Interrupt: use the 'exit' command to quit
Interrupt: use the 'exit' command to quit

Aborting...
./msfconsole: Interrupt
./msfconsole:26:in `exit': Interrupt
	from ./msfconsole:26:in `rescue in <main>'
	from ./msfconsole:9:in `<main>'
/home/msfuser/.rvm/gems/ruby-3.0.2/gems/rex-core-0.1.28/lib/rex/sync/thread_safe.rb:36:in `select': Interrupt
	from /home/msfuser/.rvm/gems/ruby-3.0.2/gems/rex-core-0.1.28/lib/rex/sync/thread_safe.rb:36:in `select'
	from /home/msfuser/.rvm/gems/ruby-3.0.2/gems/rex-core-0.1.28/lib/rex/sync/thread_safe.rb:76:in `sleep'
	from (eval):3:in `sleep'
	from /home/msfuser/git/metasploit-framework/lib/rex/ui/text/shell/history_manager.rb:56:in `flush'
	from /home/msfuser/git/metasploit-framework/lib/rex/ui/text/shell.rb:173:in `ensure in run'
	from /home/msfuser/git/metasploit-framework/lib/rex/ui/text/shell.rb:174:in `run'
	from /home/msfuser/git/metasploit-framework/lib/metasploit/framework/command/console.rb:48:in `start'
	from /home/msfuser/git/metasploit-framework/lib/metasploit/framework/command/base.rb:82:in `start'
	from ./msfconsole:23:in `<main>'
/home/msfuser/git/metasploit-framework/lib/rex/ui/text/output/stdio.rb:89:in `write': Interrupt
	from /home/msfuser/git/metasploit-framework/lib/rex/ui/text/output/stdio.rb:89:in `print'
	from /home/msfuser/git/metasploit-framework/lib/rex/ui/text/output/stdio.rb:89:in `print_raw'
	from /home/msfuser/git/metasploit-framework/lib/rex/ui/text/output.rb:68:in `print'
	from /home/msfuser/git/metasploit-framework/lib/rex/ui/text/shell.rb:169:in `rescue in run'
	from /home/msfuser/git/metasploit-framework/lib/rex/ui/text/shell.rb:168:in `run'
	from /home/msfuser/git/metasploit-framework/lib/metasploit/framework/command/console.rb:48:in `start'
	from /home/msfuser/git/metasploit-framework/lib/metasploit/framework/command/base.rb:82:in `start'
	from ./msfconsole:23:in `<main>'
/home/msfuser/git/metasploit-framework/lib/rex/ui/text/input/readline.rb:21:in `const_defined?': Interrupt
	from /home/msfuser/git/metasploit-framework/lib/rex/ui/text/input/readline.rb:21:in `initialize'
	from /home/msfuser/git/metasploit-framework/lib/rex/ui/text/shell.rb:69:in `new'
	from /home/msfuser/git/metasploit-framework/lib/rex/ui/text/shell.rb:69:in `init_tab_complete'
	from /home/msfuser/git/metasploit-framework/lib/rex/ui/text/shell.rb:142:in `run'
	from /home/msfuser/git/metasploit-framework/lib/metasploit/framework/command/console.rb:48:in `start'
	from /home/msfuser/git/metasploit-framework/lib/metasploit/framework/command/base.rb:82:in `start'
	from ./msfconsole:23:in `<main>'

msfuser@ubuntu:~/git/metasploit-framework$

After

msf6 exploit(windows/iis/ms01_033_idq) > rexploit set target 1
[*] Reloading module...
rex
^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C[-] rexploit: Interrupted
[-] rexploit: Interrupted
Interrupt: use the 'exit' command to quit
Interrupt: use the 'exit' command to quit
Interrupt: use the 'exit' command to quit
Interrupt: use the 'exit' command to quit
Interrupt: use the 'exit' command to quit
Interrupt: use the 'exit' command to quit
Interrupt: use the 'exit' command to quit
Interrupt: use the 'exit' command to quit
Interrupt: use the 'exit' command to quit
Interrupt: use the 'exit' command to quit
Interrupt: use the 'exit' command to quit
Interrupt: use the 'exit' command to quit
Interrupt: use the 'exit' command to quit
Interrupt: use the 'exit' command to quit
Interrupt: use the 'exit' command to quit
Interrupt: use the 'exit' command to quit
Interrupt: use the 'exit' command to quit
Interrupt: use the 'exit' command to quit
Interrupt: use the 'exit' command to quit
Interrupt: use the 'exit' command to quit
Interrupt: use the 'exit' command to quit
Interrupt: use the 'exit' command to quit
Interrupt: use the 'exit' command to quit
Interrupt: use the 'exit' command to quit
Interrupt: use the 'exit' command to quit
Interrupt: use the 'exit' command to quit
Interrupt: use the 'exit' command to quit
Interrupt: use the 'exit' command to quit
Interrupt: use the 'exit' command to quit
Interrupt: use the 'exit' command to quit
msf6 exploit(windows/iis/ms01_033_idq) >

Spamming ctrl+c in this scenario no longer kills msfconsole 👍

@jheysel-r7 jheysel-r7 merged commit a8697cd into rapid7:master Dec 28, 2022
@jheysel-r7 jheysel-r7 added the rn-fix release notes fix label Dec 28, 2022
@jheysel-r7
Copy link
Contributor

Release Notes

Update rhost walker to handle interrupt signal

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

Successfully merging this pull request may close these issues.

None yet

2 participants