HELK/docker/helk-jupyter/notebooks/sigma/win_powershell_dll_executio...

134 lines
3.1 KiB
Plaintext

{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Detection of PowerShell Execution via DLL\n",
"Detects PowerShell Strings applied to rundllas seen in PowerShdll.dll"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Rule Content\n",
"```\n",
"- title: Detection of PowerShell Execution via DLL\n",
" id: 6812a10b-60ea-420c-832f-dfcc33b646ba\n",
" status: experimental\n",
" description: Detects PowerShell Strings applied to rundllas seen in PowerShdll.dll\n",
" references:\n",
" - https://github.com/p3nt4/PowerShdll/blob/master/README.md\n",
" tags:\n",
" - attack.execution\n",
" - attack.t1086\n",
" - car.2014-04-003\n",
" author: Markus Neis\n",
" date: 2018/08/25\n",
" logsource:\n",
" category: process_creation\n",
" product: windows\n",
" service: null\n",
" detection:\n",
" selection1:\n",
" Image:\n",
" - '*\\rundll32.exe'\n",
" selection2:\n",
" Description:\n",
" - '*Windows-Hostprozess (Rundll32)*'\n",
" selection3:\n",
" CommandLine:\n",
" - '*Default.GetString*'\n",
" - '*FromBase64String*'\n",
" condition: (selection1 or selection2) and selection3\n",
" falsepositives:\n",
" - Unknown\n",
" level: high\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-*', 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='((process_path.keyword:(*\\\\rundll32.exe) OR file_description.keyword:(*Windows\\-Hostprozess\\ \\(Rundll32\\)*)) AND process_command_line.keyword:(*Default.GetString* OR *FromBase64String*))')\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
}