Query Details

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 desc

About 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:

  1. 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.

  2. 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.
  3. Data Source: The query uses the DeviceNetworkEvents table to gather information about network connections.

  4. Exclusions: To reduce false positives, it suggests excluding known legitimate scanners and management systems from triggering alerts.

  5. 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.
  6. 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.