-
Notifications
You must be signed in to change notification settings - Fork 5
/
1. Template Forest.ps1
125 lines (98 loc) · 5.41 KB
/
1. Template Forest.ps1
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
116
117
118
119
120
121
122
123
124
125
#--------------------------------------------------------------------------------------------------------------------
# CHANGEME - Global parameters
$LabName = 'EnterpriseLab'
$Subnet = '10.10.X.0/24'
# CHANGEME - Credential parameters
$DomainUser = 'domadmin'
$DomainPass = 'complexpassword'
# CHANGEME - Domain parameters
$RootDomain = 'evilcorp.com'
$ChildDomain = 'eu.evilcorp.com'
$SecondDomain = 'us.allsafe.com'
$RootDC = 'ECDC01'
$RootCA = 'ECCA01'
$ChildDC = 'ECEUDC02'
$SecondDC = 'ASDC01'
# CHANGEME - Certificate Authority parameters
$CAName = 'EvilCorpCA'
# CHANGEME - Operating System parameters
$OperatingSystem = 'Windows Server 2022 Standard Evaluation' # Core has less footprint
# Domain Hash Table
$DCDictionary = @{
$RootDC = $RootDomain
$ChildDC = $ChildDomain
$SecondDC = $SecondDomain
}
# Path to our custom provisioning scripts
$ABLPostInstallActivitiesFilePath = Join-Path $PSScriptRoot "..\PostInstallationActivities"
#--------------------------------------------------------------------------------------------------------------------
# CUSTOMROLE INSTALLATION
$ABLCustomRolesFilePath = Join-Path $PSScriptRoot "..\CustomRoles"
# Copy the subdirectories of CustomRoles to the lab sources
Copy-Item -Path $ABLCustomRolesFilePath -Destination $labSources -Force -Recurse
#--------------------------------------------------------------------------------------------------------------------
# LAB CREATION
# Create our lab using HyperV (Azure is also supported)
New-LabDefinition -Name $LabName -DefaultVirtualizationEngine HyperV
# LAB ACCOUNTS
Set-LabInstallationCredential -Username $DomainUser -Password $DomainPass
Add-LabDomainDefinition -Name $RootDomain -AdminUser $DomainUser -AdminPassword $DomainPass
Add-LabDomainDefinition -Name $ChildDomain -AdminUser $DomainUser -AdminPassword $DomainPass
Add-LabDomainDefinition -Name $SecondDomain -AdminUser $DomainUser -AdminPassword $DomainPass
# NETWORKING - Simple flat internal network
Add-LabVirtualNetworkDefinition -Name $labName -AddressSpace $Subnet
#--------------------------------------------------------------------------------------------------------------------
# Defining default parameter values, as these ones are the same for all the machines.
$PSDefaultParameterValues = @{
'Add-LabMachineDefinition:Network' = $labName
'Add-LabMachineDefinition:ToolsPath' = "$labSources\Tools"
'Add-LabMachineDefinition:MinMemory' = 1GB
'Add-LabMachineDefinition:Memory' = 4GB
'Add-LabMachineDefinition:MaxMemory' = 8GB
'Add-LabMachineDefinition:OperatingSystem' = $OperatingSystem
}
#--------------------------------------------------------------------------------------------------------------------
# CA ROLE
$CARole = Get-LabMachineRoleDefinition -Role CaRoot @{
CACommonName = $CAName
KeyLength = '4096'
ValidityPeriod = 'Years'
ValidityPeriodUnits = '20'
}
# AUTOMATEDBADLAB ROLES
$AutomatedBadLabRole = Get-LabPostInstallationActivity -CustomRole AutomatedBadLab
$AutomatedBadLabADCSRole = Get-LabPostInstallationActivity -CustomRole AutomatedBadLabADCS
#--------------------------------------------------------------------------------------------------------------------
# MACHINE CREATION
# Forest A Root Domain Controller
Add-LabMachineDefinition -Name $RootDC -Roles RootDC -DomainName $RootDomain -PostInstallationActivity $AutomatedBadLabRole
# Forest A Certificate Authority
Add-LabMachineDefinition -Name $RootCA -Roles $CARole -DomainName $RootDomain -PostInstallationActivity $AutomatedBadLabADCSRole
# Forest A Child Domain Controller
Add-LabMachineDefinition -Name $ChildDC -Roles FirstChildDC -DomainName $ChildDomain -PostInstallationActivity $AutomatedBadLabRole
# Forest B Root Domain Controller
Add-LabMachineDefinition -Name $SecondDC -Roles RootDC -DomainName $SecondDomain -PostInstallationActivity $AutomatedBadLabRole
# Install our lab, has flags for level of output
Install-Lab # -Verbose -Debug
#--------------------------------------------------------------------------------------------------------------------
# Trust Provisioning
foreach ($DC in $DCDictionary.GetEnumerator()) {
Invoke-LabCommand -ComputerName $DC.Name -ActivityName CreateForeignMemberships -FileName Add-ForeignMemberships.ps1 `
-DependencyFolderPath $ABLPostInstallActivitiesFilePath\AutomatedBadLabTrusts
# Retrieve logs from each DC
$DC = Get-LabVM -ComputerName $DC.Name
$DCSession = New-LabPSSession -ComputerName $DC.Name
Receive-File -SourceFilePath C:\AutomatedBadLab.log -DestinationFilePath "$PSScriptRoot\$($DC.DomainName)_AutomatedBadLab.log" -Session $DCSession
Remove-LabPSSession -ComputerName $DC.Name
Write-ScreenInfo "Downloaded logs to $PSScriptRoot\$($DC.DomainName)_AutomatedBadLab.log"
}
# Provides a pretty table detailing all elements of what has been created
Show-LabDeploymentSummary -Detailed
<# Debugging - Remove all objects created by AutomatedBadLab
foreach ($DC in $DCDictionary.GetEnumerator()) {
Invoke-LabCommand -ComputerName $DC.Name -ActivityName RemoveAutomatedBadLab -FileName Remove-AllBLADObjects -DependencyFolderPath $CustomScripts\AutomatedBadLab\AD_Delete_All
}
Write-ScreenInfo "Removing Insecure ADCS Templates" # Runs locally
. "$CustomScripts\AutomatedBadLab\ADCS_Delete_All\Remove-AllBLADCSObjects.ps1"
Remove-AllBLADCSObjects
#>