Detect Junk Code Insertion in Sumo Logic CSE
Adversaries may insert junk code or dead code into malware to obfuscate its functionality, hinder static analysis, and evade signature-based detections. Junk code includes NOP (No-Operation) sleds, dummy API calls, excessive mathematical operations, infinite loops that are never reached, and random garbage instructions interspersed between legitimate code. Unlike Binary Padding (T1027.001), which changes file size/hash, junk code insertion specifically targets analyst workflow and automated analysis engines. Real-world actors including Maze ransomware, FIN7, Gamaredon Group, APT32, Kimsuky, and StrelaStealer have employed this technique.
MITRE ATT&CK
- Tactic
- Defense Evasion
- Technique
- T1027 Obfuscated Files or Information
- Sub-technique
- T1027.016 Junk Code Insertion
- Canonical reference
- https://attack.mitre.org/techniques/T1027/016/
Sumo Detection Query
// T1027.016 Junk Code Insertion - Sumo Logic CSE Detection
// Signal 1: Executable created by suspicious parent process
(_sourceCategory="*sysmon*" OR _sourceCategory="*windows*")
| where EventID = "11"
| where (TargetFilename endswith ".exe" OR TargetFilename endswith ".dll" OR TargetFilename endswith ".scr")
| where (Image matches "*\\winword.exe" OR Image matches "*\\excel.exe" OR Image matches "*\\powerpnt.exe"
OR Image matches "*\\outlook.exe" OR Image matches "*\\mshta.exe" OR Image matches "*\\wscript.exe"
OR Image matches "*\\cscript.exe" OR Image matches "*\\cmd.exe" OR Image matches "*\\rundll32.exe"
OR Image matches "*\\regsvr32.exe")
| fields _time, Computer, User, Image, TargetFilename, Hashes
| withtime _time
| count_distinct(TargetFilename) as FileCount, values(Hashes) as Hashes by Computer, User, Image
| where FileCount >= 1
| eval Signal = "NewExeFromSuspiciousParent"
// Signal 2: Script process with junk string concatenation patterns
// Run separately and union
(_sourceCategory="*sysmon*" OR _sourceCategory="*windows*")
| where EventID = "1"
| where (Image matches "*\\powershell.exe" OR Image matches "*\\pwsh.exe"
OR Image matches "*\\wscript.exe" OR Image matches "*\\cscript.exe" OR Image matches "*\\cmd.exe")
| where (CommandLine matches /(?i)(chr\(\d+\)(\s*[&+]\s*chr\(\d+\)){4,})/
OR CommandLine matches /(\+\s*['"]{1}[a-zA-Z0-9]{1,3}['"]{1}\s*){5,}/
OR CommandLine matches /(?i)(string\.concat|\[string\]::join)/)
| fields _time, Computer, User, Image, CommandLine, ParentImage, Hashes
| eval Signal = "ExcessiveStringConcatenation"
| count by Computer, User, Image, Signal
// Signal 3: Unsigned binary in temp/writable dir spawned by suspicious parent
(_sourceCategory="*sysmon*" OR _sourceCategory="*windows*")
| where EventID = "1"
| where (Image matches "*\\Temp\\*" OR Image matches "*\\AppData\\Local\\*"
OR Image matches "*\\AppData\\Roaming\\*" OR Image matches "*\\Downloads\\*"
OR Image matches "*\\Users\\Public\\*")
| where (Image matches "*.exe" OR Image matches "*.scr" OR Image matches "*.com")
| where (ParentImage matches "*\\winword.exe" OR ParentImage matches "*\\excel.exe"
OR ParentImage matches "*\\powerpnt.exe" OR ParentImage matches "*\\mshta.exe"
OR ParentImage matches "*\\wscript.exe" OR ParentImage matches "*\\cscript.exe")
| fields _time, Computer, User, Image, CommandLine, ParentImage, Hashes
| eval Signal = "UnsignedTempDirExecution"
| count by Computer, User, Image, Signal
// Aggregate and score across signals
| append [signals combined above via union in real deployment]
| stats count as AlertCount, values(Signal) as Signals, min(_time) as EarliestActivity,
max(_time) as LatestActivity, values(CommandLine) as CommandLines, values(Hashes) as FileHashes
by Computer, User, Image
| eval SignalCount = arraylength(Signals)
| where SignalCount >= 1
| eval RiskScore = if(SignalCount >= 3, "High", if(SignalCount == 2, "Medium", "Low"))
| sort by SignalCount desc, AlertCount desc Detects T1027.016 Junk Code Insertion behavioral indicators in Sumo Logic using Sysmon Windows event data. Three signals are correlated: (1) executable files created by Office applications or script interpreters (Sysmon EID 11), (2) script interpreter processes with command lines matching excessive string concatenation patterns typical of junk code obfuscated scripts (Sysmon EID 1), and (3) unsigned executables running from user-writable temp directories with suspicious parent processes (Sysmon EID 1). Risk scoring applies based on signal count per host/user/process tuple.
Data Sources
Required Tables
False Positives & Tuning
- Legitimate packaged applications that extract and execute binaries from AppData during self-updating (Electron apps, Slack, VS Code)
- Administrative PowerShell scripts performing string-heavy operations for configuration management or data transformation
- Security scanning tools (e.g., vulnerability scanners) that drop temporary executables for assessment
- Software development workflows where IDEs or build tools spawn compilers from temp directories
Other platforms for T1027.016
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.
- Test 1PowerShell Script with Excessive String Concatenation Junk Code
Expected signal: Sysmon Event ID 1: Process Create with Image=powershell.exe, CommandLine containing excessive variable concatenation. PowerShell ScriptBlock Log Event ID 4104 will show full script with dead variable assignments and Invoke-Expression. The final executed command 'whoami' will also appear in script block logs.
- Test 2VBScript with Dead Code Padding (chr() Concatenation Pattern)
Expected signal: Sysmon Event ID 11: File Create for %TEMP%\junktest.vbs (created by cmd.exe). Sysmon Event ID 1: Process Create for cscript.exe executing junktest.vbs. Sysmon Event ID 1: Child process cmd.exe spawned by cscript.exe with whoami command. Sysmon Event ID 11: File Create for %TEMP%\vbsout.txt.
- Test 3Compile and Execute Binary with NOP Sled Simulation via Inline Assembly
Expected signal: Sysmon Event ID 1: PowerShell.exe process with Add-Type command. Sysmon Event ID 11: File Create for %TEMP%\junkcode_test.exe compiled by csc.exe (invoked by Add-Type). Sysmon Event ID 1: Execution of junkcode_test.exe from %TEMP% directory. PowerShell ScriptBlock Log Event ID 4104 showing the source code with NOP-equivalent patterns.
- Test 4Batch File with Dead Code Branches and Junk Variable Inflation
Expected signal: Sysmon Event ID 11: File Create for %TEMP%\junkbatch.bat. Sysmon Event ID 1: cmd.exe executing junkbatch.bat from %TEMP%. Sysmon Event ID 1: Child cmd.exe process executing whoami. Sysmon Event ID 11: File Create for %TEMP%\batchout.txt. Security Event ID 4688 (if process creation auditing enabled) for all cmd.exe instances.
References (12)
- https://attack.mitre.org/techniques/T1027/016/
- https://cyberpedia.reasonlabs.com/EN/dead%20code%20insertion.html
- https://cyberpedia.reasonlabs.com/EN/junk%20code.html
- https://www.mcafee.com/blogs/other-blogs/mcafee-labs/maze-ransomware-no-promised-decryption-key-after-ransom-payment/
- https://www.welivesecurity.com/2016/10/25/lifting-lid-sednit-closer-look-group/
- https://www.mandiant.com/resources/blog/fin7-shim-databases-persistence
- https://www.welivesecurity.com/2020/06/11/gamaredon-group-grows-its-game/
- https://research.nccgroup.com/2020/06/23/wastedlocker-a-new-ransomware-variant-developed-by-the-evil-corp-group/
- https://www.cybereason.com/blog/operation-cobalt-kitty-apt
- https://github.com/redcanaryco/atomic-red-team/blob/master/atomics/T1027/T1027.md
- https://github.com/SigmaHQ/sigma/tree/master/rules/windows
- https://docs.microsoft.com/en-us/windows/security/threat-protection/windows-defender-application-control/microsoft-recommended-block-rules
Unlock Pro Content
Get the full detection package for T1027.016 including response playbook, investigation guide, and atomic red team tests.