smbexec.py Service Installation

Detects the use of smbexec.py tool by detecting a specific service installation

Rule Content

- title: smbexec.py Service Installation
  id: 52a85084-6989-40c3-8f32-091e12e13f09
  description: Detects the use of smbexec.py tool by detecting a specific service
    installation
  author: Omer Faruk Celik
  date: 2018/03/20
  references:
  - https://blog.ropnop.com/using-credentials-to-own-windows-boxes-part-2-psexec-and-services/
  tags:
  - attack.lateral_movement
  - attack.execution
  - attack.t1077
  - attack.t1035
  logsource:
    product: windows
    service: system
    category: null
  detection:
    service_installation:
      EventID: 7045
      ServiceName: BTOBTO
      ServiceFileName: '*\execute.bat'
    condition: service_installation
  fields:
  - ServiceName
  - ServiceFileName
  falsepositives:
  - Penetration Test
  - 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-system-*', doc_type='doc')

Run Elasticsearch Query


In [ ]:
s = searchContext.query('query_string', query='(event_id:"7045" AND service_name:"BTOBTO" AND service_image_path.keyword:*\\execute.bat)')
response = s.execute()
if response.success():
    df = pd.DataFrame((d.to_dict() for d in s.scan()))

Show Results


In [ ]:
df.head()