PowerShell ShellCode

Detects Base64 encoded Shellcode

Rule Content

- title: PowerShell ShellCode
  id: 16b37b70-6fcf-4814-a092-c36bd3aafcbd
  status: experimental
  description: Detects Base64 encoded Shellcode
  references:
  - https://twitter.com/cyb3rops/status/1063072865992523776
  tags:
  - attack.privilege_escalation
  - attack.execution
  - attack.t1055
  - attack.t1086
  author: David Ledbetter (shellcode), Florian Roth (rule)
  date: 2018/11/17
  logsource:
    product: windows
    service: powershell
    description: Script block logging must be enabled
    category: null
  detection:
    selection:
      EventID: 4104
    keyword1:
    - '*AAAAYInlM*'
    keyword2:
    - '*OiCAAAAYInlM*'
    - '*OiJAAAAYInlM*'
    condition: selection and keyword1 and keyword2
  falsepositives:
  - Unknown
  level: critical

Querying Elasticsearch

Import Libraries


In [ ]:
from elasticsearch import Elasticsearch
from elasticsearch_dsl import Search
import pandas as pd

Initialize Elasticsearch client


In [ ]:
es = Elasticsearch(['http://helk-elasticsearch:9200'])
searchContext = Search(using=es, index='logs-endpoint-winevent-powershell-*', doc_type='doc')

Run Elasticsearch Query


In [ ]:
s = searchContext.query('query_string', query='((event_id:"4104" AND "*AAAAYInlM*") AND \*.keyword:(*OiCAAAAYInlM* OR *OiJAAAAYInlM*))')
response = s.execute()
if response.success():
    df = pd.DataFrame((d.to_dict() for d in s.scan()))

Show Results


In [ ]:
df.head()