Query Details

Rule : AD Reconnaissance Followed by Webhook Egress on the Same Device

Correlation AD Recon Then Webhook Egress

Query

let lookback=24h;
let Recon=DeviceProcessEvents
| where Timestamp > ago(lookback)
| where ProcessCommandLine has_any ("Get-ADUser","Get-ADComputer","Get-ADGroup","/dclist","Domain Admins","ldapsearch","setspn")
| summarize ReconCount=count(), ReconFirst=min(Timestamp), ReconLast=max(Timestamp), ReconCommands=make_set(substring(ProcessCommandLine,0,140),6) by DeviceId, DeviceName;
let Egress=DeviceNetworkEvents
| where Timestamp > ago(lookback)
| where RemoteUrl contains "webhook.site"
| project DeviceId, EgressTime=Timestamp, RemoteUrl;
Recon
| where ReconCount >= 3
| join kind=inner Egress on DeviceId
| where EgressTime between (ReconFirst .. (ReconLast + 30m))
| summarize EgressCount=count(), EgressFirst=min(EgressTime), EgressLast=max(EgressTime), EgressUrls=make_set(RemoteUrl,8), ReconCommands=take_any(ReconCommands) by DeviceId, DeviceName, ReconCount, ReconFirst, ReconLast
| project DeviceId, DeviceName, ReconCount, ReconFirst, ReconLast, EgressCount, EgressFirst, EgressLast, ReconCommands, EgressUrls
| order by EgressFirst desc

About this query

Explanation

This query is designed to detect suspicious activity on a device by identifying a specific sequence of events that could indicate a security threat. Here's a simple breakdown:

  1. Purpose: The query looks for devices that first perform Active Directory (AD) reconnaissance (a way to gather information about a network) and then connect to a specific external site (webhook.site) within 30 minutes. This pattern mimics a known attack method where attackers gather network information and then send it out to an external server.

  2. Data Sources: It uses two sets of data:

    • DeviceProcessEvents: Logs of command-line activities on devices.
    • DeviceNetworkEvents: Logs of network connections made by devices.
  3. Detection Criteria:

    • The device must execute at least three AD-related commands (like Get-ADUser, Get-ADComputer, etc.).
    • The device must connect to webhook.site after the first command and within 30 minutes after the last command.
  4. Output: The query lists devices that meet these criteria, showing details like the number of reconnaissance commands, the times they were executed, and the URLs accessed.

  5. Severity and Response: This is considered a high-severity alert, suggesting immediate investigation. If unauthorized, the device should be isolated to prevent further potential data exfiltration.

  6. False Positives: The query accounts for legitimate activities by red teams (security testing teams) or automated admin tasks, suggesting these should be excluded from alerts.

  7. Usage Note: The query is a starting point for investigation and should be fine-tuned based on the environment. It’s recommended to use it initially as a hunting tool rather than an automatic alert.

In essence, this query helps identify potential security breaches by correlating network reconnaissance with data exfiltration attempts on the same device.