{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Data Compressed - Powershell\n", "An adversary may compress data (e.g., sensitive documents) that is collected prior to exfiltration in order to make it portable and minimize the amount of data sent over the network" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Rule Content\n", "```\n", "- title: Data Compressed - Powershell\n", " id: 6dc5d284-69ea-42cf-9311-fb1c3932a69a\n", " status: experimental\n", " description: An adversary may compress data (e.g., sensitive documents) that is\n", " collected prior to exfiltration in order to make it portable and minimize the\n", " amount of data sent over the network\n", " author: Timur Zinniatullin, oscd.community\n", " date: 2019/10/21\n", " modified: 2019/11/04\n", " references:\n", " - https://github.com/redcanaryco/atomic-red-team/blob/master/atomics/T1002/T1002.yaml\n", " logsource:\n", " product: windows\n", " service: powershell\n", " description: Script block logging must be enabled\n", " category: null\n", " detection:\n", " selection:\n", " EventID: 4104\n", " keywords|contains|all:\n", " - -Recurse\n", " - '|'\n", " - Compress-Archive\n", " condition: selection\n", " falsepositives:\n", " - highly likely if archive ops are done via PS\n", " level: low\n", " tags:\n", " - attack.exfiltration\n", " - attack.t1002\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:\"4104\" AND keywords.keyword:*\\-Recurse* AND keywords.keyword:*|* AND keywords.keyword:*Compress\\-Archive*)')\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 }