THM Block
August 23, 2024•763 words
Files given
There was a zip file with the files for the lab. Unzip the file and you have an lsass.dmp file and a wireshark file.
Wireshark
Check through the file and see if you can find a user that logged in.
User 1
Frame number 11 gives the username of that user.
User 2
I searched through the dump file and got user 2.
lsass.dmp file
To make this a human readable file use: pypykatz lsa minidump lsass.DMP > clean.txt. I added the > clean.txt to the end of the command to get the output to go to a file that I could reference later.
Password for User 1
User 1 password
Within the dump file you will see an NT hash for the user. Copy that to a separate word file and then I used john to crack it. The command for john is john --format=nt --wordlist=/home/mark/CTF/words/pass.txt hash.
User 2 hash
The hash for this users was found in the dump file right below the username, which is towards the bottom of the file.
Flags that were found
User 1
Need the following information for the script that I found:
username: [Redacted]
domain: workgroup
password: [Redacted]
Session Key: [Redacted]
NtProofString: [Redacted]
Random Key from script: [Redacted]
SessionID: [Redacted]
Below is the script that I need to generate the key needed to decrypt the SMBv3 traffic in the wireshark capture.
import hashlib
import hmac
import argparse
# stolen from impacket. Thank you all for your wonderful contributions to the community
try:
from Cryptodome.Cipher import ARC4
from Cryptodome.Cipher import DES
from Cryptodome.Hash import MD4
except Exception:
import logging as LOG
LOG.critical("Warning: You don't have any crypto installed. You need pycryptodomex")
LOG.critical("See https://pypi.org/project/pycryptodomex/")
def generateEncryptedSessionKey(keyExchangeKey, exportedSessionKey):
cipher = ARC4.new(keyExchangeKey)
cipher_encrypt = cipher.encrypt
sessionKey = cipher_encrypt(exportedSessionKey)
return sessionKey
###
parser = argparse.ArgumentParser(description="Calculate the Random Session Key based on data from a PCAP (maybe).")
parser.add_argument("-u", "--user", required=True, help="User name")
parser.add_argument("-d", "--domain", required=True, help="Domain name")
parser.add_argument("-p", "--password", required=True, help="Password of User")
parser.add_argument("-n", "--ntproofstr", required=True, help="NTProofStr. This can be found in PCAP (provide Hex Stream)")
parser.add_argument("-k", "--key", required=True, help="Encrypted Session Key. This can be found in PCAP (provide Hex Stream)")
parser.add_argument("-v", "--verbose", action="store_true", help="increase output verbosity")
args = parser.parse_args()
# Upper Case User and Domain
user = str(args.user).upper().encode('utf-16le')
domain = str(args.domain).upper().encode('utf-16le')
# Create 'NTLM' Hash of password
passw = args.password.encode('utf-16le')
hash1 = hashlib.new('md4', passw)
password = hash1.digest()
# Calculate the ResponseNTKey
h = hmac.new(password, digestmod=hashlib.md5)
h.update(user + domain)
respNTKey = h.digest()
# Use NTProofSTR and ResponseNTKey to calculate Key Exchange Key
NTproofStr = bytes.fromhex(args.ntproofstr)
h = hmac.new(respNTKey, digestmod=hashlib.md5)
h.update(NTproofStr)
KeyExchKey = h.digest()
# Calculate the Random Session Key by decrypting Encrypted Session Key with Key Exchange Key via RC4
RsessKey = generateEncryptedSessionKey(KeyExchKey, bytes.fromhex(args.key))
if args.verbose:
print("USER WORK: " + user.decode('utf-16le') + domain.decode('utf-16le'))
print("PASS HASH: " + password.hex())
print("RESP NT: " + respNTKey.hex())
print("NT PROOF: " + NTproofStr.hex())
print("KeyExKey: " + KeyExchKey.hex())
print("Random SK: " + RsessKey.hex())
User 2
username: [Redacted]
domain: workgroup
hash: [Redacted]
Session Key: [Redacted]
NtProofString: [Redacted]
Random key from script: [Redacted]
SessionID: [Redacted]
Below is the script that I need to use because there is no password that can be found or cracked and I am given the hash of the user.
import hmac
import argparse
from Cryptodome.Cipher import ARC4
import binascii
import hashlib
def generate_encrypted_session_key(key_exchange_key, exported_session_key):
cipher = ARC4.new(key_exchange_key)
return cipher.encrypt(exported_session_key)
def main():
parser = argparse.ArgumentParser(description="Calculate the Random Session Key based on data from a PCAP (maybe).")
parser.add_argument("-u", "--user", required=True, help="User name")
parser.add_argument("-d", "--domain", required=True, help="Domain name")
parser.add_argument("-n", "--ntlmhash", required=True, help="NTLM Hash (provide as hex string)")
parser.add_argument("-nps", "--ntproofstr", required=True, help="NTProofStr (provide as hex string)")
parser.add_argument("-k", "--key", required=True, help="Encrypted Session Key (provide as hex string)")
parser.add_argument("-v", "--verbose", action="store_true", help="Increase output verbosity")
args = parser.parse_args()
# Upper case User and Domain
user = args.user.upper().encode('utf-16le')
domain = args.domain.upper().encode('utf-16le')
# Decode the NTLM hash from hex string
password_hash = binascii.unhexlify(args.ntlmhash)
# Calculate the ResponseNTKey
hmac_md5 = hmac.new(password_hash, digestmod=hashlib.md5)
hmac_md5.update(user + domain)
resp_nt_key = hmac_md5.digest()
# Use NTProofSTR and ResponseNTKey to calculate Key Exchange Key
nt_proof_str = binascii.unhexlify(args.ntproofstr)
hmac_md5 = hmac.new(resp_nt_key, digestmod=hashlib.md5)
hmac_md5.update(nt_proof_str)
key_exch_key = hmac_md5.digest()
# Calculate the Random Session Key by decrypting Encrypted Session Key with Key Exchange Key via RC4
encrypted_session_key = binascii.unhexlify(args.key)
random_session_key = generate_encrypted_session_key(key_exch_key, encrypted_session_key)
if args.verbose:
print("USER WORK: " + user.decode('utf-16le'))
print("PASS HASH: " + binascii.hexlify(password_hash).decode())
print("RESP NT: " + binascii.hexlify(resp_nt_key).decode())
print("NT PROOF: " + binascii.hexlify(nt_proof_str).decode())
print("KeyExKey: " + binascii.hexlify(key_exch_key).decode())
print("Random SK: " + binascii.hexlify(random_session_key).decode())
if __name__ == "__main__":
main()
As always if you have any questions please email me: feedback@markschindel.com. Have a great day and happy hacking.