dSHeuristics, KB5008383 (CVE-2021-42291) – Die heilige Handgranate von Antiochia?

dSHeuristics oder doch die heilige Handgranate von Antiochia? Eins, Zwei, Fünf!
dSHeuristics oder doch die heilige Handgranate von Antiochia? Eins, Zwei, Fünf!

Hier ein kleines Script, um das dSHeuristics Attribut auf den Enforcement-Mode für „Additional AuthZ verifications for LDAP Add operations“ und „Temporary removal of Implicit Owner for LDAP Modify operations“ zu setzen (KB5008383 / CVE-2021-42291).

Der Hintergrund:

Summary
CVE-2021-42291 addresses a security bypass vulnerability that allows certain users to set arbitrary values on security-sensitive attributes of specific objects stored in Active Directory (AD). To exploit this vulnerability, a user must have sufficient privileges to create a computer account, such as a user granted CreateChild permissions for computer objects. That user could create a computer account using a Lightweight Directory Access Protocol (LDAP) Add call that allows overly permissive access to the securityDescriptor attribute. Additionally, creators and owners can modify security-sensitive attributes after creating an account.

Mitigations in CVE-2021-42291 consist of:

  1. Additional authorization verification when users without domain administrator rights attempt an LDAP Add operation for a computer-derived object. This includes an Audit-By-Default mode that audits when such attempts occur without interfering with the request and an Enforcement mode that blocks such attempts.
  2. Temporary removal of the Implicit Owner privileges when users without domain administrator rights attempt an LDAP Modify operation on the securityDescriptor attribute. A verification occurs to confirm if the user would be allowed to write the security descriptor without Implicit Owner privileges. This also includes an Audit-By-Default mode that audits when such attempts occur without interfering with the request and an Enforcement mode that blocks such attempts.
KB5008383—Active Directory permissions updates (CVE-2021-42291) – Microsoft Support

Was ist zu tun? Unterm Strich muss lediglich das dSHeuristics Attribut auf 29 Bits erweitert werden und dabei muss das Bit 28 sowie 29 auf „1“ gesetzt werden, um die Mitigations „Additional AuthZ verifications for LDAP Add operations“ und „Temporary removal of Implicit Owner for LDAP Modify operations“ zu erzwingen. Dabei muss allerdings beachtet werden, dass der „tenthChar“ – das zehnte Bit – auf „1“ sowie der „twentiethChar“ – das zwanzigste Bit – auf „2“ – Ja! Auf zwei, nicht auf eins. – gesetzt sind. Ein, zwei Beispiele:

  • Ist das Attribut leer oder „0“ (also Default): 00000000010000000002000000011
    • Bis zum zehnten Bit wird mit „0“ gefüllt
    • Das zehnten Bit wird auf „1“ gesetzt
    • Bit 11 bis 19 wird mit „0“ aufgefüllt
    • Das zwanzigste Bit wird auf „2“ gesetzt
    • Bit 21 bis 27 wird auf „0“ gesetzt
    • Bit 28 wird für den Enforcement-Mode auf „1“ gesetzt
    • Bit 29 wird für den Enforcement-Mode auf „1“ gesetzt
  • Gibt es bereits Werte, werden diese einfach übernommen und am Ende mit „0“ aufgefüllt, außer Bit 10 (-> „1“), Bit 20 (-> „2“), Bit 28 (-> „1“) und Bit 29 (-> „1“): 00100000010000000002000000011
    • Das Attribut war beispielsweise auf den Wert „001“ konfiguriert, was dem List Object Mode entspricht
    • Ab Bit 4 werden Nullen bis Bit 10 aufgefüllt
    • Das zehnten Bit wird auf „1“ gesetzt
    • Bit 11 bis 19 wird mit „0“ aufgefüllt
    • Das zwanzigste Bit wird auf „2“ gesetzt
    • Bit 21 bis 27 wird auf „0“ gesetzt
    • Bit 28 wird für den Enforcement-Mode auf „1“ gesetzt
    • Bit 29 wird für den Enforcement-Mode auf „1“ gesetzt
  • Hat das Attribut bereits mehr als 10 und/oder 20 Bits, muss Bit 10 bereits „1“ und Bit 20 „2“ sein und es wird einfach am Ende bis Bit 28 erweitert, welchea dann „1“ wird und das 29igste Bit wird ebenfalls „1“: 00000000010000001002000001011
    • Hier war dSHeuristics beispielsweise auf „00000000010000001002000001“ gesetzt; Was auch immer Bit 17 („fKVNOEmuW2K“) und 26 („fLoadV1AddressBooksOnlySetting“) machen. 🙂
    • Die Bits 1 bis 26 sind bereits gesetzt
    • Dass Attribut wird um Bit 26 mit „0“ erweitert
    • Bit 28 wird für den Enforcement-Mode auf „1“ gesetzt
    • Bit 29 wird für den Enforcement-Mode auf „1“ gesetzt
  • Das Attribut ist bereits länger als 10 und/oder 20 Bits und Bit 10 entspricht nicht „1“ sowie Bit 20 nicht „2“ sind wir bei der „Heiligen Handgranate von Antiochia“ 😀

Wer sich ein wenig weiter mit dem dsHeuristics Attribut auseinander setzen möchte, der kann hier eine Übersicht der möglichen Optionen finden: [MS-ADTS]: dSHeuristics | Microsoft Learn.

Um diesen Wirr-Warr zu vereinfachen bzw. die Bits nicht händisch abzählen zu müssen, hier das Script:

$ADDomain = Get-ADDomain -Current LocalComputer
$DN = -join(
    "CN=Directory Service,CN=Windows NT,CN=Services,CN=Configuration,",
    $ADDomain.DistinguishedName
)
$ADObject = Get-ADObject -Identity $DN `
    -Properties dsHeuristics
    
[string]$dSHeuristics = $ADObject.dsHeuristics

while($dSHeuristics.Length -lt 29){
    $dSHeuristics = -join(
        $dSHeuristics,
        "0"
    )
}

# fLDAPBlockAnonOps
<#
    https://learn.microsoft.com/de-de/openspecs/windows_protocols/ms-adts/e5899be4-862e-496f-9a38-33950617d2c5
    If this character is "2", then the fLDAPBlockAnonOps heuristic is false;
    otherwise, the fLDAPBlockAnonOps heuristic is true. If this character is
    not present in the string, it defaults to "2" when the DC functional
    level is less than DS_BEHAVIOR_WIN2003, and to "0" otherwise.

    https://learn.microsoft.com/de-de/openspecs/windows_protocols/ms-adts/4e11a7e6-e18c-46e4-a781-3ca2b4de6f30
    If the fLDAPBlockAnonOps heuristic of the dSHeuristics attribute (see
    section 6.1.1.2.4.1.2) is true, anonymous (unauthenticated) users are
    limited to performing rootDSE searches and binds. If fLDAPBlockAnonOps is
    false, anonymous users can perform any LDAP operation, subject to access
    checks that use the ACL mechanisms described in this section.
#>
# $dSHeuristics = $dSHeuristics -replace "(?<=^.{6}).","0"
$dSHeuristics = $dSHeuristics -replace "(?<=^.{9}).","1"
$dSHeuristics = $dSHeuristics -replace "(?<=^.{19}).","2"
$dSHeuristics = $dSHeuristics -replace "(?<=^.{27}).","1"
$dSHeuristics = $dSHeuristics -replace "(?<=^.{28}).","1"

Write-Output "Das Attribut `"dSHeuristics`" sollte auf diesen Wert konfiguriert werden: $dSHeuristics"

<#
Set-ADObject -Identity $DN `
    -Replace @{dsHeuristics=$dSHeuristics}
#>

Wer das Attribut direkt per Script schreiben möchte, muss den Kommentarblock am Ende, also das „<#“ sowie „#>“, entfernen und somit den Befehl „Set-ADObject“ scharf schalten. Alle anderen können den Output des Scripts händisch per ADSIEdit in das Attribut „dSHeuristics“ übertragen:

In der Ereignisanzeige lassen sich jetzt in den „Application and Service Logs“ -> „Directory Service“ die Events 3050 sowie 3053 finden, welche darüber informieren, dass man die sicherste Option gewählt hat und keine weitere Arbeit nötig ist: „This is the most secure setting and no further action is required.“

Get-WinEvent -LogName "Directory Service" `
    -MaxEvents 100 |
        Where-Object { $_.Id -match "3050|3053" } |
            Select-Object Id, Message -First 2 |
                fl

Id: 3050
Message: The directory has been configured to enforce per-attribute authorization during LDAP add operations.

This is the most secure setting and no further action is required.

For more information, please see https://go.microsoft.com/fwlink/?linkid=2174032.

Id: 3053

Message: The directory has been configured to block implicit owner privileges when initially setting or modifying the nTSecurityDescriptor attribute during LDAP add and modify operations.

This is the most secure setting and no further action is required.

For more information, please see https://go.microsoft.com/fwlink/?linkid=2174032.

Events „3050“ und „3053“ aus der Windows Ereignisanzeige

Viel Erfolg. 🙂

P.S.: Sollte Bit 7 nicht 0 sein, dann sollte geprüft werden, warum hier eine andere Option gesetzt ist und ob das beabsichtigt ist/war! Ein Anfang zur Informationsbeschaffung ist im auskommentierten Bereich des Scripts in den Zeilen 18 bis 33 zu finden.


Die gesuchte Lösung noch nicht gefunden oder benötigen Sie Hilfe bei anderen Themen aus meinem Blog? Nehmen Sie gerne Kontakt mit mir bzw. meinem Unternehmen Jan Mischo IT auf. Ich freue mich auf Ihre Anfrage: https://janmischo.it/kontakt/


+49 2801 7004300

info@janmischo.it


Beitrag veröffentlicht

in

, ,

von

Kommentare

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert

Diese Website verwendet Akismet, um Spam zu reduzieren. Erfahre mehr darüber, wie deine Kommentardaten verarbeitet werden.