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

158 lines
3.7 KiB
Plaintext

{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# PsExec Tool Execution\n",
"Detects PsExec service installation and execution events (service and Sysmon)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Rule Content\n",
"```\n",
"- action: global\n",
" title: PsExec Tool Execution\n",
" id: 42c575ea-e41e-41f1-b248-8093c3e82a28\n",
" status: experimental\n",
" description: Detects PsExec service installation and execution events (service and\n",
" Sysmon)\n",
" author: Thomas Patzke\n",
" references:\n",
" - https://www.jpcert.or.jp/english/pub/sr/ir_research.html\n",
" - https://jpcertcc.github.io/ToolAnalysisResultSheet\n",
" tags:\n",
" - attack.execution\n",
" - attack.t1035\n",
" - attack.s0029\n",
" detection:\n",
" condition: 1 of them\n",
" fields:\n",
" - EventID\n",
" - CommandLine\n",
" - ParentCommandLine\n",
" - ServiceName\n",
" - ServiceFileName\n",
" falsepositives:\n",
" - unknown\n",
" level: low\n",
"- logsource:\n",
" product: windows\n",
" service: system\n",
" detection:\n",
" service_installation:\n",
" EventID: 7045\n",
" ServiceName: PSEXESVC\n",
" ServiceFileName: '*\\PSEXESVC.exe'\n",
" service_execution:\n",
" EventID: 7036\n",
" ServiceName: PSEXESVC\n",
"- logsource:\n",
" category: process_creation\n",
" product: windows\n",
" detection:\n",
" sysmon_processcreation:\n",
" Image: '*\\PSEXESVC.exe'\n",
" User: NT AUTHORITY\\SYSTEM\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='(service_name:\"PSEXESVC\" AND ((event_id:\"7045\" AND service_image_path.keyword:*\\\\PSEXESVC.exe) OR event_id:\"7036\"))')\n",
"response = s.execute()\n",
"if response.success():\n",
" df = pd.DataFrame((d.to_dict() for d in s.scan()))"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"s = searchContext.query('query_string', query='(process_path.keyword:*\\\\PSEXESVC.exe AND user_account:\"NT\\ AUTHORITY\\\\SYSTEM\")')\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
}