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

146 lines
3.9 KiB
Plaintext

{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Windows Processes Suspicious Parent Directory\n",
"Detect suspicious parent processes of well-known Windows processes"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Rule Content\n",
"```\n",
"- title: Windows Processes Suspicious Parent Directory\n",
" id: 96036718-71cc-4027-a538-d1587e0006a7\n",
" status: experimental\n",
" description: Detect suspicious parent processes of well-known Windows processes\n",
" author: vburov\n",
" references:\n",
" - https://securitybytes.io/blue-team-fundamentals-part-two-windows-processes-759fe15965e2\n",
" - https://www.carbonblack.com/2014/06/10/screenshot-demo-hunt-evil-faster-than-ever-with-carbon-black/\n",
" - https://www.13cubed.com/downloads/windows_process_genealogy_v2.pdf\n",
" - https://attack.mitre.org/techniques/T1036/\n",
" date: 2019/02/23\n",
" modified: 2019/08/20\n",
" tags:\n",
" - attack.defense_evasion\n",
" - attack.t1036\n",
" logsource:\n",
" category: process_creation\n",
" product: windows\n",
" service: null\n",
" detection:\n",
" selection:\n",
" Image:\n",
" - '*\\svchost.exe'\n",
" - '*\\taskhost.exe'\n",
" - '*\\lsm.exe'\n",
" - '*\\lsass.exe'\n",
" - '*\\services.exe'\n",
" - '*\\lsaiso.exe'\n",
" - '*\\csrss.exe'\n",
" - '*\\wininit.exe'\n",
" - '*\\winlogon.exe'\n",
" filter:\n",
" ParentImage:\n",
" - '*\\System32\\\\*'\n",
" - '*\\SysWOW64\\\\*'\n",
" - '*\\SavService.exe'\n",
" - '*\\Windows Defender\\\\*\\MsMpEng.exe'\n",
" filter_null:\n",
" ParentImage: null\n",
" condition: selection and not filter and not filter_null\n",
" falsepositives:\n",
" - Some security products seem to spawn these\n",
" level: low\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:(*\\\\svchost.exe OR *\\\\taskhost.exe OR *\\\\lsm.exe OR *\\\\lsass.exe OR *\\\\services.exe OR *\\\\lsaiso.exe OR *\\\\csrss.exe OR *\\\\wininit.exe OR *\\\\winlogon.exe) AND (NOT (process_parent_path.keyword:(*\\\\System32\\\\* OR *\\\\SysWOW64\\\\* OR *\\\\SavService.exe OR *\\\\Windows\\ Defender\\\\*\\\\MsMpEng.exe)))) AND (NOT (NOT _exists_:process_parent_path)))')\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
}