Windows Internals

Core concepts for understanding and testing Windows systems.


Architecture Overview

User mode:
  Applications, Services, Win32 Subsystem, Ntdll.dll

Kernel mode:
  Executive (I/O, memory, process/thread mgr, security)
  Kernel (scheduling, interrupts, synchronisation)
  HAL (Hardware Abstraction Layer)
  Device Drivers

User mode processes communicate with the kernel via system calls through ntdll.dll.


Processes & Threads

  • Every process has its own virtual address space, access token, and handle table
  • Threads share the process’s address space
  • PID 4 = System process (kernel-level activity)
# Enumerate processes
Get-Process
tasklist /v
Get-CimInstance Win32_Process | Select Name,ProcessId,ParentProcessId,CommandLine

Access Tokens

Every process and thread has an access token defining its security context:

  • User SID — who owns the process
  • Group SIDs — group memberships
  • Privileges — special capabilities (SeDebugPrivilege, SeImpersonatePrivilege, etc.)
  • Integrity level — Low, Medium, High, System

Key privileges for attackers:

PrivilegeImpact
SeDebugPrivilegeRead/write memory of any process (incl. LSASS)
SeImpersonatePrivilegeImpersonate tokens → SYSTEM (via Potato attacks)
SeAssignPrimaryTokenPrivilegeAssign tokens to processes
SeTakeOwnershipPrivilegeTake ownership of any object
SeBackupPrivilegeRead any file regardless of ACL
SeRestorePrivilegeWrite any file regardless of ACL
SeLoadDriverPrivilegeLoad kernel drivers
# Check current token privileges
whoami /priv
 
# Check group memberships
whoami /groups

Registry

Hierarchical database storing configuration for OS and applications.

Root hives:

HiveDescription
HKLMLocal Machine — system-wide settings
HKCUCurrent User — current user settings
HKUUsers — all user profiles
HKCRClasses Root — file type associations
HKCCCurrent Config — hardware profile
# Query
reg query HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run
Get-ItemProperty "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion"
 
# Search for passwords
reg query HKLM /f password /t REG_SZ /s
reg query HKCU /f password /t REG_SZ /s
 
# Autorun persistence locations
HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run
HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Run
HKLM\SYSTEM\CurrentControlSet\Services\  # Services

Windows Services

# List services
sc query type=all state=all
Get-Service
Get-CimInstance Win32_Service | Select Name,StartName,PathName,State
 
# Service permissions
sc sdshow <service>
accesschk.exe -ucqv <service>

Service binary path hijacking: If a service binary path is writable, replace it. Unquoted service path: If path has spaces and isn’t quoted, Windows tries each component as an executable.


SAM & Credential Storage

LocationContents
C:\Windows\System32\config\SAMLocal account NTLM hashes
C:\Windows\System32\config\SYSTEMSYSKEY (needed to decrypt SAM)
LSASS process memoryLogged-on user credentials, Kerberos tickets
LSA Secrets (registry)Service account passwords, cached domain creds
DPAPIProtected credential blobs (browser passwords, WiFi keys)
Credential ManagerStored passwords (cmdkey /list)

Windows Defender & AV

# Check Defender status
Get-MpComputerStatus
Get-MpPreference | Select ExclusionPath, ExclusionExtension
 
# Disable real-time protection (requires admin/SYSTEM)
Set-MpPreference -DisableRealtimeMonitoring $true
 
# Add exclusion
Add-MpPreference -ExclusionPath "C:\Users\Public"

Event Logs

Key logs and event IDs:

LogEvent IDDescription
Security4624Successful logon
Security4625Failed logon
Security4648Logon with explicit credentials
Security4688Process creation
Security4697Service installed
Security4720User account created
Security4732Member added to security-enabled group
Security4768Kerberos TGT request
Security4769Kerberos service ticket request
Security4776NTLM authentication
Security7045New service installed (System log)
Sysmon1Process creation
Sysmon3Network connection
Sysmon7Image (DLL) loaded
# Query event log
Get-WinEvent -LogName Security -FilterHashtable @{Id=4624} -MaxEvents 50
wevtutil qe Security /c:20 /q:"*[System[EventID=4624]]"

See Also