Query Details

Rule : Rapid AD Reconnaissance Utility and Script Invocation

Discovery Automated AD Recon

Query

let lookback=24h;
DeviceProcessEvents
| where Timestamp > ago(lookback)
| where FileName in~ ("nltest.exe","dsquery.exe","setspn.exe","net.exe","net1.exe","whoami.exe","adfind.exe","ldapsearch","powershell.exe","pwsh.exe")
| where ProcessCommandLine has_any ("/domain_trusts","/dclist","/all_trusts","Domain Admins","Get-ADUser","Get-ADComputer","Get-ADGroup","Get-ADTrust","Get-ADServiceAccount","Get-ADObject","Get-ADForest","Get-ADDomain","Get-ADDefaultDomainPasswordPolicy","setspn","dsquery","ldapsearch","/domain","adfind","objectcategory","trustdmp","dcmodes","domainlist")
| summarize Commands=count(), DistinctQueries=dcount(ProcessCommandLine), Tools=make_set(FileName,8), Examples=make_set(substring(ProcessCommandLine,0,200),8), FirstSeen=min(Timestamp), LastSeen=max(Timestamp) by DeviceId, DeviceName, AccountName, bin(Timestamp,5m)
| where Commands >= 6 and DistinctQueries >= 4
| order by Commands desc

About this query

Explanation

This query is designed to detect suspicious activity related to Active Directory (AD) reconnaissance, which could indicate a security threat. It specifically looks for rapid execution of certain commands and scripts that are commonly used to gather information about an AD environment. Here's a simplified breakdown of the query:

  1. Purpose: The query aims to identify bursts of AD enumeration commands, which might suggest an automated tool is being used to map out an organization's AD structure. This could be a sign of malicious activity, such as an attacker trying to understand the network to plan further attacks.

  2. Monitored Commands: It focuses on commands and tools like nltest, dsquery, setspn, net group "Domain Admins", AdFind, ldapsearch, and PowerShell cmdlets starting with Get-AD*. These are typically used to discover information about domain trusts, domain controllers, users, groups, and service principal names (SPNs).

  3. Detection Criteria: The query looks for at least 6 commands with 4 or more distinct command lines executed within a 5-minute window. This pattern suggests a rapid and automated reconnaissance effort.

  4. Data Source: The query analyzes data from the DeviceProcessEvents table, which logs process execution events on devices.

  5. Exclusions: To reduce false positives, the query suggests excluding known legitimate activities, such as IT inventory checks or identity administration tasks, especially those originating from specific devices or accounts used for these purposes.

  6. Triage Steps: If the query triggers an alert, further investigation is recommended to check for related malicious activities, such as Kerberoasting (a technique to extract service account credentials) or attempts to synchronize domain controller data (DCSync).

  7. Additional Notes: The query is intended as a starting point for threat hunting and may need tuning to fit specific environments. It also notes that some PowerShell activities might not be fully captured in the process arguments.

Overall, this query is part of a security monitoring strategy to detect potential threats related to AD reconnaissance, which is often an early step in a cyber attack.