Windows Registry Internals

Objective: Explore the internal structure and functionality of the Windows Registry, including its hive-based architecture, key-value model, data types, and how it enables system configuration. Understand how attackers leverage registry paths such as Run keys for persistence, and how defenders can detect and investigate these techniques.

Introduction

The Windows Registry is a centralized, hierarchical database used by the Windows operating system and many applications for configuration and operational data.

It stores everything from hardware driver configs, installed software settings, user preferences, and system boot configuration to startup execution paths, which makes it an attractive target for attackers seeking persistence and privilege escalation.


Registry Architecture Overview

The Windows Registry is structured like a file system:

  • Keys = Folders
  • Values = Files
  • Hives = Root-level logical divisions (backed by real files)

The Registry is accessible via:

  • Registry Editor (regedit.exe)
  • API calls like RegOpenKeyEx, RegQueryValueEx, RegSetValueEx
  • Command-line tools (reg.exe, powershell, regedit, wmic)

Core Registry Hives

Each hive maps to a physical file on disk. Hives are loaded into memory during system boot or user login.

Major Root Hives

HiveDescriptionBacking File
HKEY_LOCAL_MACHINE (HKLM)Machine-wide configurationSYSTEM, SOFTWARE, etc.
HKEY_CURRENT_USER (HKCU)Current logged-in user’s settingsNTUSER.DAT
HKEY_CLASSES_ROOT (HKCR)File extension and COM associationsAlias of HKLM\Software\Classes and HKCU\Software\Classes
HKEY_USERS (HKU)All user profiles loadedIncludes SID-named keys
HKEY_CURRENT_CONFIG (HKCC)Dynamic hardware profile dataDerived from HKLM\SYSTEM

Registry File Locations

FilePurposePath
SYSTEMKernel drivers, boot info%SystemRoot%\System32\Config\SYSTEM
SOFTWAREInstalled programs, OS settings%SystemRoot%\System32\Config\SOFTWARE
SECURITYLocal security policies%SystemRoot%\System32\Config\SECURITY
SAMLocal user/password database%SystemRoot%\System32\Config\SAM
NTUSER.DATCurrent user settings%UserProfile%\NTUSER.DAT

These files are locked during runtime and can be accessed offline using tools like FTK Imager or Registry Explorer.


Keys, Values, and Data Types

Keys

A key is similar to a directory and can contain:

  • Subkeys
  • Values
  • A default unnamed value

Values

Each key can contain one or more values, which consist of:

  • Name
  • Data Type
  • Data

Registry Data Types

TypeSymbolDescription
REG_SZStringPlain text string
REG_EXPAND_SZExpandable stringSupports environment variables
REG_DWORD32-bit numberOften used for flags/settings
REG_QWORD64-bit numberUsed in newer configurations
REG_BINARYBinary dataRaw hex, often device configurations
REG_MULTI_SZMulti-stringArray of strings, null-delimited

Registry Pathing

Registry paths are expressed like filesystem paths:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion

PowerShell can be used to browse and interact with registry keys as if they are drives:

cd HKLM:\SOFTWARE\Microsoft\Windows
Get-ItemProperty .


Run Key Persistence

One of the most abused persistence techniques is via the Run or RunOnce registry keys.

Common Run Key Paths

LocationDescription
HKLM\Software\Microsoft\Windows\CurrentVersion\RunRuns for all users at boot
HKLM\Software\Microsoft\Windows\CurrentVersion\RunOnceRuns only once for all users
HKCU\Software\Microsoft\Windows\CurrentVersion\RunRuns at login for the current user
HKCU\Software\Microsoft\Windows\CurrentVersion\RunOnceRuns only once for current user

Example (Manual Persistence)

Set-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Run" `
 -Name "Updater" `
 -Value "C:\Users\Public\updater.exe"

This would launch updater.exe at user logon.

Detection Tip:

  • Use Autoruns from Sysinternals or check registry directly:
Get-ItemProperty 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Run'


Other Registry Persistence Locations

KeyPurpose
HKLM\Software\Microsoft\Active Setup\Installed ComponentsUsed by IE and apps to auto-start on login
HKLM\SYSTEM\CurrentControlSet\ServicesCreate a persistent service
HKLM\Software\Microsoft\Windows NT\CurrentVersion\Winlogon\UserinitModify login initialization
HKLM\Software\Microsoft\Windows\CurrentVersion\ShellServiceObjectDelayLoadDelayed loading COM object
HKCU\Software\Microsoft\Windows NT\CurrentVersion\Windows\loadLegacy autorun vector
HKLM\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\RunPersistence in 32-bit view on 64-bit system

Registry Backup and Restore

Backup entire hives with:

reg export HKLM\Software software_backup.reg

Restore with:

reg import software_backup.reg

For forensics, extract registry hives offline and analyze them using:

  • Registry Explorer
  • Eric Zimmerman’s RECmd
  • FTK Imager
  • Autopsy or Volatility plugins for memory dumps

Registry Permissions and ACLs

Each key has its own ACL (Access Control List), viewable with:

(Get-Acl 'HKLM:\Software\Microsoft\Windows').Access

Tools like SetACL, PowerShell, or psexec can be used to escalate via insecure permissions (e.g., attacker can write to a privileged run key).


Red Team & Malware Use Cases

TechniqueAbuse
Startup ExecutionRun keys, RunOnce, ActiveSetup
Service HijackingModify ImagePath under Services
Userinit/LoginAppend malicious payload to Userinit or Shell
COM HijackRegister fake COM object in HKCR\CLSID
AV EvasionHide payload in registry as base64 or encrypted blob under benign key, decode in memory

Example of storing payload as encoded string:

Set-ItemProperty -Path "HKCU:\Software\Microsoft\Something" -Name "Config" -Value ([Convert]::ToBase64String([IO.File]::ReadAllBytes("payload.dll")))


Registry Forensics

For DFIR analysts, registry artifacts can indicate:

  • Malware persistence
  • User activity (recent files, typed paths)
  • USB device history (SYSTEM\CurrentControlSet\Enum\USBSTOR)
  • Program execution evidence (e.g., UserAssist, ShimCache)
  • MRU (Most Recently Used) lists

Recommended Tools:

  • Eric Zimmerman’s Registry Explorer + RECmd
  • NirSoft tools (ShellBagsView, USBDeview, etc.)
  • Velociraptor for live enterprise-wide registry search

Summary

  • The Windows Registry is a core part of system configuration and operation.
  • It uses hives, keys, values, and types to store structured data.
  • Persistence via Run keys is trivial and highly common.
  • Powerful red team techniques involve modifying service, COM, or logon keys.
  • Defensive tools can monitor or lock registry keys to prevent abuse.

0 0 votes
Article Rating
guest
0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments