Overview
SysWhispers4 provides direct syscall access to Windows token manipulation functions. These bypass user-mode hooks onadvapi32.dll functions like OpenProcessToken, AdjustTokenPrivileges, etc.
Tokens control access rights and privileges for processes and threads. Manipulating tokens is essential for privilege escalation and impersonation techniques.
NtOpenProcessToken
Opens the access token associated with a process.Parameters
HANDLE
required
Handle to the process. Use
GetCurrentProcess() for current process, or a handle from SW4_NtOpenProcess().ACCESS_MASK
required
Access rights for the token:
TOKEN_QUERY(0x0008) — Query token informationTOKEN_ADJUST_PRIVILEGES(0x0020) — Enable/disable privilegesTOKEN_DUPLICATE(0x0002) — Duplicate the tokenTOKEN_ALL_ACCESS(0x000F01FF) — All access rights
PHANDLE
required
Pointer to variable that receives the token handle.
Example
NtOpenThreadToken
Opens the access token associated with a thread.Parameters
HANDLE
required
Handle to the thread (use
GetCurrentThread() for current thread).ACCESS_MASK
required
Access rights (same as
NtOpenProcessToken).BOOLEAN
required
TRUE— Open using the calling thread’s security contextFALSE— Open using impersonation context
PHANDLE
required
Receives the token handle.
Example
NtQueryInformationToken
Retrieves information about a token.Parameters
TOKEN_INFORMATION_CLASS
required
Type of information to retrieve:
TokenUser(1) — User SIDTokenGroups(2) — Group SIDsTokenPrivileges(3) — Privilege arrayTokenOwner(4) — Owner SIDTokenPrimaryGroup(5) — Primary group SIDTokenSessionId(12) — Session IDTokenElevation(20) — Elevation status (UAC)TokenIntegrityLevel(25) — Integrity level
PVOID
required
Pointer to buffer that receives the information.
ULONG
required
Size of the buffer in bytes.
PULONG
required
Receives the actual size needed/written.
Example: Check Token Elevation
Example: Enumerate Privileges
NtAdjustPrivilegesToken
Enables or disables privileges in a token.Parameters
HANDLE
required
Handle to token with
TOKEN_ADJUST_PRIVILEGES access.BOOLEAN
required
If
TRUE, disables all privileges (ignores NewState).PTOKEN_PRIVILEGES
required
Pointer to
TOKEN_PRIVILEGES structure specifying privileges to modify.ULONG
required
Size of
PreviousState buffer (use 0 if not interested).PTOKEN_PRIVILEGES
Optional buffer to receive previous state (can be
NULL).PULONG
Receives actual size of previous state (can be
NULL).Example: Enable SeDebugPrivilege
Common Privileges
NtDuplicateToken
Duplicates a token.Parameters
HANDLE
required
Handle to token to duplicate (requires
TOKEN_DUPLICATE access).ACCESS_MASK
required
Access rights for the new token.
POBJECT_ATTRIBUTES
Optional attributes (use
NULL).BOOLEAN
required
If
TRUE, only enabled privileges are copied.TOKEN_TYPE
required
Type of new token:
TokenPrimary(1) — Primary token (for process creation)TokenImpersonation(2) — Impersonation token (for thread impersonation)
PHANDLE
required
Receives the new token handle.
Example: Token Duplication for Impersonation
NtImpersonateThread
Makes a server thread impersonate a client thread’s security context.Parameters
HANDLE
required
Handle to the thread that will impersonate (usually
GetCurrentThread()).HANDLE
required
Handle to the thread being impersonated.
PSECURITY_QUALITY_OF_SERVICE
required
Pointer to QOS structure:
Example
Complete Example: Token Theft (SYSTEM)
Steal SYSTEM token from a privileged process:Use Cases
Privilege Escalation
- Enable SeDebugPrivilege → Open protected processes
- Steal SYSTEM token from winlogon.exe, lsass.exe, or PID 4
- Duplicate token as primary or impersonation
- Create elevated process or impersonate
Lateral Movement
- Duplicate token from remote process (via handle duplication)
- Impersonate network logon token
- Access remote resources with stolen credentials
Defense Evasion
- Lower token integrity level to appear less privileged
- Remove privileges to reduce detection surface
- Token spoofing to masquerade as different user
Next Steps
Evasion Helpers
SW4_PatchEtw, SW4_PatchAmsi, SW4_UnhookNtdll
Supported Functions
Complete list of all 64 NT functions
