A security analyst is creating a custom detection rule in Microsoft 365 Defender using Advanced Hunting. The rule should alert when a user signs in from an IP address that is not in the company's approved IP range (192.168.0.0/16). Which KQL function should be used to compare the sign-in IP against the approved range?
The ipv4_is_in_range function parses both the IP address and the CIDR range, then performs a proper bitwise comparison of the network prefix based on the specified prefix length. It returns true only when the SigninIP falls within the exact 192.168.0.0/16 address space, correctly handling subnet boundaries. This is the recommended KQL approach for testing IP membership in a specific CIDR range and is both reliable and efficient.
Why this answer
The correct KQL function is `ipv4_is_in_range()` because it is specifically designed to check whether an IPv4 address falls within a given CIDR range. In this scenario, the function compares the `SigninIP` field against the company's approved range `192.168.0.0/16` and returns `true` if the IP is within that range, enabling the rule to alert on out-of-range sign-ins. This function handles subnet mask calculations natively, ensuring accurate and efficient IP range matching without manual parsing.
Exam trap
The trap here is that candidates may choose `ipv4_is_private()` thinking it covers all internal ranges, but it does not account for custom or non-RFC 1918 ranges, and it misses the requirement to match a specific CIDR block like 192.168.0.0/16.
How to eliminate wrong answers
Option B is wrong because `has_any()` is a string-matching operator that checks if any substring from a dynamic array exists in a field; it does not perform CIDR range calculations and would incorrectly treat the CIDR notation as a literal string. Option C is wrong because `ipv4_is_private()` only checks if an IP belongs to any private address space (RFC 1918), not whether it falls within a specific custom range like `192.168.0.0/16`; it would also match other private ranges (e.g., 10.0.0.0/8, 172.16.0.0/12), causing false positives. Option D is wrong because `startswith` performs a simple prefix match on the string representation of the IP, which fails for IPs like `192.168.255.255` (correctly in range) but also fails to exclude IPs like `192.169.0.1` (outside the /16 range) because it only checks the first three octets.