{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# PowerShell Base64 Encoded Shellcode\n", "Detects Base64 encoded Shellcode" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Rule Content\n", "```\n", "- title: PowerShell Base64 Encoded Shellcode\n", " id: 2d117e49-e626-4c7c-bd1f-c3c0147774c8\n", " description: Detects Base64 encoded Shellcode\n", " status: experimental\n", " references:\n", " - https://twitter.com/cyb3rops/status/1063072865992523776\n", " author: Florian Roth\n", " date: 2018/11/17\n", " tags:\n", " - attack.defense_evasion\n", " - attack.t1036\n", " logsource:\n", " category: process_creation\n", " product: windows\n", " service: null\n", " detection:\n", " selection1:\n", " CommandLine: '*AAAAYInlM*'\n", " selection2:\n", " CommandLine:\n", " - '*OiCAAAAYInlM*'\n", " - '*OiJAAAAYInlM*'\n", " condition: selection1 and selection2\n", " falsepositives:\n", " - Unknown\n", " level: critical\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:*AAAAYInlM* AND process_command_line.keyword:(*OiCAAAAYInlM* OR *OiJAAAAYInlM*))')\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 }