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

139 lines
3.6 KiB
Plaintext
Raw Normal View History

{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Pass the Hash Activity 2\n",
"Detects the attack technique pass the hash which is used to move laterally inside the network"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Rule Content\n",
"```\n",
"- title: Pass the Hash Activity 2\n",
" id: 8eef149c-bd26-49f2-9e5a-9b00e3af499b\n",
" status: production\n",
" description: Detects the attack technique pass the hash which is used to move laterally\n",
" inside the network\n",
" references:\n",
" - https://github.com/iadgov/Event-Forwarding-Guidance/tree/master/Events\n",
" - https://blog.binarydefense.com/reliably-detecting-pass-the-hash-through-event-log-analysis\n",
" - https://blog.stealthbits.com/how-to-detect-pass-the-hash-attacks/\n",
" author: Dave Kennedy, Jeff Warren (method) / David Vassallo (rule)\n",
" tags:\n",
" - attack.lateral_movement\n",
" - attack.t1075\n",
" logsource:\n",
" product: windows\n",
" service: security\n",
" definition: The successful use of PtH for lateral movement between workstations\n",
" would trigger event ID 4624\n",
" category: null\n",
" detection:\n",
" selection:\n",
" - EventID: 4624\n",
" SubjectUserSid: S-1-0-0\n",
" LogonType: '3'\n",
" LogonProcessName: NtLmSsp\n",
" KeyLength: '0'\n",
" - EventID: 4624\n",
" LogonType: '9'\n",
" LogonProcessName: seclogo\n",
" filter:\n",
" AccountName: ANONYMOUS LOGON\n",
" condition: selection and not filter\n",
" falsepositives:\n",
" - Administrator activity\n",
" - Penetration tests\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-security-*', 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:\"4624\" AND ((SubjectUserSid:\"S\\-1\\-0\\-0\" AND logon_type:\"3\" AND logon_process_name:\"NtLmSsp\" AND KeyLength:\"0\") OR (logon_type:\"9\" AND logon_process_name:\"seclogo\"))) AND (NOT (user_name:\"ANONYMOUS\\ LOGON\")))')\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
}