{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Suspicious Keyboard Layout Load\n", "Detects the keyboard preload installation with a suspicious keyboard layout, e.g. Chinese, Iranian or Vietnamese layout load in user session on systems maintained by US staff only" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Rule Content\n", "```\n", "- title: Suspicious Keyboard Layout Load\n", " id: 34aa0252-6039-40ff-951f-939fd6ce47d8\n", " description: Detects the keyboard preload installation with a suspicious keyboard\n", " layout, e.g. Chinese, Iranian or Vietnamese layout load in user session on systems\n", " maintained by US staff only\n", " references:\n", " - https://renenyffenegger.ch/notes/Windows/registry/tree/HKEY_CURRENT_USER/Keyboard-Layout/Preload/index\n", " - https://github.com/SwiftOnSecurity/sysmon-config/pull/92/files\n", " author: Florian Roth\n", " date: 2019/10/12\n", " modified: 2019/10/15\n", " logsource:\n", " product: windows\n", " service: sysmon\n", " definition: 'Requirements: Sysmon config that monitors \\Keyboard Layout\\Preload\n", " subkey of the HKLU hives - see https://github.com/SwiftOnSecurity/sysmon-config/pull/92/files'\n", " category: null\n", " detection:\n", " selection_registry:\n", " EventID: 13\n", " TargetObject:\n", " - '*\\Keyboard Layout\\Preload\\*'\n", " - '*\\Keyboard Layout\\Substitutes\\*'\n", " Details:\n", " - 00000429\n", " - 00050429\n", " - 0000042a\n", " condition: selection_registry\n", " falsepositives:\n", " - Administrators or users that actually use the selected keyboard layouts (heavily\n", " depends on the organisation's user base)\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-endpoint-winevent-sysmon-*', 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='(event_id:\"13\" AND registry_key_path.keyword:(*\\\\Keyboard\\ Layout\\\\Preload\\* OR *\\\\Keyboard\\ Layout\\\\Substitutes\\*) AND registry_key_value:(\"00000429\" OR \"00050429\" OR \"0000042a\"))')\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 }