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

extend error message for timeouts to include more detail to user #18299

Merged
merged 1 commit into from Oct 25, 2023

Conversation

zgoldman-r7
Copy link
Contributor

@zgoldman-r7 zgoldman-r7 commented Aug 18, 2023

Partially addresses #6274 - specifically implements #6274 (comment) for all functions that use that timeout error.

Verification

List the steps needed to make sure this thing works
Short version - trigger any Rex::TimeoutError and verify more verbose text
Longer version:
For interactive:

  • Start msfconsole
  • Open up a reverse shell (ie in windows/meterpreter/reverse_http)
  • `sessions -i your_session_id
  • Send a command that triggers the timeout error (ie powershell_execute 'sleep 20; echo abc')
  • Error should read "Send timed out. Timeout currently 15 seconds, you can configure this with sessions --interact --timeout "

For script:

  • create a foo.rc file with the following contents:
<ruby>
puts run_single("load powershell")
puts run_single("powershell_execute 'sleep 20; echo abc'")
</ruby>
  • start msfconsole
  • sessions --script foo.rc your_session_id
  • verify the output reads "Send timed out. Timeout currently 15 seconds, you can configure this with sessions --timeout --script <script> "

For command:

  • start msfconsole
  • Open up a reverse shell (ie in windows/meterpreter/reverse_http)
  • sessions -C "load powershell" your_session_id
  • sessions -C "powershell_execute 'sleep 20; echo abc'" your_session_id
  • verify the output reads "Send timed out. Timeout currently 15 seconds, you can configure this with sessions -C --timeout "

@zgoldman-r7 zgoldman-r7 force-pushed the ms9108improve-us branch 5 times, most recently from ce438c9 to 888ee07 Compare October 17, 2023 14:34
lib/rex/post/meterpreter/ui/console.rb Outdated Show resolved Hide resolved
lib/rex/post/meterpreter/ui/console.rb Outdated Show resolved Hide resolved
lib/msf/ui/console/command_dispatcher/core.rb Outdated Show resolved Hide resolved
lib/msf/ui/console/command_dispatcher/core.rb Outdated Show resolved Hide resolved
lib/msf/ui/console/command_dispatcher/core.rb Outdated Show resolved Hide resolved
lib/rex/ui/interactive.rb Outdated Show resolved Hide resolved
@adfoster-r7
Copy link
Contributor

Let's rename that final variable, and squash the commits down for git hygiene purposes

initial functionality, testing/cleanup still needed

script and command functionality

remove unnecessary accessor

switch puts to print_error in proc

ensure proc is reset, run on every error, add yard docs

fix yard, refactor/remove dead code

rename on_error_proc
@adfoster-r7
Copy link
Contributor

adfoster-r7 commented Oct 25, 2023

OSX osx/x64/shell_reverse_tcp

⚪ No timeout error printed, the timeout also seems to be lower than Meterpreter

msf6 payload(osx/x64/shell_reverse_tcp) > time sessions -i -1 -c 'sleep 20; echo abc'
[*] Running 'sleep 20; echo abc' on shell session -1 (127.0.0.1)

[+] Command "sessions -i -1 -c sleep\\ 20\\;\\ echo\\ abc" completed in 5.006230000006326 seconds

It looks like this is because the shell first tcp session has no configurable timeout

# osx/x64/shell_reverse_tcp
>> framework.sessions.values.last.methods.grep /timeout/
=> []
# osx Meterpreter
>> framework.sessions.values.first.methods.grep /timeout/
=> [:response_timeout, :response_timeout=, :comm_timeout, :comm_timeout

OSX Meterpreter

🔴 Looks like this doesn't work with the OSX Meterpreter with the -c flag

msf6 payload(osx/x64/meterpreter_reverse_tcp) > time sessions -c 'sleep 20; echo abc; echo abc'
[+] Command "sessions -c sleep\\ 20\\;\\ echo\\ abc\\;\\ echo\\ abc" completed in 14.324570000004314 seconds

The timeout exception is swallowed deeper down in the stack and the channel response is just read as being empty

Windows Meterpreter

🍏 Original windows UX improvement is working as expected:

meterpreter > powershell_execute 'sleep 20; echo abc'
[-] Send timed out. Timeout currently 15 seconds, you can configure this with sessions --interact <id> --timeout <value>

🍏 via sessions -C

msf6 exploit(windows/smb/psexec) > sessions -C "powershell_execute 'sleep 20; echo abc'"
[*] Running 'powershell_execute 'sleep 20; echo abc'' on meterpreter session 2 (192.168.123.133)

[-] Send timed out. Timeout currently 15 seconds, you can configure this with sessions -C <cmd> --timeout <value>

🍏 Works with the -c flag:

msf6 exploit(windows/smb/psexec) > sessions -i -1 -c 'powershell -command "Start-Sleep -s 20; echo abc"'
[*] Running 'powershell -command "Start-Sleep -s 20; echo abc"' on meterpreter session -1 (192.168.123.133)
[-] Operation timed out. Timeout currently 15 seconds, you can configure this with sessions -c <cmd> --timeout <value>

@adfoster-r7
Copy link
Contributor

adfoster-r7 commented Oct 25, 2023

I don't think the OSX edgecase is a blocker, as we've made improvements to the powershell side of things now which was our main focus/target user workflow 👍

@adfoster-r7 adfoster-r7 merged commit b58f963 into rapid7:master Oct 25, 2023
34 checks passed
@adfoster-r7
Copy link
Contributor

adfoster-r7 commented Oct 25, 2023

Release Notes

Improves error messages for timeouts when interacting with a Meterpreter session. Before an unclear error was printed. Now the user is notified how to increase the timeout limit.

@cgranleese-r7 cgranleese-r7 added the rn-enhancement release notes enhancement label Oct 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement rn-enhancement release notes enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants