Detection rules › Splunk
Obfuscated Powershell Techniques (PowerShell)
Attackers and commodity malware have started using extremely basic obfuscation techniques to hide the majority of the command from the command line arguments of powershell.exe. This use case relies on URL Toolbox to function
MITRE ATT&CK coverage
| Tactic | Techniques |
|---|---|
| Stealth | |
| Command & Control |
References
Telemetry coverage
| Provider | Record / event type |
|---|---|
| PowerShell | Event ID 4103: Payload Context: ContextInfo User Data: UserData. |
Rule body
id: '5869.6200'
title: Obfuscated Powershell Techniques
description: 'Attackers and commodity malware have started using extremely basic obfuscation
techniques to hide the majority of the command from the command line arguments of
powershell.exe. This use case relies on URL Toolbox to function. -- Software Association:
AsyncRAT, Midas --'
logic_format: Splunk
logic: '`get_endpoint_data` `get_endpoint_data_powershell` EventCode=4103 (Invoke-Expression
OR Invoke-Command OR Invoke-WebRequest)| rex field=Message "(?i)\"Command\"\;\svalue=\"?(?<obfuscated_cmd>.+.\)?\")"
| rex field=Message "(?i)script\s+name\s+?\=(?<script_name>.+\.ps1)" | regex obfuscated_cmd!="(?i)(\.ps1|powershell)"|
regex obfuscated_cmd=".{25,}" |`ut_shannon(obfuscated_cmd)` | table _time, host,
user process, process_*, signature_id, user, obfuscated_cmd, ut_shannon, script_name
| bin span=1s | stats values(*) as * by _time, host | where ut_shannon > 4 OR match(obfuscated_cmd,
"\s{30}") OR match(obfuscated_cmd, "\W{30}") OR (match(obfuscated_cmd, "(\s?\d{1,8}(\s+|\,)(\s+|\,)?){15}"))
OR match(obfuscated_cmd, "(?i)bxor") '
techniques:
- defense-evasion:obfuscated files or information
- command-and-control:data obfuscation
technique_id:
- T1027
- T1001
data_category:
- Windows event logs
- PowerShell logs
references:
- https://github.com/danielbohannon/Invoke-Obfuscation
- https://github.com/oddcod3/Phantom-Evasion
Stages and Predicates
Stage 1: search
`get_endpoint_data` `get_endpoint_data_powershell` EventCode=4103 (Invoke-Expression OR Invoke-Command OR Invoke-WebRequest)
Stage 2: rex
| rex field=Message "(?i)\"Command\"\;\svalue=\"?(?<obfuscated_cmd>.+.\)?\")"
Stage 3: rex
| rex field=Message "(?i)script\s+name\s+?\=(?<script_name>.+\.ps1)"
Stage 4: regex
| regex obfuscated_cmd!="(?i)(\.ps1|powershell)"
Stage 5: regex
| regex obfuscated_cmd=".{25,}"
Stage 6: search
| `ut_shannon(obfuscated_cmd)`
Stage 7: table
| table _time, host, user process, process_*, signature_id, user, obfuscated_cmd, ut_shannon, script_name
Stage 8: bucket
| bin span=1s
Stage 9: stats
| stats values(*) as * by _time, host
Stage 10: where
| where ut_shannon > 4 OR match(obfuscated_cmd, "\s{30}") OR match(obfuscated_cmd, "\W{30}") OR (match(obfuscated_cmd, "(\s?\d{1,8}(\s+|\,)(\s+|\,)?){15}")) OR match(obfuscated_cmd, "(?i)bxor")
Exclusions
The rule actively suppresses these predicates.
| Field | Kind | Excluded values | Search |
|---|---|---|---|
obfuscated_cmd | regex_match | "(?i)(.ps1|powershell)" | excludes:obfuscated_cmd |
Indicators
These rows show field, operator, and value matches.
| Field | Kind | Values | Search |
|---|---|---|---|
EventCode | eq |
| field:"EventID" kind:eq value:"4103" |
obfuscated_cmd | regex_match |
| field:"obfuscated_cmd" kind:regex_match |
ut_shannon | gt |
| field:"ut_shannon" kind:gt value:"4" |
Search terms
These SPL tokens match against raw event text.
| Stage | Term |
|---|---|
| 1 | Invoke-Expression |
| 1 | Invoke-Command |
| 1 | Invoke-WebRequest |