Windows Fundamentals · beginner · ~10 min
**What you will learn** - Navigate the registry's hives (HKLM, HKCU, and the others) and explain how keys, values, and value types are organized. - Read registry data safely from the command line with `reg query` and understand what `regedit` shows you. - Identify the security-relevant locations that matter on a Windows assessment: autorun (`Run`) keys, autologon credentials, and the `AlwaysInstallElevated` policy. - Explain *why* each of these is a persistence or privilege-escalation concern, in terms of who can write where. - Remediate the common misconfigurations and **verify** the fix with a follow-up query. - Know which registry-audit events to log so defenders can detect tampering.
Security objective: the asset you are protecting is the integrity and confidentiality of Windows configuration data. The registry decides what runs at boot, what privileges an installer gets, and sometimes stores credentials in plaintext. The threats are (1) persistence — an attacker plants an entry so their code re-runs after reboot, and (2) privilege escalation — a low-privileged user abuses a writable machine-wide key or a permissive policy to gain SYSTEM. By the end you will be able to detect these misconfigurations by querying the registry and prevent them by fixing permissions and policies.
The registry is Windows' central, hierarchical configuration database. Instead of scattering settings across dozens of text files (as on Unix), Windows keeps operating-system, driver, service, and application settings together in one tree. Programs read and write it constantly.
The tree is divided into hives at the top. The two you will use most are:
HKEY_LOCAL_MACHINE) — machine-wide settings that apply to every user. Writing here normally requires administrator rights.HKEY_CURRENT_USER) — settings for the user who is logged in right now. A normal user can write their own HKCU freely.This lesson sits in the Windows Fundamentals track. It builds on the previous lesson on Windows services (win-services) — many services are configured through registry keys, and a service that launches a program named in a writable key is a classic escalation path. It leads into the Event Viewer and Windows logging lesson (win-event-viewer), where you will see how registry changes are recorded so defenders can catch them. No prior lessons are required beyond basic comfort with a Windows command prompt.
Throughout, remember the difference between reading and changing the registry. Enumeration (reading) is low-risk. Changing keys can break a machine, so every write in this lesson happens only on a system you own or are explicitly authorized to test — a personal VM, a lab container, or a purpose-built vulnerable box.
In authorized professional work — a Windows penetration test, a configuration audit, or blue-team hardening — the registry is a recurring checkpoint. It holds three things that decide security outcomes:
Run keys, service definitions, and similar locations list programs that launch automatically. Attackers use them for persistence; when a machine-wide autostart key is writable by a normal user, it also becomes an escalation path.AlwaysInstallElevated change the security model of the whole machine. When set, any user can install an MSI as SYSTEM.For a defender, the same knowledge is what lets you harden a build: lock down key permissions, disable dangerous policies, remove leftover secrets, and turn on auditing so tampering shows up in the logs. Checking Run keys, autologon values, and AlwaysInstallElevated is routine on both sides of the engagement — offense reports them, defense removes them.
The registry has a small number of ideas. Learn each one on its own, then see how they combine into the security-relevant locations.
Definition: hives are the top-level roots of the registry tree.
Plain explanation: think of hives as the top folders of a filesystem. Everything else lives inside one of them.
How it works: the main hives are:
| Hive | Full name | Scope | Who can normally write |
|---|---|---|---|
| HKLM | HKEY_LOCAL_MACHINE | Whole machine, all users | Administrators / SYSTEM |
| HKCU | HKEY_CURRENT_USER | The logged-in user only | That user |
| HKCR | HKEY_CLASSES_ROOT | File-type and COM associations | Admin (it is a merged view) |
| HKU | HKEY_USERS | All loaded user profiles | Admin |
| HKCC | HKEY_CURRENT_CONFIG | Current hardware profile | Admin |
When it matters: the scope of a hive tells you the blast radius. A change in HKCU affects one user; a change in HKLM affects everyone and usually needs admin rights. That difference is the heart of most registry-based escalation reasoning.
Pitfall: HKCR and HKCC are views built from HKLM and HKU, not independent stores. Editing the same setting in two places can confuse you — prefer the underlying HKLM/HKU location.
Definition: keys are containers (like folders); values are the named data entries inside a key.
Plain explanation: a key is a folder; a value is a named setting inside it. A value has three parts: a name, a type, and data.
How it works: common value types include REG_SZ (text string), REG_DWORD (32-bit number, often a 0/1 flag), REG_BINARY (raw bytes), and REG_MULTI_SZ (list of strings). The special value name (Default) is the unnamed value every key can hold.
When/when-not: you read values to learn configuration; you change them only when hardening or in an authorized lab. Never edit values on a production machine you do not own.
Pitfall: the type matters. A policy that expects a REG_DWORD of 1 will ignore a REG_SZ value of "1". Wrong type = setting silently does nothing.
Definition: keys whose values name programs Windows starts automatically at logon or boot.
Plain explanation: each value in a Run key is "launch this program". Windows walks the list and starts everything in it.
How it works: the classic locations are HKLM\Software\Microsoft\Windows\CurrentVersion\Run (runs for every user) and HKCU\Software\Microsoft\Windows\CurrentVersion\Run (runs for the current user). There is also RunOnce (runs a single time then deletes the entry).
When it matters: for persistence, an attacker adds a value so their code re-launches after reboot. For escalation, the danger is permissions: if a normal user can write to an HKLM Run key or to the file a Run value points at, and that program later runs in an administrator's or SYSTEM context, the low-privileged user's code inherits those privileges.
Pitfall: an entry in an HKCU Run key runs only as that user — it is persistence, not escalation. Do not overstate impact: escalation needs a trust boundary to be crossed (low user's input running as high user).
Definition: credentials left in the registry as readable data.
Plain explanation: some software, and the Windows autologon feature, save a username and password so login is automatic. The autologon password is stored in cleartext under Winlogon.
How it works: the values DefaultUserName, DefaultDomainName, and DefaultPassword live under HKLM\Software\Microsoft\Windows NT\CurrentVersion\Winlogon. If DefaultPassword is present, anyone who can read that key learns the password.
When it matters: finding these during an authorized audit is a reportable finding. The fix is to stop using plaintext autologon (or at least use the LSA-secret mechanism instead of a cleartext value).
Pitfall: absence of DefaultPassword does not prove autologon is off — some setups store the secret as an LSA secret instead. Report what you can verify, not what you assume.
Definition: a policy that, when enabled in both HKLM and HKCU, lets any user install MSI packages with SYSTEM privileges.
Plain explanation: it is meant to let non-admins install approved software, but it effectively hands SYSTEM to any user who can run an installer.
How it works: the REG_DWORD value AlwaysInstallElevated must equal 1 under both HKLM\Software\Policies\Microsoft\Windows\Installer and HKCU\Software\Policies\Microsoft\Windows\Installer. If either is missing or 0, the escalation does not apply.
When it matters: it is one of the highest-severity Windows misconfigurations because it is an instant, reliable path to SYSTEM. Auditors always check it; defenders always disable it.
Pitfall: checking only HKLM (or only HKCU) is a common mistake — the policy needs both set to 1 to be exploitable. Reporting it as exploitable when only one is set is a false positive.
THREAT MODEL — Windows registry misconfigurations
ASSET: config integrity + stored secrets that decide what
runs, at what privilege, on this Windows host
ACTORS
[ Low-privileged user ] <-- untrusted, our test account
[ Administrator / SYSTEM ] <-- high trust, runs autostart items
TRUST BOUNDARY
====================================================
HKCU (user can write own) | HKLM (admin-only)
------------------------------------------------
user-scope autostart | machine-scope autostart
(persistence, same user) | (persistence + escalation
| IF writable by low user)
====================================================
ENTRY POINTS a reviewer inspects
- HKLM\...\Run, RunOnce -> autostart, check ACLs
- Winlogon DefaultPassword -> plaintext secret
- HKLM & HKCU AlwaysInstallElevated -> policy escalation
- file paths named by Run values -> writable target?
ESCALATION occurs only when the boundary is crossed:
low user controls input (key/value/file) that a high
user (admin/SYSTEM) later executes.
Knowledge check
HKCU\...\Run launches a program every time you log in. Is that persistence, escalation, or both — and what insecure assumption would make you call it escalation by mistake?AlwaysInstallElevated is 1 in HKLM but the HKCU value is missing. Is the machine exploitable through this policy? Why or why not?Run value was added or a Winlogon value changed? (You will meet it in the next lesson.)The command-line tool is reg. For enumeration you almost always use reg query. The graphical editor is regedit.
REM Read one value from a key. /v names the value.
reg query "HKLM\Software\Microsoft\Windows\CurrentVersion\Run"
REM Read a single named value.
reg query "HKCU\Software\Microsoft\Windows NT\CurrentVersion\Winlogon" /v DefaultUserName
REM Recursively search all hives for a keyword (case-insensitive).
reg query HKLM /f password /t REG_SZ /s
REM Add / change a value (LAB ONLY, admin for HKLM).
REM /t = type, /d = data, /f = don't prompt for confirmation.
reg add "HKCU\Software\Policies\Microsoft\Windows\Installer" /v AlwaysInstallElevated /t REG_DWORD /d 1 /f
REM Delete a value (used here for cleanup / remediation).
reg delete "HKCU\Software\Policies\Microsoft\Windows\Installer" /v AlwaysInstallElevated /f
Key flags: /v <name> targets a value, /t <type> sets the type, /d <data> sets the data, /s recurses, /f skips the "are you sure" prompt, and /f <pattern> with /f in a query is the search pattern. Reads are safe to run anywhere you are authorized; writes (reg add, reg delete) change the system and belong only in your lab.
A useful built-in for auditing autostarts is Get-CimInstance in PowerShell, but the community standard is Sysinternals Autoruns (autorunsc.exe) for a full inventory — mentioned here as a real tool, not required for the exercises.
The registry is Windows' hierarchical configuration database. It keeps settings for the OS, drivers, services, and applications together in one tree.
Hives are the top-level roots:
Inside a hive, keys act like folders. Each key holds values, where a name maps to typed data.
Autorun and persistence
HKLM\...\Run, HKCU\...\Run, and service keys.Stored secrets
winlogon autologon credentials are stored here in plaintext.AlwaysInstallElevated
reg query and reg add — the command-line interface.regedit — the graphical editor.Searching the registry for credentials and writable autorun keys is standard Windows enumeration.
The shape below is INSECURE → SECURE → VERIFY. All three parts run in a Windows command prompt on a machine you own or are authorized to test. The insecure step deliberately creates a bad configuration so you can practise detecting and fixing it. Nothing here is an exploit — it is a misconfiguration you plant and then remediate.
REM --- Plant the AlwaysInstallElevated misconfiguration (LAB ONLY) ---
REM Requires an elevated prompt for the HKLM half.
reg add "HKLM\Software\Policies\Microsoft\Windows\Installer" /v AlwaysInstallElevated /t REG_DWORD /d 1 /f
reg add "HKCU\Software\Policies\Microsoft\Windows\Installer" /v AlwaysInstallElevated /t REG_DWORD /d 1 /f
REM --- Plant a plaintext autologon secret (LAB ONLY, placeholder value) ---
reg add "HKLM\Software\Microsoft\Windows NT\CurrentVersion\Winlogon" /v DefaultPassword /t REG_SZ /d <development-placeholder> /f
After this, a reviewer's enumeration would flag the box: the policy is set in both hives, and a cleartext password value exists. This is exactly the state you want to be able to detect and fix.
REM Is AlwaysInstallElevated set in BOTH hives? (Both == exploitable.)
reg query "HKLM\Software\Policies\Microsoft\Windows\Installer" /v AlwaysInstallElevated
reg query "HKCU\Software\Policies\Microsoft\Windows\Installer" /v AlwaysInstallElevated
REM Any autologon password left in cleartext?
reg query "HKLM\Software\Microsoft\Windows NT\CurrentVersion\Winlogon" /v DefaultPassword
REM List machine-wide autostart programs to review.
reg query "HKLM\Software\Microsoft\Windows\CurrentVersion\Run"
Expected output when the misconfig is present (data shown as a placeholder):
HKEY_LOCAL_MACHINE\Software\Policies\Microsoft\Windows\Installer
AlwaysInstallElevated REG_DWORD 0x1
HKEY_CURRENT_USER\Software\Policies\Microsoft\Windows\Installer
AlwaysInstallElevated REG_DWORD 0x1
HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Winlogon
DefaultPassword REG_SZ <development-placeholder>
Both hives showing 0x1 is the finding. If only one hive shows it, the policy is not exploitable — report accordingly.
REM Disable AlwaysInstallElevated in both hives (set to 0 or delete).
reg add "HKLM\Software\Policies\Microsoft\Windows\Installer" /v AlwaysInstallElevated /t REG_DWORD /d 0 /f
reg add "HKCU\Software\Policies\Microsoft\Windows\Installer" /v AlwaysInstallElevated /t REG_DWORD /d 0 /f
REM Remove the plaintext autologon password.
reg delete "HKLM\Software\Microsoft\Windows NT\CurrentVersion\Winlogon" /v DefaultPassword /f
reg delete "HKLM\Software\Microsoft\Windows NT\CurrentVersion\Winlogon" /v AutoAdminLogon /f
REM Bad state should now be gone: the query should report 0x0 or "unable to find".
reg query "HKLM\Software\Policies\Microsoft\Windows\Installer" /v AlwaysInstallElevated
reg query "HKCU\Software\Policies\Microsoft\Windows\Installer" /v AlwaysInstallElevated
REM Secret should be gone: expect "ERROR: The system was unable to find the specified value".
reg query "HKLM\Software\Microsoft\Windows NT\CurrentVersion\Winlogon" /v DefaultPassword
Expected verification output:
AlwaysInstallElevated REG_DWORD 0x0
AlwaysInstallElevated REG_DWORD 0x0
ERROR: The system was unable to find the specified registry key or value: DefaultPassword
The verify step is what turns "I changed something" into "I proved the vulnerable state is gone and the safe state holds." A remediation you cannot re-query is not finished.
Walking through the DETECT and VERIFY commands, since those are the ones you will run most on an assessment.
reg query "HKLM\...\Installer" /v AlwaysInstallElevated — asks for one named value in the HKLM policy key. reg prints the key path, then a line with the value name, type, and data. If the value does not exist you get ERROR: The system was unable to find....HKCU\...\Installer — you must run both. Only if both return 0x1 is the policy exploitable. This two-key requirement is the single most common thing beginners get wrong.reg query "...\Winlogon" /v DefaultPassword — reads the autologon password value. Its mere presence is the finding; you do not need to (and should not) copy the data into a report — record that a cleartext credential exists and where.reg query "HKLM\...\Run" (no /v) — with no value name, reg lists all values under the key, giving you the full machine-wide autostart inventory to review against known-good software.The VERIFY commands are the same queries after remediation. Follow the data field:
| Step | Command target | Data before | Data after | Meaning |
|---|---|---|---|---|
| Policy HKLM | AlwaysInstallElevated | 0x1 |
0x0 |
Escalation half disabled |
| Policy HKCU | AlwaysInstallElevated | 0x1 |
0x0 |
Escalation half disabled |
| Secret | DefaultPassword | present | not found | Cleartext credential removed |
When the after column matches the right side, and the queries confirm it, the machine no longer exhibits the finding. That confirmation — re-running the exact detection command and seeing a safe result — is the mitigation-verification step required for every finding.
Mistake 1 — Reporting AlwaysInstallElevated from one hive.
AlwaysInstallElevated = 1 in HKLM only and calling the box exploitable.1. One hive alone does nothing.1.Mistake 2 — Calling an HKCU Run entry "privilege escalation."
Mistake 3 — Editing the registry on a machine you do not own.
reg add/reg delete during a test without clear scope, or on production.Mistake 4 — Wrong value type.
REG_SZ "1" instead of REG_DWORD 1./t REG_DWORD.Mistake 5 — Copying a real secret into your notes.
DefaultPassword value into a report or ticket.Common problems and how to work through them:
ERROR: Access is denied. You are querying or writing a key that needs higher rights. Reads of some HKLM subkeys and any HKLM write need an elevated (Run as administrator) prompt. Open an admin command prompt and retry. If a read is denied, that itself is information about the key's ACL.ERROR: The system was unable to find the specified registry key or value. The key or value does not exist. For a detection query this is often the good result (the misconfig is absent). Double-check the exact path and value name — a single wrong word (e.g. Windows NT vs Windows) points at a different key.reg query shows REG_DWORD vs REG_SZ; policies expect DWORDs. Re-add with the correct /t.reg query HKLM /f password /s returns nothing or hangs. Recursive searches over a whole hive are slow and can be large; scope the search to a subtree (e.g. a specific Software path) and add /t REG_SZ to limit types.reg add values — expected, and a reminder that the durable fix is at the policy layer, not a one-off value.Questions to ask when a registry check fails or surprises you:
Windows vs Windows NT, spelling)?0x1 = enabled)?Security & safety — detection, logging, and evidence handling
The registry is a favorite place for attackers to hide, so defenders must be able to see changes to it. Enable auditing and forward the events.
What to log (registry-relevant Windows events):
What to NEVER log:
DefaultPassword). Log that the value at a path changed, not the password itself.Which events signal abuse:
Run/RunOnce key, especially pointing to a user-writable path or a temp directory.AlwaysInstallElevated flipping to 1 in either hive.DefaultPassword/AutoAdminLogon appearing under Winlogon.How false positives arise:
Evidence handling: if a value must be captured as proof, store it in an approved, access-controlled evidence location, redact any secret data, and reference it by path and hash in the report rather than pasting the raw secret.
Authorized real-world use case: during a scoped internal Windows penetration test, a reviewer enumerates a workstation's registry to look for quick escalation and hygiene issues. They read (never blindly write) the Run keys, Winlogon autologon values, and the AlwaysInstallElevated policy in both hives. Finding AlwaysInstallElevated = 1 in both hives, they document a high-severity finding, provide a safe reproduction, and hand the client a remediation (set to 0/delete via GPO) plus a retest query. The blue team, in parallel, uses the same knowledge to write a detection: alert when AlwaysInstallElevated is set or when a Run key gains a value pointing at a user-writable path.
Professional best-practice habits:
| Habit | Beginner focus | Advanced focus |
|---|---|---|
| Validation | Confirm exact key paths and value types before acting | Cross-check policy across HKLM+HKCU and against GPO source |
| Least privilege | Read-only enumeration; only write in your own lab | Recommend tightening key ACLs so non-admins cannot write HKLM autostarts |
| Secure defaults | Disable AlwaysInstallElevated; avoid plaintext autologon | Enforce via Group Policy baselines (CIS-style) across the fleet |
| Logging | Know that 4657/Sysmon 12-14 record changes | Deploy SACLs + Sysmon config and tune out installer/GPO noise |
| Error handling | Treat "access denied" and "not found" as data, not failure | Automate enumeration with idempotent, logged, reversible scripts |
Beginners should aim to read, understand, report, and verify a fix. Advanced practitioners move to fleet-wide hardening baselines, detection engineering, and ACL analysis of who can write which autostart locations.
All tasks are lab-only: run them on a personal Windows VM, a disposable container, or an intentionally-vulnerable practice box you own or are explicitly authorized to use. Never against systems you do not control.
Authorization checklist (complete before any write):
Beginner 1 — Map the hives.
reg query, list the top of HKLM and HKCU, then read one value from a harmless key (e.g. HKLM\Software\Microsoft\Windows NT\CurrentVersion /v ProductName).reg add/reg delete.reg query <key> with no /v lists everything under a key.Beginner 2 — Inventory autostart entries.
HKLM\...\CurrentVersion\Run and HKCU\...\CurrentVersion\Run. For each value, write down whether it would run machine-wide or for the current user only.Intermediate 1 — Detect AlwaysInstallElevated correctly.
1), then write the exact two queries that determine exploitability. Then set HKCU to 0 and re-run — show that it is now not exploitable even though HKLM is still 1.0x1/0x0 results for each state.REG_DWORD type.1; either being 0/absent means safe.0, then verify with the same queries.Intermediate 2 — Find and safely handle a stored secret.
DefaultPassword with a <development-placeholder> value, then query Winlogon to detect it. Write a one-line finding that records the location but not the secret.reg delete the value and any AutoAdminLogon, then re-query to prove it is gone.Challenge — End-to-end detect → remediate → verify → detect (defensive).
DefaultPassword; (2) write a short script/checklist that detects both issues; (3) remediate both; (4) re-run the detection to verify a clean result; (5) describe which log/Sysmon events would have recorded each change and one plausible false positive for each.Lab cleanup / reset steps:
reg delete "HKLM\Software\Policies\Microsoft\Windows\Installer" /v AlwaysInstallElevated /freg delete "HKCU\Software\Policies\Microsoft\Windows\Installer" /v AlwaysInstallElevated /freg delete "HKLM\Software\Microsoft\Windows NT\CurrentVersion\Winlogon" /v DefaultPassword /freg delete "HKLM\Software\Microsoft\Windows NT\CurrentVersion\Winlogon" /v AutoAdminLogon /fMain concepts. The registry is Windows' central configuration database, organized into hives (HKLM = machine-wide/admin, HKCU = current user) that contain keys (folders) and values (name + type + data). Three security-relevant areas: autorun (Run) keys (persistence, and escalation when a machine-wide key or its target is writable by a low user), stored secrets (Winlogon DefaultPassword in cleartext), and the AlwaysInstallElevated policy (SYSTEM installs when set to 1 in both HKLM and HKCU).
Key syntax/commands. reg query <key> [/v <name>] [/s /f <pattern>] to read; reg add ... /t REG_DWORD /d 1 /f and reg delete ... /f to change (lab only); regedit for the GUI.
Common mistakes. Reporting AlwaysInstallElevated from one hive; calling an HKCU Run entry "escalation" (no boundary crossed); editing a machine you do not own; wrong value type; copying real secrets into notes.
What to remember. Reads are safe; writes belong only in an authorized lab. Escalation requires a low user's input to run in a higher context — always ask who writes vs who runs. Every finding needs a fix plus a verification (re-run the detection and see a clean result), and defenders should log registry changes (Event ID 4657, Sysmon 12–14) while never logging the secret values themselves. Nothing is ever "completely secure" — you reduce and detect risk, then prove it.