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

Replace Readline with Reline #19397

Merged
merged 1 commit into from
Sep 20, 2024

Conversation

sjanusz-r7
Copy link
Contributor

@sjanusz-r7 sjanusz-r7 commented Aug 19, 2024

This PR:

  • replaces the Readline library with Reline.
  • fixes Keyboard Input Issues in msfconsole on PowerShell After Update to v6.4.16 Windows11 #19294 by working around an Open3 bug reported on the gem's GitHub issue page for Windows 11 (this compliments Reline, as we need Reline as well as the work-around to fix this)
  • still uses the Readline gem, due to needing the Readline::FILENAME_COMPLETION_PROC, which is stubbed as nil in Reline. We use this to not have to write our own custom FILENAME_COMPLETION_PROC.
  • fixes an issue present on master, where pressing Ctrl+C in irb prompt would result in a deadlock exception.
  • marks the real-readline option as deprecated, due to the planned removal of the Readline gem in the future
  • removes the Readline single-line input fallback mode from SQL sessions, as Reline will be used exclusively
  • removes the history_manager input_library option, as Reline is the only library being supported moving forward, as we are planning to drop Readline

Windows 11 - Before

Can't delete characters in the prompt, and getting a bug where the input gets re-entered multiple times.

PS C:\Users\x\Desktop\metasploit-framework> bundle exec 'ruby ./msfconsole -q'
Calling `DidYouMean::SPELL_CHECKERS.merge!(error_name => spell_checker)' has been deprecated. Please call `DidYouMean.correct_error(error_name, spell_checker)' instead.
Calling `DidYouMean::SPELL_CHECKERS.merge!(error_name => spell_checker)' has been deprecated. Please call `DidYouMean.correct_error(error_name, spell_checker)' instead.
C:/Users/x/.local/share/gem/ruby/3.1.0/gems/rex-core-0.1.32/lib/rex/compat.rb:381: warning: Win32API is deprecated after Ruby 1.9.1; use fiddle directly instead
msf6 auxiliary(scanner/oracle/oracle_login) > use postggrgregresgres_gres_lgres_logres_loggres_logigres_login

Windows 11 - After

No duplicate input in prompt, prompt can be cleared using backspace and navigated using left and right arrow keys.

PS C:\Users\x\Desktop\metasploit-framework> bundle exec 'ruby ./msfconsole -q'
Calling `DidYouMean::SPELL_CHECKERS.merge!(error_name => spell_checker)' has been deprecated. Please call `DidYouMean.correct_error(error_name, spell_checker)' instead.
Calling `DidYouMean::SPELL_CHECKERS.merge!(error_name => spell_checker)' has been deprecated. Please call `DidYouMean.correct_error(error_name, spell_checker)' instead.
C:/Users/x/.local/share/gem/ruby/3.1.0/gems/rex-core-0.1.32/lib/rex/compat.rb:381: warning: Win32API is deprecated after Ruby 1.9.1; use fiddle directly instead
msf6 auxiliary(scanner/oracle/oracle_login) > use postgres_login (no duplicated input)

Matching Modules
================

   #  Name                                       Disclosure Date  Rank    Check  Description
   -  ----                                       ---------------  ----    -----  -----------
   0  auxiliary/scanner/postgres/postgres_login  .                normal  No     PostgreSQL Login Utility


Interact with a module by name or index. For example info 0, use 0 or use auxiliary/scanner/postgres/postgres_login

[*] Using auxiliary/scanner/postgres/postgres_login
[*] New in Metasploit 6.4 - The CreateSession option within this module can open an interactive session
msf6 auxiliary(scanner/postgres/postgres_login) > use postgres_login (press backspace multiple times)
msf6 auxiliary(scanner/postgres/postgres_login) > (prompt cleared)

IRB - Before

msf6 auxiliary(scanner/postgres/postgres_login) > irb
[*] Starting IRB shell...
[*] You are in auxiliary/scanner/postgres/postgres_login

>> 
^C
[-] Error during IRB: deadlock; recursive locking

/Users/x/.rvm/gems/ruby-3.1.5/gems/reline-0.5.8/lib/reline.rb:261:in `synchronize'
/Users/x/.rvm/gems/ruby-3.1.5/gems/reline-0.5.8/lib/reline.rb:261:in `readmultiline'
/Users/x/.rvm/rubies/ruby-3.1.5/lib/ruby/3.1.0/forwardable.rb:238:in `readmultiline'
./msfconsole:23:in `<main>'
msf6 auxiliary(scanner/postgres/postgres_login) > 

IRB - After

msf6 auxiliary(scanner/postgres/postgres_login) > irb
[*] Starting IRB shell...
[*] You are in auxiliary/scanner/postgres/postgres_login

>> 
^C
>> 
^C
>> 

Verification

  • Start msfconsole
  • Ensure you can run some commands as expected
  • Get a SQL session using e.g. postgres_login
  • Ensure that the query and query_interactive commands work when provided single and multi-line input
  • Ensure that the irb command works
  • Ensure that pressing Ctrl+C in irb prompt does not result in a deadlock exception
  • Ensure that after exiting irb, the autocompletion suggestions do not leak from irb, and prompt remains normal
  • Ensure that msfconsole works on Windows 11 and does not freeze (linked issue)
  • Ensure tab-completion works in msfconsole's prompt for settings, set command etc.
  • Ensure that scrolling through the prompt's history using up and down arrow keys works as expected
  • Ensure that switching history_manager contexts does not result in history leakage (go into a SQL session, type a command, exit the SQL session, ensure the command you just entered does not show up in msfconsole's prompt)
  • Ensure tests pass

@sjanusz-r7 sjanusz-r7 force-pushed the replace-readline-with-reline branch from c0a42ad to 10dee22 Compare September 4, 2024 15:39
@cgranleese-r7 cgranleese-r7 self-assigned this Sep 16, 2024
@cgranleese-r7
Copy link
Contributor

I was able to test everything expect for the Windows 11 issue. I tested against build versions:

  • 10.0.22000
  • 10.0.22631

@adfoster-r7 has confirmed he can replicate it on his machine but just needs to do some extra testing.

Only other thing worth calling out was on master when you are within a session, then enter IRB you can ctrl + c to breakout making use of [-] Error during IRB: deadlock; recursive locking. Obviously this isn't ideal, but no it's fixed from what I experienced I wasn't able to actually leave IRB now, when I would run exit it would just return true. Thought it was worth calling out and we may need to open an issue for that.

Apart from that everything worked as expected 👍

@adfoster-r7 adfoster-r7 merged commit ab7e02d into rapid7:master Sep 20, 2024
37 checks passed
@cdelafuente-r7 cdelafuente-r7 added the rn-enhancement release notes enhancement label Sep 27, 2024
@cdelafuente-r7
Copy link
Contributor

Release Notes

This replaces the Readline library with Reline.

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

Successfully merging this pull request may close these issues.

Keyboard Input Issues in msfconsole on PowerShell After Update to v6.4.16 Windows11
5 participants