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

205 lines
6.0 KiB
Plaintext

{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Suspicious Typical Malware Back Connect Ports\n",
"Detects programs that connect to typical malware back connect ports based on statistical analysis from two different sandbox system databases"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Rule Content\n",
"```\n",
"- title: Suspicious Typical Malware Back Connect Ports\n",
" id: 4b89abaa-99fe-4232-afdd-8f9aa4d20382\n",
" status: experimental\n",
" description: Detects programs that connect to typical malware back connect ports\n",
" based on statistical analysis from two different sandbox system databases\n",
" references:\n",
" - https://docs.google.com/spreadsheets/d/17pSTDNpa0sf6pHeRhusvWG6rThciE8CsXTSlDUAZDyo\n",
" author: Florian Roth\n",
" date: 2017/03/19\n",
" tags:\n",
" - attack.command_and_control\n",
" - attack.t1043\n",
" logsource:\n",
" product: windows\n",
" service: sysmon\n",
" definition: 'Use the following config to generate the necessary Event ID 10 Process\n",
" Access events: <ProcessAccess onmatch=\"include\"><CallTrace condition=\"contains\">VBE7.DLL</CallTrace></ProcessAccess><ProcessAccess\n",
" onmatch=\"exclude\"><CallTrace condition=\"excludes\">UNKNOWN</CallTrace></ProcessAccess>'\n",
" category: null\n",
" detection:\n",
" selection:\n",
" EventID: 3\n",
" Initiated: 'true'\n",
" DestinationPort:\n",
" - '4443'\n",
" - '2448'\n",
" - '8143'\n",
" - '1777'\n",
" - '1443'\n",
" - '243'\n",
" - '65535'\n",
" - '13506'\n",
" - '3360'\n",
" - '200'\n",
" - '198'\n",
" - '49180'\n",
" - '13507'\n",
" - '6625'\n",
" - '4444'\n",
" - '4438'\n",
" - '1904'\n",
" - '13505'\n",
" - '13504'\n",
" - '12102'\n",
" - '9631'\n",
" - '5445'\n",
" - '2443'\n",
" - '777'\n",
" - '13394'\n",
" - '13145'\n",
" - '12103'\n",
" - '5552'\n",
" - '3939'\n",
" - '3675'\n",
" - '666'\n",
" - '473'\n",
" - '5649'\n",
" - '4455'\n",
" - '4433'\n",
" - '1817'\n",
" - '100'\n",
" - '65520'\n",
" - '1960'\n",
" - '1515'\n",
" - '743'\n",
" - '700'\n",
" - '14154'\n",
" - '14103'\n",
" - '14102'\n",
" - '12322'\n",
" - '10101'\n",
" - '7210'\n",
" - '4040'\n",
" - '9943'\n",
" filter1:\n",
" Image: '*\\Program Files*'\n",
" filter2:\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.*\n",
" DestinationIsIpv6: 'false'\n",
" condition: selection and not ( filter1 or filter2 )\n",
" falsepositives:\n",
" - unknown\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-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 network_initiated:\"true\" AND dst_port:(\"4443\" OR \"2448\" OR \"8143\" OR \"1777\" OR \"1443\" OR \"243\" OR \"65535\" OR \"13506\" OR \"3360\" OR \"200\" OR \"198\" OR \"49180\" OR \"13507\" OR \"6625\" OR \"4444\" OR \"4438\" OR \"1904\" OR \"13505\" OR \"13504\" OR \"12102\" OR \"9631\" OR \"5445\" OR \"2443\" OR \"777\" OR \"13394\" OR \"13145\" OR \"12103\" OR \"5552\" OR \"3939\" OR \"3675\" OR \"666\" OR \"473\" OR \"5649\" OR \"4455\" OR \"4433\" OR \"1817\" OR \"100\" OR \"65520\" OR \"1960\" OR \"1515\" OR \"743\" OR \"700\" OR \"14154\" OR \"14103\" OR \"14102\" OR \"12322\" OR \"10101\" OR \"7210\" OR \"4040\" OR \"9943\")) AND (NOT ((process_path.keyword:*\\\\Program\\ Files* OR (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.*) AND DestinationIsIpv6:\"false\")))))')\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
}