Lesson 144 — The File Appeared Seconds Before It Executed
The process tree from Lesson 143 gave us another clue. A file appears on disk only seconds before it is executed.
That timing matters. In this lesson we use DeviceFileEvents to identify when the file was created, which process created it, where it was written and what hash identifies it. We then pivot back into DeviceProcessEvents to test whether the same file actually executed and whether it appears elsewhere in the estate.

Your case file
A DLL is written to a temporary path on WS-FIN-042. Seconds later the same hash appears in process execution telemetry.
Case briefing
Investigation objective
Use DeviceFileEvents and DeviceProcessEvents to correlate file creation with subsequent execution, preserve the file hash and originating process, and determine whether the file belongs to a larger endpoint incident.
Investigator's rule
Creation is not execution. A file event proves that Defender observed file-system activity. A process event proves execution-related telemetry. Correlate the two rather than assuming one proves the other.
Stage 1 — find files created around the suspicious process
Start with the device and narrow time window from the process-tree investigation. Microsoft documents DeviceFileEvents as the advanced hunting table for file creation, modification and other file-system events.
let TargetDevice = "WS-FIN-042";
let TargetTime = datetime(2026-08-18 01:22:19);
DeviceFileEvents
| where DeviceName =~ TargetDevice
| where Timestamp between (TargetTime - 5m .. TargetTime + 5m)
| where ActionType == "FileCreated"
| project Timestamp,
DeviceName,
FileName,
FolderPath,
SHA1,
InitiatingProcessFileName,
InitiatingProcessCommandLine,
InitiatingProcessId
| order by Timestamp ascKeep the creator
The file itself is only half the story. InitiatingProcessFileName, its command line and process ID can identify what wrote the file to disk.
Keep the hash
A SHA-1 hash gives the investigator a stronger pivot than filename alone. Filenames can be changed or reused; the hash helps relate the same file content across events and devices when available.
Stage 2 — follow the file's own history
Once the suspicious filename is known, look at every observed file event for that file on the device. This can show whether it was created, modified, renamed or otherwise touched before execution.
let TargetDevice = "WS-FIN-042";
let TargetFile = "payload.dll";
DeviceFileEvents
| where DeviceName =~ TargetDevice
| where FileName =~ TargetFile
| project Timestamp,
ActionType,
FileName,
FolderPath,
SHA1,
InitiatingProcessFileName,
InitiatingProcessCommandLine,
InitiatingProcessId
| order by Timestamp ascPath changes meaning
A file appearing under a user's temporary directory, downloads area or another writable path can deserve different scrutiny from the same filename under a normal application directory. Path is context, not a verdict.
ActionType matters
Do not treat every DeviceFileEvents row as a creation. Preserve ActionType so the report accurately describes what Defender observed.
Stage 3 — correlate the file hash with process execution
Now pivot the SHA-1 into DeviceProcessEvents. If the same hash appears as a process image on the same device shortly afterwards, the evidence becomes much stronger.
let TargetDevice = "WS-FIN-042";
let TargetSHA1 = "0123456789abcdef0123456789abcdef01234567";
DeviceProcessEvents
| where DeviceName =~ TargetDevice
| where SHA1 == TargetSHA1
| project Timestamp,
FileName,
FolderPath,
ProcessCommandLine,
AccountName,
ProcessId,
InitiatingProcessFileName,
InitiatingProcessCommandLine,
InitiatingProcessId
| order by Timestamp ascWhy hash correlation helps
The filename may differ between telemetry sources or be changed after arrival. Matching file content by hash provides a more resilient way to connect creation and execution.
Still keep time and device
Hash equality connects the file content. Timestamp and device context tell you whether the events belong to the same incident sequence.
Stage 4 — pivot the hash across the estate
The file hash is now an investigative entity. Ask whether the same content has been observed on other devices during the hunting window.
let TargetSHA1 = "0123456789abcdef0123456789abcdef01234567";
DeviceFileEvents
| where Timestamp > ago(7d)
| where SHA1 == TargetSHA1
| summarize FirstSeen=min(Timestamp),
LastSeen=max(Timestamp),
Events=count(),
Devices=make_set(DeviceName, 50),
Paths=make_set(FolderPath, 50),
Creators=make_set(InitiatingProcessFileName, 25)
by SHA1, FileName
| order by FirstSeen ascOne device or several?
If the same hash appears across multiple endpoints, the incident may be broader than the original workstation. Compare creation time, path and initiating process before assuming every occurrence has the same cause.
Prevalence is context
A widely seen hash can belong to legitimate software. A very rare hash can still be benign. The value comes from combining prevalence with path, signer, source process, execution and surrounding activity.
Stage 5 — build the file evidence timeline
Finish by laying the hash-related file events out chronologically across devices. This gives you the first-seen time and shows how the file moved or appeared through the environment.
let TargetSHA1 = "0123456789abcdef0123456789abcdef01234567";
DeviceFileEvents
| where Timestamp > ago(7d)
| where SHA1 == TargetSHA1
| project Timestamp,
DeviceName,
ActionType,
FileName,
FolderPath,
InitiatingProcessFileName,
InitiatingProcessCommandLine,
InitiatingProcessId
| order by Timestamp ascCreation can answer “how”
If PowerShell, a browser, archive tool or another suspicious process created the file, the creation event can connect the file to the earlier execution chain.
Execution answers “what happened next”
Process telemetry can show whether the file became active code. Together, file and process evidence can establish an arrival-to-execution sequence much more clearly than either table alone.
Agent Foskett's file timeline
Your evidence board
| Evidence | What it supports | Weight |
|---|---|---|
FileCreated event | Defender observed the file being created on the device. | Strong for creation |
| Initiating process is part of the suspicious chain | Connects file arrival to earlier execution activity. | Strong |
| SHA-1 captured | Provides a stable pivot for the same file content. | Strong |
| Matching hash appears in process telemetry seconds later | Supports a creation-to-execution relationship. | Strong |
| Same hash found on another device | May indicate wider distribution or legitimate common software. | Context requiring validation |
| Suspicious filename alone | Does not establish maliciousness. | Insufficient alone |
Write the finding like an investigator
Example: Microsoft Defender XDR file telemetry recorded payload.dll being created on WS-FIN-042 shortly after the suspicious PowerShell and command-shell activity identified in the process tree. The file event preserved the file path, SHA-1 and initiating-process context. Process telemetry was then queried using the same SHA-1 to determine whether the file content appeared in execution-related activity on the device. The close timing and shared hash support a relationship between file arrival and subsequent execution; however, the file's maliciousness should be assessed using the complete process, network, prevalence and file-reputation context.
Lesson 144 key takeaways
DeviceFileEventsrecords file creation, modification and other file-system activity.- Preserve
ActionTypeso you describe the observed file event accurately. - The initiating process can explain where a file came from.
- Filename and path provide context but are not proof of maliciousness.
- SHA-1 is a valuable pivot for relating the same file content across telemetry.
- Creation does not prove execution.
- Use
DeviceProcessEventsto test whether the file content appears in process execution telemetry. - Time + device + hash can turn separate rows into one arrival-to-execution sequence.
- Pivot suspicious hashes across the estate to determine scope.
- Prevalence is investigative context, not a verdict.
Module 12 — the attack chain continues
Lesson 143 reconstructed the suspicious process tree. Lesson 144 now connects that execution chain to a file that appeared immediately before it became active. Next we follow the process into network telemetry and ask where it communicated.
Continue your KQL investigation training
Related Agent Foskett Investigations
🔎 KQL Academy — Module 12: Advanced Endpoint Investigation
Correlate file creation and process execution with KQL
Lesson 144 of the Agent Foskett KQL Academy uses Microsoft Defender XDR DeviceFileEvents and DeviceProcessEvents to investigate a file that appears on disk immediately before execution.
Investigate file hashes and endpoint execution in Microsoft Defender XDR
Learn how to preserve file paths, SHA-1 hashes and initiating-process evidence, correlate file-system activity with process execution and pivot suspicious file content across devices to determine incident scope.
