Query Details
//Summarize your devices by their RDP activity. The data is sorted to show total outbound RDP connections, a count of distinct RDP connections and the list of IP's connected to.
//Data connector required for this query - M365 Defender - Device* tables
//Data is sorted by the devices with the most unique outbound RDP connections. Those devices have the biggest lateral movement blast radius.
//Microsoft Sentinel query
DeviceNetworkEvents
| where TimeGenerated > ago(30d)
| where ActionType == "ConnectionSuccess"
| where RemotePort == "3389"
//Exclude Defender for Identity that uses an initial RDP connection to map your network
| where InitiatingProcessCommandLine <> "\"Microsoft.Tri.Sensor.exe\""
| summarize
['RDP Outbound Connection Count']=count(),
['RDP Distinct Outbound Endpoint Count']=dcount(RemoteIP),
['RDP Outbound Endpoints']=make_set(RemoteIP)
by DeviceName
| sort by ['RDP Distinct Outbound Endpoint Count'] desc
//Advanced Hunting query
//Data connector required for this query - Advanced Hunting license
DeviceNetworkEvents
| where Timestamp > ago(30d)
| where ActionType == "ConnectionSuccess"
| where RemotePort == "3389"
//Exclude Defender for Identity that uses an initial RDP connection to map your network
| where InitiatingProcessCommandLine <> "\"Microsoft.Tri.Sensor.exe\""
| summarize
['RDP Outbound Connection Count']=count(),
['RDP Distinct Outbound Endpoint Count']=dcount(RemoteIP),
['RDP Outbound Endpoints']=make_set(RemoteIP)
by DeviceName
| sort by ['RDP Distinct Outbound Endpoint Count'] desc This query summarizes devices based on their Remote Desktop Protocol (RDP) activity. It shows the total number of outbound RDP connections, the count of distinct RDP connections, and the list of IP addresses connected to. The data is sorted to prioritize devices with the most unique outbound RDP connections, which indicates a larger potential impact if compromised. The query excludes Defender for Identity, which uses an initial RDP connection for network mapping. The query can be run in Microsoft Sentinel or with an Advanced Hunting license.

Matt Zorich
Released: June 17, 2022
Tables
Keywords
Operators