HELK/docker/helk-jupyter/notebooks/sigma/app_python_sql_exceptions.i...

124 lines
2.6 KiB
Plaintext

{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Python SQL Exceptions\n",
"Generic rule for SQL exceptions in Python according to PEP 249"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Rule Content\n",
"```\n",
"- title: Python SQL Exceptions\n",
" id: 19aefed0-ffd4-47dc-a7fc-f8b1425e84f9\n",
" description: Generic rule for SQL exceptions in Python according to PEP 249\n",
" author: Thomas Patzke\n",
" references:\n",
" - https://www.python.org/dev/peps/pep-0249/#exceptions\n",
" logsource:\n",
" category: application\n",
" product: python\n",
" service: null\n",
" detection:\n",
" exceptions:\n",
" - DataError\n",
" - IntegrityError\n",
" - ProgrammingError\n",
" - OperationalError\n",
" condition: exceptions\n",
" falsepositives:\n",
" - Application bugs\n",
" - Penetration testing\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-*', 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:(*DataError* OR *IntegrityError* OR *ProgrammingError* OR *OperationalError*)')\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
}