HELK/docker/helk-jupyter/notebooks/sigma/win_wmi_persistence.ipynb

134 lines
3.2 KiB
Plaintext

{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# WMI Persistence\n",
"Detects suspicious WMI event filter and command line event consumer based on event id 5861 and 5859 (Windows 10, 2012 and higher)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Rule Content\n",
"```\n",
"- title: WMI Persistence\n",
" id: 0b7889b4-5577-4521-a60a-3376ee7f9f7b\n",
" status: experimental\n",
" description: Detects suspicious WMI event filter and command line event consumer\n",
" based on event id 5861 and 5859 (Windows 10, 2012 and higher)\n",
" author: Florian Roth\n",
" references:\n",
" - https://twitter.com/mattifestation/status/899646620148539397\n",
" - https://www.eideon.com/2018-03-02-THL03-WMIBackdoors/\n",
" tags:\n",
" - attack.execution\n",
" - attack.persistence\n",
" - attack.t1047\n",
" logsource:\n",
" product: windows\n",
" service: wmi\n",
" category: null\n",
" detection:\n",
" selection:\n",
" EventID: 5861\n",
" keywords:\n",
" Message:\n",
" - '*ActiveScriptEventConsumer*'\n",
" - '*CommandLineEventConsumer*'\n",
" - '*CommandLineTemplate*'\n",
" selection2:\n",
" EventID: 5859\n",
" condition: selection and 1 of keywords or selection2\n",
" falsepositives:\n",
" - Unknown (data set is too small; further testing needed)\n",
" level: medium\n",
"\n",
"```"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Querying Elasticsearch"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Import Libraries"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from elasticsearch import Elasticsearch\n",
"from elasticsearch_dsl import Search\n",
"import pandas as pd"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Initialize Elasticsearch client"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"es = Elasticsearch(['http://helk-elasticsearch:9200'])\n",
"searchContext = Search(using=es, index='logs-endpoint-winevent-wmiactivity-*', doc_type='doc')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Run Elasticsearch Query"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"s = searchContext.query('query_string', query='((event_id:\"5861\" AND Message.keyword:(*ActiveScriptEventConsumer* OR *CommandLineEventConsumer* OR *CommandLineTemplate*)) OR event_id:\"5859\")')\n",
"response = s.execute()\n",
"if response.success():\n",
" df = pd.DataFrame((d.to_dict() for d in s.scan()))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Show Results"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"df.head()"
]
}
],
"metadata": {},
"nbformat": 4,
"nbformat_minor": 4
}