Detection rules › Splunk
Potential PowerShell Post-Exploitation Activity (Sysmon)
Threat actors may perform post-exploitation activities using PowerShell scripts such as ADRecon. When running ADRecon, PowerShell launches child processes to compile and execute payloads and creates several .cmdline files in AppData\Local\Temp directories. This use case detects PowerShell-invoked compilations involving csc.exe and cvtres.exe referencing multiple .cmdline files from temp directories within a 5 minute time period. This may that a malicious script like ADRecon has been executed, regardless of the script title name or cmdlets invoked
MITRE ATT&CK coverage
| Tactic | Techniques |
|---|---|
| Execution | |
| Discovery |
References
Telemetry coverage
| Provider | Record / event type |
|---|---|
| Sysmon | Event ID 1: Process creation |
Rule body
id: '27535.50074'
title: Potential PowerShell Post-Exploitation Activity
description: 'Threat actors may perform post-exploitation activities using PowerShell
scripts such as ADRecon. When running ADRecon, PowerShell launches child processes
to compile and execute payloads and creates several .cmdline files in AppData\Local\Temp
directories. This use case detects PowerShell-invoked compilations involving csc.exe
and cvtres.exe referencing multiple .cmdline files from temp directories within
a 5 minute time period. This may that a malicious script like ADRecon has been executed,
regardless of the script title name or cmdlets invoked. Atomics T1087.002 Test #4'
logic_format: Splunk
logic: '`get_endpoint_data` `get_endpoint_data_sysmon` (TERM(EventCode=1) OR "<EventID>1<")
("powershell.exe" OR "pwsh.exe") ("csc.exe" OR "cvtres.exe") ".cmdline" | regex
parent_process_name="(?i)(powershell|pwsh)\.exe"| regex process_name="(?i)(csc|cvtres)\.exe"|
regex process="(?i)\x5cAppData\x5cLocal\x5cTemp.+\.cmdline" | table _time, host,
user process, parent_process_name, event_count | bin span=300s | stats values(*)
as * by _time, host | eventstats dc(process) as dc_process by host, _time| where
dc_process > 3 '
techniques:
- execution:command and scripting interpreter:powershell
- discovery:account discovery
- discovery:system information discovery
technique_id:
- T1059.001
- T1087
- T1082
data_category:
- Windows Sysmon
references:
- https://github.com/sense-of-security/ADRecon/tree/master
- https://www.dnif.it/en/blog/strategies-to-detect-post-exploitation-active-directory-reconnaissance
- https://symantec-enterprise-blogs.security.com/blogs/threat-intelligence/ransomware-hive-conti-avoslocker
Stages and Predicates
Stage 1: search
`get_endpoint_data` `get_endpoint_data_sysmon` (TERM(EventCode=1) OR "<EventID>1<") ("powershell.exe" OR "pwsh.exe") ("csc.exe" OR "cvtres.exe") ".cmdline"
Stage 2: regex
| regex parent_process_name="(?i)(powershell|pwsh)\.exe"
Stage 3: regex
| regex process_name="(?i)(csc|cvtres)\.exe"
Stage 4: regex
| regex process="(?i)\x5cAppData\x5cLocal\x5cTemp.+\.cmdline"
Stage 5: table
| table _time, host, user process, parent_process_name, event_count
Stage 6: bucket
| bin span=300s
Stage 7: stats
| stats values(*) as * by _time, host
Stage 8: eventstats
| eventstats dc(process) as dc_process by host, _time
Stage 9: where
| where dc_process > 3
Indicators
These rows show field, operator, and value matches.
| Field | Kind | Values | Search |
|---|---|---|---|
EventCode | eq |
| field:"EventID" kind:eq value:"1" |
dc_process | gt |
| field:"dc_process" kind:gt value:"3" |
parent_process_name | regex_match |
| field:"parent_process_name" kind:regex_match |
process | regex_match |
| field:"CommandLine" kind:regex_match |
process_name | regex_match |
| field:"process_name" kind:regex_match |
Search terms
These SPL tokens match against raw event text.
| Stage | Term |
|---|---|
| 1 | "<EventID>1<" |
| 1 | "powershell.exe" |
| 1 | "pwsh.exe" |
| 1 | "csc.exe" |
| 1 | "cvtres.exe" |
| 1 | ".cmdline" |