mirror of https://github.com/infosecn1nja/HELK.git
151 lines
3.9 KiB
Plaintext
151 lines
3.9 KiB
Plaintext
{
|
|
"cells": [
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"# PowerShell Network Connections\n",
|
|
"Detects a Powershell process that opens network connections - check for suspicious target ports and target systems - adjust to your environment (e.g. extend filters with company's ip range')"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"## Rule Content\n",
|
|
"```\n",
|
|
"- title: PowerShell Network Connections\n",
|
|
" id: 1f21ec3f-810d-4b0e-8045-322202e22b4b\n",
|
|
" status: experimental\n",
|
|
" description: Detects a Powershell process that opens network connections - check\n",
|
|
" for suspicious target ports and target systems - adjust to your environment (e.g.\n",
|
|
" extend filters with company's ip range')\n",
|
|
" author: Florian Roth\n",
|
|
" references:\n",
|
|
" - https://www.youtube.com/watch?v=DLtJTxMWZ2o\n",
|
|
" tags:\n",
|
|
" - attack.execution\n",
|
|
" - attack.t1086\n",
|
|
" logsource:\n",
|
|
" product: windows\n",
|
|
" service: sysmon\n",
|
|
" category: null\n",
|
|
" detection:\n",
|
|
" selection:\n",
|
|
" EventID: 3\n",
|
|
" Image: '*\\powershell.exe'\n",
|
|
" Initiated: 'true'\n",
|
|
" filter:\n",
|
|
" DestinationIp:\n",
|
|
" - 10.*\n",
|
|
" - 192.168.*\n",
|
|
" - 172.16.*\n",
|
|
" - 172.17.*\n",
|
|
" - 172.18.*\n",
|
|
" - 172.19.*\n",
|
|
" - 172.20.*\n",
|
|
" - 172.21.*\n",
|
|
" - 172.22.*\n",
|
|
" - 172.23.*\n",
|
|
" - 172.24.*\n",
|
|
" - 172.25.*\n",
|
|
" - 172.26.*\n",
|
|
" - 172.27.*\n",
|
|
" - 172.28.*\n",
|
|
" - 172.29.*\n",
|
|
" - 172.30.*\n",
|
|
" - 172.31.*\n",
|
|
" - 127.0.0.1\n",
|
|
" DestinationIsIpv6: 'false'\n",
|
|
" User: NT AUTHORITY\\SYSTEM\n",
|
|
" condition: selection and not filter\n",
|
|
" falsepositives:\n",
|
|
" - Administrative scripts\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-endpoint-winevent-sysmon-*', 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='((event_id:\"3\" AND process_path.keyword:*\\\\powershell.exe AND network_initiated:\"true\") AND (NOT (dst_ip_addr.keyword:(10.* OR 192.168.* OR 172.16.* OR 172.17.* OR 172.18.* OR 172.19.* OR 172.20.* OR 172.21.* OR 172.22.* OR 172.23.* OR 172.24.* OR 172.25.* OR 172.26.* OR 172.27.* OR 172.28.* OR 172.29.* OR 172.30.* OR 172.31.* OR 127.0.0.1) AND DestinationIsIpv6:\"false\" 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
|
|
}
|