1. Home
  2. Application Vulnerabilities
  3. How to remediate – Active Directory – Enumeration

How to remediate – Active Directory – Enumeration

1. Introduction

Active Directory enumeration allows attackers to gather information about a network’s users, groups, computers and trusts. This can help them map out the environment and identify potential targets for further exploitation. Successful enumeration compromises confidentiality by revealing sensitive data, integrity through privilege escalation, and availability via reconnaissance leading to denial of service. Affected systems are typically Windows domain controllers and any system with access to Active Directory.

2. Technical Explanation

Active Directory enumeration occurs when an attacker queries the directory for information without proper authorization or filtering. This is often possible due to misconfigured permissions or default settings that allow excessive access. The vulnerability lies in the ability to retrieve data from Active Directory without sufficient restrictions. A common attack involves using tools like ADSI to query user accounts, group memberships and computer details.

  • Root cause: Insufficiently restricted access controls on Active Directory objects.
  • Exploit mechanism: An attacker uses queries (e.g., LDAP or ADSI) to retrieve information about users, groups, computers, and trusts. For example, an attacker could use a script to list all user accounts in the domain.
  • Scope: Windows domain controllers and systems with access to Active Directory.

3. Detection and Assessment

Confirming vulnerability involves checking current AD permissions and monitoring for unusual query activity. A quick check is to see if unauthenticated queries are allowed. Thorough assessment requires auditing AD logs for enumeration attempts.

  • Quick checks: Use the command `nltest /domain_trusts` to list domain trusts, which indicates some level of enumeration capability.
  • Scanning: There are no specific signature IDs for this broad activity; however, security scanners can detect misconfigured permissions.
  • Logs and evidence: Review Windows Event Logs (Security log) for events related to LDAP queries (Event ID 5136). Look for unusual patterns or high volumes of requests from unknown sources.
nltest /domain_trusts

4. Solution / Remediation Steps

Fixing this issue involves restricting access to Active Directory objects and monitoring for unauthorized queries. The following steps provide a secure configuration.

4.1 Preparation

  • Ensure you have appropriate administrative credentials to modify AD permissions. A roll back plan involves restoring the AD backup if needed.
  • A change window may be required, and approval from a security team is recommended.

4.2 Implementation

  1. Step 1: Review and restrict default permissions on Active Directory containers (e.g., Users, Groups, Computers). Limit access to only authorized users and groups.
  2. Step 2: Implement least privilege principles for user accounts accessing Active Directory. Grant only the necessary permissions required for their roles.
  3. Step 3: Enable auditing of Active Directory object access events in the Security log.

4.3 Config or Code Example

Before

# Default permissions allowing "Authenticated Users" read access to user objects (example)
dsacls "CN=Users,DC=domain,DC=com" /grant "Authenticated Users:(R)"

After

# Restrict permissions to specific groups with necessary access.
dsacls "CN=Users,DC=domain,DC=com" /deny "Authenticated Users:(R)"
dsacls "CN=Users,DC=domain,DC=com" /grant "Domain Admins:(F)" 

4.4 Security Practices Relevant to This Vulnerability

Practices that directly address this vulnerability type include least privilege and input validation. Least privilege reduces the impact of successful exploitation by limiting access rights. Input validation can prevent malicious queries from being executed.

  • Practice 1: Implement least privilege principles to restrict user access to only necessary resources.
  • Practice 2: Regularly review and update Active Directory permissions to ensure they align with the principle of least privilege.

4.5 Automation (Optional)

# PowerShell example to deny read access for Authenticated Users on the Users container (use with caution)
Import-Module ActiveDirectory
$containerDN = "CN=Users,DC=domain,DC=com"
$acl = Get-Acl $containerDN
$rule = New-Object System.Security.AccessControl.FileSystemAccessRule("Authenticated Users","ReadAndExecute","Deny")
$acl.SetAccessRule($rule)
Set-Acl $containerDN $acl

5. Verification / Validation

Confirming the fix involves checking Active Directory permissions and verifying that unauthorized queries are blocked. A post-fix check is to verify that “Authenticated Users” no longer have read access to sensitive containers.

  • Post-fix check: Use `dsacls “CN=Users,DC=domain,DC=com”` and confirm that “Authenticated Users” does not have Read permissions.
  • Re-test: Re-run the earlier detection command (`nltest /domain_trusts`) to ensure it still functions for authorized users but is restricted for others.
  • Smoke test: Verify that authorized users can still perform their normal tasks, such as logging in and accessing resources.
  • Monitoring: Monitor the Security log for failed LDAP queries from unauthorized sources (Event ID 5136 with a failure code).
dsacls "CN=Users,DC=domain,DC=com"

6. Preventive Measures and Monitoring

Relevant preventive measures include updating security baselines and implementing pipeline checks to prevent misconfigurations. Regular patch cycles are also important for addressing known vulnerabilities.

  • Baselines: Update your Active Directory security baseline or policy (for example, a CIS control) to enforce least privilege permissions.
  • Pipelines: Add checks in CI/CD pipelines to validate Active Directory configurations and prevent unauthorized changes.
  • Asset and patch process: Implement a regular review cycle for Active Directory configurations and apply necessary patches promptly.

7. Risks, Side Effects, and Roll Back

Risks include accidentally locking out legitimate users if permissions are configured incorrectly. Service impacts may occur if critical services rely on specific AD permissions. Roll back involves restoring the previous permissions or restoring from a backup.

  • Risk or side effect 2: Changes may impact services relying on specific AD permissions. Mitigation: Document all changes and have a roll back plan in place.
  • Roll back: Restore the Active Directory database from a backup if necessary, or manually revert the permission changes made during implementation.

8. References and Resources

Related Articles