Skip to content

Commit 3b23314

Browse files
authored
Merge pull request #252 from jakehildreth/main
Syncing testing to main
2 parents 7f6f900 + bf6822b commit 3b23314

16 files changed

Lines changed: 263 additions & 210 deletions

.github/ISSUE_TEMPLATE/bug_report.md

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,21 @@ assignees: ''
77

88
---
99

10-
**Describe the Bug**
10+
## Describe the Bug
1111
<!-- A clear and concise description of what the bug is. -->
1212

13-
**Steps To Reproduce**
13+
### Steps To Reproduce
1414
<!-- Steps to reproduce the behavior: -->
1515

16-
**Expected Behavior**
16+
### Expected Behavior
1717
<!-- A clear and concise description of what you expected to happen. -->
1818

19-
**Environment**
20-
- Locksmith Version: [e.g. 2024.8]
21-
- OS: [e.g. Windows Server 2019]
22-
- PowerShell Version: [e.g. Windows PowerShell 5.1 or PowerShell 7.4.5]
23-
- PowerShell Host: [e.g. Windows Terminal, PowerShell, PowerShell ISE, VS Code Terminal
19+
### Environment
2420

25-
**Additional Context**
21+
- Locksmith Version: (e.g. 2024.8)
22+
- OS: (e.g. Windows Server 2019)
23+
- PowerShell Version: (e.g. Windows PowerShell 5.1 or PowerShell 7.5.1)
24+
- PowerShell Host: (e.g. Windows Terminal, PowerShell, PowerShell ISE, VS Code Terminal)
25+
26+
### Additional Context
2627
<!-- Add any other context or screenshots of the problem here. -->

.github/workflows/mega-linter.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ on:
1313
# branches:
1414
# - main
1515
# - testing
16-
# workflow_dispatch:
16+
workflow_dispatch:
1717

1818
concurrency:
1919
group: ${{ github.ref }}-${{ github.workflow }}
@@ -45,7 +45,7 @@ jobs:
4545
# You can override MegaLinter flavor used to have faster performances
4646
# More info at https://megalinter.io/flavors/
4747
# The dotnet flavor includes PowerShell, MD, YAML, JSON, spelling, and more.
48-
uses: oxsecurity/megalinter/flavors/dotnet@v8.3.0
48+
uses: oxsecurity/megalinter/flavors/dotnet@v8.7.0
4949

5050
id: ml
5151

CHANGELOG.MD

Lines changed: 0 additions & 2 deletions
This file was deleted.

Docs/requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# https://github.com/readthedocs-examples/example-mkdocs-basic/blob/main/docs/requirements.txt
22
# requirements.txt
3-
jinja2==3.1.5 #https://pypi.org/project/Jinja2/
3+
jinja2==3.1.6 #https://pypi.org/project/Jinja2/
44
mkdocs>=1.6.0 #https://github.com/mkdocs/mkdocs
55
mkdocs-material==9.5.25 #https://github.com/squidfunk/mkdocs-material
66
pygments>=2.18.0 #https://pypi.org/project/Pygments/

Invoke-Locksmith.ps1

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2043,7 +2043,7 @@ function Get-CAHostObject {
20432043
[CmdletBinding()]
20442044
param (
20452045
[parameter(
2046-
Mandatory = $true,
2046+
Mandatory,
20472047
ValueFromPipeline = $true)]
20482048
[Microsoft.ActiveDirectory.Management.ADEntity[]]$ADCSObjects,
20492049
[System.Management.Automation.PSCredential]$Credential,
@@ -2053,20 +2053,20 @@ function Get-CAHostObject {
20532053
if ($Credential) {
20542054
$ADCSObjects | Where-Object objectClass -Match 'pKIEnrollmentService' | ForEach-Object {
20552055
if ($_.CAHostDistinguishedName) {
2056-
Get-ADObject $_.CAHostDistinguishedName -Properties * -Server $ForestGC -Credential $Credential
2056+
Get-ADObject $_.CAHostDistinguishedName -Properties * -Server $ForestGC -Credential $Credential
20572057
}
20582058
else {
2059-
Write-Warning "Get-CAHostObject: Unable to get information from $($_.DisplayName)"
2059+
Write-Warning "Get-CAHostObject: Unable to get information from $($_.DisplayName)"
20602060
}
20612061
}
20622062
}
20632063
else {
20642064
$ADCSObjects | Where-Object objectClass -Match 'pKIEnrollmentService' | ForEach-Object {
20652065
if ($_.CAHostDistinguishedName) {
2066-
Get-ADObject -Identity $_.CAHostDistinguishedName -Properties * -Server $ForestGC
2066+
Get-ADObject -Identity $_.CAHostDistinguishedName -Properties * -Server $ForestGC
20672067
}
20682068
else {
2069-
Write-Warning "Get-CAHostObject: Unable to get information from $($_.DisplayName)"
2069+
Write-Warning "Get-CAHostObject: Unable to get information from $($_.DisplayName)"
20702070
}
20712071
}
20722072
}
@@ -3029,7 +3029,7 @@ function Set-AdditionalCAProperty {
30293029
[CmdletBinding(SupportsShouldProcess)]
30303030
param (
30313031
[parameter(
3032-
Mandatory = $true,
3032+
Mandatory,
30333033
ValueFromPipeline = $true)]
30343034
[Microsoft.ActiveDirectory.Management.ADEntity[]]$ADCSObjects,
30353035
[PSCredential]$Credential,
@@ -3134,10 +3134,10 @@ function Set-AdditionalCAProperty {
31343134
$CAHostFQDN = (Get-ADObject -Filter { (Name -eq $CAHostName) -and (objectclass -eq 'computer') } -Properties DnsHostname -Server $ForestGC).DnsHostname
31353135
}
31363136
$ping = if ($CAHostFQDN) {
3137-
Test-Connection -ComputerName $CAHostFQDN -Count 1 -Quiet
3137+
Test-Connection -ComputerName $CAHostFQDN -Count 1 -Quiet
31383138
}
31393139
else {
3140-
Write-Warning "Unable to resolve $($_.Name) Fully Qualified Domain Name (FQDN)"
3140+
Write-Warning "Unable to resolve $($_.Name) Fully Qualified Domain Name (FQDN)"
31413141
}
31423142
if ($ping) {
31433143
try {
@@ -3727,23 +3727,23 @@ function Set-RiskRating {
37273727
switch ($Issue.objectClass) {
37283728
# Being able to modify Root CA Objects is very bad.
37293729
'certificationAuthority' {
3730-
$RiskValue += 2; $RiskScoring += 'Root Certification Authority bject: +2'
3730+
$RiskValue += 2; $RiskScoring += 'Root Certification Authority bject: +2'
37313731
}
37323732
# Being able to modify Issuing CA Objects is also very bad.
37333733
'pKIEnrollmentService' {
3734-
$RiskValue += 2; $RiskScoring += 'Issuing Certification Authority Object: +2'
3734+
$RiskValue += 2; $RiskScoring += 'Issuing Certification Authority Object: +2'
37353735
}
37363736
# Being able to modify CA Hosts? Yeah... very bad.
37373737
'computer' {
3738-
$RiskValue += 2; $RiskScoring += 'Certification Authority Host Computer: +2'
3738+
$RiskValue += 2; $RiskScoring += 'Certification Authority Host Computer: +2'
37393739
}
37403740
# Being able to modify OIDs could result in ESC13 vulns.
37413741
'msPKI-Enterprise-Oid' {
3742-
$RiskValue += 1; $RiskScoring += 'OID: +1'
3742+
$RiskValue += 1; $RiskScoring += 'OID: +1'
37433743
}
37443744
# Being able to modify PKS containers is bad.
37453745
'container' {
3746-
$RiskValue += 1; $RiskScoring += 'Container: +1'
3746+
$RiskValue += 1; $RiskScoring += 'Container: +1'
37473747
}
37483748
}
37493749
}
@@ -3764,19 +3764,19 @@ function Set-RiskRating {
37643764
# Convert Value to Name
37653765
$RiskName = switch ($RiskValue) {
37663766
{ $_ -le 1 } {
3767-
'Informational'
3767+
'Informational'
37683768
}
37693769
2 {
3770-
'Low'
3770+
'Low'
37713771
}
37723772
3 {
3773-
'Medium'
3773+
'Medium'
37743774
}
37753775
4 {
3776-
'High'
3776+
'High'
37773777
}
37783778
{ $_ -ge 5 } {
3779-
'Critical'
3779+
'Critical'
37803780
}
37813781
}
37823782

@@ -4335,7 +4335,7 @@ Set-Acl -Path `$Path -AclObject `$ACL
43354335
"@
43364336
}
43374337
4 {
4338-
break
4338+
break
43394339
}
43404340
5 {
43414341
$Issue.Fix = @"
@@ -4670,15 +4670,15 @@ Function Write-HostColorized {
46704670
# * At least for now, we remain PSv2-COMPATIBLE.
46714671
# * Thus:
46724672
# * no `[ordered]`, `::new()`, `[pscustomobject]`, ...
4673-
# * No implicit Boolean properties in [CmdletBinding()] and [Parameter()] attributes (`Mandatory = $true` instead of just `Mandatory`)
4673+
# * No implicit Boolean properties in [CmdletBinding()] and [Parameter()] attributes (`Mandatory` instead of just `Mandatory`)
46744674
# ===
46754675

46764676
[CmdletBinding(DefaultParameterSetName = 'SingleColor')]
46774677
param(
4678-
[Parameter(ParameterSetName = 'SingleColor', Position = 0, Mandatory = $True)] [string[]] $Pattern,
4678+
[Parameter(ParameterSetName = 'SingleColor', Position = 0, Mandatory)] [string[]] $Pattern,
46794679
[Parameter(ParameterSetName = 'SingleColor', Position = 1)] [ConsoleColor] $ForegroundColor = [ConsoleColor]::Yellow,
46804680
[Parameter(ParameterSetName = 'SingleColor', Position = 2)] [ConsoleColor] $BackgroundColor,
4681-
[Parameter(ParameterSetName = 'PerPatternColor', Position = 0, Mandatory = $True)] [System.Collections.IDictionary] $PatternColorMap,
4681+
[Parameter(ParameterSetName = 'PerPatternColor', Position = 0, Mandatory)] [System.Collections.IDictionary] $PatternColorMap,
46824682
[Parameter(ValueFromPipeline = $True)] $InputObject,
46834683
[switch] $WholeLine,
46844684
[switch] $SimpleMatch,
@@ -4706,10 +4706,10 @@ Function Write-HostColorized {
47064706
# We precompile them for better performance with many input objects.
47074707
[System.Text.RegularExpressions.RegexOptions] $reOpts =
47084708
if ($CaseSensitive) {
4709-
'Compiled, ExplicitCapture'
4709+
'Compiled, ExplicitCapture'
47104710
}
47114711
else {
4712-
'Compiled, ExplicitCapture, IgnoreCase'
4712+
'Compiled, ExplicitCapture, IgnoreCase'
47134713
}
47144714

47154715
# Transform the dictionary:
@@ -4731,10 +4731,10 @@ Function Write-HostColorized {
47314731
}
47324732
$colorArgs = @{ }
47334733
if ($fg) {
4734-
$colorArgs['ForegroundColor'] = [ConsoleColor] $fg
4734+
$colorArgs['ForegroundColor'] = [ConsoleColor] $fg
47354735
}
47364736
if ($bg) {
4737-
$colorArgs['BackgroundColor'] = [ConsoleColor] $bg
4737+
$colorArgs['BackgroundColor'] = [ConsoleColor] $bg
47384738
}
47394739

47404740
# Consolidate the patterns into a single pattern with alternation ('|'),
@@ -4753,7 +4753,7 @@ Function Write-HostColorized {
47534753
}
47544754
}
47554755
catch {
4756-
throw
4756+
throw
47574757
}
47584758

47594759
# Construct the arguments to pass to Out-String.
@@ -4776,7 +4776,7 @@ Function Write-HostColorized {
47764776
foreach ($m in $entry.Key.Matches($_)) {
47774777
@{ Index = $m.Index; Text = $m.Value; ColorArgs = $entry.Value }
47784778
if ($WholeLine) {
4779-
break patternLoop
4779+
break patternLoop
47804780
}
47814781
}
47824782
}

Private/Get-CAHostObject.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
[CmdletBinding()]
3232
param (
3333
[parameter(
34-
Mandatory = $true,
34+
Mandatory,
3535
ValueFromPipeline = $true)]
3636
[Microsoft.ActiveDirectory.Management.ADEntity[]]$ADCSObjects,
3737
[System.Management.Automation.PSCredential]$Credential,

Private/Set-AdditionalCAProperty.ps1

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
[CmdletBinding(SupportsShouldProcess)]
3131
param (
3232
[parameter(
33-
Mandatory = $true,
33+
Mandatory,
3434
ValueFromPipeline = $true)]
3535
[Microsoft.ActiveDirectory.Management.ADEntity[]]$ADCSObjects,
3636
[PSCredential]$Credential,
@@ -40,19 +40,19 @@
4040
begin {
4141
if (-not ([System.Management.Automation.PSTypeName]'TrustAllCertsPolicy') ) {
4242
if ($PSVersionTable.PSEdition -eq 'Desktop') {
43-
$code = @"
43+
$code = @'
4444
using System.Net;
4545
using System.Security.Cryptography.X509Certificates;
4646
public class TrustAllCertsPolicy : ICertificatePolicy {
4747
public bool CheckValidationResult(ServicePoint srvPoint, X509Certificate certificate, WebRequest request, int certificateProblem) {
4848
return true;
4949
}
5050
}
51-
"@
51+
'@
5252
Add-Type -TypeDefinition $code -Language CSharp
5353
[System.Net.ServicePointManager]::CertificatePolicy = New-Object TrustAllCertsPolicy
5454
} else {
55-
Add-Type @"
55+
Add-Type @'
5656
using System.Net;
5757
using System.Security.Cryptography.X509Certificates;
5858
using System.Net.Security;
@@ -61,7 +61,7 @@
6161
return true;
6262
}
6363
}
64-
"@
64+
'@
6565
# Set the ServerCertificateValidationCallback
6666
[System.Net.ServicePointManager]::ServerCertificateValidationCallback = [TrustAllCertsPolicy]::TrustAllCerts
6767
}
@@ -72,7 +72,7 @@
7272
$ADCSObjects | Where-Object objectClass -Match 'pKIEnrollmentService' | ForEach-Object {
7373
$CAEnrollmentEndpoint = @()
7474
#[array]$CAEnrollmentEndpoint = $_.'msPKI-Enrollment-Servers' | Select-String 'http.*' | ForEach-Object { $_.Matches[0].Value }
75-
foreach ($directory in @("certsrv/", "$($_.Name)_CES_Kerberos/service.svc", "$($_.Name)_CES_Kerberos/service.svc/CES", "ADPolicyProvider_CEP_Kerberos/service.svc", "certsrv/mscep/")) {
75+
foreach ($directory in @('certsrv/', "$($_.Name)_CES_Kerberos/service.svc", "$($_.Name)_CES_Kerberos/service.svc/CES", 'ADPolicyProvider_CEP_Kerberos/service.svc', 'certsrv/mscep/')) {
7676
$URL = "://$($_.dNSHostName)/$directory"
7777
try {
7878
$Auth = 'NTLM'
@@ -116,6 +116,7 @@
116116
'Auth' = $Auth
117117
}
118118
} catch {
119+
Write-Debug "There may have been an error or something nothing found. $_"
119120
}
120121
}
121122
}

Private/Set-AdditionalTemplateProperty.ps1

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,20 @@
2828
[Microsoft.ActiveDirectory.Management.ADEntity[]]$ADCSObjects
2929
)
3030

31-
$ADCSObjects | Where-Object objectClass -match 'pKICertificateTemplate' -PipelineVariable template | ForEach-Object {
32-
# Write-Host "[?] Checking if template `"$($template.Name)`" is Enabled on any Certification Authority." -ForegroundColor Blue
33-
$Enabled = $false
34-
$EnabledOn = @()
35-
foreach ($ca in ($ADCSObjects | Where-Object objectClass -eq 'pKIEnrollmentService')) {
36-
if ($ca.certificateTemplates -contains $template.Name) {
37-
$Enabled = $true
38-
$EnabledOn += $ca.Name
39-
}
31+
process {
32+
$ADCSObjects | Where-Object objectClass -Match 'pKICertificateTemplate' -PipelineVariable template | ForEach-Object {
33+
# Write-Host "[?] Checking if template `"$($template.Name)`" is Enabled on any Certification Authority." -ForegroundColor Blue
34+
$Enabled = $false
35+
$EnabledOn = @()
36+
foreach ($ca in ($ADCSObjects | Where-Object objectClass -EQ 'pKIEnrollmentService')) {
37+
if ($ca.certificateTemplates -contains $template.Name) {
38+
$Enabled = $true
39+
$EnabledOn += $ca.Name
40+
}
4041

41-
$template | Add-Member -NotePropertyName Enabled -NotePropertyValue $Enabled -Force
42-
$template | Add-Member -NotePropertyName EnabledOn -NotePropertyValue $EnabledOn -Force
42+
$template | Add-Member -NotePropertyName Enabled -NotePropertyValue $Enabled -Force
43+
$template | Add-Member -NotePropertyName EnabledOn -NotePropertyValue $EnabledOn -Force
44+
}
4345
}
4446
}
4547
}

0 commit comments

Comments
 (0)