← Back to SOC feed Coverage →

File Copy and Execution

kql MEDIUM Azure-Sentinel
DeviceFileEventsDeviceLogonEventsDeviceNetworkEventsDeviceProcessEvents
huntingmicrosoftofficial
This rule was pulled from an open-source repository and enriched with AI. Validate in a test environment before deploying to production.
View original rule at Azure-Sentinel →
Retrieved: 2026-05-19T23:00:00Z · Confidence: medium

Hunt Hypothesis

Adversaries may copy malicious files via SMB and execute them quickly to evade detection. SOC teams should proactively hunt for this behavior in Azure Sentinel to identify potential lateral movement or execution-based attacks.

KQL Query

let ToleranceInSeconds = 5;
DeviceNetworkEvents
| where LocalPort == 445 and isnotempty(RemoteIP)
| join kind = inner DeviceLogonEvents on DeviceId
| where Timestamp1 between (Timestamp .. datetime_add('second',ToleranceInSeconds,Timestamp)) and RemoteIP endswith RemoteIP1
| join kind=inner (
    DeviceFileEvents
    | where ActionType in ('FileModified','FileCreated') and (InitiatingProcessFileName =~ 'System' or InitiatingProcessFolderPath endswith "ntoskrnl.exe")
) on DeviceId
| where Timestamp2 between (Timestamp .. datetime_add('second',ToleranceInSeconds,Timestamp))
| join kind=inner DeviceProcessEvents on DeviceId, FolderPath
| where Timestamp3 between (Timestamp .. datetime_add('second',ToleranceInSeconds,Timestamp))
| project Timestamp, DeviceName, RemoteIP, RemotePort, AccountDomain, AccountName, AccountSid, Protocol, LogonId, RemoteDeviceName, IsLocalAdmin, FileName, FolderPath, SHA1, SHA256, MD5, ProcessCommandLine

Analytic Rule Definition

id: a27d5cb6-c533-4a81-9d11-d5c0ed257bc7
name: File Copy and Execution
description: |
  This query identifies files that are copied to a device over SMB, then executed within a
  specified threshold. Default is 5 seconds, but is configurable by tweaking the value for
  ToleranceInSeconds.
requiredDataConnectors:
- connectorId: MicrosoftThreatProtection
  dataTypes:
  - DeviceNetworkEvents
  - DeviceLogonEvents
  - DeviceFileEvents
  - DeviceProcessEvents
tactics:
- Execution
- Persistence
- Lateral movement
- Impact
query: |
  let ToleranceInSeconds = 5;
  DeviceNetworkEvents
  | where LocalPort == 445 and isnotempty(RemoteIP)
  | join kind = inner DeviceLogonEvents on DeviceId
  | where Timestamp1 between (Timestamp .. datetime_add('second',ToleranceInSeconds,Timestamp)) and RemoteIP endswith RemoteIP1
  | join kind=inner (
      DeviceFileEvents
      | where ActionType in ('FileModified','FileCreated') and (InitiatingProcessFileName =~ 'System' or InitiatingProcessFolderPath endswith "ntoskrnl.exe")
  ) on DeviceId
  | where Timestamp2 between (Timestamp .. datetime_add('second',ToleranceInSeconds,Timestamp))
  | join kind=inner DeviceProcessEvents on DeviceId, FolderPath
  | where Timestamp3 between (Timestamp .. datetime_add('second',ToleranceInSeconds,Timestamp))
  | project Timestamp, DeviceName, RemoteIP, RemotePort, AccountDomain, AccountName, AccountSid, Protocol, LogonId, RemoteDeviceName, IsLocalAdmin, FileName, FolderPath, SHA1, SHA256, MD5, ProcessCommandLine

Required Data Sources

Sentinel TableNotes
DeviceFileEventsEnsure this data connector is enabled
DeviceLogonEventsEnsure this data connector is enabled
DeviceNetworkEventsEnsure this data connector is enabled
DeviceProcessEventsEnsure this data connector is enabled

MITRE ATT&CK Context

References

False Positive Guidance

Original source: https://github.com/Azure/Azure-Sentinel/blob/main/Hunting Queries/Microsoft 365 Defender/Execution/File Copy and Execution.yaml