{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# PowerShell Script Run in AppData\n", "Detects a suspicious command line execution that invokes PowerShell with reference to an AppData folder" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Rule Content\n", "```\n", "- title: PowerShell Script Run in AppData\n", " id: ac175779-025a-4f12-98b0-acdaeb77ea85\n", " status: experimental\n", " description: Detects a suspicious command line execution that invokes PowerShell\n", " with reference to an AppData folder\n", " references:\n", " - https://twitter.com/JohnLaTwC/status/1082851155481288706\n", " - https://app.any.run/tasks/f87f1c4e-47e2-4c46-9cf4-31454c06ce03\n", " tags:\n", " - attack.execution\n", " - attack.t1086\n", " author: Florian Roth\n", " date: 2019/01/09\n", " logsource:\n", " category: process_creation\n", " product: windows\n", " service: null\n", " detection:\n", " selection:\n", " CommandLine:\n", " - '* /c powershell*\\AppData\\Local\\\\*'\n", " - '* /c powershell*\\AppData\\Roaming\\\\*'\n", " condition: selection\n", " falsepositives:\n", " - Administrative scripts\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:(*\\ \\/c\\ powershell*\\\\AppData\\\\Local\\\\* OR *\\ \\/c\\ powershell*\\\\AppData\\\\Roaming\\\\*)')\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 }