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

Reline behind a feature flag #19559

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

sjanusz-r7
Copy link
Contributor

@sjanusz-r7 sjanusz-r7 commented Oct 15, 2024

This PR is a continuation of #19397

This PR adds in the usage of the Reline library behind a feature flag.

Reline currently has some bugs/issues/inconsistencies compared to Readline. These are tracked as issue reports on Reline's GitHub.
These include:

  • Using IO's object encoding to not have to set the encoding globally
  • Tab completion append character only being appended when no more completions exist
  • Being able to change the completion append character in the completion proc (monkeypatched)
  • being able to perform multiple tab completions in a row with different values

We are moving away from Readline in favor if a pure Ruby implementation.
We are having to remove Readline on newer Windows 11 hosts due to an issue that Reline also encountered (and fixed since), where the console output handle would sometimes be incorrect, likely after calling popen, thus calls to console APIs such as SetConsoleCursorPosition would fail. A workaround is to periodically refresh the handle variable by calling handle = GetStdHandle.call(-11) // for STDOUT.

Verification

  • WIP

@sjanusz-r7 sjanusz-r7 force-pushed the readline-to-reline-behind-feature-flag branch 8 times, most recently from 1f24c46 to 879750b Compare October 17, 2024 10:42
@sjanusz-r7 sjanusz-r7 changed the title wip: Reline behind a feature flag Reline behind a feature flag Oct 17, 2024
@sjanusz-r7 sjanusz-r7 marked this pull request as ready for review October 17, 2024 12:50
@sjanusz-r7 sjanusz-r7 marked this pull request as draft October 17, 2024 14:05
@sjanusz-r7 sjanusz-r7 marked this pull request as ready for review October 17, 2024 14:16
lib/msf/ui/console/driver.rb Outdated Show resolved Hide resolved
lib/msf_autoload.rb Outdated Show resolved Hide resolved
@sjanusz-r7 sjanusz-r7 marked this pull request as draft October 18, 2024 10:43
@sjanusz-r7 sjanusz-r7 force-pushed the readline-to-reline-behind-feature-flag branch 2 times, most recently from 7753956 to 6fb1316 Compare October 21, 2024 09:36
@sjanusz-r7 sjanusz-r7 marked this pull request as ready for review October 21, 2024 09:44
@sjanusz-r7 sjanusz-r7 force-pushed the readline-to-reline-behind-feature-flag branch from 6fb1316 to d2b887e Compare October 21, 2024 13:49
@@ -22,6 +22,7 @@
require 'msfenv'
require 'rex'
require 'readline'
require 'reline'
Copy link
Contributor

@adfoster-r7 adfoster-r7 Oct 23, 2024

Choose a reason for hiding this comment

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

I think these are redundant if choosing readline libraries is handled by msfenv 👀

@sjanusz-r7 sjanusz-r7 force-pushed the readline-to-reline-behind-feature-flag branch from d2b887e to 89b9148 Compare November 18, 2024 13:38
@sjanusz-r7 sjanusz-r7 mentioned this pull request Nov 18, 2024
5 tasks
@sjanusz-r7 sjanusz-r7 force-pushed the readline-to-reline-behind-feature-flag branch 5 times, most recently from 2b30a4b to 86af256 Compare November 20, 2024 10:18
@@ -547,7 +547,7 @@ def cmd_irb(*args)
if expressions.empty?
print_status('Starting IRB shell...')
print_status("You are in the \"self\" (session) object\n")
framework.history_manager.with_context(name: :irb) do
framework.history_manager.with_context(name: :irb, input_library: :reline) do
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this meant to be using the feature flag check to choose between reline or not 👀

Copy link
Contributor Author

Choose a reason for hiding this comment

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

IRB always uses Reline, unless we specify @CONF[:USE_SINGLELINE] = true when setting up the IRB shell, which we don't currently do here:

I'll add in a helper here to check for this flag and default to :reline if !use_singleline or use_multiline as they are xor'd.

@sjanusz-r7 sjanusz-r7 force-pushed the readline-to-reline-behind-feature-flag branch from 86af256 to 76285da Compare November 20, 2024 17:20
@@ -28,6 +28,7 @@ def run

IRB.setup(nil)
IRB.conf[:PROMPT_MODE] = :SIMPLE
IRB.conf[:USE_MULTILINE] = true
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 am using this to make sure that IRB uses Reline, allowing us to set input_library: :reline in calls to with_context when interacting with the history manager.

@sjanusz-r7 sjanusz-r7 force-pushed the readline-to-reline-behind-feature-flag branch from 76285da to c743203 Compare November 20, 2024 18:02
@adfoster-r7
Copy link
Contributor

Rex::Post::Meterpreter::Ui::Console::CommandDispatcher::Core ..........F.........

  4) Rex::Post::Meterpreter::Ui::Console::CommandDispatcher::Core behaves like session command dispatcher Core commands #cmd_irb runs an irb shell instance
     Failure/Error: raise NoMethodError, msg

     NoMethodError:
       Method 'autocompletion' not found in Module
     Shared Example Group: "session command dispatcher" called from ./spec/lib/rex/post/meterpreter/ui/console/command_dispatcher/core_spec.rb:24
     # ./lib/msf/ui/console/msf_readline.rb:26:in `method_missing'
     # ./lib/msf/ui/console/msf_readline.rb:34:in `cache_current_config'
     # ./lib/msf/ui/console/command_dispatcher/session.rb:99:in `cmd_irb'
     # ./spec/support/shared/examples/msf/ui/console/command_dispatcher/session.rb:56:in `block (4 levels) in <top (required)>'
Rex::Post::PostgreSQL::Ui::Console::CommandDispatcher::Core .....F..............

  5) Rex::Post::PostgreSQL::Ui::Console::CommandDispatcher::Core behaves like session command dispatcher Core commands #cmd_irb runs an irb shell instance
     Failure/Error: raise NoMethodError, msg

     NoMethodError:
       Method 'autocompletion' not found in Module
     Shared Example Group: "session command dispatcher" called from ./spec/lib/rex/post/postgresql/ui/console/command_dispatcher/core_spec.rb:32
     # ./lib/msf/ui/console/msf_readline.rb:26:in `method_missing'
     # ./lib/msf/ui/console/msf_readline.rb:34:in `cache_current_config'
     # ./lib/msf/ui/console/command_dispatcher/session.rb:99:in `cmd_irb'
     # ./spec/support/shared/examples/msf/ui/console/command_dispatcher/session.rb:56:in `block (4 levels) in <top (required)>'


@sjanusz-r7 sjanusz-r7 force-pushed the readline-to-reline-behind-feature-flag branch from c743203 to 7692b61 Compare December 10, 2024 10:47
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.

3 participants