{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# PowerShell called from an Executable Version Mismatch\n", "Detects PowerShell called from an executable by the version mismatch method" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Rule Content\n", "```\n", "- title: PowerShell called from an Executable Version Mismatch\n", " id: c70e019b-1479-4b65-b0cc-cd0c6093a599\n", " status: experimental\n", " description: Detects PowerShell called from an executable by the version mismatch\n", " method\n", " references:\n", " - https://adsecurity.org/?p=2921\n", " tags:\n", " - attack.defense_evasion\n", " - attack.execution\n", " - attack.t1086\n", " author: Sean Metcalf (source), Florian Roth (rule)\n", " logsource:\n", " product: windows\n", " service: powershell-classic\n", " category: null\n", " detection:\n", " selection1:\n", " EventID: 400\n", " EngineVersion:\n", " - 2.*\n", " - 4.*\n", " - 5.*\n", " HostVersion: 3.*\n", " condition: selection1\n", " falsepositives:\n", " - Penetration Tests\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-endpoint-winevent-powershell-*', 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:\"400\" AND powershell.engine.version.keyword:(2.* OR 4.* OR 5.*) AND powershell.host.version.keyword:3.*)')\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 }