Coder Social home page Coder Social logo

trimarcjake / locksmith Goto Github PK

View Code? Open in Web Editor NEW
721.0 13.0 70.0 820 KB

A small tool built to find and fix common misconfigurations in Active Directory Certificate Services.

Home Page: https://github.com/TrimarcJake/Locksmith

License: Other

PowerShell 100.00%
active-directory ad-cs adcs pki powershell powershell-module powershell-script active-directory-certificate-services

locksmith's Introduction

 _       _____  _______ _     _ _______ _______ _____ _______ _     _
 |      |     | |       |____/  |______ |  |  |   |      |    |_____|
 |_____ |_____| |_____  |    \_ ______| |  |  | __|__    |    |     |
     .--.                  .--.                  .--.
    /.-. '----------.     /.-. '----------.     /.-. '----------.
    \'-' .---'-''-'-'     \'-' .--'--''-'-'     \'-' .--'--'-''-'
     '--'                  '--'                  '--'

A tiny small tool built to find and fix common misconfigurations in Active Directory Certificate Services.

GitHub release GitHub top language PowerShell Gallery Platform Support GitHub contributors PRs Welcome GitHub Actions Workflow Status PowerShell Gallery Downloads Tweet

Contents

  1. Installation
  2. Run Locksmith
    1. Mode 0
    2. Mode 1
    3. Mode 2
    4. Mode 3
    5. Mode 4
    6. Scans

Installation

Module

Install module from the PowerShell Gallery (preferred):

  1. Open a PowerShell prompt and run Install-Module -Name Locksmith -Scope CurrentUser

Install module manually from GitHub:

  1. Download the latest module version ( Locksmith-v<YEAR>.<MONTH>.zip )
  2. Extract the downloaded zip file
  3. Open a PowerShell prompt to the location of the extracted file and run Import-Module Locksmith.psd1

Script

Download the standalone script (classic) without module:

  1. Download the latest script version: https://github.com/TrimarcJake/Locksmith/releases/latest/download/Invoke-Locksmith.zip
  2. Extract the downloaded zip file

Run Locksmith

Mode 0: Identify Issues, Output to Console (Default)

Running Invoke-Locksmith.ps1 with no parameters or with -Mode 0 will scan the current Active Directory forest and output all discovered AD CS issues to the console in Table format.

# Module Syntax
Invoke-Locksmith
# Script Syntax
.\Invoke-Locksmith.ps1

Example Output for Mode 0: https://github.com/TrimarcJake/Locksmith/blob/main/examples/Mode0.md

Mode 1:  Identify Issues and Fixes, Output to Console

This mode scans the current forest and outputs all discovered AD CS issues and possible fixes to the console in List format.

# Module Syntax
Invoke-Locksmith -Mode 1
# Script Syntax
.\Invoke-Locksmith.ps1 -Mode 1

Example Output for Mode 1: https://github.com/TrimarcJake/Locksmith/blob/main/examples/Mode1.md

Mode 2:  Identify Issues, Output to CSV

Locksmith Mode 2 scans the current forest and outputs all discovered AD CS issues to ADCSIssues.CSV in the present working directory.

# Module Syntax
Invoke-Locksmith -Mode 2
# Script Syntax
.\Invoke-Locksmith.ps1 -Mode 2

Example Output for Mode 2: https://github.com/TrimarcJake/Locksmith/blob/main/examples/Mode2.md

Mode 3:  Identify Issues and Fixes, Output to CSV

In Mode 3, Locksmith scans the current forest and outputs all discovered AD CS issues and example fixes to ADCSRemediation.CSV in the present working directory.

# Module Syntax
Invoke-Locksmith -Mode 3
# Script Syntax
.\Invoke-Locksmith.ps1 -Mode 3

Example Output for Mode 3: https://github.com/TrimarcJake/Locksmith/blob/main/examples/Mode3.md

Mode 4:  Fix All Issues

Mode 4 is the "easy button." Running Locksmith in Mode 4 will identify all misconfigurations and offer to fix each issue. If there is any possible operational impact, Locksmith will warn you.

# Module Syntax
Invoke-Locksmith -Mode 4
# Script Syntax
.\Invoke-Locksmith.ps1 -Mode 4

Example Output for Mode 4: https://github.com/TrimarcJake/Locksmith/blob/main/examples/Mode4.md

Scans:  Select Which Scans to Run

Use the -Scans parameter to choose which vulnerabilities to scan for. Acceptable values include All, Auditing, ESC1, ESC2, ESC3, ESC4, ESC5, ESC6, ESC8, or PromptMe. The PromptMe option presents an interactive list allowing you to select scans.

# Run all scans
Invoke-Locksmith -Scan All
# Prompt the user for a list of scans to select
Invoke-Locksmith.ps1 -Scans PromptMe
# Scan for ESC1 vulnerable paths
Invoke-Locksmith.ps1 -Scans ESC1
# Scan for ESC1, ESC2, and ESC8 vulnerable paths
Invoke-Locksmith.ps1 -Scans ESC1,ESC2,ESC8

locksmith's People

Contributors

jakeatbgohiodotorg avatar lkarlslund avatar mickhub avatar mplattner avatar przemyslawklys avatar samerde avatar techspence avatar trimarcjake avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

locksmith's Issues

SID Translation Error in the Find-ESC4 function

I just encountered an error during SID translation in the Find-ESC4 function, and I haven't yet figured out what is causing it. This is probably related to something in my environment because we have not encountered these errors before, but I want to log it and figure it out.

[ADMIN]: D:\Files>.\Invoke-Locksmith.ps1 -Forest REDACTED
Gathering AD CS Objects from REDACTED...
Identifying auditing issues...
Identifying AD CS templates with dangerous configurations...
Identifying AD CS template and other objects with poor access control...
Exception calling "Translate" with "1" argument(s): "Some or all identity references could not be translated."
At D:\Files\Invoke-Locksmith.ps1:454 char:13
+             $SID = ($Principal.Translate([System.Security.Principal.S ...
+             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : IdentityNotMappedException

I looked a few lines above this and tried running $Principal = New-Object System.Security.Principal.NTAccount($_.nTSecurityDescriptor.Owner) and this also resulted in an error:

New-Object : A constructor was not found. Cannot find an appropriate constructor for type System.Security.Principal.NTAccount.
At line:1 char:14
+ ... Principal = New-Object System.Security.Principal.NTAccount($_.nTSecur ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (:) [New-Object], PSArgumentException
    + FullyQualifiedErrorId : CannotFindAppropriateCtor,Microsoft.PowerShell.Commands.NewObjectCommand

For some reason it is failing to get the security principal of the current user and then failing to get the SID of the user. I do want to figure out why, but as an experiment I tried this code to get the SID, and it worked:

Add-Type -AssemblyName System.DirectoryServices.AccountManagement            
$SID = ([System.DirectoryServices.AccountManagement.UserPrincipal]::Current).SID.Value 

Systems Tested:

  • Windows Server 2016
  • Windows Server 2019
  • PowerShell 5.1
  • PowerShell 7.3.2

Privileges Used:

  • Runas Admin
  • Domain Admin

Will add more notes as I have time to reproduce and test. Additional thoughts are welcomed!

Mode 4 doesn't have an option to skip one fix and continue

What I expected would happen:

  • Halting would allow continue of the fixes - i.e. just skip the one fix and move to the next one

What actually happened:

  • Halting caused the script to terminate after pressing enter

Sample output:


Confirm
Continue with this operation?
[Y] Yes  [A] Yes to All  [H] Halt Command  [S] Suspend  [?] Help (default is "Y"): H
SKIPPED!
Press enter to continue...:

AD Connect service account read access listed as ESC5 vulnerability

We're using AD Connect to replicate on-prem AD to Azure AD, which uses a service account (e.g. MSOL_db365a3ec62) to enumerate all of the AD objects to be replicated. This service account apparently has read/write access to all objects in AD, and so the Locksmith app reports it as ESC5-type misconfiguration on the AD CS computer object (see below). But doesnt this account require read/write access (or at least read) on the object to effectively replicate it to Azure AD?

Untitled

We're checking for Restricted Admin Mode twice

This appears to be a leftover from a previous PR that "moved" the Restricted Admin Mode check to the beginning of the script. I forgot to remove it here:
https://github.com/TrimarcJake/Locksmith/blob/2d54c5b1171f4a8c392e0b21a3a00eb7dd258149/Public/Invoke-Locksmith.ps1#L163C7-L163C7

    if (!$Credential -and (Get-RestrictedAdminModeSetting)) {
        Write-Warning "Restricted Admin Mode appears to be in place, re-run with the '-Credential domain\user' option"
        break;
    }

Error "You cannot call a method on a null-valued expression."

You cannot call a method on a null-valued expression.
At C:\Users\Administrator.xxx\Desktop\Invoke-Locksmith.ps1:336 char:13

  •         $Issue | Add-Member -MemberType NoteProperty -Name Forest ...
    
  •         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    • CategoryInfo : InvalidOperation: (:) [], RuntimeException
    • FullyQualifiedErrorId : InvokeMethodOnNull

Improve ESC4/5 checks with Effective Access instead of dumb checks

ESC4 and ESC5 should report issues based on effective access instead of just filtering out Deny ACEs. Filtering Denys cuts down on false positives but doesn't provide a picture of true risk.

To be clear, risky Allows should still be removed when a corresponding Deny exists, but the actual risk presented is less than an Allow without a superseding Deny.

Private/Test-IsADAdmin.ps1

This file has a typo "Domain Admins" is missing the s

([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole("Domain Admin")

False Positives in ESC4 from Incomplete Filtering

Description: Locksmith is alerting on safe objects.

Example: CN=Machine,CN=Certificate Templates... has the following set of rights:

ActiveDirectoryRights : ReadProperty, WriteProperty, ExtendedRight
InheritanceType       : None
ObjectType            : 0e10c968-78fb-11d2-90d4-00c04f79dc55
InheritedObjectType   : 00000000-0000-0000-0000-000000000000
ObjectFlags           : ObjectAceTypePresent
AccessControlType     : Allow
IdentityReference     : MARVEL\Domain Computers
IsInherited           : False
InheritanceFlags      : None
PropagationFlags      : None

This is safe because WriteProperty only applies to the 0e10c968-78fb-11d2-90d4-00c04f79dc55 (Enroll) right.

Expected Result: No alert on this template.

Actual Result: Locksmith marks this as ESC4.

Proposed Solution: ESC4 check should filter out anything to do with ObjectType 0e10c968-78fb-11d2-90d4-00c04f79dc55 (Enroll) and a05b8cc2-17bc-4802-a710-e7c15ab866a2 (AutoEnroll)

Special thanks to Thomas Andresen for bringing this to my attention!

Improve RSAT Installation Process

If RSAT is not installed, Locksmith will silently install it if the user has admin rights. Instead, Locksmith should prompt the user for confirmation before installing and Import the AD PS module before continuing.

[ ] Add Confirmation dialog
[ ] Import module automatically.

ESC8 Identification is Incomplete

Hi,

It seems that ESC8 identification is not accurate.
In my case I can confirm web enrollment is not installed and Windows authentication for CEP and CES is set to: Negoriate:Kerberos and Extended Protection is Required.
Still, running Locksmith comes up with "HTTP enrollment is enabled."

image
image
image

Switch to identifying "safe" objects by SID rather than name

Running your excellent tool on non-english Active Directory environments trigger warnings for groups otherwise suppressed by the "SafeGroups", "SafeUsers" exclusions in your script.

For instance in German installations "Domain Admins" are named "Domänen-Admins" ...

(I had the same issue with Adalanche, and changing the queries to Well Known SIDs solved it.)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.