Security Notes
Windows

Windows Registry — A Security & Forensics Primer

The Windows Registry is where attackers persist, where credentials live, and where forensic analysts reconstruct what happened on a host. For an IR/detection role on a Windows-touching estate, knowing the registry cold is non-negotiable. This primer covers what it is, how it's structured, where it lives on disk, the security-critical keys, and how you detect and investigate registry abuse.

12 min read 7 sections 6 model answers

Breadth layernotes-security-core-knowledge.md Also see: Active Directory · Digital Forensics · Endpoint Detection


What the Registry Actually Is

In plain terms: the registry is Windows' giant central configuration database — a hierarchical key-value store that holds settings for the OS, drivers, services, installed software, and every user. Before it existed (Windows 3.x), config lived in scattered .ini files; the registry consolidated all of that into one queryable, ACL-protected tree.

Structurally it's like a filesystem:

   Filesystem analogy        Registry term
   ──────────────────        ─────────────
   folder                →   KEY        (a container, e.g. ...\CurrentVersion\Run)
   sub-folder            →   subkey
   file                  →   VALUE      (name + type + data)
   file contents         →   value data (REG_SZ, REG_DWORD, REG_BINARY, ...)
Memory hook

"the registry is the filesystem for settings." Keys are folders, values are files. Once that clicks, everything else (paths, permissions, navigation) maps to filesystem intuition. And the security punchline: just like the filesystem, the registry is where persistence hides and where secrets are stored — so the same instincts (what's new, what's writable, what runs at boot) apply.

Value data types you'll see constantly:

  • REG_SZ — a string
  • REG_DWORD / REG_QWORD — 32/64-bit number (flags, toggles)
  • REG_BINARY — raw bytes (often where malware hides encoded payloads/config)
  • REG_EXPAND_SZ — string with environment variables (e.g. %SystemRoot%)
  • REG_MULTI_SZ — list of strings

The Five Root Keys (Hives You See in regedit)

HKEY_LOCAL_MACHINE   (HKLM)  → machine-wide settings (all users). The big one for security.
HKEY_USERS           (HKU)   → settings for ALL loaded user profiles, keyed by SID
HKEY_CURRENT_USER    (HKCU)  → the CURRENT user's settings = a view into HKU\<your-SID>
HKEY_CLASSES_ROOT    (HKCR)  → file associations + COM registrations = merge of HKLM & HKCU \Software\Classes
HKEY_CURRENT_CONFIG  (HKCC)  → current hardware profile (a view into HKLM)
Memory hook

only two roots are "real"; the rest are views. HKLM (machine) and HKU (all users) are the actual stored data. HKCU is just a shortcut to your SID under HKU, and HKCR and HKCC are merged/derived views. So in forensics you analyze the underlying HKLM and per-user (NTUSER.DAT) hives — the "current user" convenience views don't exist on a dead disk. Mnemonic: machine + users are real; current-anything is a live convenience.


Where Hives Live On Disk (critical for forensics)

This is the part many people miss: the registry isn't one file — it's assembled at boot from several hive files. On a dead/imaged disk you parse these directly:

Hive (in regedit)File on diskHolds
HKLM\SYSTEMC:\Windows\System32\config\SYSTEMServices, drivers, network config, last-known-good, the boot key (SYSKEY)
HKLM\SOFTWAREC:\Windows\System32\config\SOFTWAREInstalled software, OS config, many Run keys, AmCache-adjacent data
HKLM\SAMC:\Windows\System32\config\SAMLocal user accounts + password hashes
HKLM\SECURITYC:\Windows\System32\config\SECURITYLSA secrets, cached domain creds, service-account passwords
HKU\<SID> (per user)C:\Users\<user>\NTUSER.DATThat user's settings, per-user Run keys, UserAssist, recent docs, typed paths
User "classes"C:\Users\<user>\AppData\Local\Microsoft\Windows\UsrClass.datPer-user COM/classes, Shellbags
Memory hook

"SAM + SECURITY = the credential prize; NTUSER.DAT = the user's behavior." When you image a Windows box, grabbing SAM and SECURITY (plus the SYSTEM hive for the boot key needed to decrypt them) lets you extract local hashes and LSA secrets offline — which is exactly what secretsdump/mimikatz do. And each user's NTUSER.DAT is a behavioral goldmine — what they ran, opened, and typed. Both the attacker (credential theft) and the analyst (reconstruction) target the same files.

bash
# Dump local hashes + LSA secrets OFFLINE from the hive files (impacket)
secretsdump.py -sam SAM -system SYSTEM -security SECURITY LOCAL
# (SYSTEM hive provides the boot key to decrypt SAM; SECURITY holds LSA secrets/cached creds)

Security-Critical Areas

1. Persistence (where malware survives a reboot)

The registry is the #1 place for autostart persistence. The must-know keys:

KeyMechanism
...\CurrentVersion\Run and RunOnce (HKLM and HKCU)Classic autostart — runs at logon. HKLM = all users, HKCU = that user.
...\Winlogon → Userinit, ShellHijack the logon process; Shell should be explorer.exe, Userinit should be userinit.exe — extra entries = persistence
HKLM\SYSTEM\CurrentControlSet\ServicesCreate/modify a service to run a binary or driver at boot (incl. kernel drivers → rootkits)
Image File Execution Options (IFEO) → DebuggerSet a "debugger" for a target exe → your binary launches whenever the target runs (also the "sticky keys" / accessibility backdoor trick)
AppInit_DLLs / AppCertDLLsForce a DLL into every process that loads user32.dll (legacy, now often blocked)
...\Explorer\Run, ...\Policies\Explorer\RunAdditional autostart locations
COM hijacking (HKCU\Software\Classes\CLSID\...\InprocServer32)Point a CLSID at a malicious DLL → loaded when an app instantiates that COM object
Memory hook

"Run keys are the front door; Services, Winlogon, and IFEO are the back doors." Defenders and tools like Autoruns (Sysinternals) check all of these because attackers moved past the obvious Run key long ago. The detection mindset: enumerate every autostart extensibility point (ASEP), diff against a known-good baseline, and flag anything pointing at an unsigned binary or an odd path (%TEMP%, %APPDATA%). MITRE ATT&CK groups these under T1547 (Boot/Logon Autostart) and T1112 (Modify Registry).

2. Credentials & secrets

  • HKLM\SAM — local account password hashes (NTLM).
  • HKLM\SECURITY\Policy\Secrets — LSA secrets: service-account plaintext passwords, cached domain credentials, auto-logon passwords.
  • HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon → DefaultPassword when AutoAdminLogon is set — a plaintext password sitting in the registry (a classic finding).
  • Credentials carelessly stored by software in their own keys.

3. Configuration & hardening (attacker tampering / defender baseline)

Attackers disable defenses via the registry, and defenders enforce settings there:

  • Disabling Defender, the firewall, UAC (EnableLUA), or SmartScreen via policy keys.
  • LSA\RunAsPPL (LSA Protection — protects LSASS from credential dumping).
  • Disabling security event logging, ETW, or AMSI.
  • Tampering here is itself a high-fidelity detection signal.

4. Forensic artifacts (what the user/attacker did)

The registry quietly records a rich behavioral timeline — these are DFIR staples:

ArtifactWhereWhat it proves
ShimCache / AppCompatCacheSYSTEM\...\AppCompatCachePrograms that existed/were run (execution & presence evidence) — survives deletion
AmCacheAmcache.hveExecuted program metadata + SHA-1 hashes of binaries
UserAssistNTUSER.DAT\...\UserAssistGUI programs the user launched, with run counts and timestamps (ROT13-encoded names)
ShellbagsUsrClass.dat\...\BagMRUFolders the user browsed — persists even after the folder is deleted
RecentDocs / typed paths / RunMRUNTUSER.DATFiles opened, paths typed in Explorer, commands run via Win+R
USB device historySYSTEM\...\USBSTOR, MountedDevicesRemovable devices ever attached (exfiltration evidence)
Network historySOFTWARE\...\NetworkListSSIDs/networks the machine connected to
Memory hook

the registry is a "passive flight recorder." Windows writes these artifacts for performance and convenience (app-compat, MRU lists, recent files), not for you — which is exactly why they're forensic gold: malware and users rarely think to scrub them. ShimCache/AmCache prove a binary existed and ran even after it's deleted; Shellbags prove someone opened a folder that no longer exists; USBSTOR proves a thumb drive was plugged in. When the logs are wiped, the registry artifacts often still tell the story.


Detection: Watching the Registry

Sysmon Event IDs 12 / 13 / 14

registry key/value create-delete (12), value set (13), and rename (14). The backbone of registry-change detection; tune them to the ASEPs above.

Windows Security Event 4657

a registry value was modified (requires auditing enabled on the key via a SACL).

EDR

hooks registry operations natively and ships them as telemetry.

What to alert on

new values under any Run/Services/Winlogon/IFEO key, especially pointing at unsigned binaries or user-writable paths; changes to security-disabling keys (Defender, UAC, LSA protection); AutoAdminLogon/DefaultPassword being set.

# Conceptual Sysmon rule intent (config in XML):
#   EventID 13 (value set) WHERE TargetObject CONTAINS
#   '\CurrentVersion\Run' OR '\Winlogon\Shell' OR '\Image File Execution Options\'
#   → alert; enrich with the Image that made the change (Office? a script host? = suspicious)
Memory hook

process-tree context turns a registry write into a detection. A registry write to a Run key is unremarkable on its own (installers do it constantly). It becomes a signal when you ask who wrote it: winword.exe or powershell.exe -enc ... writing to a Run key is a smoking gun, because Office and encoded PowerShell don't install autostarts. This is the endpoint-detection.md principle — correlate the registry event with the parent process.


Tools & Commands

cmd
:: Native CLI — query / add / delete
reg query "HKLM\Software\Microsoft\Windows\CurrentVersion\Run"
reg query "HKCU\Software\Microsoft\Windows\CurrentVersion\Run"
reg add  "HKCU\...\Run" /v Backdoor /t REG_SZ /d "C:\Users\u\AppData\Roaming\evil.exe" /f
reg delete "HKCU\...\Run" /v Backdoor /f
reg save HKLM\SYSTEM C:\temp\system.hiv     :: export a hive (also how attackers grab SAM/SYSTEM)

:: Enumerate ALL autostart entries (Sysinternals — the go-to)
autorunsc.exe -accepteula -a * -s   :: -s = verify signatures (flag unsigned)
ToolUse
regeditGUI browsing/editing
reg.exeScriptable CLI query/add/delete/save
Autoruns / autorunsc (Sysinternals)Enumerate every autostart location, verify signatures — #1 persistence hunt tool
Registry Explorer (Eric Zimmerman)DFIR-grade offline hive parsing (handles deleted keys, transaction logs)
RegRipperScriptable extraction of forensic artifacts from hive files
reg save / offline parsingAcquire hives from a live or imaged system for offline analysis

Interview Questions

Q
What is the Windows Registry and how is it structured?
Model answer

It's Windows' central hierarchical configuration database — a key-value store holding settings for the OS, drivers, services, software, and every user, consolidating what used to live in scattered INI files. Structurally it mirrors a filesystem: keys are like folders, values are like files, and each value has a name, a type (string, DWORD, binary, etc.), and data. At the top are five root keys, but only two are "real" stored data — HKLM for machine-wide settings and HKU for all loaded user profiles; HKCU is just a view into the current user's SID under HKU, and HKCR and HKCC are merged or derived views. On disk it's assembled from several hive files under System32\config plus each user's NTUSER.DAT, which matters because offline forensics parses those files directly.

Q
Where would you look in the registry for malware persistence?
Model answer

I'd enumerate all the autostart extensibility points, not just the obvious one. The classic Run and RunOnce keys under both HKLM and HKCU's CurrentVersion. The Winlogon keys — Shell should be exactly explorer.exe and Userinit should be userinit.exe, so any extra entries are persistence. The Services key under SYSTEM\CurrentControlSet, since a malicious service or driver runs at boot. Image File Execution Options, where a Debugger value hijacks a target exe — the basis of the sticky-keys backdoor. Plus AppInit_DLLs, Explorer Run policies, and COM hijacking via CLSID InprocServer32. In practice I'd run Sysinternals Autoruns to dump every ASEP, verify signatures, and flag anything unsigned or pointing at a user-writable path like AppData or Temp. These map to MITRE T1547 and T1112.

Q
An incident response team images a Windows machine. Which registry hives matter and why?
Model answer

The credential hives first: SAM holds local account NTLM hashes, SECURITY holds LSA secrets — service-account passwords, cached domain creds, auto-logon passwords — and SYSTEM holds the boot key needed to decrypt SAM, so you grab all three together and can extract credentials offline the same way secretsdump does. SOFTWARE and SYSTEM also hold persistence keys and execution artifacts like ShimCache and AmCache. Then each user's NTUSER.DAT and UsrClass.dat for behavioral evidence — UserAssist for programs they launched, Shellbags for folders they browsed, RecentDocs and typed paths, and USBSTOR for devices attached. The reason hives are so valuable in IR is that Windows writes much of this passively for performance, so it persists even after files are deleted or logs are cleared — ShimCache proving a now-deleted binary ran is a textbook example.

Q
How do you detect malicious registry changes?
Model answer

The backbone is Sysmon registry events — ID 12 for key create/delete, 13 for value set, 14 for rename — tuned to watch the autostart and security-disabling keys, plus Windows event 4657 if you've set SACL auditing on specific keys, and EDR which hooks registry operations natively. But the key to making it a real detection rather than noise is context: a write to a Run key is unremarkable because installers do it constantly, so I correlate it with the parent process — Word or an encoded PowerShell writing a Run key is a smoking gun, because those don't legitimately install autostarts. I'd alert specifically on new autostart entries pointing at unsigned binaries or user-writable paths, and on tampering with defenses like disabling Defender, UAC, or LSA protection, or setting AutoAdminLogon with a DefaultPassword.

Q
What's the difference between HKLM and HKCU, and why does it matter for an attacker?
Model answer

HKLM is machine-wide and affects all users, while HKCU is the current user's settings — really a view into that user's SID under HKU. The difference matters for both privilege and stealth. Writing persistence to HKLM (like the machine-wide Run key or a service) affects every user and survives across accounts, but it requires administrator rights because HKLM is protected. Writing to HKCU only needs the user's own privileges and runs when that user logs in — so a non-admin attacker who's compromised a user can establish persistence in HKCU without elevation, which is quieter and a common low-privilege foothold. So an attacker's choice of HKLM versus HKCU reflects what privileges they have and how broad and persistent they want the foothold to be, and defenders should watch both.

Q
How are credentials exposed via the registry, and how do you protect them?
Model answer

Several ways. The SAM hive stores local account NTLM hashes, and the SECURITY hive's LSA secrets store service-account plaintext passwords, cached domain credentials, and any auto-logon password — and with the SYSTEM hive's boot key these can be extracted offline by tools like secretsdump or mimikatz, which is why grabbing those hive files is a top attacker objective. A specific classic finding is AutoAdminLogon set with a DefaultPassword value under Winlogon, which is a plaintext password sitting in the registry. Protections: enable LSA Protection (RunAsPPL) to harden LSASS, prefer group-managed service accounts so there's no static password in LSA secrets, avoid auto-logon, restrict local admin and use LAPS so a stolen local hash isn't reusable across machines, and enable Credential Guard to isolate secrets. And monitor for the offline-dump pattern — processes saving the SAM, SYSTEM, or SECURITY hives.