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

144 lines
3.7 KiB
Plaintext

{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Impacket Lateralization Detection\n",
"Detects wmiexec/dcomexec/atexec/smbexec from Impacket framework"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Rule Content\n",
"```\n",
"- title: Impacket Lateralization Detection\n",
" id: 10c14723-61c7-4c75-92ca-9af245723ad2\n",
" status: experimental\n",
" description: Detects wmiexec/dcomexec/atexec/smbexec from Impacket framework\n",
" references:\n",
" - https://github.com/SecureAuthCorp/impacket/blob/master/examples/wmiexec.py\n",
" - https://github.com/SecureAuthCorp/impacket/blob/master/examples/atexec.py\n",
" - https://github.com/SecureAuthCorp/impacket/blob/master/examples/smbexec.py\n",
" - https://github.com/SecureAuthCorp/impacket/blob/master/examples/dcomexec.py\n",
" author: Ecco\n",
" date: 2019/09/03\n",
" logsource:\n",
" category: process_creation\n",
" product: windows\n",
" service: null\n",
" detection:\n",
" selection_other:\n",
" ParentImage:\n",
" - '*\\wmiprvse.exe'\n",
" - '*\\mmc.exe'\n",
" - '*\\explorer.exe'\n",
" - '*\\services.exe'\n",
" CommandLine:\n",
" - '*cmd.exe* /Q /c * \\\\\\\\127.0.0.1\\\\*&1*'\n",
" selection_atexec:\n",
" ParentCommandLine:\n",
" - '*svchost.exe -k netsvcs'\n",
" - taskeng.exe*\n",
" CommandLine:\n",
" - cmd.exe /C *Windows\\\\Temp\\\\*&1\n",
" condition: (1 of selection_*)\n",
" fields:\n",
" - CommandLine\n",
" - ParentCommandLine\n",
" tags:\n",
" - attack.lateral_movement\n",
" - attack.t1047\n",
" - attack.t1175\n",
" falsepositives:\n",
" - pentesters\n",
" level: critical\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_parent_path.keyword:(*\\\\wmiprvse.exe OR *\\\\mmc.exe OR *\\\\explorer.exe OR *\\\\services.exe) AND process_command_line.keyword:(*cmd.exe*\\ \\/Q\\ \\/c\\ *\\ \\\\\\\\127.0.0.1\\\\*&1*)) OR (process_parent_command_line.keyword:(*svchost.exe\\ \\-k\\ netsvcs OR taskeng.exe*) AND process_command_line.keyword:(cmd.exe\\ \\/C\\ *Windows\\\\Temp\\\\*&1)))')\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
}