Query Details
# Defender for Endpoint - Potential suspicious TCP Flags
## Query Information
### Description
This query tries to detect network traffic with potentially malicious or uncommon TCP Flags
#### References
### Author
- **Alex Verboon**
## Defender XDR
```kql
let FlagReference = datatable(TcpFlagDecimal:string, Comment:string)
[
6, "SYN + RST (invalid, often scanning)",
7, "FIN + SYN + RST (highly abnormal)",
19, "FIN + PSH + SYN (malformed scan)",
27, "FIN + PSH + SYN + URG (malformed, stealth scan)",
30, "FIN + PSH + RST + SYN (Xmas variant)",
31, "FIN + PSH + RST + SYN + URG (classic Xmas scan)",
63, "All flags set including ECE/CWR (invalid combination)"
];
let suspiciousflags = dynamic(["6","7","19","27","30","31","63"]);
DeviceNetworkEvents
| extend info = parse_json( AdditionalFields)
| extend TcpFlags = tostring(parse_json(info)["Tcp Flags"])
| extend direction = info["direction"]
| where direction has "In"
| extend Geo_IP = tostring(geo_info_from_ip_address(RemoteIP).country)
| extend IsPrivate = ipv4_is_private(RemoteIP)
| project TimeGenerated, DeviceName, LocalIP, LocalPort, RemoteIP, IsPrivate, RemotePort, Geo_IP, TcpFlags, ActionType
//| where IsPrivate == "0"
| where TcpFlags has_any (suspiciousflags)
| lookup kind=leftouter FlagReference on $left.TcpFlags == $right.TcpFlagDecimal
```
This query is designed to identify potentially suspicious network traffic by examining TCP flags in network events. Here's a simplified breakdown:
Purpose: The query aims to detect network traffic with unusual or potentially malicious TCP flag combinations, which might indicate scanning or other suspicious activities.
Reference Table: It uses a reference table (FlagReference) that maps specific TCP flag combinations (represented as decimal values) to descriptions of why they are considered suspicious or abnormal.
Suspicious Flags: A list of suspicious TCP flag combinations is defined, including:
Data Source: The query analyzes data from DeviceNetworkEvents, which contains network event logs.
Data Processing:
AdditionalFields column, specifically the TCP flags and the direction of the traffic.direction has "In").Filtering and Output:
FlagReference table to add descriptions of the suspicious flags to the results.In summary, this query helps identify potentially malicious network activities by flagging unusual TCP flag combinations in incoming network traffic.

Alex Verboon
Released: August 29, 2025
Tables
Keywords
Operators