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

Improve interactive shell performance for pasted user input #15684

Merged

Conversation

adfoster-r7
Copy link
Contributor

Improves the interactive shell performance when reading user input.
Note that this functionality is behind a feature flag, enabled with:

features set fully_interactive_shells true

Before

When a user pastes the following input into their interactive shell -it:

echo TG9yZW0gaXBzdW0gZG9sb3Igc2l0IGFtZXQsIGNvbnNlY3RldHVyIGFkaXBpc2NpbmcgZWxpdC4gRXRpYW0gb3JjaSB0dXJwaXMsIGZpbmlidXMgaWQgYW50ZSBzaXQgYW1ldCwgcHJldGl1bSB2dWxwdXRhdGUgbGliZXJvLiBDbGFzcyBhcHRlbnQgdGFjaXRpIHNvY2lvc3F1IGFkIGxpdG9yYSB0b3JxdWVudCBwZXIgY29udWJpYSBub3N0cmEsIHBlciBpbmNlcHRvcyBoaW1lbmFlb3MuIFZpdmFtdXMgcXVhbSByaXN1cywgY3Vyc3VzIHZlbCBmaW5pYnVzIHF1aXMsIGVmZmljaXR1ciBuZWMgbnVsbGEuIEluIGhhYyBoYWJpdGFzc2UgcGxhdGVhIGRpY3R1bXN0LiBNb3JiaSBpZCBsZWN0dXMgcHJldGl1bSwgYXVjdG9yIG51bmMgaW4sIGNvbnNlY3RldHVyIHZlbGl0LiA= | base64 -d

The input is read a character at a time, and the user has to wait for the buffer to be read:
before

After

The user input is read 1024 characters at a time, and there's no longer any noticeable lag:
after

Verification

  • Acquire a linux meterpreter shell
  • Run shell -it
  • Paste the input and verify it no longer lags

@adfoster-r7 adfoster-r7 added the rn-enhancement release notes enhancement label Sep 17, 2021
@@ -75,7 +75,7 @@ def _interact_complete
#
def _stream_read_local_write_remote(channel)
if raw
data = user_input.getch
data = user_input.sysread(1024)
else
data = user_input.gets
end
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unrelated to this PR, but also noticing that there's a call to handle a line of user input:

self.on_command_proc.call(data.strip) if self.on_command_proc

Which interactive shells may break the assumptions of

@dwelch-r7 dwelch-r7 self-assigned this Sep 17, 2021
@dwelch-r7 dwelch-r7 merged commit 7856a88 into rapid7:master Sep 21, 2021
@dwelch-r7
Copy link
Contributor

Release Notes

Improves interactive shell performance for pasted user input

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.

None yet

2 participants