Hunting for Registry Run Key Persistence
Overview
Registry Run keys (T1547.001) are one of the most commonly used persistence mechanisms by adversaries. When a program is added to a Run key in the Windows registry, it executes automatically when a user logs in. Attackers abuse keys under HKLM\Software\Microsoft\Windows\CurrentVersion\Run, HKCU\Software\Microsoft\Windows\CurrentVersion\Run, and their RunOnce counterparts to maintain persistence. Sysmon Event ID 13 (RegistryEvent - Value Set) captures registry value modifications including the target object path, the process that made the change, and the new value. Detection involves monitoring these events for suspicious executables in temp directories, encoded PowerShell commands, LOLBin paths, and processes that do not normally create Run key entries. Chaining Event 13 with Event 1 (Process Creation) and Event 11 (FileCreate) strengthens detection by confirming payload creation and execution.
When to Use
Trigger phrases:
"hunting for registry run key persistence"
"Detect MITRE ATT&CK T1547"
When investigating security incidents that require hunting for registry run key persistence
When building detection rules or threat hunting queries for this domain
When SOC analysts need structured procedures for this analysis type
When validating security monitoring coverage for related attack techniques
When NOT to Use
- When you lack proper authorization for testing
- For production systems without change management
- When the task requires legal or compliance expertise beyond technical scope
Prerequisites
- Windows systems with Sysmon installed and configured to log Event ID 13
- Sysmon config with RegistryEvent rules for Run/RunOnce keys
- Python 3.9+ with
json, xml.etree.ElementTree, re modules
- SIEM or log aggregator collecting Sysmon logs (Splunk, Elastic, Sentinel)
- Knowledge of legitimate auto-start programs for baseline comparison
Steps
# Example: IOC detection
import re
IOC_PATTERNS = {
"ip": r"\b(?:\d{1,3}\.){3}\d{1,3}\b",
"domain": r"\b[a-z0-9-]+\.[a-z]{2,}\b",
"hash_md5": r"\b[a-f0-9]{32}\b",
"hash_sha256": r"\b[a-f0-9]{64}\b",
}
def extract_iocs(text: str) -> dict:
return {k: re.findall(v, text) for k, v in IOC_PATTERNS.items()}
- Collect Sysmon Event ID 13 logs filtered for Run/RunOnce key paths
- Parse event XML/JSON for TargetObject, Details (value written), Image (modifying process)
- Flag entries where the value points to temp directories, AppData, or ProgramData
- Detect encoded PowerShell commands or script interpreters in registry values
- Identify LOLBin abuse (mshta.exe, rundll32.exe, regsvr32.exe, wscript.exe)
- Compare against known-good baseline of legitimate auto-start entries
- Check if the modifying process (Image) is unusual (cmd.exe, powershell.exe, python.exe)
- Chain with Event ID 1 to verify if the registered binary was recently created
- Generate detection report with MITRE ATT&CK mapping and severity scores
- Produce Sigma/Splunk detection rules from findings
Expected Output
A JSON report listing suspicious Run key entries with the registry path, value written, modifying process, timestamp, MITRE technique mapping, severity rating, and recommended Sigma detection rules.
Red Flags
- Performing actions without explicit written authorization from the asset owner
- Testing against production systems without a defined scope and rules of engagement
- Acting on threat intelligence without validating source reliability
- Sharing classified or sensitive indicators without proper handling procedures
- Alerting threat actors to detection capabilities through visible response actions
Process
- Reconnaissance — Gather target information, identify attack surface, enumerate services
- Analysis/Exploitation — Execute the technique, analyze results, document findings
- Reporting — Document IOCs, write findings, provide remediation recommendations
Verification
- All steps executed successfully against a test environment before production use
- Output documented with screenshots or logs demonstrating expected behavior
- Results validated against known-good baselines or reference implementations
- Documentation complete enough for another analyst to reproduce findings
Anti-Rationalization Table
| Rationalization |
Reality |
| "We are too small to be targeted" |
Automated attacks target everyone. Size does not matter. |
| "Security slows us down" |
A breach slows you down 100x more. Build security in from the start. |
| "We will fix it after launch" |
Vulnerabilities in production are exploited within hours. Fix before deploy. |
1---2name: hunting-for-registry-run-key-persistence3description: Use when detect MITRE ATT&CK T1547.001 registry Run key persistence by4 analyzing Sysmon Event ID 13 logs and registry queries to identify malicious auto-start5 entries. Use when detecting mitre att&ck t1547.001 registry run key persistence6 by analyzing.7domain: cybersecurity8subdomain: threat-hunting9tags:10- persistence11- registry-run-keys12- t1547-00113- sysmon14- threat-hunting15- windows-forensics16- mitre-attack17version: '1.0'18author: oyi7719license: Apache-2.020d3fend_techniques:21- Executable Denylisting22- Execution Isolation23- File Metadata Consistency Validation24- Content Format Conversion25- File Content Analysis26nist_csf:27- DE.CM-0128- DE.AE-0229- DE.AE-0730- ID.RA-0531category: cybersecurity32metadata:33 source: https://skillmd.com/skills/oyi77/hunting-for-registry-run-key-persistence34---3536# Hunting for Registry Run Key Persistence3738## Overview3940Registry Run keys (T1547.001) are one of the most commonly used persistence mechanisms by adversaries. When a program is added to a Run key in the Windows registry, it executes automatically when a user logs in. Attackers abuse keys under `HKLM\Software\Microsoft\Windows\CurrentVersion\Run`, `HKCU\Software\Microsoft\Windows\CurrentVersion\Run`, and their RunOnce counterparts to maintain persistence. Sysmon Event ID 13 (RegistryEvent - Value Set) captures registry value modifications including the target object path, the process that made the change, and the new value. Detection involves monitoring these events for suspicious executables in temp directories, encoded PowerShell commands, LOLBin paths, and processes that do not normally create Run key entries. Chaining Event 13 with Event 1 (Process Creation) and Event 11 (FileCreate) strengthens detection by confirming payload creation and execution.414243## When to Use44**Trigger phrases:**45- "hunting for registry run key persistence"46- "Detect MITRE ATT&CK T1547"474849- When investigating security incidents that require hunting for registry run key persistence50- When building detection rules or threat hunting queries for this domain51- When SOC analysts need structured procedures for this analysis type52- When validating security monitoring coverage for related attack techniques535455## When NOT to Use5657- When you lack proper authorization for testing58- For production systems without change management59- When the task requires legal or compliance expertise beyond technical scope606162## Prerequisites6364- Windows systems with Sysmon installed and configured to log Event ID 1365- Sysmon config with RegistryEvent rules for Run/RunOnce keys66- Python 3.9+ with `json`, `xml.etree.ElementTree`, `re` modules67- SIEM or log aggregator collecting Sysmon logs (Splunk, Elastic, Sentinel)68- Knowledge of legitimate auto-start programs for baseline comparison6970## Steps7172```python73# Example: IOC detection74import re7576IOC_PATTERNS = {77 "ip": r"\b(?:\d{1,3}\.){3}\d{1,3}\b",78 "domain": r"\b[a-z0-9-]+\.[a-z]{2,}\b",79 "hash_md5": r"\b[a-f0-9]{32}\b",80 "hash_sha256": r"\b[a-f0-9]{64}\b",81}8283def extract_iocs(text: str) -> dict:84 return {k: re.findall(v, text) for k, v in IOC_PATTERNS.items()}85```86871. Collect Sysmon Event ID 13 logs filtered for Run/RunOnce key paths882. Parse event XML/JSON for TargetObject, Details (value written), Image (modifying process)893. Flag entries where the value points to temp directories, AppData, or ProgramData904. Detect encoded PowerShell commands or script interpreters in registry values915. Identify LOLBin abuse (mshta.exe, rundll32.exe, regsvr32.exe, wscript.exe)926. Compare against known-good baseline of legitimate auto-start entries937. Check if the modifying process (Image) is unusual (cmd.exe, powershell.exe, python.exe)948. Chain with Event ID 1 to verify if the registered binary was recently created959. Generate detection report with MITRE ATT&CK mapping and severity scores9610. Produce Sigma/Splunk detection rules from findings9798## Expected Output99100A JSON report listing suspicious Run key entries with the registry path, value written, modifying process, timestamp, MITRE technique mapping, severity rating, and recommended Sigma detection rules.101## Red Flags102103- Performing actions without explicit written authorization from the asset owner104- Testing against production systems without a defined scope and rules of engagement105- Acting on threat intelligence without validating source reliability106- Sharing classified or sensitive indicators without proper handling procedures107- Alerting threat actors to detection capabilities through visible response actions108109## Process1101111. **Reconnaissance** — Gather target information, identify attack surface, enumerate services1121. **Analysis/Exploitation** — Execute the technique, analyze results, document findings1131. **Reporting** — Document IOCs, write findings, provide remediation recommendations114115## Verification116117- All steps executed successfully against a test environment before production use118- Output documented with screenshots or logs demonstrating expected behavior119- Results validated against known-good baselines or reference implementations120- Documentation complete enough for another analyst to reproduce findings121122## Anti-Rationalization Table123124| Rationalization | Reality |125|---|---|126| "We are too small to be targeted" | Automated attacks target everyone. Size does not matter. |127| "Security slows us down" | A breach slows you down 100x more. Build security in from the start. |128| "We will fix it after launch" | Vulnerabilities in production are exploited within hours. Fix before deploy. |