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 by analyzing Sysmon Event ID 13 logs and registry queries to identify malicious auto-start entries. Use when detecting mitre att&ck t1547.001 registry run key persistence by analyzing.4license: Apache-2.05---67# Hunting for Registry Run Key Persistence89## Overview1011Registry 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.121314## When to Use15**Trigger phrases:**16- "hunting for registry run key persistence"17- "Detect MITRE ATT&CK T1547"181920- When investigating security incidents that require hunting for registry run key persistence21- When building detection rules or threat hunting queries for this domain22- When SOC analysts need structured procedures for this analysis type23- When validating security monitoring coverage for related attack techniques242526## When NOT to Use2728- When you lack proper authorization for testing29- For production systems without change management30- When the task requires legal or compliance expertise beyond technical scope313233## Prerequisites3435- Windows systems with Sysmon installed and configured to log Event ID 1336- Sysmon config with RegistryEvent rules for Run/RunOnce keys37- Python 3.9+ with `json`, `xml.etree.ElementTree`, `re` modules38- SIEM or log aggregator collecting Sysmon logs (Splunk, Elastic, Sentinel)39- Knowledge of legitimate auto-start programs for baseline comparison4041## Steps4243```python44# Example: IOC detection45import re4647IOC_PATTERNS = {48 "ip": r"\b(?:\d{1,3}\.){3}\d{1,3}\b",49 "domain": r"\b[a-z0-9-]+\.[a-z]{2,}\b",50 "hash_md5": r"\b[a-f0-9]{32}\b",51 "hash_sha256": r"\b[a-f0-9]{64}\b",52}5354def extract_iocs(text: str) -> dict:55 return {k: re.findall(v, text) for k, v in IOC_PATTERNS.items()}56```57581. Collect Sysmon Event ID 13 logs filtered for Run/RunOnce key paths592. Parse event XML/JSON for TargetObject, Details (value written), Image (modifying process)603. Flag entries where the value points to temp directories, AppData, or ProgramData614. Detect encoded PowerShell commands or script interpreters in registry values625. Identify LOLBin abuse (mshta.exe, rundll32.exe, regsvr32.exe, wscript.exe)636. Compare against known-good baseline of legitimate auto-start entries647. Check if the modifying process (Image) is unusual (cmd.exe, powershell.exe, python.exe)658. Chain with Event ID 1 to verify if the registered binary was recently created669. Generate detection report with MITRE ATT&CK mapping and severity scores6710. Produce Sigma/Splunk detection rules from findings6869## Expected Output7071A 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.72## Red Flags7374- Performing actions without explicit written authorization from the asset owner75- Testing against production systems without a defined scope and rules of engagement76- Acting on threat intelligence without validating source reliability77- Sharing classified or sensitive indicators without proper handling procedures78- Alerting threat actors to detection capabilities through visible response actions7980## Process81821. **Reconnaissance** — Gather target information, identify attack surface, enumerate services831. **Analysis/Exploitation** — Execute the technique, analyze results, document findings841. **Reporting** — Document IOCs, write findings, provide remediation recommendations8586## Verification8788- All steps executed successfully against a test environment before production use89- Output documented with screenshots or logs demonstrating expected behavior90- Results validated against known-good baselines or reference implementations91- Documentation complete enough for another analyst to reproduce findings9293## Anti-Rationalization Table9495| Rationalization | Reality |96|---|---|97| "We are too small to be targeted" | Automated attacks target everyone. Size does not matter. |98| "Security slows us down" | A breach slows you down 100x more. Build security in from the start. |99| "We will fix it after launch" | Vulnerabilities in production are exploited within hours. Fix before deploy. |