mirror of https://github.com/infosecn1nja/HELK.git
135 lines
3.2 KiB
Plaintext
135 lines
3.2 KiB
Plaintext
|
{
|
||
|
"cells": [
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"metadata": {},
|
||
|
"source": [
|
||
|
"# Suspicious PowerShell Invocation based on Parent Process\n",
|
||
|
"Detects suspicious powershell invocations from interpreters or unusual programs"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"metadata": {},
|
||
|
"source": [
|
||
|
"## Rule Content\n",
|
||
|
"```\n",
|
||
|
"- title: Suspicious PowerShell Invocation based on Parent Process\n",
|
||
|
" id: 95eadcb2-92e4-4ed1-9031-92547773a6db\n",
|
||
|
" status: experimental\n",
|
||
|
" description: Detects suspicious powershell invocations from interpreters or unusual\n",
|
||
|
" programs\n",
|
||
|
" author: Florian Roth\n",
|
||
|
" references:\n",
|
||
|
" - https://www.carbonblack.com/2017/03/15/attackers-leverage-excel-powershell-dns-latest-non-malware-attack/\n",
|
||
|
" tags:\n",
|
||
|
" - attack.execution\n",
|
||
|
" - attack.t1086\n",
|
||
|
" logsource:\n",
|
||
|
" category: process_creation\n",
|
||
|
" product: windows\n",
|
||
|
" service: null\n",
|
||
|
" detection:\n",
|
||
|
" selection:\n",
|
||
|
" ParentImage:\n",
|
||
|
" - '*\\wscript.exe'\n",
|
||
|
" - '*\\cscript.exe'\n",
|
||
|
" Image:\n",
|
||
|
" - '*\\powershell.exe'\n",
|
||
|
" falsepositive:\n",
|
||
|
" CurrentDirectory: '*\\Health Service State\\\\*'\n",
|
||
|
" condition: selection and not falsepositive\n",
|
||
|
" fields:\n",
|
||
|
" - CommandLine\n",
|
||
|
" - ParentCommandLine\n",
|
||
|
" falsepositives:\n",
|
||
|
" - Microsoft Operations Manager (MOM)\n",
|
||
|
" - Other scripts\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-*', 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:(*\\\\wscript.exe OR *\\\\cscript.exe) AND process_path.keyword:(*\\\\powershell.exe)) AND (NOT (process_current_directory.keyword:*\\\\Health\\ Service\\ State\\\\*)))')\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
|
||
|
}
|