Detection rule
Bad Opsec Powershell Code Artifacts
Overview
focuses on trivial artifacts observed in variants of prevalent offensive ps1 payloads, including Cobalt Strike Beacon, PoshC2, Powerview, Letmein, Empire, Powersploit, and other attack payloads that often undergo minimal changes by attackers due to bad opsec.
- Rule id
8d31a8ce-46b5-4dd6-bdc3-680931f1db86- ATT&CK techniques
- T1059.001 Command and Scripting Interpreter: PowerShell
- Severity
- Critical
- Confidence
- Low
- Origin
- SigmaHQ (community)
- SigmaHQ status
test- Used in defense packs
- n0n, The Gentlemen, qilin, Akira, safepay, rhysida, Play, nightspire, majinahanashi
Validation
- ExperimentalSyntax checked only. Not yet tested on events.
- Test-data validatedMatched positive test events and ignored near-miss events. Not yet run in a production SIEM.
- SIEM-validatedRun in a real SIEM, with a recorded result.
1 of 1 positive test events matched; 1 of 1 near-miss events were correctly ignored. Community rule reused unmodified from SigmaHQ. OffSet7 converted it and tested it on synthetic events.
Detection logic and queries
Queries are shown exactly as generated. Test them in your environment before you deploy them.
Sigma
Sigma (YAML) · 8d31a8ce-46b5-4dd6-bdc3-680931f1db86
title: Bad Opsec Powershell Code Artifacts
id: 8d31a8ce-46b5-4dd6-bdc3-680931f1db86
related:
- id: 73e733cc-1ace-3212-a107-ff2523cc9fc3
type: derived
status: test
description: |
focuses on trivial artifacts observed in variants of prevalent offensive ps1 payloads, including
Cobalt Strike Beacon, PoshC2, Powerview, Letmein, Empire, Powersploit, and other attack payloads
that often undergo minimal changes by attackers due to bad opsec.
references:
- https://newtonpaul.com/analysing-fileless-malware-cobalt-strike-beacon/
- https://labs.sentinelone.com/top-tier-russian-organized-cybercrime-group-unveils-fileless-stealthy-powertrick-backdoor-for-high-value-targets/
- https://www.mdeditor.tw/pl/pgRt
author: 'ok @securonix invrep_de, oscd.community'
date: 2020-10-09
modified: 2022-12-25
tags:
- attack.execution
- attack.t1059.001
logsource:
product: windows
category: ps_module
definition: 0ad03ef1-f21b-4a79-8ce8-e6900c54b65b
detection:
selection_4103:
Payload|contains:
- '$DoIt'
- 'harmj0y'
- 'mattifestation'
- '_RastaMouse'
- 'tifkin_'
- '0xdeadbeef'
condition: selection_4103
falsepositives:
- 'Moderate-to-low; Despite the shorter length/lower entropy for some of these, because of high specificity, fp appears to be fairly limited in many environments.'
level: criticalQRadar AQL
IBM QRadar AQL (hunting query)Hunting query
Hunting search for the Log Activity tab or the API. It is not a QRadar rule.
AQL search for the Log Activity tab or the API. It is NOT a deployable QRadar rule: real-time detection in QRadar is a CRE (Custom Rule Engine) rule, for which this build only writes a design specification (qradar_cre).
SELECT * FROM events WHERE devicetype=12 AND (LOWER(UTF8(payload)) LIKE '%$doit%' OR LOWER(UTF8(payload)) LIKE '%harmj0y%' OR LOWER(UTF8(payload)) LIKE '%mattifestation%' OR LOWER(UTF8(payload)) LIKE '%_rastamouse%' OR LOWER(UTF8(payload)) LIKE '%tifkin_%' OR LOWER(UTF8(payload)) LIKE '%0xdeadbeef%')QRadar CRE
Design for the QRadar Rule Wizard. It is not importable and has not been tested in QRadar.
- Rule name
OffSet7: Bad Opsec Powershell Code Artifacts- Rule type
- Event rule (Local)
- Log source types
- Microsoft Windows Security Event Log DSM collecting PowerShell module logging (4103)
Building blocks
BB:OffSet7:Bad Opsec Powershell Code Artifacts:selection_4103(match)All test lines must match (AND).UTF8(payload)contains:$DoIt,harmj0y,mattifestation,_RastaMouse,tifkin_,0xdeadbeef
Main rule, option A (building blocks)
- when the event(s) were detected by one or more of these log source types:
Microsoft Windows Security Event Log DSM collecting PowerShell module logging (4103) - when an event matches the condition built from these building blocks:
BB:OffSet7:Bad Opsec Powershell Code Artifacts:selection_4103
Main rule, option B (AQL filter test)
- when the event matches this AQL filter query:
devicetype=12 AND (LOWER(UTF8(payload)) LIKE '%$doit%' OR LOWER(UTF8(payload)) LIKE '%harmj0y%' OR LOWER(UTF8(payload)) LIKE '%mattifestation%' OR LOWER(UTF8(payload)) LIKE '%_rastamouse%' OR LOWER(UTF8(payload)) LIKE '%tifkin_%' OR LOWER(UTF8(payload)) LIKE '%0xdeadbeef%')
Rule response
- Severity 9, credibility 6, relevance 7
- Ensure the detected event is part of an offense; index offense on Log Source (host) and annotate with the rule title and OffSet7 rule id
- Respond no more than once per 30 minutes per Log Source (tune per environment)
Limitations
- QRadar AQL LIKE / CRE string tests are case-sensitive unless the property is lower-cased; the AQL option uses LOWER() where the backend applied it.
Splunk
Splunk SPLSearch
Search for Splunk with Windows/Sysmon field names. A scheduled search or ES correlation search also needs a schedule, time range, throttling and an adaptive response, set in your environment.
Payload IN ("*$DoIt*", "*harmj0y*", "*mattifestation*", "*_RastaMouse*", "*tifkin_*", "*0xdeadbeef*")Splunk savedsearches.conf stanzaScheduled search template
Template stanza. Review schedule, alert actions and index/sourcetype for your environment before enabling.
[default]
dispatch.earliest_time = -30d
dispatch.latest_time = now
[Bad Opsec Powershell Code Artifacts]
description = focuses on trivial artifacts observed in variants of prevalent offensive ps1 payloads, includingCobalt Strike Beacon, PoshC2, Powerview, Letmein, Empire, Powersploit, and other attack payloadsthat often undergo minimal changes by attackers due to bad opsec.
search = Payload IN ("*$DoIt*", "*harmj0y*", "*mattifestation*", "*_RastaMouse*", "*tifkin_*", "*0xdeadbeef*")Elastic
Elastic Lucene (ECS)Hunting query
Lucene query over ECS fields (Winlogbeat/Elastic Agent Windows mappings). A detection rule also needs an index pattern, schedule and actions.
powershell.file.script_block_text:(*$DoIt* OR *harmj0y* OR *mattifestation* OR *_RastaMouse* OR *tifkin_* OR *0xdeadbeef*)Elastic EQL (ECS)Hunting query
EQL query over ECS fields. Usable in an Elastic Security EQL rule after review; index pattern and schedule are set per environment.
any where powershell.file.script_block_text like~ ("*$DoIt*", "*harmj0y*", "*mattifestation*", "*_RastaMouse*", "*tifkin_*", "*0xdeadbeef*")Elastic ES|QL (ECS)Hunting query
ES|QL query over ECS fields; the FROM clause uses * and must be narrowed to your indices.
from * metadata _id, _index, _version | where powershell.file.script_block_text like "*$DoIt*" or powershell.file.script_block_text like "*harmj0y*" or powershell.file.script_block_text like "*mattifestation*" or powershell.file.script_block_text like "*_RastaMouse*" or powershell.file.script_block_text like "*tifkin_*" or powershell.file.script_block_text like "*0xdeadbeef*"No working conversion: Microsoft Sentinel KQL (ASIM) (No ASIM parser/table for this log source in the stock pipeline (see native draft on the Event table where one exists).); Microsoft Defender XDR KQL (Defender XDR advanced hunting has no PowerShell script-block/module text.)
Required telemetry
- Log source
product: windows · category: ps_module · definition: 0ad03ef1-f21b-4a79-8ce8-e6900c54b65b- Fields used
Payload
False positives
- Moderate-to-low; Despite the shorter length/lower entropy for some of these, because of high specificity, fp appears to be fairly limited in many environments.
Investigation and response
No OffSet7 investigation guidance has been written for this rule yet. Start from the false positives above and the ATT&CK technique pages.
References
Author and attribution
- Author
- ok @securonix invrep_de, oscd.community
- Source
- SigmaHQ ·
rules/windows/powershell/powershell_module/posh_pm_bad_opsec_artifacts.yml - Upstream commit
9688134317a2- Licence
- Detection Rule License (DRL) 1.1
Version history
- Version 1Imported from SigmaHQ
- OffSet7 build · SigmaHQ
9688134317a2