Detection rules › Splunk

Obfuscated Powershell Techniques (PowerShell)

Group by
_time, host
Source
github.com/anvilogic-forge/armory

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

TacticTechniques
Stealth
Command & Control

References

Telemetry coverage

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.

FieldKindExcluded valuesSearch
obfuscated_cmdregex_match"(?i)(.ps1|powershell)"excludes:obfuscated_cmd

Indicators

These rows show field, operator, and value matches.

FieldKindValuesSearch
EventCodeeq
  • 4103 corpus 105 (splunk 105)
field:"EventID" kind:eq value:"4103"
obfuscated_cmdregex_match
  • "(?i)bxor"
  • "(\s?\d{1,8}(\s+|\,)(\s+|\,)?){15}"
  • ".{25,}"
  • "\W{30}"
  • "\s{30}"
field:"obfuscated_cmd" kind:regex_match
ut_shannongt
  • 4
field:"ut_shannon" kind:gt value:"4"

Search terms

These SPL tokens match against raw event text.

StageTerm
1Invoke-Expression
1Invoke-Command
1Invoke-WebRequest