-
-
Save tuian/26987e699429056be5284f401278001c to your computer and use it in GitHub Desktop.
Find-VulnerableSchemas.ps1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Dictionary to hold superclass names | |
$superClass = @{} | |
# List to hold class names that inherit from container and are allowed to live under computer object | |
$vulnerableSchemas = [System.Collections.Generic.List[string]]::new() | |
# Resolve schema naming context | |
$schemaNC = (Get-ADRootDSE).schemaNamingContext | |
# Enumerate all class schemas | |
$classSchemas = Get-ADObject -LDAPFilter '(objectClass=classSchema)' -SearchBase $schemaNC -Properties lDAPDisplayName,subClassOf,possSuperiors | |
# Enumerate all class schemas that computer is allowed to contain | |
$computerInferiors = $classSchemas |Where-Object possSuperiors -eq 'computer' | |
# Populate superclass table | |
$classSchemas |ForEach-Object { | |
$superClass[$_.lDAPDisplayName] = $_.subClassOf | |
} | |
# Resolve class inheritance for computer inferiors | |
$computerInferiors |ForEach-Object { | |
$class = $cursor = $_.lDAPDisplayName | |
while($superClass[$cursor] -notin 'top'){ | |
if($superClass[$cursor] -eq 'container'){ | |
$vulnerableSchemas.Add($class) | |
break | |
} | |
$cursor = $superClass[$cursor] | |
} | |
} | |
# Outpupt list of vulnerable class schemas | |
$vulnerableSchemas |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment