Sysmon Event ID 22: DNS Query — QueryName, QueryResults and KQL
Published
A process looked up a name in DNS — Sysmon records which process asked, the name, the status of the answer and the addresses it returned, whether the answer came from the network or the cache.
Logged to: Microsoft-Windows-Sysmon/Operational, on the machine where it happened; filtered in a Sysmon configuration by the <DnsQuery> element.
Microsoft's description
Event ID 22: DNSEvent (DNS query)
This event is generated when a process executes a DNS query, whether the result is successful or fails, cached or not. The telemetry for this event was added for Windows 8.1 so it is not available on Windows 7 and earlier.
Source: Microsoft's Sysmon documentation
Every field of event 22
| Field | What it tells you |
|---|---|
| QueryName | The name the process looked up. Rare, newly seen or random-looking names from a process that should not resolve anything are the usual findings. |
| QueryStatus | The status of the lookup; 0 is success. A process that keeps getting failures for many different names is worth a look. |
| QueryResults | What the lookup returned, as entries separated by semicolons — addresses, and names for records such as CNAMEs. Join the addresses to event 3 for the connection that followed. |
| Image | The process that made the query — the field DNS server logs do not have, since they only see the machine. |
| User | The account the querying process runs as. |
| ProcessGuid | Joins the query to the process creation (event 1) and to the process's network connections (event 3). |
| RuleName | — |
| UtcTime | — |
| ProcessId | — |
Field names and order from Sysmon's manifest (schema 4.90), checked on every build.
What it records
Microsoft’s description: “This event is generated when a process executes a DNS query, whether the result is successful or fails, cached or not. The telemetry for this event was added for Windows 8.1 so it is not available on Windows 7 and earlier.”
The fields are QueryName (the name looked up), QueryStatus (the result status, 0 for success), QueryResults (what came back), and the asking process — Image, ProcessGuid, ProcessId and User — with UtcTime and RuleName. The process is what makes the event valuable. A DNS server sees that a workstation resolved a domain; event 22 shows that rundll32.exe running as the user did, and its ProcessGuid leads to the command line that started it and to the connection it made next.
Because every process resolves names constantly, configurations usually exclude well-known domains in the <DnsQuery> section and log the rest:
<DnsQuery onmatch="exclude">
<QueryName condition="end with">.microsoft.com</QueryName>
<QueryName condition="end with">.windowsupdate.com</QueryName>
</DnsQuery>
An exclude list is also an attacker’s hiding place: a domain on a service you excluded is invisible here.
When it matters
| Pattern | Reading |
|---|---|
| Office, script hosts, rundll32.exe or regsvr32.exe resolving external names | Code fetching a payload or contacting its server |
| A name seen on one or two hosts only, queried at regular intervals | Command and control from a small number of infected machines (T1071.004) |
Long, random-looking labels under one domain (a9f3k2….example.net) | Data carried in DNS names, or domain generation (T1568) |
| Many failed lookups (non-zero QueryStatus) for different names from one process | A domain generation algorithm trying candidate domains |
| Dynamic-DNS, paste and file-sharing domains resolved by servers | Staging or exfiltration from a machine that should not browse |
How to investigate
DNS lookups by processes that usually do not need the network:
Event
| where TimeGenerated > ago(7d)
| where Source == "Microsoft-Windows-Sysmon" and EventID == 22
| extend D = parse_xml(EventData).DataItem.EventData.Data
| mv-apply d = D on (summarize f = make_bag(bag_pack(tostring(d["@Name"]), tostring(d["#text"]))))
| extend QueryName = tostring(f.QueryName), Image = tostring(f.Image), QueryResults = tostring(f.QueryResults), Account = tostring(f.User)
| where Image has_any ("rundll32.exe", "regsvr32.exe", "mshta.exe", "wscript.exe", "cscript.exe", "WINWORD.EXE", "EXCEL.EXE")
| project TimeGenerated, Computer, Account, Image, QueryName, QueryResults
Rare names — resolved on few hosts in the last 30 days:
Event
| where TimeGenerated > ago(30d)
| where Source == "Microsoft-Windows-Sysmon" and EventID == 22
| extend D = parse_xml(EventData).DataItem.EventData.Data
| mv-apply d = D on (summarize f = make_bag(bag_pack(tostring(d["@Name"]), tostring(d["#text"]))))
| extend QueryName = tolower(tostring(f.QueryName)), Image = tostring(f.Image)
| summarize Hosts = dcount(Computer), Queries = count(), Processes = make_set(Image, 5), LastSeen = max(TimeGenerated) by QueryName
| where Hosts <= 2
| order by LastSeen desc
For a suspicious name, take the addresses in QueryResults to the process’s network connections with the same ProcessGuid, and the ProcessGuid to its process creation event for the command line and parent. Check the addresses with the IP blocklist checker.
Read a Sysmon log without a SIEM
Copy Microsoft-Windows-Sysmon%4Operational.evtx from C:\Windows\System32\winevt\Logs (or wevtutil epl Microsoft-Windows-Sysmon/Operational sysmon.evtx) and open it in the EVTX viewer: every event in a table, event 22 filterable, with the analyzer's checks for LSASS access, remote threads and suspicious command lines. Nothing is uploaded.
Related events
- Sysmon Event ID 1 Process creation
- Sysmon Event ID 3 Network connection
- Security Event ID 4688 A new process has been created
Detect it
Frequently Asked Questions
- Why is Sysmon Event ID 22 missing on some machines?
- Microsoft's documentation says the telemetry for this event "was added for Windows 8.1 so it is not available on Windows 7 and earlier". On newer systems it also depends on the configuration's <DnsQuery> rules; many configurations exclude well-known domains to keep the volume down.
- Does Sysmon Event ID 22 log cached lookups?
- Yes. Microsoft states the event is generated when a process executes a DNS query "whether the result is successful or fails, cached or not", which is why it shows lookups that never reached your DNS servers or their logs.
- How is Sysmon event 22 different from DNS server logs?
- DNS server logs show which machine asked; event 22 shows which process on the machine asked, under which account, including answers served from the local cache. Malware resolving its command-and-control domain is attributed to the malware's own process rather than to the host as a whole.
- Which DNS queries should I investigate first?
- Names resolved by processes that rarely use the network themselves (rundll32.exe, regsvr32.exe, mshta.exe, Office applications), names seen on only one or two hosts, long random-looking subdomains that can carry data out, and lookups for paste sites, dynamic DNS providers or file-sharing services from servers.
Find every Sysmon 22 that matters
Open a Sysmon .evtx or XML export in the free browser analyzer: LSASS access, remote thread injection, process tampering, suspicious command lines and reverse-shell ports are flagged, with the events behind each. Nothing is uploaded.
Investigating something right now? LogTriage checks every address in the file against threat intelligence and writes the incident report: 10 analyses a month free. The incident pack adds the in-depth AI analysis and files up to 100 MB: 25 analyses for $19, one payment, no subscription. Pricing
Every query on this site's reference pages, the Sigma rules and a cheat sheet in one download: the Incident Response Kit, $29 once.