portfolio terminal
Windows Security
Windows internals for security analysts
Follow a PowerShell process through its handles, access tokens, file operations and memory with NtObjectManager and Sysinternals.

A process starts, a file changes, and a connection appears in the logs. During a security investigation, these observations raise further questions: what caused the activity, which security context was involved, and why did Windows allow or deny the operation?
In my earlier article on using Process Monitor, I explored how to observe activity beneath the application interface. Here, I want to connect those observations to the Windows mechanisms behind them.
I also want to credit James Forshaw, author of Windows Security Internals and creator of the NtObjectManager module. His book explores Windows authentication, authorization and auditing through practical PowerShell examples. The module makes many of these mechanisms directly accessible for inspection and experimentation.
We will follow a single PowerShell process through several perspectives: its handles, access token, file operations and memory allocations. Using NtObjectManager alongside Process Explorer, Process Monitor and VMMap, we can connect what Windows is doing to the evidence available during an investigation.
The NtObjectManager commands below were checked with version 2.0.1. They assume the module is already installed. The examples use a Windows lab environment with the relevant Sysinternals tools available.
A process and its resources
A process provides the resources that code needs to run. Its virtual address space, open handles and security context belong to that execution environment. Threads perform the actual execution and receive CPU time from the scheduler. Several threads within one process can share its memory and resources.
Open PowerShell and display its process ID:
$PID
In this case it is 11740. Now find that PID in Process Explorer (as administrator). Depending on the PowerShell edition, the executable will usually be powershell.exe or pwsh.exe.
Look at the process properties, its command line and its location in the process tree. Then enable the lower pane. In handle mode, it shows references the process holds to Windows objects:
In DLL mode, it shows loaded DLLs and memory-mapped files:
This already gives us several different views of the same process. Its name identifies the executable. Its command line helps explain how it started. Its handles show resources it currently references. Its loaded modules help explain which code is available inside its address space.
Each observation answers a different question.
User mode and kernel mode
The process also operates across a distinction that is easy to confuse with administrator privileges: user mode and kernel mode.
PowerShell executes application code in user mode. When it needs an operating system service, an API call can eventually reach a native interface in ntdll.dll and cross into kernel mode through a system call (syscall). Windows then processes the request using the relevant validation and access checks.
Running PowerShell as administrator changes its security context. It does not turn the application into arbitrary kernel-mode code. Similarly, kernel32.dll is a user-mode library despite its name. Core Windows kernel and executive functionality resides in ntoskrnl.exe.
This is important when assessing a security claim. Administrator access, High integrity and kernel execution describe different properties. We need to establish which one is actually involved.
Handles and granted access
Handles make resource access concrete. Windows represents many resources as objects, including processes, threads, files, registry keys and access tokens. A handle gives a process a reference through which it can perform permitted operations on an object.
When opening an object, the caller requests particular access rights. Windows evaluates the request, and a successful handle carries the granted access. A handle that permits querying a process does not automatically permit terminating it or writing to its memory.
We can inspect the types of handles held by our PowerShell process with NtObjectManager:
Import-Module NtObjectManager
Use-NtObject ($process = Get-NtProcess -Current -Access QueryInformation) {
Get-NtHandle -Process $process -NoQuery |
Group-Object ObjectType |
Sort-Object Count -Descending |
Select-Object Name, Count
}
This opens our current process for information queries and groups its existing handles by object type. You may see types such as File, Key, Event and Thread. The exact counts will vary. An Event here is a synchronization object that threads can wait on, rather than a Windows Event Log record.
The counts represent handles. Multiple handles can reference the same underlying object.
The -NoQuery parameter skips additional queries for information such as object names. That is sufficient for this example, where we only want to count handle types.
Use-NtObject also deserves attention. It disposes of the process object opened for this query when the block finishes. It leaves the existing handles we enumerated alone. Managing these references is part of using the module correctly.
We now know that a process holds references to resources. The next question is what allows it to obtain those references.
Access tokens and elevation
The access token describes the security context. It contains information such as the user SID, group SIDs and privileges. A process has a primary token, while a thread can use an impersonation token when acting on behalf of another identity. That means the process owner alone may not explain the effective context of a particular operation.
NtObjectManager lets us inspect the primary token of our current PowerShell process (this PowerShell session is not elevated):
Use-NtObject ($token = Get-NtToken -Primary -Access Query) {
Format-NtToken -Token $token -Basic
}
-Primary selects the process token. -Access Query requests the right to read token information. The remaining commands display its basic properties. This invocation inspects the existing token without enabling privileges or changing the process identity.
Try the same block in a normal shell and an elevated shell.
For an administrator account using Admin Approval Mode, the normal shell typically uses a filtered token, while the elevated shell uses the full administrator token. You can therefore see different group attributes, privileges and integrity levels while the username remains the same. A standard user supplying another administrator’s credentials is a different situation.
Pay particular attention to the difference between a privilege being present and being enabled. Also look for groups marked deny-only. The group list carries attributes that affect how Windows uses those SIDs during access checks.
This helps turn a vague description such as “the process is running as an administrator” into a more precise question: which token was effective, and which of its properties mattered for this operation?
Exploring tokens with Token Viewer
We can explore these token differences interactively. NtObjectManager includes Token Viewer, which provides a graphical view of accessible processes and their tokens:
Show-NtToken -All
Find the PowerShell process using its PID and open its token details. Compare the user, group attributes, privileges and integrity level with the console output above. Here, -All opens the viewer’s overview; it does not print every property of the current token.
To open the current PowerShell process directly, use:
Show-NtToken -ProcessId $PID
The viewer’s permissions determine which tokens it can inspect. Show-NtToken -All -RunAsAdmin starts the viewer elevated when broader access is needed. This does not elevate the processes being inspected.
Asking focused questions with Get-NtToken
Get-NtToken lets us ask more focused questions from PowerShell. For example, we can inspect the token’s elevation properties, list only deny-only groups, and display the state of its privileges:
Use-NtObject ($token = Get-NtToken -Primary -Access Query) {
$token | Format-List User, TokenType, IntegrityLevel,
Elevated, ElevationType
Get-NtTokenGroup -Token $token -Attributes UseForDenyOnly |
Format-Table Name, Attributes
Get-NtTokenPrivilege -Token $token |
Format-Table Name, Enabled
}
ElevationType adds context to the comparison. Under UAC, Limited identifies a filtered token, while Full identifies its elevated counterpart. Default means the token has no linked UAC counterpart; it does not, by itself, tell us whether the account has administrative rights.
The group query isolates SIDs that can participate in deny checks but cannot grant access through allow entries. The privilege query shows which privileges are present and whether they are currently enabled. An elevated token can still contain disabled privileges.
To inspect another accessible process, add -ProcessId to the token query, using that process’s current PID:
$targetProcessId = 11668 # Replace with the current PID of the process to inspect
Use-NtObject (
$token = Get-NtToken -Primary -ProcessId $targetProcessId -Access Query
) {
Format-NtToken -Token $token -Basic
}
The process’s primary token is not always the effective token of a thread. A thread can impersonate another identity, for example when a service handles a client request. We can query the current thread’s effective context with:
Use-NtObject ($token = Get-NtToken -Effective -Access Query) {
$token | Format-List User, TokenType, IntegrityLevel
}
-Effective first looks for a thread impersonation token. If none exists, it returns the owning process’s primary token. Seeing TokenType: Primary in an ordinary PowerShell session is therefore expected.
Compare that with the primary token of process 11668, which has High integrity.
These queries describe the context at the time of inspection.
How access decisions fit together
The target resource has its own security information. Its discretionary access control list, or DACL, contains access control entries that allow or deny particular rights.
Suppose a process requests both read and write access to a file. An applicable deny entry for the requested write access can cause that combined request to fail, even when reading alone would be permitted. The requested access mask therefore matters alongside the identity.
Windows also applies Mandatory Integrity Control. Under the usual no-write-up policy, a Low-integrity process cannot write to a Medium-integrity object even when the DACL would otherwise allow it. Integrity policy adds another part to the decision.
An ACCESS DENIED result could consequently be a starting point for investigation. We still need the requested operation, effective token, target permissions and relevant policy to explain the failure.
Following a file operation in Process Monitor
We can observe the file side of this relationship with a small Procmon exercise.
In PowerShell, prepare a unique temporary path and display the information needed for filtering:
$file = Join-Path $env:TEMP (
"internals-{0}.txt" -f [guid]::NewGuid()
)
$PID
$file
In Process Monitor, add an Include filter for that PID and another for the exact file path. Clear the existing capture, start recording, and run:
[IO.File]::WriteAllText($file, "Windows internals lab")
[IO.File]::ReadAllText($file)
Remove-Item -LiteralPath $file
The commands create a temporary file, read its contents and remove that same file.
Stop the capture and examine the operations and their results. You should find activity associated with opening, writing, reading and closing the file. Libraries may also perform metadata queries and other supporting operations, so a single high-level command can produce several records.
Select a CreateFile operation and inspect its details, especially the requested access and disposition.
The operation name alone does not establish that Windows created a new file: the underlying interface supports opening existing files as well.
Then inspect the stack for an operation. With appropriate symbols, this can help connect the filesystem activity to the components involved in issuing it. Process Monitor supports operation details and thread stacks for precisely this kind of investigation.
The handle view and the trace now complement each other. Process Explorer shows resources currently referenced by a process. Procmon records operations during the capture interval. A file that was opened and closed quickly may appear in the trace without remaining visible in a later handle snapshot.
Understanding memory with VMMap
Memory adds another useful perspective on the same process.
A process uses virtual addresses, which Windows and the processor translate through memory mappings. A large virtual address range does not mean that the process currently occupies the same amount of physical RAM.
These terms help separate the measurements:
| Term | What it describes |
|---|---|
| Reserved memory | A range of virtual addresses set aside for possible use |
| Committed memory | Memory for which the system has accounted for the necessary backing |
| Working set | The process’s pageable memory currently resident in physical RAM |
Reservation and commitment are separate operations, and committed pages do not all require physical pages immediately.
Open the PowerShell process in VMMap and compare the memory categories and their committed and working-set values.
VMMap captures a moment in time. As PowerShell accesses memory, Windows may need to bring additional pages into its working set. Accessing a page outside that working set triggers a page fault.
A soft fault can be resolved without reading from storage. A hard fault requires a read from a mapped file or the pagefile. Both can occur during normal activity, such as loading a DLL, so interpret fault counts alongside what the process was doing.
Following a PowerShell process through these tools connects the events we observe to the mechanisms behind them. Handles, tokens, file operations and memory measurements each reveal a different part of its behaviour. Understanding Windows internals gives us a good practical foundation for security investigations on Windows devices.
Sources and further reading
Book and companion material
- James Forshaw — Windows Security Internals: A Deep Dive into Windows Authentication, Authorization, and Auditing — No Starch Press, 2024.
- Windows Security Internals — companion code — James Forshaw’s official repository of PowerShell examples and supporting files for the book.
Tools
- NtObjectManager and TokenViewer — Source repository for the PowerShell module and token inspection tools used in the examples.
- Process Explorer — Microsoft Sysinternals documentation and download for inspecting processes, handles and loaded DLLs.
- Process Monitor — Microsoft Sysinternals documentation and download for tracing file system, Registry and process/thread activity.
- VMMap — Microsoft Sysinternals documentation and download for examining virtual memory categories and their working sets.
Microsoft technical references
- About Processes and Threads — Process resources, thread execution and thread security context.
- User Mode and Kernel Mode — The execution modes used by applications, operating system components and drivers.
- Object Handles — How handles provide access to system objects and are used in subsequent operations.
- Access Tokens — Token contents and the distinction between primary and impersonation tokens.
- How User Account Control Works — Filtered administrator tokens, elevation and the UAC sign-in process.
- Mandatory Integrity Control — Integrity levels, mandatory labels and the relationship between MIC and discretionary access checks.
- How AccessCheck Works — How access control entries and the effective security context determine whether requested access is allowed.
- Working Set — Resident pageable memory, working-set changes, and the difference between soft and hard page faults.
- CreateFileW — Requested access, creation disposition, sharing modes and file-opening flags.