Cisco Secure Endpoint - Run Key Registry Payload Executed

 Original Source: [splunk source]
Name:Cisco Secure Endpoint - Run Key Registry Payload Executed
id:28713184-7465-499e-8b1a-74eec9148047
version:1
date:None
author:Nasreddine Bencherchali, Splunk
status:production
type:TTP
Description:This analytic detects a registry-resident PowerShell payload referenced by a long Run value and later by a fileless execution alert, using Cisco Secure Endpoint Behavioral Protection alerts for the same endpoint and registry payload key. A matching task creation command and earlier download command enrich the result when observed; neither is required. The linked persistence setting and observed execution can indicate fileless malware. A Run-key write may be blocked in Protect mode, and neither the Run alert nor a task creation command proves logon execution or task registration. Inspect the stored value, process lineage, and prevention response.
Data_source:
  • -Cisco Secure Endpoint Behavioral Protection Threat Detection
search:`cisco_secure_endpoint`
event_type="Threat Detection"

| `cisco_secure_endpoint_extract_bp_fields`

| where sig_id IN ("20200719101800","20201208164752","20220408163700","20170104055521")

| spath path=bp_data.details.matched_activity.events{0}.registry:set.key output=run_key
| spath path=bp_data.details.matched_activity.events{0}.registry:set.value output=run_value
| spath path=bp_data.details.matched_activity.events{0}.registry:set.data_txt output=run_data
| spath path=bp_data.details.matched_activity.events{0}.registry:set.puid output=setter_puid
| spath path=bp_data.details.matched_activity.events{0}.process:start.parent_puid output=parent_puid
| spath path=bp_data.details.matched_activity.events{0}.process:start.cmd_line output=process_command
| spath path=bp_data.details.matched_activity.events{0}.process:start.parent_app.name output=parent_name
| spath path=bp_data.details.matched_activity.events{0}.process:start.ts output=process_event_ts
| spath path=bp_data.details.matched_activity.events{0}.registry:set.ts output=registry_event_ts

| rex field=process_command "(?i)DownloadString\('(?<download_url>https?://[^']+)'\)"
| rex field=process_command "(?i)/TN\s+(?<task_name>\S+)"

| rex field=run_data "(?i)(?<run_payload_key>HK(?:CU|LM):[^)\s]+)"

| rex field=process_command "(?i)(?<execution_payload_key>HK(?:CU|LM):[^)\s]+)"

| eval payload_key=lower(coalesce(run_payload_key,execution_payload_key)),
writer_puid=coalesce(setter_puid,parent_puid)

| eval stage=case(sig_id="20200719101800","download",
sig_id="20201208164752","persist",
sig_id="20220408163700","task",
sig_id="20170104055521","execute")

| eval event_time=coalesce(tonumber(process_event_ts)/1000000000,
tonumber(registry_event_ts)/1000000000,
tonumber(timestamp)+coalesce(tonumber(timestamp_nanoseconds),0)/1000000000)

| where isnotnull(endpoint_guid)
AND isnotnull(payload_key)
AND isnotnull(stage)
AND isnotnull(event_time)

| sort 0 endpoint_guid payload_key event_time

| streamstats max(eval(if(stage="download",event_time,null()))) as download_time
last(eval(if(stage="download",process_command,null()))) as download_command
last(eval(if(stage="download",download_url,null()))) as download_url
max(eval(if(stage="persist",event_time,null()))) as run_time
last(eval(if(stage="persist",run_data,null()))) as run_command
last(eval(if(stage="persist",run_key,null()))) as stored_run_key
last(eval(if(stage="persist",run_value,null()))) as stored_run_value
last(eval(if(stage="persist",writer_puid,null()))) as run_writer_puid
last(eval(if(stage="persist",bp_response,null()))) as run_bp_response
max(eval(if(stage="task",event_time,null()))) as task_time
last(eval(if(stage="task",process_command,null()))) as task_command
last(eval(if(stage="task",task_name,null()))) as task_name
last(eval(if(stage="task",bp_response,null()))) as task_bp_response
by endpoint_guid payload_key

| where stage="execute"
AND isnotnull(run_time)
AND event_time>=run_time
AND event_time-run_time<=300

| eval execution_command=process_command,
firstTime=run_time,
lastTime=event_time

| eval download_command=if(isnotnull(download_time) AND download_time<=run_time AND event_time-download_time<=300,download_command,null()),
download_url=if(isnotnull(download_time) AND download_time<=run_time AND event_time-download_time<=300,download_url,null()),
task_command=if(isnotnull(task_time) AND task_time>=run_time AND task_time<=event_time,task_command,null()),
task_name=if(isnotnull(task_command),task_name,null()),
task_bp_response=if(isnotnull(task_command),task_bp_response,null())

| dedup endpoint_guid payload_key run_time

| eval user=coalesce(user,"unknown")

| table dest user endpoint_guid run_writer_puid payload_key
stored_run_key stored_run_value download_url download_command
run_command run_bp_response task_name task_command task_bp_response execution_command bp_response firstTime
lastTime
| `security_content_ctime(firstTime)`
| `security_content_ctime(lastTime)`
| `cisco_secure_endpoint___run_key_registry_payload_executed_filter`


how_to_implement: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:A managed application may use a long Run command to invoke a script stored in the registry. Review the referenced key, its actual value, child process, account, signer, and deployment change record. The Run key alert alone does not prove later logon execution.
References:
  -https://docs.amp.cisco.com/en/SecureEndpoint/Secure%20Endpoint%20User%20Guide.pdf
  -https://attack.mitre.org/techniques/T1547/001/
  -https://attack.mitre.org/techniques/T1112/
  -https://attack.mitre.org/techniques/T1059/001/
  -https://attack.mitre.org/techniques/T1105/
drilldown_searches:
 name:'View BP Activity for - $dest$'
 search:'`cisco_secure_endpoint` event_type="Threat Detection" | spath path=computer.connector_guid output=endpoint_guid | search endpoint_guid="$endpoint_guid$" | spath path=bp_data.details.sig_id output=sig_id | spath path=bp_data.remediated output=remediated | 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 | spath path=bp_data.details.matched_activity.events{0}.process:start.cmd_line output=process_command | spath path=bp_data.details.matched_activity.events{0}.script:execution.cmd_line output=script_command | eval observed_command=coalesce(process_command,script_command) | table _time detection severity sig_id bp_audit bp_action bp_action_status remediated observed_command _raw | sort - _time'
 earliest_offset:'7d'
 latest_offset:'0'
 name:'View Cloud IOC Activity for - $dest$'
 search:'`cisco_secure_endpoint` event_type="Cloud IOC" | spath path=computer.connector_guid output=endpoint_guid | search endpoint_guid="$endpoint_guid$" | spath path=cloud_ioc.short_description output=ioc_name | spath path=cloud_ioc.description output=ioc_description | spath path=command_line.arguments output=process_command | spath path=file.file_name output=file_name | spath path=file.file_path output=file_path | spath path=file.identity.sha256 output=file_sha256 | eval activity_time=strftime(tonumber(coalesce(start_timestamp,timestamp)),"%Y-%m-%d %H:%M:%S") | table _time activity_time ioc_name severity process_command file_name file_path file_sha256 ioc_description _raw | sort - _time'
 earliest_offset:'7d'
 latest_offset:'0'
 name:'View risk events for the last 7 days for - "$user$"'
 search:'| from datamodel Risk.All_Risk | search normalized_risk_object IN ("$user$", "$dest$") | stats count min(_time) as firstTime max(_time) as lastTime values(search_name) as "Search Name" values(risk_message) as "Risk Message" values(analyticstories) as "Analytic Stories" values(annotations._all) as "Annotations" values(annotations.mitre_attack.mitre_tactic) as "ATT&CK Tactics" by normalized_risk_object | `security_content_ctime(firstTime)` | `security_content_ctime(lastTime)`'
 earliest_offset:'7d'
 latest_offset:'0'
analytic_story:['Compromised Windows Host', 'Windows Post-Exploitation', 'Cisco Secure Endpoint - Correlated Threat Activity']

asset_type:Endpoint

mitre_attack_id:['T1547.001', 'T1112', 'T1059.001']

product:['Splunk Enterprise', 'Splunk Enterprise Security', 'Splunk Cloud']

category:endpoint

security_domain:endpoint

tags:

tests:
 name:'True Positive Test - Cisco Secure Endpoint BP'
 attack_data:
  data: https://media.githubusercontent.com/media/splunk/attack_data/master/datasets/cisco_secure_endpoint/behavioral_protection/run_key_registry_payload_execution/cisco_se.log
  source: not_applicable
  sourcetype: cisco:se
 test_type:'unit'
 name:'True Positive Test - Cisco Secure Endpoint BP With Download'
 attack_data:
  data: https://media.githubusercontent.com/media/splunk/attack_data/master/datasets/cisco_secure_endpoint/behavioral_protection/downloaded_registry_payload_run_execution/cisco_se.log
  source: not_applicable
  sourcetype: cisco:se
 test_type:'unit'
 name:'True Positive Test - Cisco Secure Endpoint BP With Task'
 attack_data:
  data: https://media.githubusercontent.com/media/splunk/attack_data/master/datasets/cisco_secure_endpoint/behavioral_protection/registry_payload_run_task_execution/cisco_se.log
  source: not_applicable
  sourcetype: cisco:se
 test_type:'unit'
 name:'True Positive Test - Cisco Secure Endpoint BP With Download and Task'
 attack_data:
  data: https://media.githubusercontent.com/media/splunk/attack_data/master/datasets/cisco_secure_endpoint/behavioral_protection/downloaded_registry_payload_run_task_execution/cisco_se.log
  source: not_applicable
  sourcetype: cisco:se
 test_type:'unit'
manual_test:None