Performing Malware Persistence Investigation
When to Use
- When investigating how malware maintains presence on a compromised system after reboots
- During incident response to identify all persistence mechanisms for complete remediation
- For threat hunting to discover unauthorized autostart entries across endpoints
- When analyzing malware behavior to understand its persistence strategy
- For verifying that all persistence has been removed after incident remediation
Prerequisites
- Forensic image or live system access with administrative privileges
- Autoruns (Sysinternals) for Windows persistence enumeration
- RegRipper for offline registry analysis
- Understanding of Windows and Linux persistence mechanisms
- YARA rules for scanning persistence locations
- Baseline of known-good autorun entries for comparison
Workflow
Step 1: Enumerate Windows Registry Persistence
# Extract registry hives from forensic image
mount -o ro,loop,offset=$((2048*512)) /cases/case-2024-001/images/evidence.dd /mnt/evidence
# Key registry persistence locations
python3 << 'PYEOF'
from Registry import Registry
import json
results = {'registry_persistence': []}
# SYSTEM hive analysis
system_reg = Registry.Registry("/cases/case-2024-001/registry/SYSTEM")
select = system_reg.open("Select")
current = select.value("Current").value()
cs = f"ControlSet{current:03d}"
# Services (very common persistence)
services = system_reg.open(f"{cs}\\Services")
for svc in services.subkeys():
try:
start_type = svc.value("Start").value()
image_path = ""
try:
image_path = svc.value("ImagePath").value()
except:
pass
# Start types: 0=Boot, 1=System, 2=Auto, 3=Manual, 4=Disabled
if start_type in (0, 1, 2) and image_path:
svc_type = svc.value("Type").value() if svc.values() else 0
results['registry_persistence'].append({
'location': f'HKLM\\SYSTEM\\{cs}\\Services\\{svc.name()}',
'type': 'Service',
'value': image_path,
'start_type': start_type,
'timestamp': str(svc.timestamp())
})
except Exception:
pass
# SOFTWARE hive analysis
sw_reg = Registry.Registry("/cases/case-2024-001/registry/SOFTWARE")
# Machine Run keys
run_keys = [
"Microsoft\\Windows\\CurrentVersion\\Run",
"Microsoft\\Windows\\CurrentVersion\\RunOnce",
"Microsoft\\Windows\\CurrentVersion\\RunServices",
"Microsoft\\Windows\\CurrentVersion\\RunServicesOnce",
"Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer\\Run",
"Wow6432Node\\Microsoft\\Windows\\CurrentVersion\\Run",
"Wow6432Node\\Microsoft\\Windows\\CurrentVersion\\RunOnce",
]
for key_path in run_keys:
try:
key = sw_reg.open(key_path)
for value in key.values():
results['registry_persistence'].append({
'location': f'HKLM\\SOFTWARE\\{key_path}',
'type': 'Run Key',
'name': value.name(),
'value': str(value.value()),
'timestamp': str(key.timestamp())
})
except Exception:
pass
> 📎 Detailed content (full examples / references / data tables) has been split into `reference.md` in the same directory; use Read to load the relevant section on demand.
1---2name: performing-malware-persistence-investigation3description: "Systematically investigate Windows persistence mechanisms. Signals: persistence, backdoor, privilege maintenance."4zh-signals: "Systematically investigate all persistence mechanisms on Windows and 信号:持久化,后门,权限维持。"5when-to-use: Systematically investigate all persistence mechanisms on Windows and6 Linux systems to identify how malware survives reboots and maintains access.7domain: cybersecurity8subdomain: digital-forensics9tags:10- forensics11- malware-persistence12- autoruns13- registry14- scheduled-tasks15- rootkit-detection16- incident-response17mitre_attack:18- T100519- T107420- T111921- T107022- T154723version: '1.0'24author: mahipal25license: Apache-2.026nist_csf:27- RS.AN-0328- DE.AE-0229- RS.MA-0130metadata:31 source: https://skillmd.com/skills/dangeroussong/performing-malware-persistence-investigation32---3334# Performing Malware Persistence Investigation3536## When to Use37- When investigating how malware maintains presence on a compromised system after reboots38- During incident response to identify all persistence mechanisms for complete remediation39- For threat hunting to discover unauthorized autostart entries across endpoints40- When analyzing malware behavior to understand its persistence strategy41- For verifying that all persistence has been removed after incident remediation4243## Prerequisites44- Forensic image or live system access with administrative privileges45- Autoruns (Sysinternals) for Windows persistence enumeration46- RegRipper for offline registry analysis47- Understanding of Windows and Linux persistence mechanisms48- YARA rules for scanning persistence locations49- Baseline of known-good autorun entries for comparison5051## Workflow5253### Step 1: Enumerate Windows Registry Persistence5455```bash56# Extract registry hives from forensic image57mount -o ro,loop,offset=$((2048*512)) /cases/case-2024-001/images/evidence.dd /mnt/evidence5859# Key registry persistence locations60python3 << 'PYEOF'61from Registry import Registry62import json6364results = {'registry_persistence': []}6566# SYSTEM hive analysis67system_reg = Registry.Registry("/cases/case-2024-001/registry/SYSTEM")68select = system_reg.open("Select")69current = select.value("Current").value()70cs = f"ControlSet{current:03d}"7172# Services (very common persistence)73services = system_reg.open(f"{cs}\\Services")74for svc in services.subkeys():75 try:76 start_type = svc.value("Start").value()77 image_path = ""78 try:79 image_path = svc.value("ImagePath").value()80 except:81 pass82 # Start types: 0=Boot, 1=System, 2=Auto, 3=Manual, 4=Disabled83 if start_type in (0, 1, 2) and image_path:84 svc_type = svc.value("Type").value() if svc.values() else 085 results['registry_persistence'].append({86 'location': f'HKLM\\SYSTEM\\{cs}\\Services\\{svc.name()}',87 'type': 'Service',88 'value': image_path,89 'start_type': start_type,90 'timestamp': str(svc.timestamp())91 })92 except Exception:93 pass9495# SOFTWARE hive analysis96sw_reg = Registry.Registry("/cases/case-2024-001/registry/SOFTWARE")9798# Machine Run keys99run_keys = [100 "Microsoft\\Windows\\CurrentVersion\\Run",101 "Microsoft\\Windows\\CurrentVersion\\RunOnce",102 "Microsoft\\Windows\\CurrentVersion\\RunServices",103 "Microsoft\\Windows\\CurrentVersion\\RunServicesOnce",104 "Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer\\Run",105 "Wow6432Node\\Microsoft\\Windows\\CurrentVersion\\Run",106 "Wow6432Node\\Microsoft\\Windows\\CurrentVersion\\RunOnce",107]108109for key_path in run_keys:110 try:111 key = sw_reg.open(key_path)112 for value in key.values():113 results['registry_persistence'].append({114 'location': f'HKLM\\SOFTWARE\\{key_path}',115 'type': 'Run Key',116 'name': value.name(),117 'value': str(value.value()),118 'timestamp': str(key.timestamp())119 })120 except Exception:121 pass122123> 📎 Detailed content (full examples / references / data tables) has been split into `reference.md` in the same directory; use Read to load the relevant section on demand.