KQL Example Generator — ready-to-use Microsoft Sentinel and Defender hunting queries
1 · Table
2 · Filters
3 · Output
Your query
has matches whole words and is faster than contains.has matches whole words and is faster than contains.Pick a category such as Identity or Endpoint, filter on Sentinel or Defender XDR, or search for a technique like T1110 or a word like lsass.
Choose the period at the top. Optionally type a user, IP, host or hash under Focus on to narrow every query to that entity.
Change the parameters, such as the minimum number of failures. They become let statements at the top of the query.
Copy the query or download it as .kql and paste it into Sentinel Logs or Defender advanced hunting. Try on sample data shows what it returns on test tables.
In the Query builder, pick a table, add filters and choose rows, counts or a time chart. Explain step by step opens any query in the KQL Pipeline Visualizer.
Mapped to MITRE ATT&CK.
Who changed what.
Keep Sentinel in shape.
KQL (Kusto Query Language) is the language of Microsoft Sentinel, Defender XDR advanced hunting and Azure Monitor. Security teams use it for two jobs: hunting, where an analyst runs a query to look for signs of an attacker, and detection, where the same query runs every few minutes as a scheduled analytics rule and raises an alert when it returns rows. Every query in this library works for both. The examples are written to be read: one step per line, a time filter first, clear column names and a comment header with the MITRE ATT&CK technique.
Microsoft Sentinel stores logs in a Log Analytics workspace: Entra ID sign-ins (SigninLogs), audit logs, Windows security events, Azure activity, Office 365 activity and firewall logs. Defender XDR advanced hunting holds the rich endpoint, email and identity tables from the Defender products (DeviceProcessEvents, EmailEvents and more) for 30 days. With the Defender XDR connector those tables also flow into Sentinel. The main difference in syntax is the time column: Timestamp in advanced hunting, TimeGenerated in Sentinel; in Sentinel both exist for the Defender tables.
| Table | Contains | Source |
|---|---|---|
| SigninLogs | Interactive Entra ID sign-ins | Entra ID diagnostic settings |
| AuditLogs | Directory changes: roles, apps, MFA | Entra ID diagnostic settings |
| SecurityEvent | Windows security log (4624, 4625, 4720…) | Azure Monitor Agent |
| DeviceProcessEvents | Every process start on endpoints | Defender for Endpoint |
| DeviceNetworkEvents | Network connections from endpoints | Defender for Endpoint |
| EmailEvents, UrlClickEvents | Mail flow and Safe Links clicks | Defender for Office 365 |
| OfficeActivity | Exchange, SharePoint and Teams audit | Microsoft 365 connector |
| AzureActivity | Control-plane operations in Azure | Azure Activity connector |
When a query proves useful, turn it into a scheduled analytics rule in Sentinel. Set the run frequency and the lookup period to the same value as the ago() in the query (for example every hour, looking back one hour), map the entities (account, IP, host) so incidents correlate, and start with a higher threshold to avoid alert fatigue. In Defender XDR the equivalent is a custom detection rule, which also needs the Timestamp, DeviceId and ReportId columns in the output.
Every detection fires on some legitimate activity. Each query lists its typical false positives. Tune by raising thresholds, by excluding known service accounts and scanners with !in, or by keeping an allow-list in a Sentinel watchlist and filtering with _GetWatchlist('name'). Re-test after every change, and keep the original query so you can see what you are filtering away.
Filter on time first, then on the most selective column. Prefer has over contains and == over =~ when you can. Use project before a join and put the smaller table on the left. The Focus on field in this tool adds where * has "…", which searches every column: handy for an investigation, but name a column in queries that run as rules.