Sysmon Event ID 22
Sysmon Event ID 22: DNS Query
DNSEvent (DNS query)
- Log source
- Microsoft-Windows-Sysmon/Operational
- How to enable it
- Sysmon 10 or later, with a DnsQuery section. Windows 8.1 and later only
- Category
- Process Execution
- Priority
- Medium
- Typical volume
- Very high
- MITRE ATT&CK
What Sysmon Event ID 22 means
Sysmon event 22 records DNS queries made through the Windows client, with the program that asked and the answer it received. A DNS server sees only the address of the computer. This event adds the missing half.
Attribution changes what a name means. A lookup for a file-sharing site by a browser is ordinary, and the same lookup by rundll32.exe is not. Rules that combine rare names with unusual programs give far fewer false alarms than a blocklist of names.
It has a limit that attackers use. Programs that bring their own DNS implementation, or that use DNS over HTTPS, do not pass through the Windows client and are not logged. nslookup.exe is the well-known example, and browsers with secure DNS are the most common one.
Key fields to inspect
| Field | Meaning | Suspicious when |
|---|---|---|
QueryName | Name that was requested. | Long random labels, recently registered domains, dynamic DNS, or names that imitate your own. |
Image | Program that asked. | rundll32.exe, regsvr32.exe, mshta.exe, powershell.exe, or a program in a user folder. |
QueryResults | Answers, including type and address. | Internal addresses for external names, or long TXT answers. |
QueryStatus | Result code. 0 is success and 9003 means that the name does not exist. | Many 9003 results, as with generated domain names. |
ProcessGuid | Unique identifier of the process. | Join it with events 1 and 3. |
User | Account of the process, on newer versions. | SYSTEM asking for consumer services. |
Detection queries
Find parent domains with many unique long subdomains, and programs that receive many nonexistent-name answers. Adjust names and thresholds to your environment. About these queries.
Splunk SPL
index=windows source="XmlWinEventLog:Microsoft-Windows-Sysmon/Operational" EventCode=22
| rex field=QueryName "(?<parent>[^.]+\.[^.]+)$"
| eval length=len(QueryName)
| bin _time span=1h
| stats dc(QueryName) AS names avg(length) AS average_length count(eval(QueryStatus="9003")) AS missing BY _time Computer Image parent
| where (names>=100 AND average_length>40) OR missing>=100 Microsoft Sentinel KQL
Event
| where EventLog == "Microsoft-Windows-Sysmon/Operational" and EventID == 22
| extend QueryName = extract(@'Name="QueryName">([^<]*)<', 1, EventData)
| extend QueryStatus = extract(@'Name="QueryStatus">([^<]*)<', 1, EventData)
| extend Image = extract(@'Name="Image">([^<]*)<', 1, EventData)
| extend Labels = split(QueryName, ".")
| extend Parent = strcat(tostring(Labels[-2]), ".", tostring(Labels[-1]))
| summarize Names = dcount(QueryName), AverageLength = avg(strlen(QueryName)), Missing = countif(QueryStatus == "9003") by Computer, Image, Parent, bin(TimeGenerated, 1h)
| where (Names >= 100 and AverageLength > 40) or Missing >= 100 PowerShell
Get-WinEvent -FilterHashtable @{ LogName = 'Microsoft-Windows-Sysmon/Operational'; Id = 22; StartTime = (Get-Date).AddDays(-1) } |
ForEach-Object { $d = @{ Time = $_.TimeCreated }; ([xml]$_.ToXml()).Event.EventData.Data | ForEach-Object { $d[$_.Name] = $_.'#text' }; [pscustomobject]$d } |
Where-Object { $_.Image -match 'rundll32|regsvr32|mshta|powershell|wscript|cscript|msbuild' } |
Select-Object Time, Image, QueryName, QueryStatus, QueryResults | Format-Table -AutoSize Attack scenarios
DNS tunneling
Data is carried in subdomain labels and TXT or NULL answers. Hundreds of unique, long names under one parent domain by a single program within an hour are hard to explain in any other way.
Generated domain names
Malware that computes its contact domains tries many that do not exist. A run of status 9003 for random-looking names from one program is the trace.
Staging from legitimate services
A script host that resolves a paste site, a code hosting service or a chat platform is frequently about to download a payload. The name is reputable, and the program asking for it is not.
Investigation checklist
- Join with event 1 on ProcessGuid for the command line and parent.
- Check the age, registrar and passive DNS history of the domain.
- Join with event 3 for connections to the addresses in QueryResults.
- Search all hosts for the same name and the same parent domain.
- Sinkhole or block the domain once you have identified every affected host.
Common benign causes
- Content delivery networks, telemetry and advertising, which use long random names.
- Antivirus reputation lookups, which look very much like tunneling and need exclusion.
- Browsers, which cause most of the volume.
Sysmon Event ID 22 FAQ
Why does Sysmon event 22 not show nslookup queries?
nslookup.exe sends its own DNS packets and does not use the Windows DNS client that Sysmon monitors. Use network DNS logs, or look for the process start and its connection to port 53.
What does QueryStatus 9003 mean?
The name does not exist (NXDOMAIN). A few are normal. Many in a short time from one program can indicate generated domain names or a misconfigured application.
Does Sysmon log DNS over HTTPS?
No. Programs that resolve names through HTTPS bypass the Windows client. Disable secure DNS in managed browsers or force it through your own resolver to keep visibility.