Rule : Rapid East-West Port and Host Scanning
Discovery Internal Network Sweep
Query
let lookback=24h;
DeviceNetworkEvents
| where Timestamp > ago(lookback)
| where ActionType in ("ConnectionSuccess","ConnectionAttempt","ConnectionFailed")
| where ipv4_is_private(RemoteIP) == true
| where RemotePort in (22,88,135,139,389,445,636,1433,1521,3306,3389,5432,5985,5986,8080,8443)
| summarize Connections=count(), DistinctHosts=dcount(RemoteIP), DistinctPorts=dcount(RemotePort), Ports=make_set(RemotePort,20), Targets=make_set(RemoteIP,12) by DeviceId, DeviceName, InitiatingProcessFileName, InitiatingProcessAccountName, bin(Timestamp,5m)
| where DistinctHosts >= 12 and DistinctPorts >= 3
| order by DistinctHosts descAbout this query
Explanation
This query is designed to detect suspicious network activity that might indicate a security threat, specifically focusing on internal network scanning. Here's a simplified breakdown:
-
Purpose: The query aims to identify a single process on a device that is connecting to many different internal hosts using a variety of important administrative and database ports. This behavior is typical of malicious software trying to discover services within a network before attempting further attacks.
-
How it Works:
- It examines network connection events over the past 24 hours.
- It filters for outbound connection attempts (successful, attempted, or failed) to ensure it doesn't confuse incoming connections as scanning attempts.
- It focuses on connections to private IP addresses on specific high-value ports (like SSH, Kerberos, and database ports).
- It groups these events by device, process, and user account in 5-minute intervals.
- It triggers an alert if a process connects to 12 or more different hosts using 3 or more different ports within these intervals.
-
Data Source: The query uses the
DeviceNetworkEventstable to gather information about network connections. -
Exclusions: To reduce false positives, it suggests excluding known legitimate scanners and management systems from triggering alerts.
-
Investigation Steps:
- If an alert is triggered, investigate the process and its parent process to determine if it's legitimate or malicious.
- Check if any of the scanned hosts were accessed from the device that initiated the scan.
-
Considerations: The thresholds for triggering alerts are initial suggestions and should be adjusted based on the specific environment. The query should be used as a hunting tool initially to refine these thresholds.
Overall, this query is a proactive measure to detect potential lateral movement within a network by identifying unusual scanning activities.