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

Fix broken msfconsole histories when switching between shell sessions #18223

Conversation

adfoster-r7
Copy link
Contributor

@adfoster-r7 adfoster-r7 commented Jul 27, 2023

Fixes broken msfconsole command history management when switching between shell sessions

Changes #15062

Verification

Verifying history tracking

Verify msfconsole's history works:

  • Open msfconsole
  • type echo "this is msfconsole history" and press enter
  • close msfconsole
  • Reopen msfconsole and verify pressing the up arrow shows echo "this is msfconsole history"

Verify swapping between shells works:

  • Open and interact with a new Meterpreter session

  • Verify the history works

  • Background the session, and verify pressing the up arrow shows the session interaction and eventually echo "this is msfconsole history"

  • Verify swapping between a command shell session works (i.e. osx/x86/shell_reverse_tcp)

  • Verify backgrounding the session will keep the top level history working

Verifying _historymanager command

Enable the manager commands:

msf6 > features set manager_commands true
manager_commands => true
msf6 > features

Features table
==============

   #  Name                      Enabled  Description
   -  ----                      -------  -----------
...
   2  manager_commands          true     When enabled you will have access to manager commands such as _servicemanager and _historymanager
...

msf6 >

Verify you can now see the history context stack:

msf6 > _historymanager 
History contexts
================

 Id  File                       Name
 --  ----                       ----
 0   /Users/user/.msf4/history  msfconsole

Verify you can enable the history logging:

msf6 > _historymanager -d
[*] HistoryManager debugging is now on

And the stack push/pops are now logged to stderr:

msf6 payload(osx/x64/shell_reverse_tcp) > sessions -i -1
[*] Starting interaction with 1...

Push context before
[
  {
    "history_file": "/Users/user/.msf4/history",
    "name": "msfconsole"
  }
]
Push context after
[
  {
    "history_file": "/Users/user/.msf4/history",
    "name": "msfconsole"
  },
  {
    "history_file": null,
    "name": "shell"
  }
]

background

Background session 1? [y/N]  y
Pop context before
[
  {
    "history_file": "/Users/user/.msf4/history",
    "name": "msfconsole"
  },
  {
    "history_file": null,
    "name": "shell"
  }
]
Pop context after
[
  {
    "history_file": "/Users/user/.msf4/history",
    "name": "msfconsole"
  }
]


msf6 payload(osx/x64/meterpreter_reverse_tcp) > sessions -i -1
[*] Starting interaction with 2...

Push context before
[
  {
    "history_file": "/Users/user/.msf4/history",
    "name": "msfconsole"
  }
]
Push context after
[
  {
    "history_file": "/Users/user/.msf4/history",
    "name": "msfconsole"
  },
  {
    "history_file": "/Users/user/.msf4/meterpreter_history",
    "name": "meterpreter"
  }
]
meterpreter > irb
[*] Starting IRB shell...
[*] You are in the "client" (session) object

Push context before
[
  {
    "history_file": "/Users/user/.msf4/history",
    "name": "msfconsole"
  },
  {
    "history_file": "/Users/user/.msf4/meterpreter_history",
    "name": "meterpreter"
  }
]
Push context after
[
  {
    "history_file": "/Users/user/.msf4/history",
    "name": "msfconsole"
  },
  {
    "history_file": "/Users/user/.msf4/meterpreter_history",
    "name": "meterpreter"
  },
  {
    "history_file": null,
    "name": "irb"
  }
]
irb: warn: can't alias kill from irb_kill.
irb: warn: can't alias info from irb_debug_info.
>>

@adfoster-r7 adfoster-r7 force-pushed the fix-broken-msfconsole-histories-when-switching-between-shell-sessions branch from bc8a545 to 026925c Compare July 27, 2023 12:01
shell Outdated Show resolved Hide resolved
@adfoster-r7 adfoster-r7 force-pushed the fix-broken-msfconsole-histories-when-switching-between-shell-sessions branch from 026925c to 449af8d Compare July 27, 2023 15:13
@cgranleese-r7
Copy link
Contributor

cgranleese-r7 commented Aug 3, 2023

Looks good to me 👍

Verify msfconsole's history works:

  • Open msfconsole
  • type echo "this is msfconsole history" and press enter
  • close msfconsole
  • Reopen msfconsole and verify pressing the up arrow shows echo "this is msfconsole history"
  • Verify swapping between shells works:

Open and interact with a new Meterpreter session

  • Background the session, and verify pressing the up arrow shows the session interaction and eventually echo "this is msfconsole history"
  • Verify swapping between a command shell session works (i.e. osx/x86/shell_reverse_tcp)
  • Verify backgrounding the session will keep the top level history working
  • Verifying _historymanager command

Enable the manager commands:

  • Verify you can now see the history context stack:
  • stack push/pops are now logged to stderr:

@cgranleese-r7 cgranleese-r7 self-assigned this Aug 3, 2023
@cgranleese-r7 cgranleese-r7 added the rn-enhancement release notes enhancement label Aug 3, 2023
@cgranleese-r7 cgranleese-r7 merged commit 5756241 into rapid7:master Aug 3, 2023
35 checks passed
@cgranleese-r7
Copy link
Contributor

Release Notes

This PR fixes broken msfconsole command history management when switching between shell sessions.

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

3 participants