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

128 lines
2.8 KiB
Plaintext

{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Suspicious Code Page Switch\n",
"Detects a code page switch in command line or batch scripts to a rare language"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Rule Content\n",
"```\n",
"- title: Suspicious Code Page Switch\n",
" id: c7942406-33dd-4377-a564-0f62db0593a3\n",
" status: experimental\n",
" description: Detects a code page switch in command line or batch scripts to a rare\n",
" language\n",
" author: Florian Roth\n",
" date: 2019/10/14\n",
" references:\n",
" - https://docs.microsoft.com/en-us/windows/win32/intl/code-page-identifiers\n",
" - https://twitter.com/cglyer/status/1183756892952248325\n",
" logsource:\n",
" category: process_creation\n",
" product: windows\n",
" service: null\n",
" detection:\n",
" selection:\n",
" CommandLine:\n",
" - chcp* 936\n",
" - chcp* 1258\n",
" condition: selection\n",
" fields:\n",
" - ParentCommandLine\n",
" falsepositives:\n",
" - Administrative activity (adjust code pages according to your organisation's region)\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='process_command_line.keyword:(chcp*\\ 936 OR chcp*\\ 1258)')\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
}