Cisco Secure Endpoint - Hidden Script After Delivery Or Zone Change

 Original Source: [splunk source]
Name:Cisco Secure Endpoint - Hidden Script After Delivery Or Zone Change
id:08d7aef4-3c58-4a36-b482-71fb55470771
version:1
date:None
author:Nasreddine Bencherchali, Splunk
status:production
type:TTP
Description:This analytic detects hidden PowerShell execution of a Temp script after a BITS transfer command, a PowerShell download command writing the same file, or a Zone.Identifier change. It correlates Cisco Secure Endpoint Behavioral Protection alerts by endpoint, parent process, file path, and time. A staged script followed by concealed execution can indicate payload delivery and evasion. BITS and download alerts record commands; they do not by themselves prove transfer completion, and a zone-marker change does not prove a security control was bypassed. Check prevention actions and inspect the script and source URL.
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 ("20170804213338","20190603173116","20200719101800","20201202215412")

| spath path=bp_data.details.matched_activity.events{0}.process:start.parent_guid output=parent_guid
| 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.args{} output=process_args

| eval stage=case(sig_id="20170804213338","transfer",
sig_id="20190603173116","zone",
sig_id="20200719101800","download",
sig_id="20201202215412","execute")

| eval bits_transfer_index=mvfind(process_args,"(?i)^/transfer$")
| rex field=process_command "(?i)WriteAllText\(\s*['\"](?<download_file>[A-Za-z]:[^'\"]+\.ps1)"
| rex field=process_command "(?i)DownloadString\(\s*['\"](?<powershell_url>https?://[^'\"]+)"
| eval transfer_file=if(stage="transfer" AND isnotnull(bits_transfer_index),lower(mvindex(process_args,-1)),null()),
transfer_url=if(stage="transfer" AND isnotnull(bits_transfer_index),mvindex(process_args,-2),null())

| rex field=process_command "(?i)ReadAllText\('(?<executed_file>[A-Za-z]:[^']+\.ps1)'"

| rex field=process_command "(?i)>\s*(?<zone_file>[A-Za-z]:.+?\.ps1):Zone\.Identifier"

| eval file_ref=lower(coalesce(transfer_file,download_file,zone_file,executed_file))

| eval event_time=tonumber(timestamp)+tonumber(timestamp_nanoseconds)/1000000000

| where isnotnull(endpoint_guid)
AND isnotnull(parent_guid)
AND isnotnull(file_ref)
AND isnotnull(event_time)

| eval stage=if(stage="transfer" AND isnull(transfer_file),null(),stage)
| where isnotnull(stage)
| sort 0 endpoint_guid parent_guid file_ref event_time

| streamstats max(eval(if(stage="transfer" OR stage="download",event_time,null()))) as transfer_time
last(eval(if(stage="transfer" OR stage="download",process_command,null()))) as transfer_command
last(eval(case(stage="transfer","BITS transfer command",stage="download","PowerShell download command"))) as delivery_method
last(eval(if(stage="transfer" OR stage="download",coalesce(transfer_url,powershell_url),null()))) as download_url
max(eval(if(stage="zone",event_time,null()))) as zone_time
last(eval(if(stage="zone",process_command,null()))) as zone_command
by endpoint_guid parent_guid file_ref

| where stage="execute"

| eval transfer_time=if(isnotnull(transfer_time) AND event_time-transfer_time<=300,transfer_time,null()),
zone_time=if(isnotnull(zone_time) AND event_time-zone_time<=300,zone_time,null())

| where isnotnull(transfer_time) OR isnotnull(zone_time)

| eval download_url=if(isnotnull(transfer_time),download_url,null()),
transfer_command=if(isnotnull(transfer_time),transfer_command,null()),
zone_command=if(isnotnull(zone_time),zone_command,null()),
activity=case(isnotnull(transfer_time) AND isnotnull(zone_time),delivery_method." and zone change",
isnotnull(transfer_time),delivery_method,
isnotnull(zone_time),"zone marker change"),
script_file=file_ref,
execution_command=process_command,
firstTime=if(isnull(transfer_time),zone_time,if(isnull(zone_time),transfer_time,min(transfer_time,zone_time))),
lastTime=event_time

| sort 0 endpoint_guid parent_guid script_file firstTime -lastTime

| dedup endpoint_guid parent_guid script_file firstTime

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

| table dest user endpoint_guid parent_guid script_file activity
download_url transfer_command zone_command execution_command bp_response firstTime lastTime
| `security_content_ctime(firstTime)`
| `security_content_ctime(lastTime)`
| `cisco_secure_endpoint___hidden_script_after_delivery_or_zone_change_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 legitimate deployment workflow may transfer a script with BITS, change its zone marker, or run it hidden. Review the source URL when present, script content, account, parent process, and deployment change record.
References:
  -https://docs.amp.cisco.com/en/SecureEndpoint/Secure%20Endpoint%20User%20Guide.pdf
  -https://attack.mitre.org/techniques/T1197/
  -https://attack.mitre.org/techniques/T1553/005/
  -https://attack.mitre.org/techniques/T1059/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:['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/bits_transfer_hidden_script_execution/cisco_se.log
  source: not_applicable
  sourcetype: cisco:se
 test_type:'unit'
 name:'True Positive Test - Cisco Secure Endpoint BP Zone Change'
 attack_data:
  data: https://media.githubusercontent.com/media/splunk/attack_data/master/datasets/cisco_secure_endpoint/behavioral_protection/zone_marker_hidden_script_execution/cisco_se.log
  source: not_applicable
  sourcetype: cisco:se
 test_type:'unit'
 name:'True Positive Test - Cisco Secure Endpoint BP BITS and Zone Change'
 attack_data:
  data: https://media.githubusercontent.com/media/splunk/attack_data/master/datasets/cisco_secure_endpoint/behavioral_protection/bits_zone_hidden_script_execution/cisco_se.log
  source: not_applicable
  sourcetype: cisco:se
 test_type:'unit'
 name:'True Positive Test - Cisco Secure Endpoint BP PowerShell Download'
 attack_data:
  data: https://media.githubusercontent.com/media/splunk/attack_data/master/datasets/cisco_secure_endpoint/behavioral_protection/downloaded_script_hidden_temp_execution/cisco_se.log
  source: not_applicable
  sourcetype: cisco:se
 test_type:'unit'
manual_test:None