Execution in Non-Executable Folder

Detects a suspicious exection from an uncommon folder

Rule Content

- title: Execution in Non-Executable Folder
  id: 3dfd06d2-eaf4-4532-9555-68aca59f57c4
  status: experimental
  description: Detects a suspicious exection from an uncommon folder
  author: Florian Roth
  tags:
  - attack.defense_evasion
  - attack.t1036
  logsource:
    category: process_creation
    product: windows
    service: null
  detection:
    selection:
      Image:
      - '*\$Recycle.bin'
      - '*\Users\All Users\\*'
      - '*\Users\Default\\*'
      - '*\Users\Public\\*'
      - C:\Perflogs\\*
      - '*\config\systemprofile\\*'
      - '*\Windows\Fonts\\*'
      - '*\Windows\IME\\*'
      - '*\Windows\addins\\*'
    condition: selection
  fields:
  - CommandLine
  - ParentCommandLine
  falsepositives:
  - Unknown
  level: high

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_path.keyword:(*\\$Recycle.bin OR *\\Users\\All\ Users\\* OR *\\Users\\Default\\* OR *\\Users\\Public\\* OR C\:\\Perflogs\\* OR *\\config\\systemprofile\\* OR *\\Windows\\Fonts\\* OR *\\Windows\\IME\\* OR *\\Windows\\addins\\*)')
response = s.execute()
if response.success():
    df = pd.DataFrame((d.to_dict() for d in s.scan()))

Show Results


In [ ]:
df.head()