Cisco Secure Endpoint - WMI MSHTA and Run Key

 Original Source: [splunk source]
Name:Cisco Secure Endpoint - WMI MSHTA and Run Key
id:167ad3d9-e255-41cf-bef1-3ed3685d815c
version:1
date:None
author:Nasreddine Bencherchali, Splunk
status:production
type:TTP
Description:This analytic detects a WMI process-creation command naming an MSHTA URL, a later MSHTA process alert for the same URL, and a Run value referencing that URL, by correlating Cisco Secure Endpoint Behavioral Protection alerts. This links a remote execution attempt to persistence on the same endpoint. URL equality alone does not prove WMI launched the observed process, and a blocked Run write may not persist; verify lineage and response actions.
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 ("20190409192004","20210616150648","20220810091525")

| 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}.registry:set.data_txt output=run_data
| 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}.process:start.ts output=process_event_ts
| spath path=bp_data.details.matched_activity.events{0}.registry:set.ts output=registry_event_ts

| eval stage=case(sig_id="20190409192004","wmi",
sig_id="20210616150648","mshta",
sig_id="20220810091525","persist")

| rex field=process_command "(?i)mshta(?:\.exe)?\s+['\"]?(?<process_url>https?://[^\s'\"]+)"

| rex field=run_data "(?i)mshta(?:\.exe)?\s+['\"]?(?<run_url>https?://[^\s'\"]+)"

| eval remote_url=coalesce(process_url,run_url),
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(remote_url)
AND isnotnull(event_time)

| sort 0 endpoint_guid remote_url event_time
| streamstats last(eval(if(stage="wmi",event_time,null()))) as wmi_time
last(eval(if(stage="wmi",process_command,null()))) as wmi_command
by endpoint_guid remote_url
| eval valid_mshta=if(stage="mshta" AND isnotnull(wmi_time)
AND event_time>=wmi_time AND event_time-wmi_time<=300,1,0)
| streamstats last(eval(if(valid_mshta=1,event_time,null()))) as mshta_time
last(eval(if(valid_mshta=1,wmi_time,null()))) as first_event_time
last(eval(if(valid_mshta=1,process_command,null()))) as mshta_command
last(eval(if(valid_mshta=1,wmi_command,null()))) as prior_wmi_command
by endpoint_guid remote_url
| where stage="persist" AND isnotnull(mshta_time)
AND event_time>=mshta_time AND event_time-first_event_time<=300
| eval wmi_command=prior_wmi_command, firstTime=first_event_time,
lastTime=event_time, user=coalesce(user,"unknown")
| dedup endpoint_guid remote_url mshta_time

| table dest user endpoint_guid remote_url run_key
run_value wmi_command mshta_command firstTime lastTime
| `security_content_ctime(firstTime)`
| `security_content_ctime(lastTime)`
| `cisco_secure_endpoint___wmi_mshta_and_run_key_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:An approved application may launch remote content through mshta and WMI and register it for logon. Inspect the content and URL, WMI process result, Run key scope, account, and change record.
References:
  -https://docs.amp.cisco.com/en/SecureEndpoint/Secure%20Endpoint%20User%20Guide.pdf
  -https://attack.mitre.org/techniques/T1047/
  -https://attack.mitre.org/techniques/T1218/005/
  -https://attack.mitre.org/techniques/T1547/001/
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:['T1047', 'T1218.005', 'T1547.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/wmi_remote_hta_run_key/cisco_se.log
  source: not_applicable
  sourcetype: cisco:se
 test_type:'unit'
manual_test:None