Query Details
// External Attack Surface Monitoring (EASM) KQL // "The one KQL query that unveils the entire external surface of your MDE device fleet" let InternetFacingDevices = ExposureGraphNodes | where NodeLabel == 'device' or (Categories has 'virtual_machine' and set_has_element(Categories, 'virtual_machine')) | where NodeProperties.rawData.isInternetFacing == true | distinct NodeName; DeviceNetworkEvents | where Timestamp > ago(30d) | where ActionType == "ListeningConnectionCreated" | where DeviceName has_any(InternetFacingDevices) | where LocalIP != @"127.0.0.1" | summarize ListeningPortExposed=dcount(LocalPort) by DeviceName | sort by ListeningPortExposed desc
This KQL query is designed to identify and analyze devices in your Microsoft Defender for Endpoint (MDE) fleet that are exposed to the internet. Here's a simplified breakdown of what the query does:
Identify Internet-Facing Devices:
ExposureGraphNodes to find devices that are either labeled as 'device' or categorized as 'virtual_machine'.isInternetFacing == true).InternetFacingDevices.Analyze Network Events:
DeviceNetworkEvents from the past 30 days.DeviceName has_any(InternetFacingDevices)).127.0.0.1), which is not relevant for external exposure.Summarize and Sort Results:
ListeningPortExposed).In summary, this query helps you understand which devices in your network are exposed to the internet and how many ports they have open for listening, which is crucial for assessing potential security risks.

Steven Lim
Released: June 18, 2025
Tables
Keywords
Operators