PowerShell-Powered AD Lab: Build a Hacker’s Playground for OSCP Prep in Under an Hour + Video

Listen to this Post

Featured Image

Introduction:

Active Directory (AD) remains the prime attack surface in enterprise environments, and penetration testers need repeatable, vulnerable labs to hone their skills. Manual AD setup is tedious and error‑prone, but PowerShell automates the entire process—from domain controller promotion to user/OU injection—giving red teams a scalable, realistic playground. This article delivers a full PowerShell script‑based lab, including attack vector configurations and mitigation commands, tailored for OSCP preparation and real‑world adversary simulation.

Learning Objectives:

  • Automate deployment of a Domain Controller, AD DS, and DNS using native PowerShell cmdlets.
  • Populate the AD forest with custom Organizational Units (OUs), users, groups, and service accounts via scripts.
  • Configure intentionally vulnerable policies and service settings (LLMNR, SMB signing, Kerberos) for penetration testing exercises.

You Should Know:

1. Automating Domain Controller Deployment with PowerShell

Step‑by‑step guide to turning a Windows Server (2019/2022) into a fully automated AD lab master.

First, run PowerShell as Administrator. Install the AD DS role and DNS without rebooting:

Install-WindowsFeature -Name AD-Domain-Services,DNS -IncludeManagementTools

Create a new forest and domain controller (e.g., lab.local). Wait for the promotion to complete:

$domain = "lab.local"
$domainCred = (Get-Credential -Message "Set Directory Services Restore Mode password")
Install-ADDSForest -DomainName $domain -SafeModeAdministratorPassword $domainCred.Password -Force

After reboot, verify with Get-ADDomain. This script promotes the server in less than five minutes—ideal for disposable pentest labs.

  1. Bulk User and OU Creation for Realistic AD Environment
    A realistic target domain contains hundreds of users and nested OUs. Use `New-ADOrganizationalUnit` and `New-ADUser` with CSV import.

Create OUs (e.g., `IT`, `HR`, `SALES`):

$ous = @("IT", "HR", "SALES", "ADMINS")
foreach ($ou in $ous) { New-ADOrganizationalUnit -Name $ou -Path "DC=lab,DC=local" }

Generate 50 users from a CSV (or loop with for). Example password `P@ssw0rd123` (vulnerable by design):

1..50 | ForEach-Object {
$name = "user$<em>"
New-ADUser -Name $name -SamAccountName $name -UserPrincipalName "[email protected]" -GivenName "Test" -Surname "User$</em>" -Enabled $true -AccountPassword (ConvertTo-SecureString "P@ssw0rd123" -AsPlainText -Force) -ChangePasswordAtLogon $false -Path "OU=IT,DC=lab,DC=local"
}

Add domain admins group and assign privileged users:

New-ADGroup -Name "Domain Admins" -GroupScope Global -GroupCategory Security
Add-ADGroupMember -Identity "Domain Admins" -Members "Administrator","user1"

3. Configuring Vulnerable Group Policies for Penetration Testing

Attackers often abuse weak GPOs. Create a policy that disables Windows Defender and sets weak password policies.

Export default GPO, modify, then link:

New-GPO -Name "Weak Security GPO" | New-GPLink -Target "DC=lab,DC=local"
Set-GPRegistryValue -Name "Weak Security GPO" -Key "HKLM\SOFTWARE\Policies\Microsoft\Windows Defender" -ValueName "DisableAntiSpyware" -Type DWord -Value 1
Set-GPRegistryValue -Name "Weak Security GPO" -Key "HKLM\SECURITY\Policy\PasswordPolicy" -ValueName "MinimumPasswordLength" -Type DWord -Value 4

Force policy update: gpupdate /force. This allows password spraying and AV bypass testing.

  1. Enabling Classic Attack Vectors: LLMNR, SMB Signing, and Kerberoastable Accounts
    To make the lab “vulnerable,” disable security features that real attackers target.
  • Enable LLMNR (default on older builds; ensure it’s on for responder attacks):
    Set-ItemProperty -Path "HKLM:\Software\Policies\Microsoft\Windows NT\DNSClient" -Name "EnableMulticast" -Value 1 -Type DWord
    
  • Disable SMB signing (allows NTLM relay):
    Set-SmbServerConfiguration -RequireSecuritySignature $false -EnableSMB2Protocol $true -Force
    
  • Create a Kerberoastable service account:
    New-ADUser -Name "svc_sql" -SamAccountName "svc_sql" -ServicePrincipalNames @{Add="MSSQLSvc/sql.lab.local:1433"} -AccountPassword (ConvertTo-SecureString "P@ssw0rd" -AsPlainText -Force) -Enabled $true
    

    These settings mimic real misconfigurations and are essential for tools like Responder, Impacket, and Kerberoast.

5. Post‑Setup Validation and Common Attack Simulation

After running the scripts, validate the lab from a Kali Linux attacker machine.

Check reachability and AD discovery:

nmap -p 88,389,445,5986 <DC_IP>
enum4linux -a <DC_IP>

Simulate LLMNR poisoning with `Responder`:

sudo responder -I eth0 -dwPv

Then from a Windows victim, trigger a name resolution (e.g., ping randomname).

For Kerberoasting from Linux:

impacket-GetUserSPNs -dc-ip <DC_IP> lab.local/svc_sql:P@ssw0rd -request

From Windows (PowerView):

Get-DomainUser -SPN | Get-DomainSPNTicket -OutputFormat Hashcat

This validates your lab’s attack surface.

6. Hardening and Cleanup Scripts for Safe Reuse

When not testing, revert to a hardened state or tear down the lab with automation.

Disable weak services:

Set-SmbServerConfiguration -RequireSecuritySignature $true -Force
Set-ItemProperty -Path "HKLM:\Software\Policies\Microsoft\Windows NT\DNSClient" -Name "EnableMulticast" -Value 0 -Type DWord

Remove all added test users:

Get-ADUser -Filter {SamAccountName -like "user"} | Remove-ADUser -Confirm:$false

Demote domain controller:

Uninstall-ADDSDomainController -Demote -Force -RemoveApplicationPartitions

These commands ensure you can rebuild the lab fresh without snapshot clutter.

7. Integrating with C2 Frameworks and BloodHound

A realistic lab feeds into advanced attack chains. Install SharpHound on the DC to collect AD data:

.\SharpHound.exe -c All --domain lab.local --Stealth

Transfer the zip to Kali and import into BloodHound:

sudo neo4j start
bloodhound --no-sandbox

Then run pre‑built queries (e.g., “Find all Kerberoastable users”). For C2 integration, deploy a Covenant or Sliver listener inside the lab to simulate post‑exploitation persistence.

What Undercode Say:

  • Automation dramatically reduces lab setup time – from hours to minutes, enabling testers to focus on attack vectors rather than infrastructure.
  • Intentional misconfigurations are the key to realistic training – harden one side, then attack the other. This PowerShell blueprint gives you both.

The convergence of PowerShell automation and deliberately vulnerable AD builds is reshaping how red teams prepare for exams like OSCP and CRTP. By scripting the entire lifecycle – deployment, user flooding, policy weakening, and cleanup – practitioners can iterate attack techniques (Kerberoasting, NTLM relay, LLMNR poisoning) without accumulating technical debt. However, this power also warns defenders: if an attacker gains administrative privileges, they can deploy identical scripts to expand their foothold across an entire forest. The future of AD security will see more Infrastructure‑as‑Code (IaC) abuse, where tools like Terraform or Ansible become adversary weapons. Blue teams must adopt immutable domain controllers and continuous authentication auditing to counter this shift.

Prediction:

As PowerShell and cross‑platform automation tools mature, we will see entire “adversary labs” compiled into containerized DCs (using Windows containers) and orchestrated via GitHub Actions. This will democratize advanced pentesting but also lower the barrier for malicious automation. Expect detection analytics to evolve toward behavioral anomaly detection on AD administrative cmdlets—watching for mass user creation or GPO tampering as direct IoCs. The arms race between script‑based lab builders and defensive ML models will define the next three years of enterprise identity security.

▶️ Related Video (80% Match):

🎯Let’s Practice For Free:

IT/Security Reporter URL:

Reported By: Powershell Based – Hackers Feeds
Extra Hub: Undercode MoN
Basic Verification: Pass ✅

🔐JOIN OUR CYBER WORLD [ CVE News • HackMonitor • UndercodeNews ]

💬 Whatsapp | 💬 Telegram

📢 Follow UndercodeTesting & Stay Tuned:

𝕏 formerly Twitter 🐦 | @ Threads | 🔗 Linkedin | 🦋BlueSky