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

142 lines
3.6 KiB
Plaintext

{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Suspicious User Agent\n",
"Detects suspicious malformed user agent strings in proxy logs"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Rule Content\n",
"```\n",
"- title: Suspicious User Agent\n",
" id: 7195a772-4b3f-43a4-a210-6a003d65caa1\n",
" status: experimental\n",
" description: Detects suspicious malformed user agent strings in proxy logs\n",
" references:\n",
" - https://github.com/fastly/waf_testbed/blob/master/templates/default/scanners-user-agents.data.erb\n",
" author: Florian Roth\n",
" logsource:\n",
" category: proxy\n",
" product: null\n",
" service: null\n",
" detection:\n",
" selection:\n",
" c-useragent:\n",
" - user-agent\n",
" - '* (compatible;MSIE *'\n",
" - '*.0;Windows NT *'\n",
" - Mozilla/3.0 *\n",
" - Mozilla/2.0 *\n",
" - Mozilla/1.0 *\n",
" - Mozilla *\n",
" - ' Mozilla/*'\n",
" - Mozila/*\n",
" - _\n",
" - CertUtil URL Agent\n",
" - Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:60.0)\n",
" - Mozilla/5.0 (Windows NT 6.3; WOW64; rv:28.0) Gecko/20100101 Firefox/28.0\n",
" - HTTPS\n",
" falsepositives:\n",
" c-useragent:\n",
" - Mozilla/3.0 * Acrobat *\n",
" condition: selection and not falsepositives\n",
" fields:\n",
" - ClientIP\n",
" - c-uri\n",
" - c-useragent\n",
" falsepositives:\n",
" - Unknown\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='(c-useragent.keyword:(user\\-agent OR *\\ \\(compatible;MSIE\\ * OR *.0;Windows\\ NT\\ * OR Mozilla\\/3.0\\ * OR Mozilla\\/2.0\\ * OR Mozilla\\/1.0\\ * OR Mozilla\\ * OR \\ Mozilla\\/* OR Mozila\\/* OR _ OR CertUtil\\ URL\\ Agent OR Mozilla\\/5.0\\ \\(Windows\\ NT\\ 10.0;\\ Win64;\\ x64;\\ rv\\:60.0\\) OR Mozilla\\/5.0\\ \\(Windows\\ NT\\ 6.3;\\ WOW64;\\ rv\\:28.0\\)\\ Gecko\\/20100101\\ Firefox\\/28.0 OR HTTPS) AND (NOT (c-useragent.keyword:(Mozilla\\/3.0\\ *\\ Acrobat\\ *))))')\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
}