|
| 1 | +[[prebuilt-rule-8-19-5-command-line-obfuscation-via-whitespace-padding]] |
| 2 | +=== Command Line Obfuscation via Whitespace Padding |
| 3 | + |
| 4 | +Identifies process execution events where the command line value contains a long sequence of whitespace characters or multiple occurrences of contiguous whitespace. Attackers may attempt to evade signature-based detections by padding their malicious command with unnecessary whitespace characters. These observations should be investigated for malicious behavior. |
| 5 | + |
| 6 | +*Rule type*: esql |
| 7 | + |
| 8 | +*Rule indices*: None |
| 9 | + |
| 10 | +*Severity*: medium |
| 11 | + |
| 12 | +*Risk score*: 47 |
| 13 | + |
| 14 | +*Runs every*: 5m |
| 15 | + |
| 16 | +*Searches indices from*: now-9m ({ref}/common-options.html#date-math[Date Math format], see also <<rule-schedule, `Additional look-back time`>>) |
| 17 | + |
| 18 | +*Maximum alerts per execution*: 100 |
| 19 | + |
| 20 | +*References*: None |
| 21 | + |
| 22 | +*Tags*: |
| 23 | + |
| 24 | +* Domain: Endpoint |
| 25 | +* OS: Windows |
| 26 | +* OS: macOS |
| 27 | +* OS: Linux |
| 28 | +* Use Case: Threat Detection |
| 29 | +* Tactic: Defense Evasion |
| 30 | +* Tactic: Execution |
| 31 | +* Resources: Investigation Guide |
| 32 | + |
| 33 | +*Version*: 1 |
| 34 | + |
| 35 | +*Rule authors*: |
| 36 | + |
| 37 | +* Elastic |
| 38 | + |
| 39 | +*Rule license*: Elastic License v2 |
| 40 | + |
| 41 | + |
| 42 | +==== Investigation guide |
| 43 | + |
| 44 | + |
| 45 | + |
| 46 | +*Triage and analysis* |
| 47 | + |
| 48 | + |
| 49 | + |
| 50 | +*Investigating Command Line Obfuscation via Whitespace Padding* |
| 51 | + |
| 52 | + |
| 53 | +This rule identifies process execution events where the command line value contains a long sequence of whitespace |
| 54 | +characters or multiple occurrences of contiguous whitespace. Attackers may attempt to evade signature-based detections |
| 55 | +by padding their malicious command with unnecessary whitespace characters. |
| 56 | + |
| 57 | + |
| 58 | +*Possible investigation steps* |
| 59 | + |
| 60 | + |
| 61 | +- Analyze the command line of the process in question for evidence of malicious code execution. |
| 62 | +- Investigate the process execution chain (parent process tree) for unknown processes. Examine their executable files |
| 63 | +for prevalence, whether they are located in expected locations, and if they are signed with valid digital signatures. |
| 64 | +- Investigate other alerts associated with the user/host during the past 48 hours. |
| 65 | +- Investigate abnormal behaviors observed by the subject process such as network connections, registry or file |
| 66 | +modifications, and any spawned child processes. |
| 67 | +- Retrieve the process executable and determine if it is malicious: |
| 68 | + - Use a private sandboxed malware analysis system to perform analysis. |
| 69 | + - Observe and collect information about the following activities: |
| 70 | + - Attempts to contact external domains and addresses. |
| 71 | + - File and registry access, modification, and creation activities. |
| 72 | + - Service creation and launch activities. |
| 73 | + - Scheduled tasks creation. |
| 74 | + - Use the PowerShell `Get-FileHash` cmdlet to get the files' SHA-256 hash values. |
| 75 | + - Search for the existence and reputation of the hashes in resources like VirusTotal, Hybrid-Analysis, CISCO Talos, Any.run, etc. |
| 76 | + |
| 77 | + |
| 78 | +*False positive analysis* |
| 79 | + |
| 80 | + |
| 81 | +- Alerts derived from this rule are not inherently malicious. Analysts can dismiss the alert if they don't find enough |
| 82 | +evidence of further suspicious activity. |
| 83 | + |
| 84 | + |
| 85 | +*Response and remediation* |
| 86 | + |
| 87 | + |
| 88 | +- Initiate the incident response process based on the outcome of the triage. |
| 89 | +- Isolate the involved host to prevent further post-compromise behavior. |
| 90 | +- If the triage identified malware, search the environment for additional compromised hosts. |
| 91 | + - Implement temporary network rules, procedures, and segmentation to contain the malware. |
| 92 | + - Stop suspicious processes. |
| 93 | + - Immediately block the identified indicators of compromise (IoCs). |
| 94 | + - Inspect the affected systems for additional malware backdoors like reverse shells, reverse proxies, or droppers that |
| 95 | + attackers could use to reinfect the system. |
| 96 | +- Remove the malicious certificate from the root certificate store. |
| 97 | +- Remove and block malicious artifacts identified during triage. |
| 98 | +- Run a full antimalware scan. This may reveal additional artifacts left in the system, persistence mechanisms, and |
| 99 | +malware components. |
| 100 | +- Investigate credential exposure on systems compromised or used by the attacker to ensure all compromised accounts are |
| 101 | +identified. Reset passwords for these accounts and other potentially compromised credentials, such as email, business |
| 102 | +systems, and web services. |
| 103 | +- Determine the initial vector abused by the attacker and take action to prevent reinfection through the same vector. |
| 104 | +- Using the incident response data, update logging and audit policies to improve the mean time to detect (MTTD) and the |
| 105 | +mean time to respond (MTTR). |
| 106 | + |
| 107 | + |
| 108 | +==== Rule query |
| 109 | + |
| 110 | + |
| 111 | +[source, js] |
| 112 | +---------------------------------- |
| 113 | +FROM logs-* metadata _id, _version, _index |
| 114 | +| where event.category == "process" and event.type == "start" and event.action != "fork" |
| 115 | +// more than 100 spaces in process.command_line |
| 116 | +| eval multi_spaces = LOCATE(process.command_line, space(100)) |
| 117 | +| where multi_spaces > 0 |
| 118 | +| keep user.name, host.id, host.name, process.command_line, process.executable, process.parent.executable |
| 119 | +
|
| 120 | +---------------------------------- |
| 121 | + |
| 122 | +*Framework*: MITRE ATT&CK^TM^ |
| 123 | + |
| 124 | +* Tactic: |
| 125 | +** Name: Defense Evasion |
| 126 | +** ID: TA0005 |
| 127 | +** Reference URL: https://attack.mitre.org/tactics/TA0005/ |
| 128 | +* Technique: |
| 129 | +** Name: Obfuscated Files or Information |
| 130 | +** ID: T1027 |
| 131 | +** Reference URL: https://attack.mitre.org/techniques/T1027/ |
| 132 | +* Technique: |
| 133 | +** Name: Deobfuscate/Decode Files or Information |
| 134 | +** ID: T1140 |
| 135 | +** Reference URL: https://attack.mitre.org/techniques/T1140/ |
| 136 | +* Tactic: |
| 137 | +** Name: Execution |
| 138 | +** ID: TA0002 |
| 139 | +** Reference URL: https://attack.mitre.org/tactics/TA0002/ |
| 140 | +* Technique: |
| 141 | +** Name: Command and Scripting Interpreter |
| 142 | +** ID: T1059 |
| 143 | +** Reference URL: https://attack.mitre.org/techniques/T1059/ |
| 144 | +* Sub-technique: |
| 145 | +** Name: PowerShell |
| 146 | +** ID: T1059.001 |
| 147 | +** Reference URL: https://attack.mitre.org/techniques/T1059/001/ |
0 commit comments