Detection rules › Elastic

Suspicious PowerShell Base64 Decoding

Source
github.com/elastic/protections-artifacts

Identifies the execution of PowerShell with suspicious base64 decoding activity. This behavior is often observed during malware installation leveraging PowerShell.

MITRE ATT&CK coverage

Rule body

[rule]
description = """
Identifies the execution of PowerShell with suspicious base64 decoding activity. This behavior is often observed during
malware installation leveraging PowerShell.
"""
id = "08fa5da1-81af-413d-a960-f7e489c75cfb"
license = "Elastic License v2"
name = "Suspicious PowerShell Base64 Decoding"
os_list = ["windows"]
version = "1.0.13"

query = '''
api where process.Ext.api.name == "AmsiScanBuffer" and process.parent.executable != null and
  process.name in~ ("powershell.exe")  and
  process.Ext.api.parameters.buffer : "*FromBase64String*" and
  /* suspicious activity along base64 decoding */
  process.Ext.api.parameters.buffer :
                       ("*.downloadstring*", "*.downloadfile*", "*.downloaddata*", "*.WebClient*", "*(iWr *", "* iwr*", "iwr *",
                        "*-bxor*", "*).Content*", "*IEX *", "*iex(*", "*Invoke-Expression", "*Invoke-Expression $*", "*iex;*",
                        "*Start-Process*", "*SeDebugPrivilege*", "*Cryptography.Aes*") and

  not process.Ext.api.parameters.buffer : ("function Get-DecryptedConfig*", "function Unprotect-ConfigFile*") and
  not process.Ext.api.parameters.content_name :
                   ("C:\\WINDOWS\\CCM\\SystemTemp\\*.ps1",
                    "C:\\PowerShell\\AES.ps1",
                    "C:\\sysmgt\\sw\\ADSMonitoring\\modules\\POSAntiVirusHealth\\POSAntiVirusHealth.psm1",
                    "C:\\Packages\\Plugins\\Rapid7.InsightPlatform.InsightAgentWindows\\*\\bin\\shared.psm1",
                    "C:\\sysmgt\\sw\\Monitoring\\PSModule\\POSAntiVirusHealth\\POSAntiVirusHealth.psm1",
                    "C:\\WINDOWS\\_IS\\PostESPconfig\\clienthealth\\uploadDeviceHealth_remediation.ps1",
                    "C:\\Program Files\\*", "C:\\Program Files (x86)\\*",
                    "D:\\*", "E:\\*" ,"F:\\*", "I:\\*", "\\\\*",
                    "C:\\Octopus\\*.ps1",
                    "C:\\Octopus??\\*.ps1",
                    "C:\\*\\Bootstrap.Octopus.FunctionAppenderContext.ps1",
                    "C:\\ProgramData\\HP\\MIK\\RunHPIA.ps1",
                    "C:\\Packages\\Plugins\\*.ps1",
                    "C:\\Packages\\Plugins\\*.psm1",
                    "C:\\temp\\intune-install.ps1",
                    "C:\\temp\\*\\intune-install.ps1",
                    "C:\\mdeanalyzer\\MDEClientAnalyzer\\MDEClientAnalyzer.ps1",
                    "C:\\Users\\*\\scoop\\apps\\scoop\\current\\lib\\autoupdate.ps1",
                    "C:\\WINDOWS\\IMECache\\HealthScripts\\*.ps1",
                    "C:\\sysmgt\\sw\\A\\DSMonitoring\\modules\\POSAntiVirusHealth\\POSAntiVirusHealth.psm1",
                    "C:\\ProgramData\\Microsoft\\Windows Defender Advanced Threat Protection\\DataCollection\\*.ps1",
                    "C:\\Windows\\IMECache\\*\\intune-install.ps1",
                    "C:\\*\\IntuneManagement*\\Extensions\\IntuneAppManagement.psm1",
                    "C:\\SCS\\*\\Scripts\\Get-SCCMInventoryData.ps1",
                    "C:\\ProgramData\\NinjaRMMAgent\\scripting\\customscript_gen*.ps1",
                    "C:\\Tenable\\Tenable.ad\\Tools\\Run_RelayUpdater.ps1",
                    "C:\\Hexnode\\Resources\\*.ps1") and
  not process.parent.executable :
                   ("C:\\Program Files\\Windows Defender Advanced Threat Protection\\SenseIR.exe",
                    "C:\\Program Files\\Octopus Deploy\\Tentacle\\Tentacle.exe",
                    "C:\\Program Files (x86)\\CentraStage\\CagService.exe",
                    "C:\\Program Files (x86)\\Common Files\\VAudio\\Interop.Exe",
                    "C:\\ProgramData\\CentraStage*\\AEMAgent\\AEMAgent.exe",
                    "C:\\Program Files\\Git\\usr\\bin\\sh.exe",
                    "C:\\Windows\\SysWOW64\\msiexec.exe",
                    "C:\\Windows\\CCM\\CcmExec.exe") and
  not (process.Ext.api.parameters.size == 2434 and process.Ext.api.parameters.buffer : "function Load-Assembly*" and process.parent.executable : "C:\\Windows\\Sys*\\cmd.exe") and 
  not process.command_line : ("*JgBjAGgAYwBwAC4AYwBvAG0AIAA2AD*", "*UwBlAHQALQBFAHgAZQBjAHUAdABpAG8AbgBQAG8AbABpAGMAeQAgAC0ARQB4AGUAYwB1A*", "*AQAAANCMnd8BFdERjHoAwE*", "*C:\\Program Files (x86)\\Microsoft Office\\root\\vfs\\SystemX86\\sppc.dll*") and
  not (process.executable : "C:\\Windows\\System32\\wsmprovhost.exe" and process.Ext.api.parameters.buffer : "*Ansible*") and
  not process.executable :
                 ("?:\\Program Files\\*.exe",
                  "?:\\Program Files (x86)\\*.exe",
                  "C:\\CloudEngRinnovoCertificati\\bin\\CloudEngCertificati.exe",
                  "D:\\SF-Deploy\\Console\\Jobs\\ClearNetBootGUID.exe")
'''

min_endpoint_version = "8.16.0"
[[actions]]
action = "kill_process"
field = "process.entity_id"
state = 0
tree = true

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

[[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 = "8.16.0"

Stages and Predicates

Stage 1: api

api where process.Ext.api.name == "AmsiScanBuffer" and process.parent.executable != null and
  process.name in~ ("powershell.exe")  and
  process.Ext.api.parameters.buffer : "*FromBase64String*" and
  process.Ext.api.parameters.buffer :
                       ("*.downloadstring*", "*.downloadfile*", "*.downloaddata*", "*.WebClient*", "*(iWr *", "* iwr*", "iwr *",
                        "*-bxor*", "*).Content*", "*IEX *", "*iex(*", "*Invoke-Expression", "*Invoke-Expression $*", "*iex;*",
                        "*Start-Process*", "*SeDebugPrivilege*", "*Cryptography.Aes*") and
  not process.Ext.api.parameters.buffer : ("function Get-DecryptedConfig*", "function Unprotect-ConfigFile*") and
  not process.Ext.api.parameters.content_name :
                   ("C:\\WINDOWS\\CCM\\SystemTemp\\*.ps1",
                    "C:\\PowerShell\\AES.ps1",
                    "C:\\sysmgt\\sw\\ADSMonitoring\\modules\\POSAntiVirusHealth\\POSAntiVirusHealth.psm1",
                    "C:\\Packages\\Plugins\\Rapid7.InsightPlatform.InsightAgentWindows\\*\\bin\\shared.psm1",
                    "C:\\sysmgt\\sw\\Monitoring\\PSModule\\POSAntiVirusHealth\\POSAntiVirusHealth.psm1",
                    "C:\\WINDOWS\\_IS\\PostESPconfig\\clienthealth\\uploadDeviceHealth_remediation.ps1",
                    "C:\\Program Files\\*", "C:\\Program Files (x86)\\*",
                    "D:\\*", "E:\\*" ,"F:\\*", "I:\\*", "\\\\*",
                    "C:\\Octopus\\*.ps1",
                    "C:\\Octopus??\\*.ps1",
                    "C:\\*\\Bootstrap.Octopus.FunctionAppenderContext.ps1",
                    "C:\\ProgramData\\HP\\MIK\\RunHPIA.ps1",
                    "C:\\Packages\\Plugins\\*.ps1",
                    "C:\\Packages\\Plugins\\*.psm1",
                    "C:\\temp\\intune-install.ps1",
                    "C:\\temp\\*\\intune-install.ps1",
                    "C:\\mdeanalyzer\\MDEClientAnalyzer\\MDEClientAnalyzer.ps1",
                    "C:\\Users\\*\\scoop\\apps\\scoop\\current\\lib\\autoupdate.ps1",
                    "C:\\WINDOWS\\IMECache\\HealthScripts\\*.ps1",
                    "C:\\sysmgt\\sw\\A\\DSMonitoring\\modules\\POSAntiVirusHealth\\POSAntiVirusHealth.psm1",
                    "C:\\ProgramData\\Microsoft\\Windows Defender Advanced Threat Protection\\DataCollection\\*.ps1",
                    "C:\\Windows\\IMECache\\*\\intune-install.ps1",
                    "C:\\*\\IntuneManagement*\\Extensions\\IntuneAppManagement.psm1",
                    "C:\\SCS\\*\\Scripts\\Get-SCCMInventoryData.ps1",
                    "C:\\ProgramData\\NinjaRMMAgent\\scripting\\customscript_gen*.ps1",
                    "C:\\Tenable\\Tenable.ad\\Tools\\Run_RelayUpdater.ps1",
                    "C:\\Hexnode\\Resources\\*.ps1") and
  not process.parent.executable :
                   ("C:\\Program Files\\Windows Defender Advanced Threat Protection\\SenseIR.exe",
                    "C:\\Program Files\\Octopus Deploy\\Tentacle\\Tentacle.exe",
                    "C:\\Program Files (x86)\\CentraStage\\CagService.exe",
                    "C:\\Program Files (x86)\\Common Files\\VAudio\\Interop.Exe",
                    "C:\\ProgramData\\CentraStage*\\AEMAgent\\AEMAgent.exe",
                    "C:\\Program Files\\Git\\usr\\bin\\sh.exe",
                    "C:\\Windows\\SysWOW64\\msiexec.exe",
                    "C:\\Windows\\CCM\\CcmExec.exe") and
  not (process.Ext.api.parameters.size == 2434 and process.Ext.api.parameters.buffer : "function Load-Assembly*" and process.parent.executable : "C:\\Windows\\Sys*\\cmd.exe") and
  not process.command_line : ("*JgBjAGgAYwBwAC4AYwBvAG0AIAA2AD*", "*UwBlAHQALQBFAHgAZQBjAHUAdABpAG8AbgBQAG8AbABpAGMAeQAgAC0ARQB4AGUAYwB1A*", "*AQAAANCMnd8BFdERjHoAwE*", "*C:\\Program Files (x86)\\Microsoft Office\\root\\vfs\\SystemX86\\sppc.dll*") and
  not (process.executable : "C:\\Windows\\System32\\wsmprovhost.exe" and process.Ext.api.parameters.buffer : "*Ansible*") and
  not process.executable :
                 ("?:\\Program Files\\*.exe",
                  "?:\\Program Files (x86)\\*.exe",
                  "C:\\CloudEngRinnovoCertificati\\bin\\CloudEngCertificati.exe",
                  "D:\\SF-Deploy\\Console\\Jobs\\ClearNetBootGUID.exe")

Exclusions

The rule actively suppresses these predicates.

FieldKindExcluded valuesSearch
process.Ext.api.parameters.buffermatchAnsibleexcludes:process.Ext.api.parameters.buffer field:"process.Ext.api.parameters.buffer" value:"Ansible"
process.executableeqC:\Windows\System32\wsmprovhost.exeexcludes:process.executable field:"process.executable" value:"C:\Windows\System32\wsmprovhost.exe"
process.Ext.api.parameters.bufferstarts_withfunction Load-Assemblyexcludes:process.Ext.api.parameters.buffer field:"process.Ext.api.parameters.buffer" value:"function Load-Assembly"
process.Ext.api.parameters.sizeeq2434excludes:process.Ext.api.parameters.size field:"process.Ext.api.parameters.size" value:"2434"
process.parent.executablewildcardC:\Windows\Sys*\cmd.exeexcludes:process.parent.executable field:"process.parent.executable" value:"C:\Windows\Sys*\cmd.exe"
process.Ext.api.parameters.bufferstarts_withfunction Get-DecryptedConfig, function Unprotect-ConfigFileexcludes:process.Ext.api.parameters.buffer field:"process.Ext.api.parameters.buffer" value:"function Get-DecryptedConfig" field:"process.Ext.api.parameters.buffer" value:"function Unprotect-ConfigFile"
process.Ext.api.parameters.content_namewildcardC:\WINDOWS\CCM\SystemTemp\*.ps1, C:\PowerShell\AES.ps1, C:\sysmgt\sw\ADSMonitoring\modules\POSAntiVirusHealth\POSAntiVirusHealth.psm1, C:\Packages\Plugins\Rapid7.InsightPlatform.InsightAgentWindows\*\bin\shared.psm1, C:\sysmgt\sw\Monitoring\PSModule\POSAntiVirusHealth\POSAntiVirusHealth.psm1, C:\WINDOWS\_IS\PostESPconfig\clienthealth\uploadDeviceHealth_remediation.ps1, C:\Program Files\*, C:\Program Files (x86)\*, D:\*, E:\*, F:\*, I:\*, \\*, C:\Octopus\*.ps1, C:\Octopus??\*.ps1, C:\*\Bootstrap.Octopus.FunctionAppenderContext.ps1, C:\ProgramData\HP\MIK\RunHPIA.ps1, C:\Packages\Plugins\*.ps1, C:\Packages\Plugins\*.psm1, C:\temp\intune-install.ps1, C:\temp\*\intune-install.ps1, C:\mdeanalyzer\MDEClientAnalyzer\MDEClientAnalyzer.ps1, C:\Users\*\scoop\apps\scoop\current\lib\autoupdate.ps1, C:\WINDOWS\IMECache\HealthScripts\*.ps1, C:\sysmgt\sw\A\DSMonitoring\modules\POSAntiVirusHealth\POSAntiVirusHealth.psm1, C:\ProgramData\Microsoft\Windows Defender Advanced Threat Protection\DataCollection\*.ps1, C:\Windows\IMECache\*\intune-install.ps1, C:\*\IntuneManagement*\Extensions\IntuneAppManagement.psm1, C:\SCS\*\Scripts\Get-SCCMInventoryData.ps1, C:\ProgramData\NinjaRMMAgent\scripting\customscript_gen*.ps1, C:\Tenable\Tenable.ad\Tools\Run_RelayUpdater.ps1, C:\Hexnode\Resources\*.ps1excludes:process.Ext.api.parameters.content_name
process.command_linematchJgBjAGgAYwBwAC4AYwBvAG0AIAA2AD, UwBlAHQALQBFAHgAZQBjAHUAdABpAG8AbgBQAG8AbABpAGMAeQAgAC0ARQB4AGUAYwB1A, AQAAANCMnd8BFdERjHoAwE, C:\Program Files (x86)\Microsoft Office\root\vfs\SystemX86\sppc.dllexcludes:process.command_line
process.executablewildcard?:\Program Files\*.exe, ?:\Program Files (x86)\*.exe, C:\CloudEngRinnovoCertificati\bin\CloudEngCertificati.exe, D:\SF-Deploy\Console\Jobs\ClearNetBootGUID.exeexcludes:process.executable
process.parent.executablewildcardC:\Program Files\Windows Defender Advanced Threat Protection\SenseIR.exe, C:\Program Files\Octopus Deploy\Tentacle\Tentacle.exe, C:\Program Files (x86)\CentraStage\CagService.exe, C:\Program Files (x86)\Common Files\VAudio\Interop.Exe, C:\ProgramData\CentraStage*\AEMAgent\AEMAgent.exe, C:\Program Files\Git\usr\bin\sh.exe, C:\Windows\SysWOW64\msiexec.exe, C:\Windows\CCM\CcmExec.exeexcludes:process.parent.executable

Indicators

These rows show field, operator, and value matches.

FieldKindValuesSearch
process.Ext.api.nameeq
  • AmsiScanBuffer corpus 16 (elastic 16)
field:"process.Ext.api.name" kind:eq value:"AmsiScanBuffer"
process.Ext.api.parameters.bufferwildcard
  • * iwr*
  • *(iWr *
  • *).Content*
  • *-bxor*
  • *.WebClient*
  • *.downloaddata*
  • *.downloadfile*
  • *.downloadstring*
  • *Cryptography.Aes*
  • *FromBase64String*
  • *IEX *
  • *Invoke-Expression
  • *Invoke-Expression $*
  • *SeDebugPrivilege*
  • *Start-Process*
  • *iex(*
  • *iex;*
  • iwr *
field:"process.Ext.api.parameters.buffer" kind:wildcard
process.namein
  • powershell.exe corpus 184 (elastic 140, splunk 44)
field:"process_name" kind:in value:"powershell.exe"
process.parent.executableis_not_null
  • (no value, null check)
field:"ParentImage" kind:is_not_null