Detection: Cisco Secure Endpoint - Encoded Script Decode and Run

Description

This analytic detects a PowerShell download command writing an encoded file, a certutil decode command naming that file and a decoded script, and a later hidden PowerShell execution alert naming the decoded script. It correlates Cisco Secure Endpoint Behavioral Protection alerts by endpoint, parent process, exact paths, and order. The file relationships suggest a staged payload. The certutil alert may trigger an end-process response in Protect mode, so a decode command alone does not prove the file was produced. Confirm the file and response status before concluding the sequence completed.

 1`cisco_secure_endpoint`
 2event_type="Threat Detection"
 3
 4
 5| `cisco_secure_endpoint_extract_bp_fields`
 6
 7
 8| where sig_id IN ("20200719101800","20200716100139","20201202215412")
 9
10
11| spath path=bp_data.details.matched_activity.events{0}.process:start.parent_guid output=parent_guid
12
13| spath path=bp_data.details.matched_activity.events{0}.process:start.cmd_line output=process_command
14
15| spath path=bp_data.details.matched_activity.events{0}.process:start.args{} output=process_args
16
17
18| eval stage=case(sig_id="20200719101800","download",
19           sig_id="20200716100139","decode",
20           sig_id="20201202215412","execute")
21
22
23| rex field=process_command "(?i)WriteAllText\('(?<download_file>[A-Za-z]:[^']+)'"
24
25
26| rex field=process_command "(?i)ReadAllText\('(?<executed_file>[A-Za-z]:[^']+\.ps1)'"
27
28
29| eval download_file=lower(download_file),
30       executed_file=lower(executed_file)
31
32
33| eval decode_index=mvfind(process_args,"(?i)^[-/]decode$"),
34       encoded_input=if(stage="decode",lower(mvindex(process_args,decode_index+1)),null()),
35       decoded_output=if(stage="decode",lower(mvindex(process_args,decode_index+2)),null())
36
37
38| eval event_time=tonumber(timestamp)+tonumber(timestamp_nanoseconds)/1000000000
39
40
41| where isnotnull(endpoint_guid)
42        AND isnotnull(parent_guid)
43        AND isnotnull(event_time)
44
45
46| sort 0 endpoint_guid parent_guid event_time
47
48
49| streamstats last(eval(if(stage="download",download_file,null()))) as prior_download_file
50              last(eval(if(stage="download",process_command,null()))) as prior_download_command
51              max(eval(if(stage="download",event_time,null()))) as download_time
52  by endpoint_guid parent_guid
53
54
55| eval valid_decode=if(stage="decode" AND encoded_input=prior_download_file AND isnotnull(decoded_output) AND event_time>=download_time AND event_time-download_time<=300,1,0)
56
57
58| streamstats last(eval(if(valid_decode=1,decoded_output,null()))) as prior_decoded_file
59              last(eval(if(valid_decode=1,encoded_input,null()))) as prior_encoded_file
60              last(eval(if(valid_decode=1,prior_download_command,null()))) as download_command
61              last(eval(if(valid_decode=1,process_command,null()))) as decode_command
62              max(eval(if(valid_decode=1,event_time,null()))) as decode_time
63              max(eval(if(valid_decode=1,download_time,null()))) as first_event_time
64  by endpoint_guid parent_guid
65
66
67| where stage="execute"
68        AND executed_file=prior_decoded_file
69        AND isnotnull(decode_time)
70        AND event_time>=decode_time
71        AND event_time-decode_time<=300
72        AND event_time-first_event_time<=300
73
74
75| eval encoded_file=prior_encoded_file,
76       decoded_file=prior_decoded_file,
77       execution_command=process_command,
78       firstTime=first_event_time,
79       lastTime=event_time
80
81
82| dedup endpoint_guid parent_guid encoded_file decoded_file firstTime
83
84
85| eval user=coalesce(user,"unknown")
86
87
88| table dest user endpoint_guid parent_guid encoded_file
89        decoded_file download_command decode_command execution_command bp_response firstTime
90        lastTime
91
92| `security_content_ctime(firstTime)`
93
94| `security_content_ctime(lastTime)`
95
96| `cisco_secure_endpoint___encoded_script_decode_and_run_filter`

Data Source

Name Platform Sourcetype Source
Cisco Secure Endpoint Behavioral Protection Threat Detection Other 'cisco:se' 'not_applicable'

Macros Used

Name Value
cisco_secure_endpoint_extract_bp_fields `spath path=bp_data.engine output=bp_engine
search bp_engine=apde
spath path=bp_data.details.sig_id output=sig_id
spath path=computer.connector_guid output=endpoint_guid
spath path=computer.hostname output=dest
spath path=bp_data.details.matched_activity.events{0}.process:start.user.name output=user
spath path=bp_data.details.matched_activity.events{0}.registry:set.user.name output=registry_user
spath path=bp_data.details.matched_activity.events{0}.file:create.user.name output=file_user
eval user=coalesce(user,registry_user,file_user)
spath path=bp_data.audit output=bp_audit
spath path=bp_data.details.actions{}.action output=bp_action
spath path=bp_data.details.actions{}.status output=bp_action_status
eval bp_response=case(bp_audit="true","audit mode",isnotnull(bp_action_status),mvjoin(bp_action,", "),true(),"no action reported")`
cisco_secure_endpoint___encoded_script_decode_and_run_filter search *
cisco_secure_endpoint___encoded_script_decode_and_run_filter is an empty macro by default. It allows the user to filter out any results (false positives) without editing the SPL.

Annotations

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 Finding (Notable) Yes
Rule Title %name%
Rule Description %description%
Notable Event Fields user, dest
Creates Intermediate Finding (Risk Event) No
TTP detections generate a Finding (Notable) and may generate Intermediate Findings (Risk Events) for associated entities.

Implementation

This search requires Cisco Secure Endpoint Behavioral Protection Threat Detection alerts, which include event_type="Threat Detection". This search uses an input macro named cisco_secure_endpoint. We strongly recommend that you specify your environment-specific configurations (index, source, sourcetype, etc.) for Cisco Secure Endpoint Behavioral Protection Threat Detection alerts. Replace the macro definition with configurations for your Splunk environment. The cisco_secure_endpoint_extract_bp_fields macro extracts the common signature, endpoint, actor, and prevention-response fields used by this search. The search also uses a post-filter macro designed to filter out known false positives. The logs are to be ingested using the Cisco Security Cloud App for Splunk (https://splunkbase.splunk.com/app/7404). In Protect mode, a Behavioral Protection response can kill or quarantine an earlier stage, so this search requires each later alert to have actually appeared. Review bp_data.audit and bp_data.details.actions in the source events before concluding that a task registered, a process completed, or a transfer succeeded. The included audit-mode fixtures verify alert correlation, not survival of an enforced prevention action.

Known False Positives

An approved deployment workflow may download encoded scripts, decode them with certutil, and execute them from Temp. Review the source URL, decoded script, account, parent process, and deployment change record.

Associated Analytic Story

Finding

Title Entity Field Entity Type Risk Score
Encoded script download, certutil decode and hidden execution from parent process $parent_guid$ on $dest$ dest system 50

Threat Objects

Field Type
decoded_file file_path
encoded_file file_path
execution_command command

References

Detection Testing

Test Type Status Dataset Source Sourcetype
Validation ✅ Passing N/A N/A N/A
Unit ✅ Passing Dataset not_applicable cisco:se
Integration ✅ Passing Dataset not_applicable cisco:se

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: 1