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

122 lines
2.7 KiB
Plaintext

{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Buffer Overflow Attempts\n",
"Detects buffer overflow attempts in Unix system log files"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Rule Content\n",
"```\n",
"- title: Buffer Overflow Attempts\n",
" id: 18b042f0-2ecd-4b6e-9f8d-aa7a7e7de781\n",
" description: Detects buffer overflow attempts in Unix system log files\n",
" references:\n",
" - https://github.com/ossec/ossec-hids/blob/master/etc/rules/attack_rules.xml\n",
" logsource:\n",
" product: unix\n",
" service: null\n",
" category: null\n",
" detection:\n",
" keywords:\n",
" - attempt to execute code on stack by\n",
" - FTP LOGIN FROM .* 0bin0sh\n",
" - 'rpc.statd[\\d+]: gethostbyname error for'\n",
" - AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\n",
" condition: keywords\n",
" falsepositives:\n",
" - Unkown\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='\\*.keyword:(*attempt\\ to\\ execute\\ code\\ on\\ stack\\ by* OR *FTP\\ LOGIN\\ FROM\\ .*\\ 0bin0sh* OR *rpc.statd\\[\\\\d\\+\\]\\:\\ gethostbyname\\ error\\ for* OR *AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA*)')\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
}