Home / Blog / Cheat Sheets

Beginner Cheat Sheets

Windows Registry Basics: Hives, Keys, Values and Persistence Spots

A beginner guide to the Windows registry: hives, keys and values, the Run keys attackers abuse for persistence, and how to spot registry changes in logs.

The Windows registry is a database of settings that Windows and your applications read all the time, and it is one of the first places a SOC (Security Operations Centre) analyst looks when a machine behaves oddly. This guide explains the words you need (hive, key, value), the five root keys, and the handful of locations attackers use to make malware start again after a reboot.

TopicWindows registry structure and persistence locations
You will meet it inEDR alerts, Sysmon logs, malware write-ups, MITRE ATT&CK T1547.001
Study nextScheduled tasks, services and the Sysmon registry events
>

Scenario: Your EDR (Endpoint Detection and Response) tool raises an alert on workstation WS-114. A program called updater.exe started at logon from a user's AppData folder. Nothing looks wrong on screen, so you ask the obvious question: what made it start? The answer is often a single value in the registry.

What the registry actually is

Think of the registry as a folder tree, a bit like File Explorer, but for settings instead of documents. Windows stores things like which programs start at logon, how services are configured and what each user's desktop looks like. Microsoft describes it as a hierarchical database of configuration settings.

Four words matter, and you will see them in every alert:

KeyA folder in the tree. Keys can hold other keys (subkeys) and values.
ValueA named setting inside a key. It has a name, a type and some data.
HiveA group of keys and values stored together in a file on disk.

The fourth word is data: the actual content of a value. For a startup entry, the data is usually the path of the program to run. Common value types you will see are REG_SZ (text), REG_EXPAND_SZ (text with variables such as %APPDATA%), REG_DWORD (a number) and REG_BINARY (raw bytes).

The five root keys

When you open Registry Editor (regedit.exe), you see five top level keys. Each has a short form that you will see in logs and queries.

Root keyShort formWhat it holds
HKEY_LOCAL_MACHINEHKLMSettings for the whole computer, for every user
HKEY_CURRENT_USERHKCUSettings for the user who is logged on right now
HKEY_USERSHKUSettings for every loaded user profile, each under a SID (Security Identifier)
HKEY_CLASSES_ROOTHKCRFile type and program associations, a merged view of two other places
HKEY_CURRENT_CONFIGHKCCInformation about the hardware profile used at startup

Two of these are really shortcuts. HKCU points into HKU for the current user's SID, and HKCR merges entries from HKLM\SOFTWARE\Classes and HKCU\SOFTWARE\Classes. So the real storage is mainly HKLM and HKU.

i

Note: On disk, the machine hives live as files in C:\Windows\System32\Config (named SAM, SECURITY, SOFTWARE, SYSTEM and DEFAULT). Each user's HKCU hive is a file called NTUSER.DAT in their profile folder. Forensic tools read these files directly, which is why you may hear analysts talk about "pulling the hives" from a machine.

Reading the registry safely

You do not need to open regedit on a suspect machine. Read-only commands are quicker and leave less room for mistakes. Here are two ways to look at the per-user Run key, which lists programs that start when that user logs on.

Command Promptreg.exe
reg query "HKCU\Software\Microsoft\Windows\CurrentVersion\Run"

The command reg query only reads. It prints each value name, its type and its data. Nothing is changed.

PowerShellPowerShell
Get-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Run"

PowerShell treats the registry like a drive, so HKCU: works like C:. Get-ItemProperty shows every value in that key. Swap HKCU: for HKLM: to check the machine-wide version.

!

Watch out: Never edit or delete a registry value on a live machine as part of triage. Record what you saw (screenshot or copy the output), then follow your team's containment process. A wrong change can break Windows, and you may destroy evidence.

Where persistence hides

Persistence means an attacker arranges for their program to run again after a reboot or logon. MITRE ATT&CK, a public catalogue of attacker behaviour, lists this as technique T1547.001, Registry Run Keys / Startup Folder, under the Persistence tactic. The idea is simple: add a value to a Run key and Windows launches the program for you.

These are the locations to learn first:

HKCU Run and RunOnce

Medium
Path

HKCU\Software\Microsoft\Windows\CurrentVersion\Run

Why it matters

Runs at that user's logon and does not need administrator rights to change, so it is easy for an attacker who has only a normal user account.

HKLM Run and RunOnce

High
Path

HKLM\Software\Microsoft\Windows\CurrentVersion\Run

Why it matters

Runs for every user who logs on. Changing it needs administrator rights, so a new entry here suggests the attacker already has high privileges.

Winlogon Shell and Userinit

High
Path

HKLM\Software\Microsoft\Windows NT\CurrentVersion\Winlogon

Why it matters

The Shell value normally says explorer.exe. Anything extra added to it runs when the desktop loads, which is rare and worth a close look.

RunOnce keys work the same way but Windows removes the entry after it runs once, so you may only catch it in logs. The startup folder is a file-based cousin of the Run keys: C:\Users\<name>\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup for one user, and C:\ProgramData\Microsoft\Windows\Start Menu\Programs\StartUp for everyone.

+

Tip: Plenty of normal software uses Run keys, such as cloud storage clients, chat apps and printer tools. A Run entry is not bad by itself. Look at the path (Program Files is expected, AppData or Temp deserves a question) and at who or what created it.

What registry changes look like in logs

Windows does not record every registry change by default. You need something turned on first, and it helps to know which tool produces which event.

  • Sysmon event ID 13 (Registry value set) records a value being written. It includes the process (Image), the full key path (TargetObject) and the new data (Details). Sysmon only logs it if your configuration has registry rules.
  • Sysmon event ID 12 covers keys and values being created or deleted, and 14 covers renames.
  • Security event 4657 (A registry value was modified) only appears if registry auditing is enabled and the key has an audit rule on it.
  • EDR tools usually collect registry activity themselves, so check the process tree in the console before anything else.

Here is a made-up Sysmon event 13, shortened, for the scenario above. Notice the process that did the writing and the data it wrote.

Sysmon event 13Example
EventType: SetValue
Image: C:\Windows\System32\reg.exe
TargetObject: HKU\S-1-5-21-1111111111-2222222222-3333333333-1001\Software\Microsoft\Windows\CurrentVersion\Run\Updater
Details: C:\Users\jsmith\AppData\Roaming\updater.exe

A built-in tool (reg.exe) wrote a startup entry that points at an executable in AppData. Neither fact proves an attack, but together they are a good reason to keep digging.

A simple Splunk search

If your Sysmon logs are in Splunk, this short search finds new Run key values. The index name is a placeholder, so use the one in your own environment.

SplunkSPL
index=sysmon EventCode=13 TargetObject="*CurrentVersion\\Run*"
| table _time host Image TargetObject Details
| sort - _time

Line by line: the first line picks Sysmon event 13 where the key path contains CurrentVersion\Run (in SPL, a backslash inside quotes is written twice). The second line shows only the columns you need. The third line puts the newest first. This also matches RunOnce, which is useful. Field names depend on how your Sysmon data is parsed, so check one raw event first.

Triage questions to ask

When a registry persistence alert lands in your queue, work through these questions in order.

  • Which key and value changed, and what is the data (the program path)?
  • Which process made the change? A software installer is very different from cmd.exe or powershell.exe.
  • Does the path look normal? Program Files is expected. AppData, Temp, Public or ProgramData need a second look.
  • Which user or account was involved, and were they logged on at the time?
  • Did the same program appear on other hosts? Search for the file name or hash across the estate.
  • Was a software install or patch running at that time? If so, this may be a false positive (an alert that fires on harmless activity).

If the answers look suspicious, escalate with your notes. Include the key path, value name, data, process, user and timestamps (in UTC, ideally), so the next person does not repeat your work.

Key takeaways

  1. A key is a folder, a value is a named setting, and a hive is a group of keys stored in one file.
  2. Remember the five roots (HKLM, HKCU, HKU, HKCR, HKCC). In practice, HKLM and HKU hold the real data.
  3. Run and RunOnce keys, the Winlogon Shell value and the Startup folders are the first persistence spots to check (MITRE ATT&CK T1547.001 and related techniques).
  4. Read the registry with read-only commands and never change values on a live system during triage.
  5. Sysmon event 13 and Security event 4657 record registry changes, but only when you have switched on the right logging.

To keep going, practise on a lab virtual machine you own: look at your own Run keys with the two commands above, install a harmless program, and watch what changes. Then read about scheduled tasks and services, the other two common persistence places. When you plan your CySA+ and Security+ study, check the official CompTIA exam objectives pages for the current topic lists rather than relying on any single blog.

Written by Ben, Cybersecurity Student

Keep going

More in Cheat Sheets