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

141 lines
4.0 KiB
Plaintext

{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Default PowerSploit and Empire Schtasks Persistence\n",
"Detects the creation of a schtask via PowerSploit or Empire Default Configuration."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Rule Content\n",
"```\n",
"- title: Default PowerSploit and Empire Schtasks Persistence\n",
" id: 56c217c3-2de2-479b-990f-5c109ba8458f\n",
" status: experimental\n",
" description: Detects the creation of a schtask via PowerSploit or Empire Default\n",
" Configuration.\n",
" references:\n",
" - https://github.com/0xdeadbeefJERKY/PowerSploit/blob/8690399ef70d2cad10213575ac67e8fa90ddf7c3/Persistence/Persistence.psm1\n",
" - https://github.com/EmpireProject/Empire/blob/master/lib/modules/powershell/persistence/userland/schtasks.py\n",
" - https://github.com/EmpireProject/Empire/blob/master/lib/modules/powershell/persistence/elevated/schtasks.py\n",
" author: Markus Neis, @Karneades\n",
" date: 2018/03/06\n",
" logsource:\n",
" product: windows\n",
" category: process_creation\n",
" service: null\n",
" detection:\n",
" selection:\n",
" ParentImage:\n",
" - '*\\powershell.exe'\n",
" CommandLine:\n",
" - '*schtasks*/Create*/SC *ONLOGON*/TN *Updater*/TR *powershell*'\n",
" - '*schtasks*/Create*/SC *DAILY*/TN *Updater*/TR *powershell*'\n",
" - '*schtasks*/Create*/SC *ONIDLE*/TN *Updater*/TR *powershell*'\n",
" - '*schtasks*/Create*/SC *Updater*/TN *Updater*/TR *powershell*'\n",
" condition: selection\n",
" tags:\n",
" - attack.execution\n",
" - attack.persistence\n",
" - attack.privilege_escalation\n",
" - attack.t1053\n",
" - attack.t1086\n",
" - attack.s0111\n",
" - attack.g0022\n",
" - attack.g0060\n",
" - car.2013-08-001\n",
" falsepositives:\n",
" - False positives are possible, depends on organisation and processes\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_parent_path.keyword:(*\\\\powershell.exe) AND process_command_line.keyword:(*schtasks*\\/Create*\\/SC\\ *ONLOGON*\\/TN\\ *Updater*\\/TR\\ *powershell* OR *schtasks*\\/Create*\\/SC\\ *DAILY*\\/TN\\ *Updater*\\/TR\\ *powershell* OR *schtasks*\\/Create*\\/SC\\ *ONIDLE*\\/TN\\ *Updater*\\/TR\\ *powershell* OR *schtasks*\\/Create*\\/SC\\ *Updater*\\/TN\\ *Updater*\\/TR\\ *powershell*))')\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
}