Skip to content

Commit

Permalink
Merge branch 'testing' into fix-auditingissues-esc6
Browse files Browse the repository at this point in the history
  • Loading branch information
TrimarcJake authored Jan 20, 2024
2 parents d3e4e88 + a4383fc commit f4d1277
Show file tree
Hide file tree
Showing 8 changed files with 631 additions and 326 deletions.
2 changes: 1 addition & 1 deletion CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ representative at an online or offline event.
## Enforcement

Instances of abusive, harassing, or otherwise unacceptable behavior may be
reported to the community leaders responsible for enforcement at .
reported to the community leaders responsible for enforcement at coc@dotdot.horse.
All complaints will be reviewed and investigated promptly and fairly.

All community leaders are obligated to respect the privacy and security of the
Expand Down
6 changes: 3 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ All types of contributions are encouraged and valued. See the [Table of Contents
This project and everyone participating in it is governed by the
[Locksmith Code of Conduct](https://github.com/TrimarcJake/Locksmithblob/master/CODE_OF_CONDUCT.md).
By participating, you are expected to uphold this code. Please report unacceptable behavior
to .
to coc@dotdot.horse.


## I Have a Question
Expand All @@ -43,7 +43,7 @@ If you then still feel the need to ask a question and need clarification, we rec

- Open an [Issue](https://github.com/TrimarcJake/Locksmith/issues/new).
- Provide as much context as you can about what you're running into.
- Provide project and platform versions (nodejs, npm, etc), depending on what seems relevant.
- Provide project and platform versions (Windows Version, Powershell Version, Windows Terminal, etc.), depending on what seems relevant.

We will then take care of the issue as soon as possible.

Expand Down Expand Up @@ -98,7 +98,7 @@ This section guides you through submitting an enhancement suggestion for Locksmi
- Make sure that you are using the latest version.
- Read the [documentation](https://github.com/TrimarcJake/Locksmith/blob/main/README.md) carefully and find out if the functionality is already covered, maybe by an individual configuration.
- Perform a [search](https://github.com/TrimarcJake/Locksmith/issues) to see if the enhancement has already been suggested. If it has, add a comment to the existing issue instead of opening a new one.
- Find out whether your idea fits with the scope and aims of the project. It's up to you to make a strong case to convince the project's developers of the merits of this feature. Keep in mind that we want features that will be useful to the majority of our users and not just a small subset. If you're just targeting a minority of users, consider writing an add-on/plugin library.
- Find out whether your idea fits with the scope and aims of the project. It's up to you to make a strong case to convince the project's developers of the merits of this feature. Keep in mind that we want features that will be useful to the majority of our users and not just a small subset. If you're just targeting a minority of users, consider writing a new function.

<!-- omit in toc -->
#### How Do I Submit a Good Enhancement Suggestion?
Expand Down
485 changes: 320 additions & 165 deletions Invoke-Locksmith.ps1

Large diffs are not rendered by default.

11 changes: 5 additions & 6 deletions Private/Export-RevertScript.ps1
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
function Export-RevertScript {
[CmdletBinding()]
param(
[Parameter(Mandatory = $false)]
[array]$AuditingIssues,
[Parameter(Mandatory = $false)]
[array]$ESC1,
[Parameter(Mandatory = $false)]
[array]$ESC2,
[Parameter(Mandatory = $false)]
[array]$ESC3,
[array]$ESC4,
[array]$ESC5,
[array]$ESC6
)
begin {
$Output = 'Invoke-RevertLocksmith.ps1'
Set-Content -Path $Output -Value "<#`nScript to revert changes performed by Locksmith`nCreated $(Get-Date)`n#>" -Force
$Objects = $AuditingIssues + $ESC1 + $ESC2 + $ESC6
$Objects = $AuditingIssues + $ESC1 + $ESC2 + $ESC3 + $ESC4 + $ESC5 + $ESC6
}
process {
if ($Objects) {
Expand All @@ -23,4 +22,4 @@
}
}
}
}
}
3 changes: 1 addition & 2 deletions Private/Format-Result.ps1
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
function Format-Result {
[CmdletBinding()]
param(
[Parameter(Mandatory = $false)]
$Issue,
[Parameter(Mandatory = $true)]
[int]$Mode
Expand Down Expand Up @@ -37,4 +36,4 @@
}
}
}
}
}
266 changes: 266 additions & 0 deletions Private/Invoke-Remediation.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,266 @@
function Invoke-Remediation {
<#
.SYNOPSIS
Runs any remediation scripts available.
.DESCRIPTION
This function offers to run any remediation code associated with identified issues.
.PARAMETER AuditingIssues
A PS Object containing all necessary information about auditing issues.
.PARAMETER ESC1
A PS Object containing all necessary information about ESC1 issues.
.PARAMETER ESC2
A PS Object containing all necessary information about ESC2 issues.
.PARAMETER ESC3
A PS Object containing all necessary information about ESC3 issues.
.PARAMETER ESC4
A PS Object containing all necessary information about ESC4 issues.
.PARAMETER ESC5
A PS Object containing all necessary information about ESC5 issues.
.PARAMETER ESC6
A PS Object containing all necessary information about ESC6 issues.
.INPUTS
PS Objects
.OUTPUTS
Console output
#>

[CmdletBinding()]
param (
$AuditingIssues,
$ESC1,
$ESC2,
$ESC3,
$ESC4,
$ESC5,
$ESC6
)

Write-Host "`nExecuting Mode 4 - Attempting to fix identified issues!`n" -ForegroundColor Green
Write-Host 'Creating a script (' -NoNewline
Write-Host 'Invoke-RevertLocksmith.ps1' -ForegroundColor White -NoNewline
Write-Host ") which can be used to revert all changes made by Locksmith...`n"
try {
Export-RevertScript -AuditingIssues $AuditingIssues -ESC1 $ESC1 -ESC2 $ESC2 -ESC3 $ESC3 -ESC4 $ESC4 -ESC5 $ESC5 -ESC6 $ESC6
} catch {
Write-Warning 'Creation of Invoke-RevertLocksmith.ps1 failed.'
Write-Host "Continue with this operation? [Y] Yes " -NoNewline
Write-Host "[N] " -ForegroundColor Yellow -NoNewline
Write-Host "No: " -NoNewLine
$WarningError = ''
$WarningError = Read-Host
if ($WarningError -like 'y') {
# Continue
} else {
break
}
}
if ($AuditingIssues) {
$AuditingIssues | ForEach-Object {
$FixBlock = [scriptblock]::Create($_.Fix)
Write-Host 'ISSUE:' -ForegroundColor White
Write-Host "Auditing is not fully enabled on Certification Authority `"$($_.Name)`".`n"
Write-Host 'TECHNIQUE:' -ForegroundColor White
Write-Host "$($_.Technique)`n"
Write-Host 'ACTION TO BE PERFORMED:' -ForegroundColor White
Write-Host "Locksmith will attempt to fully enable auditing on Certification Authority `"$($_.Name)`".`n"
Write-Host 'COMMAND(S) TO BE RUN:'
Write-Host 'PS> ' -NoNewline
Write-Host "$($_.Fix)`n" -ForegroundColor Cyan
Write-Host 'OPERATIONAL IMPACT:' -ForegroundColor White
Write-Host "This change should have little to no impact on the AD CS environment.`n" -ForegroundColor Green
Write-Host "If you continue, Locksmith will attempt to fix this issue.`n" -ForegroundColor Yellow
Write-Host "Continue with this operation? [Y] Yes " -NoNewline
Write-Host "[N] " -ForegroundColor Yellow -NoNewline
Write-Host "No: " -NoNewLine
$WarningError = ''
$WarningError = Read-Host
if ($WarningError -like 'y') {
try {
Invoke-Command -ScriptBlock $FixBlock
} catch {
Write-Error 'Could not modify AD CS auditing. Are you a local admin on the CA host?'
}
} else {
Write-Host "SKIPPED!`n" -ForegroundColor Yellow
}
}
}
if ($ESC1) {
$ESC1 | ForEach-Object {
$FixBlock = [scriptblock]::Create($_.Fix)
Write-Host 'ISSUE:' -ForegroundColor White
Write-Host "Security Principals can enroll in `"$($_.Name)`" template using a Subject Alternative Name without Manager Approval.`n"
Write-Host 'TECHNIQUE:' -ForegroundColor White
Write-Host "$($_.Technique)`n"
Write-Host 'ACTION TO BE PERFORMED:' -ForegroundColor White
Write-Host "Locksmith will attempt to enable Manager Approval on the `"$($_.Name)`" template.`n"
Write-Host 'CCOMMAND(S) TO BE RUN:'
Write-Host 'PS> ' -NoNewline
Write-Host "$($_.Fix)`n" -ForegroundColor Cyan
Write-Host 'OPERATIONAL IMPACT:' -ForegroundColor White
Write-Host "WARNING: This change could cause some services to stop working until certificates are approved.`n" -ForegroundColor Yellow
Write-Host "If you continue, Locksmith will attempt to fix this issue.`n" -ForegroundColor Yellow
Write-Host "Continue with this operation? [Y] Yes " -NoNewline
Write-Host "[N] " -ForegroundColor Yellow -NoNewline
Write-Host "No: " -NoNewLine
$WarningError = ''
$WarningError = Read-Host
if ($WarningError -like 'y') {
try {
Invoke-Command -ScriptBlock $FixBlock
} catch {
Write-Error 'Could not enable Manager Approval. Are you an Active Directory or AD CS admin?'
}
} else {
Write-Host "SKIPPED!`n" -ForegroundColor Yellow
}

}
}
if ($ESC2) {
$ESC2 | ForEach-Object {
$FixBlock = [scriptblock]::Create($_.Fix)
Write-Host 'ISSUE:' -ForegroundColor White
Write-Host "Security Principals can enroll in `"$($_.Name)`" template and create a Subordinate Certification Authority without Manager Approval.`n"
Write-Host 'TECHNIQUE:' -ForegroundColor White
Write-Host "$($_.Technique)`n"
Write-Host 'ACTION TO BE PERFORMED:' -ForegroundColor White
Write-Host "Locksmith will attempt to enable Manager Approval on the `"$($_.Name)`" template.`n"
Write-Host 'COMMAND(S) TO BE RUN:' -ForegroundColor White
Write-Host 'PS> ' -NoNewline
Write-Host "$($_.Fix)`n" -ForegroundColor Cyan
Write-Host 'OPERATIONAL IMPACT:' -ForegroundColor White
Write-Host "WARNING: This change could cause some services to stop working until certificates are approved.`n" -ForegroundColor Yellow
Write-Host "If you continue, Locksmith will attempt to fix this issue.`n" -ForegroundColor Yellow
Write-Host "Continue with this operation? [Y] Yes " -NoNewline
Write-Host "[N] " -ForegroundColor Yellow -NoNewline
Write-Host "No: " -NoNewLine
$WarningError = ''
$WarningError = Read-Host
if ($WarningError -like 'y') {
try {
Invoke-Command -ScriptBlock $FixBlock
} catch {
Write-Error 'Could not enable Manager Approval. Are you an Active Directory or AD CS admin?'
}
} else {
Write-Host "SKIPPED!`n" -ForegroundColor Yellow
}
}
}
if ($ESC4) {
$ESC4 | Where-Object Issue -like "* Owner rights *" | ForEach-Object { # This selector sucks - Jake
$FixBlock = [scriptblock]::Create($_.Fix)
Write-Host 'ISSUE:' -ForegroundColor White
Write-Host "$($_.Issue)`n"
Write-Host 'TECHNIQUE:' -ForegroundColor White
Write-Host "$($_.Technique)`n"
Write-Host 'ACTION TO BE PERFORMED:' -ForegroundColor White
Write-Host "Locksmith will attempt to set the owner of `"$($_.Name)`" template to Enterprise Admins.`n"
Write-Host 'COMMAND(S) TO BE RUN:' -ForegroundColor White
Write-Host 'PS> ' -NoNewline
Write-Host "$($_.Fix)`n" -ForegroundColor Cyan
Write-Host 'OPERATIONAL IMPACT:' -ForegroundColor White
Write-Host "This change should have little to no impact on the AD CS environment.`n" -ForegroundColor Green
Write-Host "If you continue, Locksmith will attempt to fix this issue.`n" -ForegroundColor Yellow
Write-Host "Continue with this operation? [Y] Yes " -NoNewline
Write-Host "[N] " -ForegroundColor Yellow -NoNewline
Write-Host "No: " -NoNewLine
$WarningError = ''
$WarningError = Read-Host
if ($WarningError -like 'y') {
try {
Invoke-Command -ScriptBlock $FixBlock
} catch {
Write-Error 'Could not change Owner. Are you an Active Directory admin?'
}
} else {
Write-Host "SKIPPED!`n" -ForegroundColor Yellow
}
}
}
if ($ESC5) {
$ESC5 | Where-Object Issue -like "* Owner rights *" | ForEach-Object { # This selector sucks - Jake
$FixBlock = [scriptblock]::Create($_.Fix)
Write-Host 'ISSUE:' -ForegroundColor White
Write-Host "$($_.Issue)`n"
Write-Host 'TECHNIQUE:' -ForegroundColor White
Write-Host "$($_.Technique)`n"
Write-Host 'ACTION TO BE PERFORMED:' -ForegroundColor White
Write-Host "Locksmith will attempt to set the owner of `"$($_.Name)`" object to Enterprise Admins.`n"
Write-Host 'COMMAND(S) TO BE RUN:' -ForegroundColor White
Write-Host 'PS> ' -NoNewline
Write-Host "$($_.Fix)`n" -ForegroundColor Cyan
Write-Host 'OPERATIONAL IMPACT:' -ForegroundColor White
Write-Host "This change should have little to no impact on the AD CS environment.`n" -ForegroundColor Green
Write-Host "If you continue, Locksmith will attempt to fix this issue.`n" -ForegroundColor Yellow
Write-Host "Continue with this operation? [Y] Yes " -NoNewline
Write-Host "[N] " -ForegroundColor Yellow -NoNewline
Write-Host "No: " -NoNewLine
$WarningError = ''
$WarningError = Read-Host
if ($WarningError -like 'y') {
try {
Invoke-Command -ScriptBlock $FixBlock
} catch {
Write-Error 'Could not change Owner. Are you an Active Directory admin?'
}
} else {
Write-Host "SKIPPED!`n" -ForegroundColor Yellow
}
}
}
if ($ESC6) {
$ESC6 | ForEach-Object {
$FixBlock = [scriptblock]::Create($_.Fix)
Write-Host 'ISSUE:' -ForegroundColor White
Write-Host "The Certification Authority `"$($_.Name)`" has the dangerous EDITF_ATTRIBUTESUBJECTALTNAME2 flag enabled.`n"
Write-Host 'TECHNIQUE:' -ForegroundColor White
Write-Host "$($_.Technique)`n"
Write-Host 'ACTION TO BE PERFORMED:' -ForegroundColor White
Write-Host "Locksmith will attempt to disable the EDITF_ATTRIBUTESUBJECTALTNAME2 flag on Certifiction Authority `"$($_.Name)`".`n"
Write-Host 'COMMAND(S) TO BE RUN' -ForegroundColor White
Write-Host 'PS> ' -NoNewline
Write-Host "$($_.Fix)`n" -ForegroundColor Cyan
$WarningError = 'n'
Write-Host 'OPERATIONAL IMPACT:' -ForegroundColor White
Write-Host "WARNING: This change could cause some services to stop working.`n" -ForegroundColor Yellow
Write-Host "If you continue, Locksmith will attempt to fix this issue.`n" -ForegroundColor Yellow
Write-Host "Continue with this operation? [Y] Yes " -NoNewline
Write-Host "[N] " -ForegroundColor Yellow -NoNewline
Write-Host "No: " -NoNewLine
$WarningError = ''
$WarningError = Read-Host
if ($WarningError -like 'y') {
try {
Invoke-Command -ScriptBlock $FixBlock
} catch {
Write-Error 'Could not disable the EDITF_ATTRIBUTESUBJECTALTNAME2 flag. Are you an Active Directory or AD CS admin?'
}
} else {
Write-Host "SKIPPED!`n" -ForegroundColor Yellow
}
}
}

Write-Host "Mode 4 Complete! There are no more issues that Locksmith can automatically resolve.`n" -ForegroundColor Green
Write-Host 'If you experience any operational impact from using Locksmith Mode 4, use ' -NoNewline
Write-Host 'Invoke-RevertLocksmith.ps1 ' -ForegroundColor White
Write-Host "to revert all changes made by Locksmith. It can be found in the current working directory.`n"
Write-Host @"
REMINDER: Locksmith cannot automatically resolve all AD CS issues at this time.
There may be more AD CS issues remaining in your environment.
Use Locksmith in Modes 0-3 to further investigate your environment
or reach out to the Locksmith team for assistance. We'd love to help!`n
"@ -ForegroundColor Yellow
}
Loading

0 comments on commit f4d1277

Please sign in to comment.