Detection rules › Elastic

PowerShell Obfuscation Spawned via Microsoft Office

Source
github.com/elastic/protections-artifacts

Identifies a Microsoft Office application (Word, PowerPoint, Excel) starting Windows PowerShell with a suspicious command line.

MITRE ATT&CK coverage

Rule body

[rule]
description = """
Identifies a Microsoft Office application (Word, PowerPoint, Excel) starting Windows PowerShell with a suspicious
command line.
"""
id = "93ef8a09-0f8d-4aa1-b0fb-47d5d5b40cf2"
license = "Elastic License v2"
name = "PowerShell Obfuscation Spawned via Microsoft Office"
os_list = ["windows"]
reference = [
    "https://github.com/danielbohannon/Invoke-Obfuscation",
    "https://www.elastic.co/security-labs/effective-parenting-detecting-lrpc-based-parent-pid-spoofing",
]
version = "1.0.41"

query = '''
process where event.action == "start" and
 (process.pe.original_file_name == "PowerShell.EXE" or process.name : ("powershell.exe", "pwsh.exe")) and
 (
  process.parent.name : ("excel.exe", "powerpnt.exe", "winword.exe") or
  (descendant of [process where event.action == "start" and process.name : ("excel.exe", "powerpnt.exe", "winword.exe")] and
   /* Issue #263 */
   not process.parent.executable : ("?:\\Program Files\\*.exe", "?:\\Program Files (x86)\\*.exe"))
  ) and
  not process.Ext.token.integrity_level_name == "system" and process.parent.executable != null and 
  process.command_line :
              ("*^*^*^*^*^*^*^*^*^*",
              "*''*''*''*",
              "*`*`*`*`*",
              "*{*{*{*{*{*{*{*{*{*{*{*{*{*{*{*{*{*{*{*",
              "*+*+*+*+*+*",
              "*$*$*$*$*",
              "*[char[]](*)*-join",
              "*Base64String*",
              "*[*Convert]*",
              "*.Text.Encoding*",
              "*.Compression.*",
              "*.replace(*",
              "*MemoryStream*",
              "*WriteAllBytes*",
              "* -en* *",
              "* -ec *",
              "* -e *",
              "* -ex* *",
              "* -ep *",
              "* /e *",
              "* /en* *",
              "* /ec *",
              "* /ex* *",
              "* /ep *",
              "*WebClient*",
              "*DownloadFile*",
              "*DownloadString*",
              "*BitsTransfer*",
              "*Invoke-Exp*",
              "*invoke-web*",
              "*iex*",
              "*iwr*",
              "*Reflection.Assembly*",
              "*Assembly.GetType*",
              "*.Sockets.*",
              "*PromptForCredential*",
              "*nslookup*-q=txt*",
              "*wget*http*") and
  /* Issue #263 */
  not process.parent.executable :
                 ("?:\\ProgramData\\CentraStage\\AEMAgent\\AEMAgent.exe",
                  "?:\\Windows\\System32\\svchost.exe",
                  "?:\\Windows\\System32\\CompatTelRunner.exe",
                  "?:\\Windows\\System32\\taskeng.exe") and

  not process.args : ("Get-AuthenticodeSignature*", "Write-Host") and not process.command_line : "*Get-AppxPackage*Microsoft.Office*" and
  not (process.name : "powershell.exe" and process.command_line : "*Get-CIMInstance -Class Win32_Service*" and 
       process.parent.executable : "C:\\WINDOWS\\System32\\cmd.exe" and process.parent.args : "C:\\WINDOWS\\TEMP\\nessus_*.TMP") and
  not process.command_line : "powershell.exe -NoProfile -NoLogo -InputFormat Text -NoExit -ExecutionPolicy Unrestricted -Command -" and
  not (process.name : "powershell.exe" and process.args : "$ErrorActionPreference='silentlycontinue'; $tmp = (Get-Item -Path $env:PROGRAMFILES\\Google\\Chrome\\Application\\chrome.exe).VersionInfo.FileVersion; if ($tmp) {echo $tmp; Exit;}; $tmp = (Get-Item -Path $env:PROGRAMFILES") and
  not (process.parent.name : "cmd.exe" and process.parent.args : "chcp 65001 & powershell -NonInteractive -WindowStyle Hidden -command &") and
  not (process.args : "-NoLogo" and process.args : "\\\\*.ps1") and 
  not process.args : "$bytes=[System.Text.Encoding]::UTF8.GetBytes('*');$hash=[System.Security.Cryptography.SHA256]::Create().ComputeHash($bytes);[BitConverter]::ToString($hash).Replace('-','').ToLower()"
'''

min_endpoint_version = "7.15.0"
[[actions]]
action = "kill_process"
field = "process.entity_id"
state = 0

[[actions]]
action = "kill_process"
field = "process.parent.entity_id"
state = 0

[[optional_actions]]
action = "rollback"
field = "process.parent.entity_id"
state = 0

[[threat]]
framework = "MITRE ATT&CK"
[[threat.technique]]
id = "T1566"
name = "Phishing"
reference = "https://attack.mitre.org/techniques/T1566/"
[[threat.technique.subtechnique]]
id = "T1566.001"
name = "Spearphishing Attachment"
reference = "https://attack.mitre.org/techniques/T1566/001/"



[threat.tactic]
id = "TA0001"
name = "Initial Access"
reference = "https://attack.mitre.org/tactics/TA0001/"
[[threat]]
framework = "MITRE ATT&CK"
[[threat.technique]]
id = "T1059"
name = "Command and Scripting Interpreter"
reference = "https://attack.mitre.org/techniques/T1059/"
[[threat.technique.subtechnique]]
id = "T1059.001"
name = "PowerShell"
reference = "https://attack.mitre.org/techniques/T1059/001/"



[threat.tactic]
id = "TA0002"
name = "Execution"
reference = "https://attack.mitre.org/tactics/TA0002/"

[internal]
min_endpoint_version = "7.15.0"

Stages and Predicates

Stage 1: process

process where event.action == "start" and
 (process.pe.original_file_name == "PowerShell.EXE" or process.name : ("powershell.exe", "pwsh.exe")) and
 (
  process.parent.name : ("excel.exe", "powerpnt.exe", "winword.exe") or
  (descendant of [process where event.action == "start" and process.name : ("excel.exe", "powerpnt.exe", "winword.exe")] and
   not process.parent.executable : ("?:\\Program Files\\*.exe", "?:\\Program Files (x86)\\*.exe"))
  ) and
  not process.Ext.token.integrity_level_name == "system" and process.parent.executable != null and
  process.command_line :
              ("*^*^*^*^*^*^*^*^*^*",
              "*''*''*''*",
              "*`*`*`*`*",
              "*{*{*{*{*{*{*{*{*{*{*{*{*{*{*{*{*{*{*{*",
              "*+*+*+*+*+*",
              "*$*$*$*$*",
              "*[char[]](*)*-join",
              "*Base64String*",
              "*[*Convert]*",
              "*.Text.Encoding*",
              "*.Compression.*",
              "*.replace(*",
              "*MemoryStream*",
              "*WriteAllBytes*",
              "* -en* *",
              "* -ec *",
              "* -e *",
              "* -ex* *",
              "* -ep *",
              "* /e *",
              "* /en* *",
              "* /ec *",
              "* /ex* *",
              "* /ep *",
              "*WebClient*",
              "*DownloadFile*",
              "*DownloadString*",
              "*BitsTransfer*",
              "*Invoke-Exp*",
              "*invoke-web*",
              "*iex*",
              "*iwr*",
              "*Reflection.Assembly*",
              "*Assembly.GetType*",
              "*.Sockets.*",
              "*PromptForCredential*",
              "*nslookup*-q=txt*",
              "*wget*http*") and
  not process.parent.executable :
                 ("?:\\ProgramData\\CentraStage\\AEMAgent\\AEMAgent.exe",
                  "?:\\Windows\\System32\\svchost.exe",
                  "?:\\Windows\\System32\\CompatTelRunner.exe",
                  "?:\\Windows\\System32\\taskeng.exe") and
  not process.args : ("Get-AuthenticodeSignature*", "Write-Host") and not process.command_line : "*Get-AppxPackage*Microsoft.Office*" and
  not (process.name : "powershell.exe" and process.command_line : "*Get-CIMInstance -Class Win32_Service*" and
       process.parent.executable : "C:\\WINDOWS\\System32\\cmd.exe" and process.parent.args : "C:\\WINDOWS\\TEMP\\nessus_*.TMP") and
  not process.command_line : "powershell.exe -NoProfile -NoLogo -InputFormat Text -NoExit -ExecutionPolicy Unrestricted -Command -" and
  not (process.name : "powershell.exe" and process.args : "$ErrorActionPreference='silentlycontinue'; $tmp = (Get-Item -Path $env:PROGRAMFILES\\Google\\Chrome\\Application\\chrome.exe).VersionInfo.FileVersion; if ($tmp) {echo $tmp; Exit;}; $tmp = (Get-Item -Path $env:PROGRAMFILES") and
  not (process.parent.name : "cmd.exe" and process.parent.args : "chcp 65001 & powershell -NonInteractive -WindowStyle Hidden -command &") and
  not (process.args : "-NoLogo" and process.args : "\\\\*.ps1") and
  not process.args : "$bytes=[System.Text.Encoding]::UTF8.GetBytes('*');$hash=[System.Security.Cryptography.SHA256]::Create().ComputeHash($bytes);[BitConverter]::ToString($hash).Replace('-','').ToLower()"

Exclusions

The rule actively suppresses these predicates.

FieldKindExcluded valuesSearch
process.argseq$ErrorActionPreference='silentlycontinue'; $tmp = (Get-Item -Path $env:PROGRAMFILES\Google\Chrome\Application\chrome.exe).VersionInfo.FileVersion; if ($tmp) {echo $tmp; Exit;}; $tmp = (Get-Item -Path $env:PROGRAMFILESexcludes:process.args field:"process.args" value:"$ErrorActionPreference='silentlycontinue'; $tmp = (Get-Item -Path $env:PROGRAMFILES\Google\Chrome\Application\chrome.exe).VersionInfo.FileVersion; if ($tmp) {echo $tmp; Exit;}; $tmp = (Get-Item -Path $env:PROGRAMFILES"
process.nameeqpowershell.exeexcludes:process.name field:"process.name" value:"powershell.exe"
process.argseq-NoLogoexcludes:process.args field:"process.args" value:"-NoLogo"
process.argswildcard\\*.ps1excludes:process.args field:"process.args" value:"\\*.ps1"
process.command_linematchGet-CIMInstance -Class Win32_Serviceexcludes:process.command_line field:"process.command_line" value:"Get-CIMInstance -Class Win32_Service"
process.parent.argswildcardC:\WINDOWS\TEMP\nessus_*.TMPexcludes:process.parent.args field:"process.parent.args" value:"C:\WINDOWS\TEMP\nessus_*.TMP"
process.parent.executableeqC:\WINDOWS\System32\cmd.exeexcludes:process.parent.executable field:"process.parent.executable" value:"C:\WINDOWS\System32\cmd.exe"
process.parent.argseqchcp 65001 & powershell -NonInteractive -WindowStyle Hidden -command &excludes:process.parent.args field:"process.parent.args" value:"chcp 65001 & powershell -NonInteractive -WindowStyle Hidden -command &"
process.parent.nameeqcmd.exeexcludes:process.parent.name field:"process.parent.name" value:"cmd.exe"
process.Ext.token.integrity_level_nameeqsystemexcludes:process.Ext.token.integrity_level_name field:"process.Ext.token.integrity_level_name" value:"system"
process.argswildcard$bytes=[System.Text.Encoding]::UTF8.GetBytes('*');$hash=[System.Security.Cryptography.SHA256]::Create().ComputeHash($bytes);[BitConverter]::ToString($hash).Replace('-','').ToLower()excludes:process.args field:"process.args" value:"$bytes=[System.Text.Encoding]::UTF8.GetBytes('*');$hash=[System.Security.Cryptography.SHA256]::Create().ComputeHash($bytes);[BitConverter]::ToString($hash).Replace('-','').ToLower()"
process.argswildcardGet-AuthenticodeSignature*, Write-Hostexcludes:process.args field:"process.args" value:"Get-AuthenticodeSignature*" field:"process.args" value:"Write-Host"
process.command_lineeqpowershell.exe -NoProfile -NoLogo -InputFormat Text -NoExit -ExecutionPolicy Unrestricted -Command -excludes:process.command_line field:"process.command_line" value:"powershell.exe -NoProfile -NoLogo -InputFormat Text -NoExit -ExecutionPolicy Unrestricted -Command -"
process.command_linewildcard*Get-AppxPackage*Microsoft.Office*excludes:process.command_line field:"process.command_line" value:"*Get-AppxPackage*Microsoft.Office*"
process.parent.executableeq?:\ProgramData\CentraStage\AEMAgent\AEMAgent.exe, ?:\Windows\System32\svchost.exe, ?:\Windows\System32\CompatTelRunner.exe, ?:\Windows\System32\taskeng.exeexcludes:process.parent.executable

Indicators

These rows show field, operator, and value matches.

FieldKindValuesSearch
event.actioneq
  • start corpus 391 (elastic 391)
field:"EventType" kind:eq value:"start"
process.command_linewildcard
  • * -e * corpus 17 (sigma 14, elastic 3)
  • * -ec * corpus 2 (sigma 2)
  • * -en* * corpus 3 (elastic 3)
  • * -ep *
  • * -ex* *
  • * /e * corpus 3 (sigma 3)
  • * /ec *
  • * /en* * corpus 3 (elastic 3)
  • * /ep *
  • * /ex* *
  • *$*$*$*$* corpus 3 (elastic 3)
  • *''*''*''* corpus 3 (elastic 3)
  • *+*+*+*+*+* corpus 3 (elastic 3)
  • *.Compression.*
  • *.Sockets.*
  • *.Text.Encoding*
  • *.replace(*
  • *Assembly.GetType*
  • *Base64String*
  • *BitsTransfer*
  • *DownloadFile* corpus 6 (sigma 4, elastic 1, chronicle 1)
  • *DownloadString* corpus 9 (sigma 7, elastic 1, kusto 1)
  • *Invoke-Exp*
  • *MemoryStream*
  • *PromptForCredential*
  • *Reflection.Assembly* corpus 2 (elastic 2)
  • *WebClient* corpus 2 (elastic 2)
  • *WriteAllBytes*
  • *[*Convert]* corpus 5 (elastic 5)
  • *[char[]](*)*-join corpus 3 (elastic 3)
  • *^*^*^*^*^*^*^*^*^* corpus 5 (elastic 5)
  • *`*`*`*`* corpus 5 (elastic 5)
  • *iex* corpus 6 (sigma 5, splunk 1)
  • *invoke-web*
  • *iwr*
  • *nslookup*-q=txt*
  • *wget*http* corpus 3 (elastic 3)
  • *{*{*{*{*{*{*{*{*{*{*{*{*{*{*{*{*{*{*{* corpus 2 (elastic 2)
field:"CommandLine" kind:wildcard
process.namewildcard
  • powershell.exe corpus 184 (elastic 140, splunk 44)
  • pwsh.exe corpus 77 (elastic 48, splunk 29)
field:"process_name" kind:wildcard
process.parent.executableis_not_null
  • (no value, null check)
field:"ParentImage" kind:is_not_null
process.parent.namewildcard
  • excel.exe corpus 28 (elastic 27, splunk 1)
  • powerpnt.exe corpus 23 (elastic 23)
  • winword.exe corpus 26 (elastic 26)
field:"parent_process_name" kind:wildcard
process.pe.original_file_nameeq
  • PowerShell.EXE corpus 138 (sigma 84, splunk 30, elastic 24)
field:"OriginalFileName" kind:eq value:"PowerShell.EXE"