PowerShell Base64 Encoded Shellcode

Detects Base64 encoded Shellcode

Rule Content

- title: PowerShell Base64 Encoded Shellcode
  id: 2d117e49-e626-4c7c-bd1f-c3c0147774c8
  description: Detects Base64 encoded Shellcode
  status: experimental
  references:
  - https://twitter.com/cyb3rops/status/1063072865992523776
  author: Florian Roth
  date: 2018/11/17
  tags:
  - attack.defense_evasion
  - attack.t1036
  logsource:
    category: process_creation
    product: windows
    service: null
  detection:
    selection1:
      CommandLine: '*AAAAYInlM*'
    selection2:
      CommandLine:
      - '*OiCAAAAYInlM*'
      - '*OiJAAAAYInlM*'
    condition: selection1 and selection2
  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-*', doc_type='doc')

Run Elasticsearch Query


In [ ]:
s = searchContext.query('query_string', query='(process_command_line.keyword:*AAAAYInlM* AND process_command_line.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()