suspicious_powershell_in_registry_run_keys


Description

Detects potential PowerShell commands or code within registry run keys

Query · yara_l

events:
    $reg.metadata.event_type = "REGISTRY_MODIFICATION"
    (
        (
            strings.contains(strings.to_lower($reg.target.registry.registry_key), "\\software\\microsoft\\windows\\currentversion\\run") or
            strings.contains(strings.to_lower($reg.target.registry.registry_key), "\\software\\wow6432node\\microsoft\\windows\\currentversion\\run") or
            strings.contains(strings.to_lower($reg.target.registry.registry_key), "\\software\\microsoft\\windows\\currentversion\\policies\\explorer\\run")
        )
        and
        (
            strings.contains(strings.to_lower($reg.target.registry.registry_value_data), "powershell") or
            strings.contains(strings.to_lower($reg.target.registry.registry_value_data), "pwsh ") or
            strings.contains(strings.to_lower($reg.target.registry.registry_value_data), "frombase64string") or
            strings.contains(strings.to_lower($reg.target.registry.registry_value_data), ".downloadfile(") or
            strings.contains(strings.to_lower($reg.target.registry.registry_value_data), ".downloadstring(") or
            strings.contains(strings.to_lower($reg.target.registry.registry_value_data), " -w hidden ") or
            strings.contains(strings.to_lower($reg.target.registry.registry_value_data), " -w 1 ") or
            strings.contains(strings.to_lower($reg.target.registry.registry_value_data), "-windowstyle hidden") or
            strings.contains(strings.to_lower($reg.target.registry.registry_value_data), "-window hidden") or
            strings.contains(strings.to_lower($reg.target.registry.registry_value_data), " -nop ") or
            strings.contains(strings.to_lower($reg.target.registry.registry_value_data), " -encodedcommand ") or
            strings.contains(strings.to_lower($reg.target.registry.registry_value_data), "-executionpolicy bypass") or
            strings.contains(strings.to_lower($reg.target.registry.registry_value_data), "invoke-expression") or
            strings.contains(strings.to_lower($reg.target.registry.registry_value_data), "iex (") or
            strings.contains(strings.to_lower($reg.target.registry.registry_value_data), "invoke-command") or
            strings.contains(strings.to_lower($reg.target.registry.registry_value_data), "icm -") or
            strings.contains(strings.to_lower($reg.target.registry.registry_value_data), "invoke-webrequest") or
            strings.contains(strings.to_lower($reg.target.registry.registry_value_data), "iwr ") or
            strings.contains(strings.to_lower($reg.target.registry.registry_value_data), " -noni ") or
            strings.contains(strings.to_lower($reg.target.registry.registry_value_data), " -noninteractive ")
        )
    )

    $reg.principal.hostname = $hostname

  match:
    $hostname over 5m

  outcome:
    //example usage of specifying test user and hostname to adjust risk score
    $risk_score = max(if($reg.principal.user.userid = "user" and $reg.principal.hostname = "hostname", 0, 15))
    $principal_hostname = array_distinct($reg.principal.hostname)
    $principal_process_pid = array_distinct($reg.principal.process.pid)
    $principal_process_file_full_path = array_distinct($reg.principal.process.file.full_path)
    $principal_process_product_specific_process_id = array_distinct($reg.principal.process.product_specific_process_id)
    $principal_user_userid = array_distinct($reg.principal.user.userid)
    $target_registry_key = array_distinct($reg.target.registry.registry_key)
    $target_registry_value_data = array_distinct($reg.target.registry.registry_value_data)
    $log_type = array_distinct(strings.concat($reg.metadata.log_type,"/",$reg.metadata.product_event_type))

  condition:
    $reg
Raw source suspicious_powershell_in_registry_run_keys · YARA-L
Esc
Published by chronicle/detection-rules ↗, licensed under Apache 2.0 ↗. Reproduced here unmodified.
rule suspicious_powershell_in_registry_run_keys {

  meta:
    author = "frack113, Florian Roth (Nextron Systems)"
    description = "Detects potential PowerShell commands or code within registry run keys"
    reference = "https://github.com/SigmaHQ/sigma/blob/master/rules/windows/registry/registry_set/registry_set_powershell_in_run_keys.yml"
    license = "https://github.com/SigmaHQ/Detection-Rule-License/blob/main/LICENSE.Detection.Rules.md"
    rule_name = "Suspicious Powershell In Registry Run Keys"
    rule_id = "mr_ad75681b-474a-4022-9e35-d6beffcf9a4a"
    sigma_uuid = "8d85cf08-bf97-4260-ba49-986a2a65129c"
    sigma_status = "test"
    tactic = "TA0003"
    technique = "T1547.001"
    data_source = "Sysmon"
    platform = "Windows"
    severity = "Medium"
    priority = "Medium"
    false_positives = "Legitimate admin or third party scripts"

  events:
    $reg.metadata.event_type = "REGISTRY_MODIFICATION"
    (
        (
            strings.contains(strings.to_lower($reg.target.registry.registry_key), "\\software\\microsoft\\windows\\currentversion\\run") or
            strings.contains(strings.to_lower($reg.target.registry.registry_key), "\\software\\wow6432node\\microsoft\\windows\\currentversion\\run") or
            strings.contains(strings.to_lower($reg.target.registry.registry_key), "\\software\\microsoft\\windows\\currentversion\\policies\\explorer\\run")
        )
        and
        (
            strings.contains(strings.to_lower($reg.target.registry.registry_value_data), "powershell") or
            strings.contains(strings.to_lower($reg.target.registry.registry_value_data), "pwsh ") or
            strings.contains(strings.to_lower($reg.target.registry.registry_value_data), "frombase64string") or
            strings.contains(strings.to_lower($reg.target.registry.registry_value_data), ".downloadfile(") or
            strings.contains(strings.to_lower($reg.target.registry.registry_value_data), ".downloadstring(") or
            strings.contains(strings.to_lower($reg.target.registry.registry_value_data), " -w hidden ") or
            strings.contains(strings.to_lower($reg.target.registry.registry_value_data), " -w 1 ") or
            strings.contains(strings.to_lower($reg.target.registry.registry_value_data), "-windowstyle hidden") or
            strings.contains(strings.to_lower($reg.target.registry.registry_value_data), "-window hidden") or
            strings.contains(strings.to_lower($reg.target.registry.registry_value_data), " -nop ") or
            strings.contains(strings.to_lower($reg.target.registry.registry_value_data), " -encodedcommand ") or
            strings.contains(strings.to_lower($reg.target.registry.registry_value_data), "-executionpolicy bypass") or
            strings.contains(strings.to_lower($reg.target.registry.registry_value_data), "invoke-expression") or
            strings.contains(strings.to_lower($reg.target.registry.registry_value_data), "iex (") or
            strings.contains(strings.to_lower($reg.target.registry.registry_value_data), "invoke-command") or
            strings.contains(strings.to_lower($reg.target.registry.registry_value_data), "icm -") or
            strings.contains(strings.to_lower($reg.target.registry.registry_value_data), "invoke-webrequest") or
            strings.contains(strings.to_lower($reg.target.registry.registry_value_data), "iwr ") or
            strings.contains(strings.to_lower($reg.target.registry.registry_value_data), " -noni ") or
            strings.contains(strings.to_lower($reg.target.registry.registry_value_data), " -noninteractive ")
        )
    )

    $reg.principal.hostname = $hostname

  match:
    $hostname over 5m

  outcome:
    //example usage of specifying test user and hostname to adjust risk score
    $risk_score = max(if($reg.principal.user.userid = "user" and $reg.principal.hostname = "hostname", 0, 15))
    $principal_hostname = array_distinct($reg.principal.hostname)
    $principal_process_pid = array_distinct($reg.principal.process.pid)
    $principal_process_file_full_path = array_distinct($reg.principal.process.file.full_path)
    $principal_process_product_specific_process_id = array_distinct($reg.principal.process.product_specific_process_id)
    $principal_user_userid = array_distinct($reg.principal.user.userid)
    $target_registry_key = array_distinct($reg.target.registry.registry_key)
    $target_registry_value_data = array_distinct($reg.target.registry.registry_value_data)
    $log_type = array_distinct(strings.concat($reg.metadata.log_type,"/",$reg.metadata.product_event_type))

  condition:
    $reg
}

Detection rules belong to the projects that publish them and remain under their own licenses. This site indexes and links to them; it claims no rights in them.