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

128 lines
2.7 KiB
Plaintext

{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Webshell Detection by Keyword\n",
"Detects webshells that use GET requests by keyword searches in URL strings"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Rule Content\n",
"```\n",
"- title: Webshell Detection by Keyword\n",
" id: 7ff9db12-1b94-4a79-ba68-a2402c5d6729\n",
" description: Detects webshells that use GET requests by keyword searches in URL\n",
" strings\n",
" author: Florian Roth\n",
" logsource:\n",
" category: webserver\n",
" product: null\n",
" service: null\n",
" detection:\n",
" keywords:\n",
" - =whoami\n",
" - =net%20user\n",
" - =cmd%20/c%20\n",
" condition: keywords\n",
" fields:\n",
" - client_ip\n",
" - vhost\n",
" - url\n",
" - response\n",
" falsepositives:\n",
" - Web sites like wikis with articles on os commands and pages that include the os\n",
" commands in the URLs\n",
" - User searches in search boxes of the respective website\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:(*\\=whoami* OR *\\=net%20user* OR *\\=cmd%20\\/c%20*)')\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
}