11function Install-ADCSGoat {
22 [CmdletBinding ()]
33 param (
4- [switch ]$Randomize
4+ [switch ]$Randomize ,
5+ [string ]$TemplatePrefix = " AG" ,
6+ [string ]$Server
57 )
68
9+ if ([string ]::IsNullOrEmpty($Server )) {
10+ $Server = [System.Net.Dns ]::GetHostEntry($env: LOGONSERVER.TrimStart (' \' )).HostName
11+ }
12+
713 # region template issues
814 $Templates = @ (
9- @ {Name = ' AGESC1 ' ; ESC = ' ESC1' }
10- @ {Name = ' AGESC2 ' ; ESC = ' ESC2' }
11- @ {Name = ' AGESC3c1 ' ; ESC = ' ESC3c1' }
12- @ {Name = ' AGESC3c2 ' ; ESC = ' ESC3c2' }
13- @ {Name = ' AGESC4 ' ; ESC = ' ESC4' }
14- @ {Name = ' AGESC9 ' ; ESC = ' ESC9' }
15+ @ {Name = " ${TemplatePrefix} ESC1 " ; ESC = ' ESC1' }
16+ @ {Name = " ${TemplatePrefix} ESC2 " ; ESC = ' ESC2' }
17+ @ {Name = " ${TemplatePrefix} ESC3c1 " ; ESC = ' ESC3c1' }
18+ @ {Name = " ${TemplatePrefix} ESC3c2 " ; ESC = ' ESC3c2' }
19+ @ {Name = " ${TemplatePrefix} ESC4 " ; ESC = ' ESC4' }
20+ @ {Name = " ${TemplatePrefix} ESC9 " ; ESC = ' ESC9' }
1521 )
1622
1723 # What: Create blank template objects.
1824 # Why:
1925 $Templates | ForEach-Object {
2026 Write-Verbose " Creating blank template object: $ ( $_.Name ) "
21- New-AGBlankTemplateObject - TemplateName $_.Name
27+ New-AGBlankTemplateObject - TemplateName $_.Name - Server $Server
2228 }
2329
2430 # What: Assign properties to the blank template objects to turn them into real templates with vulnerable configs.
@@ -27,21 +33,21 @@ function Install-ADCSGoat {
2733 Write-Verbose " Assigning $ ( $_.ESC ) configuration to: $ ( $_.Name ) "
2834 $PropertiesPath = Join-Path - Path $PSScriptRoot - ChildPath " ..\Private\Template\$ ( $_.ESC ) .xml"
2935 $Properties = Import-Clixml - Path $PropertiesPath
30- Set-AGTemplateProperty - TemplateName $_.Name - Properties $Properties
36+ Set-AGTemplateProperty - TemplateName $_.Name - Properties $Properties - Server $Server
3137 }
3238
3339 # What: Grant low privileged users Enroll right on template objects to turn them into ESC issues (except ESC4)
3440 # Why:
3541 $Templates.Where ( { $_.ESC -ne ' ESC4' } ) | ForEach-Object {
3642 Write-Verbose " Granting Authenticated Users Enroll rights on: $ ( $_.Name ) "
37- Set-AGTemplateAce - TemplateName $_.Name - AceType Enroll
43+ Set-AGTemplateAce - TemplateName $_.Name - AceType Enroll - Server $Server
3844 }
3945
4046 # What: Grant low privileged users Full Control over a template object to turn it into an ESC4.
4147 # Why:
4248 $Templates.Where ( { $_.ESC -eq ' ESC4' } ) | ForEach-Object {
4349 Write-Verbose " Granting Authenticated Users Full Control of: $ ( $_.Name ) "
44- Set-AGTemplateAce - TemplateName $_.Name - AceType GenericAll
50+ Set-AGTemplateAce - TemplateName $_.Name - AceType GenericAll - Server $Server
4551 }
4652 # endregion template issues
4753
@@ -67,10 +73,20 @@ function Install-ADCSGoat {
6773
6874 # What: Enable ESC11 configuration on all CAs.
6975 # Why:
76+
7077 $EnrollmentServices | ForEach-Object {
7178 Write-Verbose " Assigning ESC11 configuration to: $ ( $_.Name ) "
7279 Disable-PSCInterfaceFlag - CAFullName $_.FullName - Flag IF_ENFORCEENCRYPTICERTREQUEST
7380 }
7481
82+ # What: Publish Certificate Templates
83+ # Why:
84+ $EnrollmentServices = Find-AGEnrollmentService
85+ $Templates | ForEach-Object {
86+ Write-Verbose " Publish $ ( $_.Name ) to: $ ( $EnrollmentServices.Path ) "
87+ Publish-AGCertifcateTemplate - TemplateName $_.Name - EnrollmentService $EnrollmentServices.Path - Server $Server
88+ }
89+
7590 # endregion ca issues
7691}
92+
0 commit comments