Query Details

Device Detect RDP Recon

Query

//Search for devices connecting to multiple IP addresses via RDP witin a time window and alert when over a particular threshold

//Data connector required for this query - M365 Defender - Device* tables

let timerange=1d;
let window=20m;
let threshold=5;
DeviceNetworkEvents
| where TimeGenerated > ago(timerange)
| where ActionType == "ConnectionSuccess"
| where RemotePort == "3389"
// Exclude Defender for Identity which uses RDP to map your network
| where InitiatingProcessFileName <> "Microsoft.Tri.Sensor.exe"
| summarize ['Target Device List']=make_set(RemoteIP), ['Count of Devices']=dcount(RemoteIP) by bin(TimeGenerated, window), DeviceName
| where ['Count of Devices'] > threshold
| sort by ['Count of Devices'] desc

Explanation

This query is designed to monitor and alert on unusual Remote Desktop Protocol (RDP) activity from devices within a network. Here's a simplified explanation of what it does:

  1. Time Frame: It looks at data from the past day (1d).

  2. Activity Window: It examines connections in 20-minute intervals.

  3. Threshold: It focuses on devices that connect to more than 5 different IP addresses via RDP within each 20-minute window.

  4. Data Source: The query uses data from Microsoft 365 Defender, specifically from tables related to device network events.

  5. Filtering Criteria:

    • It only considers successful connection attempts (ActionType == "ConnectionSuccess").
    • It specifically looks at connections made to port 3389, which is commonly used for RDP.
    • It excludes connections initiated by "Microsoft.Tri.Sensor.exe" to avoid false positives from legitimate network mapping activities by Defender for Identity.
  6. Summarization:

    • For each device, it compiles a list of unique IP addresses it has connected to within each 20-minute window.
    • It counts how many different IP addresses each device has connected to.
  7. Alert Condition: If a device connects to more than 5 different IP addresses in a 20-minute window, it triggers an alert.

  8. Output: The results are sorted to show devices with the highest number of connections first.

This query helps identify potentially suspicious behavior, such as a device making numerous RDP connections in a short period, which could indicate a security risk.

Details

Matt Zorich profile picture

Matt Zorich

Released: June 17, 2022

Tables

DeviceNetworkEvents

Keywords

Devices

Operators

let|where>ago()==<>summarizemake_set()dcount()bybin()sort bydesc

Actions

GitHub