PowerShell Script Run in AppData

Detects a suspicious command line execution that invokes PowerShell with reference to an AppData folder

Rule Content

- title: PowerShell Script Run in AppData
  id: ac175779-025a-4f12-98b0-acdaeb77ea85
  status: experimental
  description: Detects a suspicious command line execution that invokes PowerShell
    with reference to an AppData folder
  references:
  - https://twitter.com/JohnLaTwC/status/1082851155481288706
  - https://app.any.run/tasks/f87f1c4e-47e2-4c46-9cf4-31454c06ce03
  tags:
  - attack.execution
  - attack.t1086
  author: Florian Roth
  date: 2019/01/09
  logsource:
    category: process_creation
    product: windows
    service: null
  detection:
    selection:
      CommandLine:
      - '* /c powershell*\AppData\Local\\*'
      - '* /c powershell*\AppData\Roaming\\*'
    condition: selection
  falsepositives:
  - Administrative scripts
  level: medium

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:(*\ \/c\ powershell*\\AppData\\Local\\* OR *\ \/c\ powershell*\\AppData\\Roaming\\*)')
response = s.execute()
if response.success():
    df = pd.DataFrame((d.to_dict() for d in s.scan()))

Show Results


In [ ]:
df.head()