Detection rules › YARA-L
YARA-L rules: 3j
| Rule | Severity |
|---|---|
| PowerShell DownloadFile | high |
| Windows Short Term Account Use | medium |
PowerShell DownloadFile
#Detects the execution of powershell, a WebClient object creation and the invocation of DownloadFile in a single command line
Known False Positives
- Unknown
MITRE ATT&CK Coverage
| Tactic | Techniques |
|---|---|
| Execution |
References
Telemetry Coverage
| Provider | Record / event type |
|---|---|
| Sysmon | Event ID 1: Process creation |
| Security-Auditing | Event ID 4688: A new process has been created. |
Rule Body
// Copyright 2025 Google LLC. Licensed under Apache-2.0.
rule powershell_downloadfile {
meta:
author = "Florian Roth (Nextron Systems)"
description = "Detects the execution of powershell, a WebClient object creation and the invocation of DownloadFile in a single command line"
reference = "https://github.com/SigmaHQ/sigma/blob/master/rules/windows/process_creation/proc_creation_win_powershell_susp_ps_downloadfile.yml"
license = "https://github.com/SigmaHQ/Detection-Rule-License/blob/main/LICENSE.Detection.Rules.md"
rule_name = "PowerShell DownloadFile"
sigma_uuid = "8f70ac5f-1f6f-4f8e-b454-db19561216c5"
sigma_status = "test"
rule_id = "mr_aabbd11f-06fb-41fb-a15c-a226a4bf20e2"
tactic = "TA0002"
technique = "T1059.001"
type = "Detection"
data_source = "Sysmon"
platform = "Windows"
severity = "High"
priority = "High"
false_positives = "Unknown"
events:
$process.metadata.event_type = "PROCESS_LAUNCH"
(
strings.contains(strings.to_lower($process.target.process.command_line), "powershell") and
strings.contains(strings.to_lower($process.target.process.command_line), ".downloadfile") and
strings.contains(strings.to_lower($process.target.process.command_line), "system.net.webclient")
)
$process.principal.hostname = $hostname
match:
$hostname over 5m
outcome:
//example usage of specifying test user and hostname to adjust risk score
$risk_score = max(if($process.principal.user.userid = "user" and $process.principal.hostname = "hostname", 0, 15))
$principal_process_pid = array_distinct($process.principal.process.pid)
$principal_process_command_line = array_distinct($process.principal.process.command_line)
$principal_process_file_sha256 = array_distinct($process.principal.process.file.sha256)
$principal_process_file_full_path = array_distinct($process.principal.process.file.full_path)
$principal_process_product_specfic_process_id = array_distinct($process.principal.process.product_specific_process_id)
$principal_process_parent_process_product_specfic_process_id = array_distinct($process.principal.process.parent_process.product_specific_process_id)
$target_process_pid = array_distinct($process.target.process.pid)
$target_process_command_line = array_distinct($process.target.process.command_line)
$target_process_file_sha256 = array_distinct($process.target.process.file.sha256)
$target_process_file_full_path = array_distinct($process.target.process.file.full_path)
$target_process_product_specfic_process_id = array_distinct($process.target.process.product_specific_process_id)
$principal_user_userid = array_distinct($process.principal.user.userid)
$log_type = array_distinct(strings.concat($process.metadata.log_type,"/",$process.metadata.product_event_type))
condition:
$process
}
YARA-L Rule Structure
Condition
Fires when at least one $process event in the 5m window.
Events
$process
target.process.command_line contains "powershell"target.process.command_line contains ".downloadfile"target.process.command_line contains "system.net.webclient"
Match and Correlation
Outcome
Outcome variables add context to a detection. When the rule generates an alert, $risk_score is displayed with it.
| Field | Expression |
|---|---|
risk_score | max(if($process.principal.user.userid = "user" and $process.principal.hostname = "hostname", 0, 15)) |
principal_process_pid | array_distinct($process.principal.process.pid) |
principal_process_command_line | array_distinct($process.principal.process.command_line) |
principal_process_file_sha256 | array_distinct($process.principal.process.file.sha256) |
principal_process_file_full_path | array_distinct($process.principal.process.file.full_path) |
principal_process_product_specfic_process_id | array_distinct($process.principal.process.product_specific_process_id) |
principal_process_parent_process_product_specfic_process_id | array_distinct($process.principal.process.parent_process.product_specific_process_id) |
target_process_pid | array_distinct($process.target.process.pid) |
target_process_command_line | array_distinct($process.target.process.command_line) |
target_process_file_sha256 | array_distinct($process.target.process.file.sha256) |
target_process_file_full_path | array_distinct($process.target.process.file.full_path) |
target_process_product_specfic_process_id | array_distinct($process.target.process.product_specific_process_id) |
principal_user_userid | array_distinct($process.principal.user.userid) |
log_type | array_distinct(strings.concat($process.metadata.log_type,"/",$process.metadata.product_event_type)) |
Windows Short Term Account Use
#Detects the creation, login, and deletion of a user account over a predefined timeframe
Telemetry Coverage
Rule Body
// Copyright 2023 Google LLC. Licensed under Apache-2.0.
rule win_short_term_account_use {
meta:
author = "Google Cloud Security"
description = "Detects the creation, login, and deletion of a user account over a predefined timeframe"
rule_id = "mr_ac28ce76-8197-4354-af0d-d77c5771d9df"
rule_name = "Windows Short Term Account Use"
type = "alert"
platform = "windows"
data_source = "microsoft windows events"
severity = "Medium"
priority = "Medium"
events:
$create.metadata.event_type = "USER_CREATION"
$create.target.user.userid = $targetUser
$create.metadata.event_timestamp.seconds < $login.metadata.event_timestamp.seconds
$login.metadata.event_type = "USER_LOGIN"
//Focus is on Windows login events with this event code but could be modified for other platforms as well
$login.metadata.product_event_type = "4624"
$login.target.user.userid = $targetUser
$login.metadata.event_timestamp.seconds < $delete.metadata.event_timestamp.seconds
$delete.metadata.event_type = "USER_DELETION"
$delete.target.user.userid = $targetUser
match:
$targetUser over 4h
outcome:
$risk_score = 65
$event_count = count_distinct($login.metadata.id)
// added to populate alert graph with additional context
$principal_hostname = array_distinct($login.principal.hostname)
$src_hostname = array_distinct($login.src.hostname)
$src_ip = array_distinct($login.src.ip)
$principal_user_userid = array_distinct($login.principal.user.userid)
$principal_user_employee_id = array_distinct($login.principal.user.employee_id)
// principal_process_id for each of the three types of events
$user_creation_process_id = array_distinct($create.principal.process.pid)
$user_login_process_id = array_distinct($login.principal.process.pid)
$user_deletion_process_id = array_distinct($delete.principal.process.pid)
$target_process_file_full_path = array_distinct($login.target.process.file.full_path)
// Commented out target.user.userid because it is already represented in graph as match variable. If match changes, can uncomment to add to results
//$target_user_userid = array_distinct($login.target.user.userid)
$principal_resource_name = array_distinct($login.principal.resource.name)
$target_resource_name = array_distinct($login.target.resource.name)
$target_url = array_distinct($login.target.url)
condition:
$create and $login and $delete
}
YARA-L Rule Structure
Condition
Fires when at least one $create event in the 4h window and at least one $login event in the 4h window and at least one $delete event in the 4h window.
Events
$create
$login
metadata.product_event_type = "4624"
$delete
Match and Correlation
Outcome
Outcome variables add context to a detection. When the rule generates an alert, $risk_score is displayed with it.
| Field | Expression |
|---|---|
risk_score | 65 |
event_count | count_distinct($login.metadata.id) |
principal_hostname | array_distinct($login.principal.hostname) |
src_hostname | array_distinct($login.src.hostname) |
src_ip | array_distinct($login.src.ip) |
principal_user_userid | array_distinct($login.principal.user.userid) |
principal_user_employee_id | array_distinct($login.principal.user.employee_id) |
user_creation_process_id | array_distinct($create.principal.process.pid) |
user_login_process_id | array_distinct($login.principal.process.pid) |
user_deletion_process_id | array_distinct($delete.principal.process.pid) |
target_process_file_full_path | array_distinct($login.target.process.file.full_path) |
principal_resource_name | array_distinct($login.principal.resource.name) |
target_resource_name | array_distinct($login.target.resource.name) |
target_url | array_distinct($login.target.url) |