title: Suspicious PowerShell Command Line
id: d7bcd677-645d-4691-a8d4-7a5602b780d1
status: test
description: Detects the PowerShell command lines with special characters
author: Teymur Kheirkhabarov (idea), Vasiliy Burov (rule), oscd.community, Tim Shelton (fp)
references:
  - https://speakerdeck.com/heirhabarov/hunting-for-powershell-abuse?slide=64
date: 2020/10/15
modified: 2022/03/08
logsource:
  category: process_creation
  product: windows
detection:
  selection1:
    Image|endswith: '\powershell.exe'
    CommandLine|re: '.*\+.*\+.*\+.*\+.*\+.*\+.*\+.*\+.*\+.*\+.*\+.*\+.*\+.*\+.*'
  selection2:
    Image|endswith: '\powershell.exe'
    CommandLine|re: '.*\{.*\{.*\{.*\{.*\{.*\{.*\{.*\{.*\{.*\{.*'
  selection3:
    Image|endswith: '\powershell.exe'
    CommandLine|re: '.*{.*{.*{.*{.*{.*'
  selection4:
    Image|endswith: '\powershell.exe'
    CommandLine|re: '.*\^.*\^.*\^.*\^.*\^.*'
  selection5:
    Image|endswith: '\powershell.exe'
    CommandLine|re: '.*`.*`.*`.*`.*`.*'
  filter_amazonSSM:
    ParentImage: C:\Program Files\Amazon\SSM\ssm-document-worker.exe
  filter_windef_atp:
    CommandLine|contains:
      - 'new EventSource("Microsoft.Windows.Sense.Client.Management"'
      - 'public static extern bool InstallELAMCertificateInfo(SafeFileHandle handle);'
  condition: (selection1 or selection2 or selection3 or selection4 or selection5) and not filter_amazonSSM and not (selection3 and filter_windef_atp)
falsepositives:
  - Unlikely
  - Amazon SSM Document Worker # fp example: powershell " [Console]::OutputEncoding = [System.Text.Encoding]::UTF8 $keyExists = Test-Path "Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Setup\OC Manager\Subcomponents" $jsonObj = @() if ($keyExists) { $key = Get-Item "Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Setup\OC Manager\Subcomponents" $valueNames = $key.GetValueNames(); foreach ($valueName in $valueNames) { $value = $key.GetValue($valueName); if ($value -gt 0) { $installed = "True" } else { $installed = "False" } $jsonObj += @" {"Name": "$valueName", "Installed": "$installed"} "@ } } $result = $jsonObj -join "," $result = "[" + $result + "]" [Console]::WriteLine($result)
  - Windows Defender ATP
level: high
tags:
  - attack.defense_evasion
  - attack.t1027
  - attack.execution
  - attack.t1059.001
