T1027.013 Microsoft Sentinel · KQL

Detect Encrypted/Encoded File in Microsoft Sentinel

Adversaries encrypt or encode files to conceal malicious content and evade static signature detection. Techniques include XOR (single-byte and multi-byte), RC4, AES, 3DES, Base64, and custom encoding schemes applied to malware payloads, configuration files, C2 communication blobs, and dropped files. The full content or only specific values (such as C2 addresses or strings) may be obfuscated, sometimes in multiple redundant layers. Common delivery vectors include password-protected ZIP/Word documents and self-extracting (SFX) archives. Threat actors ranging from APT28 and Inception Group to ransomware families like Qilin and RansomHub consistently use encrypted/encoded files to defeat antivirus and EDR static analysis.

MITRE ATT&CK

Tactic
Defense Evasion
Technique
T1027 Obfuscated Files or Information
Sub-technique
T1027.013 Encrypted/Encoded File
Canonical reference
https://attack.mitre.org/techniques/T1027/013/

KQL Detection Query

Microsoft Sentinel (KQL)
kusto
// T1027.013 - Encrypted/Encoded File
// Detect execution patterns associated with decoding/decrypting payloads at runtime
let EncodedPayloadExecution = DeviceProcessEvents
| where ActionType == "ProcessCreated"
| where (
    // certutil decoding Base64 or hex-encoded files
    (FileName =~ "certutil.exe" and ProcessCommandLine has_any ("-decode", "-decodehex", "decode"))
    // PowerShell decoding Base64 blobs and executing
    or (FileName =~ "powershell.exe" and ProcessCommandLine has_any ("[Convert]::FromBase64String", "FromBase64String", "System.Convert") and ProcessCommandLine has_any ("Invoke-Expression", "iex", "IEX", "&(", ".Invoke"))
    // expand/extract SFX or password-protected archives via common tools
    or (FileName in~ ("7z.exe", "7za.exe", "winrar.exe", "wrar.exe") and ProcessCommandLine has_any ("-p", "-p\"", "x ") and ProcessCommandLine matches regex @"-p\S+")
    // XOR decode pattern: PowerShell with bxor operator
    or (FileName =~ "powershell.exe" and ProcessCommandLine has_any ("-bxor", "bxor"))
    // mshta/wscript executing content that was previously decoded
    or (FileName in~ ("mshta.exe", "wscript.exe", "cscript.exe") and ProcessCommandLine has_any ("Base64", "FromBase64", "bxor", "Encoding"))
)
| extend DetectionType = case(
    FileName =~ "certutil.exe", "certutil_decode",
    FileName =~ "powershell.exe" and ProcessCommandLine has_any ("-bxor", "bxor"), "powershell_xor_decode",
    FileName =~ "powershell.exe", "powershell_base64_decode_exec",
    FileName in~ ("7z.exe", "7za.exe", "winrar.exe", "wrar.exe"), "password_protected_archive_extract",
    "encoded_content_execution"
);
let SuspiciousFileWrites = DeviceFileEvents
| where ActionType in ("FileCreated", "FileModified")
| where FolderPath has_any ("\\Temp\\", "\\AppData\\Local\\Temp\\", "\\AppData\\Roaming\\", "\\ProgramData\\")
| where FileName endswith ".bin" or FileName endswith ".dat" or FileName endswith ".tmp" or FileName endswith ".cfg" or FileName endswith ".enc"
| where InitiatingProcessFileName in~ ("powershell.exe", "cmd.exe", "wscript.exe", "cscript.exe", "mshta.exe")
| extend DetectionType = "suspicious_encoded_file_drop";
EncodedPayloadExecution
| union SuspiciousFileWrites
| project-reorder Timestamp, DeviceName, DetectionType, FileName, ProcessCommandLine, FolderPath, InitiatingProcessFileName, InitiatingProcessCommandLine
medium severity medium confidence

Covers certutil -decode, PowerShell Base64 decode+execute, PowerShell XOR (-bxor), password-protected archive extraction with -p flag, and scripting engines executing encoded content. Also includes suspicious .bin/.dat/.enc file drops to staging directories by interpreters. High false positive potential — tune for your environment's legitimate use of certutil and PowerShell encoding.

Download portable Sigma rule (.yml)

Other platforms for T1027.013


Testing Methodology

Validate this detection against 4 adversary techniques from Atomic Red Team. Each test below lists the behaviour to exercise and the telemetry you should expect to see. Executable commands and cleanup steps are available with Pro.

  1. Test 1Base64 Encode, Drop, and Decode with certutil

    Expected signal: Sysmon EventCode 1 (ProcessCreate) for certutil.exe with '-decode' in CommandLine. EventCode 11 for both the .b64 source file and decoded output file creation in %TEMP%.

  2. Test 2PowerShell XOR Decryption Simulating Single-Byte XOR Malware

    Expected signal: Sysmon EventCode 1 (ProcessCreate) for powershell.exe. PowerShell Script Block Logging EventCode 4104 will capture the deobfuscated script including the -bxor operator and Invoke-Expression call.

  3. Test 3Password-Protected ZIP Delivery and Extraction

    Expected signal: Sysmon EventCode 1 for 7z.exe invocations with '-p' flag in CommandLine. EventCode 11 for .zip creation and extracted file creation in %TEMP%.

  4. Test 4Base64 Blob Decode and Execute via PowerShell

    Expected signal: Sysmon EventCode 1 for powershell.exe. PowerShell Script Block Logging EventCode 4104 will capture both the FromBase64String call and the decoded Invoke-Expression content — this is the primary high-value telemetry source.

Unlock Pro Content

Get the full detection package for T1027.013 including response playbook, investigation guide, and atomic red team tests.

Response PlaybookInvestigation GuideHunting QueriesAtomic Red Team TestsTuning Guidance

Related Detections