Detection: WinEvent Scheduled Task Created to Spawn Shell

Description

The following analytic detects the creation of scheduled tasks designed to execute commands using native Windows shells like PowerShell, Cmd, Wscript, or Cscript. It leverages Windows Security EventCode 4698 to identify when such tasks are registered. This activity is significant as it may indicate an attempt to establish persistence or execute malicious commands on a system. If confirmed malicious, this could allow an attacker to maintain access, execute arbitrary code, or escalate privileges, posing a severe threat to the environment.

1`wineventlog_security` EventCode=4698 TaskContent IN ("*powershell.exe*", "*wscript.exe*", "*cscript.exe*", "*cmd.exe*", "*sh.exe*", "*ksh.exe*", "*zsh.exe*", "*bash.exe*", "*scrcons.exe*", "*pwsh.exe*") 
2| stats count min(_time) as firstTime max(_time) as lastTime by Computer, TaskName, TaskContent 
3| rename Computer as dest 
4| `security_content_ctime(firstTime)` 
5| `security_content_ctime(lastTime)` 
6| `winevent_scheduled_task_created_to_spawn_shell_filter`

Data Source

Name Platform Sourcetype Source Supported App
Windows Event Log Security 4698 Windows icon Windows 'xmlwineventlog' 'XmlWinEventLog:Security' N/A

Macros Used

Name Value
security_content_ctime convert timeformat="%Y-%m-%dT%H:%M:%S" ctime($field$)
winevent_scheduled_task_created_to_spawn_shell_filter search *
winevent_scheduled_task_created_to_spawn_shell_filter is an empty macro by default. It allows the user to filter out any results (false positives) without editing the SPL.

Annotations

- MITRE ATT&CK
+ Kill Chain Phases
+ NIST
+ CIS
- Threat Actors
ID Technique Tactic
T1053.005 Scheduled Task Execution
T1053 Scheduled Task/Job Persistence
KillChainPhase.EXPLOITAITON
KillChainPhase.INSTALLATION
NistCategory.DE_CM
Cis18Value.CIS_10
APT-C-36
APT29
APT3
APT32
APT33
APT37
APT38
APT39
APT41
BITTER
BRONZE BUTLER
Blue Mockingbird
Chimera
Cobalt Group
Confucius
Dragonfly
FIN10
FIN13
FIN6
FIN7
FIN8
Fox Kitten
GALLIUM
Gamaredon Group
HEXANE
Higaisa
Kimsuky
Lazarus Group
LuminousMoth
Machete
Magic Hound
Molerats
MuddyWater
Mustang Panda
Naikon
OilRig
Patchwork
Rancor
Silence
Stealth Falcon
TA2541
ToddyCat
Wizard Spider
menuPass
Earth Lusca

Default Configuration

This detection is configured by default in Splunk Enterprise Security to run with the following settings:

Setting Value
Disabled true
Cron Schedule 0 * * * *
Earliest Time -70m@m
Latest Time -10m@m
Schedule Window auto
Creates Notable Yes
Rule Title %name%
Rule Description %description%
Notable Event Fields user, dest
Creates Risk Event True
This configuration file applies to all detections of type TTP. These detections will use Risk Based Alerting and generate Notable Events.

Implementation

To successfully implement this search, you need to be ingesting Windows Security Event Logs with 4698 EventCode enabled. The Windows TA is also required.

Known False Positives

False positives are possible if legitimate applications are allowed to register tasks that call a shell to be spawned. Filter as needed based on command-line or processes that are used legitimately.

Associated Analytic Story

Risk Based Analytics (RBA)

Risk Message Risk Score Impact Confidence
A windows scheduled task was created (task name=$TaskName$) on $dest$ by the following command: $TaskContent$ 70 70 100
The Risk Score is calculated by the following formula: Risk Score = (Impact * Confidence/100). Initial Confidence and Impact is set by the analytic author.

References

Detection Testing

Test Type Status Dataset Source Sourcetype
Validation Passing N/A N/A N/A
Unit Passing Dataset XmlWinEventLog:Security XmlWinEventLog
Integration ✅ Passing Dataset XmlWinEventLog:Security XmlWinEventLog

Replay any dataset to Splunk Enterprise by using our replay.py tool or the UI. Alternatively you can replay a dataset into a Splunk Attack Range


Source: GitHub | Version: 4