Certutil Encode

Detects suspicious a certutil command that used to encode files, which is sometimes used for data exfiltration

Rule Content

- title: Certutil Encode
  id: e62a9f0c-ca1e-46b2-85d5-a6da77f86d1a
  status: experimental
  description: Detects suspicious a certutil command that used to encode files, which
    is sometimes used for data exfiltration
  references:
  - https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/certutil
  - https://unit42.paloaltonetworks.com/new-babyshark-malware-targets-u-s-national-security-think-tanks/
  author: Florian Roth
  date: 2019/02/24
  logsource:
    category: process_creation
    product: windows
    service: null
  detection:
    selection:
      CommandLine:
      - certutil -f -encode *
      - certutil.exe -f -encode *
      - certutil -encode -f *
      - certutil.exe -encode -f *
    condition: selection
  falsepositives:
  - unknown
  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:(certutil\ \-f\ \-encode\ * OR certutil.exe\ \-f\ \-encode\ * OR certutil\ \-encode\ \-f\ * OR certutil.exe\ \-encode\ \-f\ *)')
response = s.execute()
if response.success():
    df = pd.DataFrame((d.to_dict() for d in s.scan()))

Show Results


In [ ]:
df.head()