Encrypted/Encoded File
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.
// 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 References (7)
- https://attack.mitre.org/techniques/T1027/013
- https://www.crowdstrike.com/blog/self-extracting-archives-decoy-files-and-their-hidden-payloads/
- https://www.crowdstrike.com/blog/shlayer-malvertising-campaigns-still-using-flash-update-disguise/
- https://www.mandiant.com/resources/apt41-dual-espionage-and-cyber-crime-operation
- https://securelist.com/the-darkhotel-apt/66779/
- https://unit42.paloaltonetworks.com/sofacy-attacks-multiple-government-entities/
- https://www.secureworks.com/research/threat-profiles/gold-southfield
Unlock Pro Content
Get the full detection package for T1027.013 including response playbook, investigation guide, and atomic red team tests.