Huntbook by Predefender

part-5

File Staging and User-writable Paths

Author: Roger C.B. Johnsen

User-writable locations are normal working areas and convenient attacker staging locations. A path does not establish intent. Hunt the sequence that produced the file, the process that touched it, what happened next, and whether the behavior fits the user and device.

Locations worth monitoring

LocationNormal useHunting context
DownloadsBrowser and application downloadsExecutables, scripts, disk images, shortcuts, archives, and rapid execution.
DesktopUser-created and copied filesOperator tools, command output, archives, and temporary staging.
DocumentsUser documents and application dataCollection, bulk copying, and archives inconsistent with the user role.
%TEMP%Installers and temporary application contentShort-lived payloads, extraction, compilation, and execution.
AppData\LocalPer-user application state and cachesPayloads, persistence, side-loading, and browser or collaboration-app artifacts.
AppData\RoamingRoaming application stateLogon persistence, scripts, and configuration.
OneDrive or other sync rootsCloud-synchronized workExternal delivery, staging, cross-device propagation, and bulk upload.
Public and shared profile pathsCross-user contentShared staging and execution by another account.
Recycle BinUser deletionCleanup context; deletion does not remove all evidence.

Do not exclude AppData globally. Reduce noise with process, extension, path depth, prevalence, signer, and sequence.

Useful file context

Field or artifactQuestion
ActionTypeWas the file created, modified, renamed, or deleted?
FolderPath, FileNameIs the location and name consistent with the producing process?
SHA1Where else did the same content appear?
FileOriginUrlWhich URL supplied the file when origin telemetry is available?
FileOriginReferrerUrlWhich page or application led to the download?
FileOriginIPWhich remote address supplied the content?
Initiating process fieldsWhich process performed the file operation?
RequestProtocol, RequestSourceIP, ShareNameWas it written remotely over SMB or NFS?
Zone.IdentifierDid Windows preserve Mark of the Web information?
Signer and original filenameIs a familiar filename actually the expected binary?
Sensitivity labelDoes staging involve protected information?

Hash fields can be empty when files are remote, locked, compressed, or virtual. In Defender endpoint tables, SHA1 is commonly more populated than SHA256.

High-value sequences

SequencePossible explanationValidate
Create -> executeDownloaded or staged payloadOrigin, signer, parent, user action, and reputation.
Archive -> extraction -> executeTool or payload stagingArchive source, extracted set, and execution chain.
Rename -> executeUnpacking or masqueradingOriginal name, signer, extension, and producer.
Create -> execute -> deleteTemporary execution and cleanupProcess, network, prefetch, service/task, and hash prevalence.
Documents -> archiveData collection or legitimate packagingFile sensitivity, volume, account role, destination.
Remote SMB write -> executeLateral tool transferSource host, share, logon, service/task/WMI activity.
Browser/Office/Teams -> script hostUser-assisted executionMark of the Web, child process, URL, and message context.
Many reads -> one archive -> outbound transferCollection and stagingBytes, destination, cloud upload, and DLP telemetry.

These are hypotheses, not severity labels.

Baseline query

let TargetName = "TARGET-DEVICE.contoso.invalid";
DeviceFileEvents
| where Timestamp > ago(7d)
| where DeviceName =~ TargetName
| where FolderPath has @"\Users\"
| where FolderPath has_any (
    @"\Downloads\", @"\Desktop\", @"\Documents\",
    @"\AppData\Local\Temp\", @"\AppData\Roaming\"
)
| project Timestamp, DeviceId, DeviceName, ActionType,
          FolderPath, FileName, FileSize, SHA1,
          FileOriginUrl, FileOriginReferrerUrl, FileOriginIP,
          RequestProtocol, RequestSourceIP, ShareName,
          InitiatingProcessFileName,
          InitiatingProcessCommandLine,
          InitiatingProcessAccountUpn,
          InitiatingProcessUniqueId
| order by Timestamp asc

Path matching should be adapted for localized or redirected profiles and synchronized folders.

File to process pivot

let TargetHash = "SHA1-HERE";
let FileActivity =
    DeviceFileEvents
    | where Timestamp > ago(30d)
    | where SHA1 == TargetHash
    | project FileTime=Timestamp, DeviceId, DeviceName,
              FolderPath, FileName, SHA1,
              InitiatingProcessFileName,
              InitiatingProcessUniqueId;
FileActivity
| join kind=leftouter (
    DeviceProcessEvents
    | where Timestamp > ago(30d)
    | project ProcessTime=Timestamp, DeviceId,
              ProcessUniqueId, FileName,
              FolderPath, ProcessCommandLine,
              AccountUpn, SHA1
) on DeviceId, SHA1
| where ProcessTime between (FileTime - 5m .. FileTime + 1h)
| order by FileTime asc

A file event does not prove execution. Use DeviceProcessEvents, Prefetch where available, service/task telemetry, or other execution evidence.

Remote file activity

DeviceFileEvents
| where Timestamp > ago(7d)
| where RequestProtocol in~ ("SMB", "NFS")
| project Timestamp, DeviceName, ActionType,
          ShareName, FolderPath, FileName, SHA1,
          RequestProtocol, RequestSourceIP,
          RequestAccountDomain, RequestAccountName
| order by Timestamp desc

Correlate remote writes with logon, network, named-pipe, service, task, WMI, WinRM, and process activity on the target.

Burst and staging candidates

DeviceFileEvents
| where Timestamp > ago(7d)
| where FolderPath has @"\Users\"
| summarize Events=count(),
            Files=dcount(strcat(FolderPath, @"\", FileName)),
            Bytes=sum(FileSize),
            Archives=countif(FileName matches regex @"(?i)\.(zip|7z|rar|cab)$"),
            Executables=countif(FileName matches regex @"(?i)\.(exe|dll|scr|com)$"),
            Scripts=countif(FileName matches regex @"(?i)\.(ps1|bat|cmd|vbs|js|hta)$")
    by DeviceId, DeviceName,
       InitiatingProcessFileName,
       InitiatingProcessAccountUpn,
       bin(Timestamp, 15m)
| where Files >= 50 or Archives > 0 or Executables > 0 or Scripts > 0
| order by Timestamp desc

Tune this candidate generator for software deployment, development, build tools, browsers, synchronization clients, archive utilities, and endpoint management.

Triage workflow

  1. Preserve path, timestamps, size, hash, origin, and initiating process.
  2. Determine whether the file arrived locally, through a browser, sync client, email, SMB, NFS, or removable media.
  3. Inspect archive contents and scripts safely without execution.
  4. Reconstruct create, rename, extract, execute, network, and delete events.
  5. Identify the user and logon session that produced and executed the content.
  6. Compare signer, original filename, prevalence, and peer behavior.
  7. Search the hash, origin URL, filename, and infrastructure fleet-wide.
  8. Record whether telemetry proves presence, transfer, execution, or only access.

ATT&CK references

References

Revision

Revised DateComment
2026-07-22Article added