Assembly language is a class of languages, not one single language. Every compiler platform has its own assembly language. It is a low-level language that is a human-readable representation of machine code. If a software performs an operation, it must be visible in the assembly language code.
Machine Code / Binary code or Object code are not the same thing. They are two different representations of low-level program instructions.
Byte Code: Byte codes are similar to Object Codes, except that they are usually decoded by a program instead of a CPU. The idea is to have a Compiler generate the bytecode, and to then use a program called a Virtual Machine (VM) to decode the bytecode for the CPU and perform operations described in it. Of course, at some point, the VM converts the bytecode into standard Object Code that is compatible with the underlying CPU. Platform independence is the most significant advantage of using byte-code based languages.
Is a program that manages the computer, including the hardware and software applications.
System-Monitoring Tools: Reverse engineering requires various tools that sniff, monitor, explore, and otherwise expose the program being reversed.
The Registry is a system database containing information required to boot and configure the system. It contains:
Debugger: Is a program that allows developers (and reversers) to observe their program while it is running. Most basic features of a debugger are the ability to set breakpoints and trace through code.
A Breakpoint allows users to select a certain function or address and instruct the debugger to pause program execution once that location is reached.
Most debuggers also allow you to trace through a program while it's running, called Single Stepping. Reversers use debuggers in disassembly mode (using a built-in disassembler to disassemble code on the fly). Reversers can step through the disassembled code, essentially watching the CPU as it executes the program one instruction at a time. Reversers can install breakpoints in locations of interest in the disassembled code and then examine the state of the program. Kernel Debugging means examining internal kernel data structures and stepping through functions in the kernel.
Symbol Files: Contain names of functions and variables and the layout of data structures. They are generated by the linker and used by debuggers to reference and display these names.
| Tool | Kernel Mode | User Mode | Console/GUI |
|---|---|---|---|
| KD | \checkmark | Console | |
| WinDbg | \checkmark | \checkmark | GUI Interface |
| CDB | \checkmark | Console | |
| NTSD | \checkmark | Console (Default) | |
| Windbgl (WinDbg -I) | \checkmark | Console (GUI, uses -W switch for WinDbg) |
Invasive Debugging: (DebugActiveProcess() API) Establishes a connection between the debugger and an active process (User mode).
Non-Invasive Debugging: (OpenProcess() API) Doesn't attach to the active process; simply opens the process (User mode).
Crash Dump File: A snapshot of the system's memory and state at the time a system crash (Blue Screen) occurred, used for post-mortem analysis.
Connecting to a Live, Running System: Such an operation requires the use of two computers. The Target System must be booted in Debugging Mode (configured using bcdedit.exe or msconfig.exe). You may have to disable Secure Boot in the UEFI BIOS settings.
Connecting to a Local System (Local Kernel Debugging): Examining the state of the kernel on the same machine. To initiate, ensure the system is set to debug mode. Some debugger commands don't work when used in local kernel debugging.
LiveKd (Sysinternals): Provides a simulated Crash Dump File to the debugger and performs any operations supported on a Crash Dump. Because it depends on physical memory (disk) to back the simulated dump, it could run into inconsistent state issues with Windows.
A SHIM is a small layer of code that intercepts, modifies, or redirects the behavior of another program — without changing the program’s code itself. It’s like a transparent adapter that sits between an application and the Windows APIs it calls. In Windows, shims are part of the Application Compatibility (AppCompat) Framework. They allow old or poorly behaved applications (written for older Windows versions) to still run properly on newer versions of Windows. The shim doesn’t modify the application binary on disk.
Procedural-Based Design: A procedure is the most fundamental building block of a program. A piece of code with a well-defined purpose that can be called from anywhere in the program. They optionally receive input data from the caller and return data to the caller. This is the most commonly used form of encapsulation in any programming language. Object-Oriented Design (OOD): The OOD methodology defines an object as a program component that has both data and code associated with it. The code can be a set of procedures that is related to the object and can manipulate its data. The data is part of the object, usually private, and can be accessed only by the object's code but not from the outside world. Developers are forced to treat objects as completely isolated entities that can only be accessed through well-defined interfaces.
To view a program and understand what is happening, you must understand how data is managed by the program.
Control Flow: Are statements that affect the flow of execution of the program based on certain values and conditions:
Virtual Memory is an abstract address space that includes all the memory address space a program can use. It is a complete list of all possible memory locations available to the process. Instead of letting software directly access the Physical Memory(RAM), a combination of the processor and the operating system creates a more flexible layer between software and the physical memory (RAM). Processors divide memory into pages (fixed size chunks) of memory (RAM). Each page of Virtual Memory is tagged by the system to indicate what access mode the processor must be in to read and/or write the page.
Pages (Number of Read-only pages in memory/RAM). Memory management is done in distinct chunks called pages. This is because the hardware memory management unit translates virtual to physical addresses at the granularity of a page. Hence, a page is the smallest unit of protection at the hardware level
Kernel Memory: Includes the PAGED and NON-PAGED Pools, HEAPS, SYSTEM CACHE, STACKS, PAGE TABLES, and HYPERSPACE.
Executables
SYSTEM WORKING SET
PRIVATE ALLOCATIONS
SYSTEM PAGE-TABLE ENTRIES
MAPPED VIEWS
Memory Manager: has two primary tasks: Translating, or mapping, a process’s virtual address space into physical memory so that when a thread running in the context of that process reads or writes to the virtual address space, the correct physical address is referenced. (The subset of a process’s virtual address space that is physically resident is called the working set. W orking sets are described in more detail in the section “W orking sets” later in this chapter.) Paging some of the contents of memory to disk when it becomes overcommitted—that is, when running threads try to use more physical memory than is currently available—and bringing the contents back into physical memory when needed.
SECTION OBJECT: A special chunk of memory managed by the O.S. Mapping a section object means that a virtual address range is allocated for the object and its content can become accessible through that range.
KERNEL OBJECTS: The Windows KERNEL manages its objects using a centralized OBJECT MANAGER(The Object Manager is a core executive component that lives inside the kernel mode part of Windows, specifically within the Executive layer of the Windows kernel) responsible for all Kernel Objects such as SECTIONS, Handles and Modules, Files, Device Objects(Named & Unnamed), Synchronization Objects, Processes, and Threads. The O.S. tags each page of Virtual memory with the access mode the processor must be in to read or write the page. Pages in the system space can be accessed by the Kernel Mode, meanwhile, pages in the user address space are accessible from the user mode. The Windows Kernel manages Objects using a centralized Object Manager component.
The Object Manager (in ntoskrnl.exe) is like the central directory service for all kernel-mode resources. It:
The Executive is responsible for all kernel objects. Kernel code accesses objects using direct pointers. The Handle Entry also stores the current access rights the process was granted at the time it opened the object, which enables the system to make sure it doesn't allow the process to perform an operation on the object for which it didn't ask permission.
A PROCESS is predominantly an isolated memory space. An address space is created for every program in order to ensure each program runs in its private address space. Inside a process's address space, the system can load Code Modules (Binary files that contain isolated areas of a program's executable).
HOW & WHY A THREAD CONTEXT-SWITCHES? The truth is that threads frequently just give up the CPU on their own volition. This happens whenever a program is waiting for something external to finish (e.g., I/O).
Windows supports several built-in Sync Objects, each related to a specific type of data structure that needs to be protected. All Synchronization Objects (except Critical Section) are managed by the Kernel Object Manager and are implemented in Kernel Mode, which means that the system must switch into the Kernel Mode for any operation that needs to be performed on them.
API's are a set of functions that the Operating System makes available to application programs for communicating with the Operating System.
In their user-mode implementation in NTDLL.DLL, the two groups of APIs are identical and actually point to the same code. In kernel mode, they are different: the Nt versions are the actual implementations of the APIs, while the Zw versions are stubs that go through the system-call mechanism. The reason you would want to go through the system-call mechanism when calling an API from kernel mode is to “prove” to the API being called that you’re actually calling it from kernel mode. If you don’t do that, the API might think it is being called from user-mode code and will verify that all parameters only contain user-mode addresses. This is a safety mechanism employed by the system to make sure user mode calls don’t corrupt the system by passing kernel-memory pointers. For kernel-mode code, calling the Zw APIs is a way to simplify the process of calling functions because you can pass regular kernel-mode pointers.
WINDOWS 32 API: Is a very large set of functions that make up the official low-level programming interface for Windows applications. Recently, Microsoft introduced some higher-level interfaces (e.g., .NET Framework, C++ objects) that exposed most of the features offered by the Win32 API. The .NET Framework uses System Classes for accessing O.S. services, which is again an interface into the Win32 API. No matter the high-level interface an application employs, it's eventually going to use the Win32 API for communicating with the O.S. The Win32 API (kernel32, user32, gdi32, advapi32) is therefore a wrapper layer over the Native API and acts as the public interface to the subsystem that CSRSS helps manage. CSRSS works alongside the win32k.sys (in kernel mode) and the Win32 DLLs (in user mode). Together they form the Windows subsystem that gives user processes their GUI and environment.
User App → kernel32.dll (Win32 API) → ntdll.dll (Native API) → syscalls into ntoskrnl.exe (Kernel)
These APIs are divided into two categories: User and Kernel API Layers | Component | Description | Layer | | Kernel32.DLL | Base API Client Component (Non-GUI related services) | User Mode | | User32.DLL | Hosts the USER API Client Component (GUI-related services) | User Mode | | GDI32.DLL | GDI API Client Component (Low-level graphics services) | User Mode | | NTDLL.DLL | NATIVE API Interface Client Component | User Mode | | NTOSKRNL.EXE | NATIVE OS KERNEL Executable, Kernel Implementation of the User API, and NATIVE API | Kernel Mode | | Win32k.SYS | The Windows Kernel implementation of the Win32 Kernel (Graphics and User Interface implementation) | Kernel Mode |
The Win32 subsystem is the component responsible for every aspect of the Windows user interface. This starts with the low-level graphics engine, the graphics device interface (GDI), and ends with the USER component, which is responsible for higher-level GUI constructs such as windows and menus, and for processing user input. First of all, it’s important to realize that the components considered the Win32 subsystem are not responsible for the entire Win32 API, only for the USER and GDI portions of it. As described earlier, the BASE API exported from KERNEL32.DLL is implemented using direct calls into the native API, and has really nothing to do with the Win32 subsystem. The Win32 subsystem is implemented inside the WIN32K.SYS kernel component and is controlled by the USER32.DLL and GDI32.DLL user components. Communications between the user-mode DLLs and the kernel component is performed using conventional system calls (the same mechanism used throughout the system for calling into the kernel)
A System Call takes place when user-mode code needs to call a kernel-mode function, which frequently happens when an application calls an Operating System API. The user-mode side of the API usually performs basic parameter validation checks and calls down into the Kernel to actually perform the requested operation. It's not possible to directly call a kernel function from user-mode, as this would be a serious vulnerability. The O.S. has a special mechanism for switching from User-Mode to Kernel Mode. The idea is that the user-mode code invokes a special CPU instruction that tells the processor to switch to its privileged mode and call a special dispatch routine. The dispatch routine then calls the specific system function requested from the user-mode.
Executable(Library)!<Prefix><Operation><Object> + Offset, aligns perfectly with how analysts view function calls and addresses in a debugger:
| Prefix | Component | Notes |
|---|---|---|
| Alpc | Asynchronous Local Procedure Call | Communication mechanism. |
| Cm | Configuration Manager | Registry handling. |
| Dbg | Debug | Debugging support routines. |
| Etw | Event Tracing for Windows | Logging and tracing. |
| Ex | Executive Support | General-purpose support routines (e.g., ExAllocatePoolWithTag / ExInitializeResource). |
| Io | I/O Manager | I/O request packet handling. |
| Kd | Kernel Debugger | Debugger communication. |
| Ke | Kernel | Low-level kernel primitives. |
| Kse | Kernel Security Engine | Security enforcement. |
| Lsa | Local Security Authority | Security functions. |
| Mm | Memory Manager | Virtual memory and page file management. |
| Ob | Object Manager | Object creation, deletion, and reference counting. |
| Pp | Plug and Play Manager | Device and driver management. |
| Ps | Process Structure | Process and thread management. |
| Rtl | Run-Time Library | General utility functions (accessible from User Mode via System Call). |
| Se | Security | Core security operations. |
| Sm | Session Manager | Session creation and management. |
| Woi | Windows OS Isolation | Isolation features. |
| Wmi | Windows Management Instrumentation | Management/monitoring framework. |
| Zw / Nt | Native System Services | Interface called from User Mode to Kernel Mode (NTDLL.DLL exports these). |
Static Libraries: Represent a certain component of a program, a feature, or area of functionality in the program. Static Libraries are added to a program while it's being built, adding certain functionality to it. Dynamic Link Libraries (DLLs) in Windows: Similar to static libraries, except that they are not embedded into the program. They remain in a separate file, even when the program is shipped to the end user. DLLs allow for upgrading individual components in a program without updating the entire program. The idea is that a program can be broken into more than one executable file where each is responsible for one feature or area of program functionality. The benefit is that overall memory consumption is reduced as executables are not loaded until the features they implement are required. DLLs are different from build-time Static Libraries (.lib). The latter are permanently embedded in an executable. The code in .lib files is statically linked into an executable while it's built, just as if the code in .lib files was part of the original program source code. Windows programs use two methods of loading and attaching to DLLs at runtime:
When a Dynamic Link Library (DLL) such as user32.dll or kernel32.dll is loaded by multiple processes, Windows optimizes memory usage through shared memory mapping rather than duplicating the DLL in physical memory for each process.
This allows multiple processes to execute the same DLL code while consuming memory for only one physical copy.
Private Data Sections While code sections are shared, data sections (which include writable areas such as global variables) are not shared. Each process receives its own copy of the DLL’s writable data region, ensuring process isolation and preventing data corruption.
Efficiency and Performance By sharing read-only sections:
Program's Executables (PE) are Relocatable. This simply means that they could be loaded at different Virtual Addresses each time they are loaded (but cannot be relocated after they have been loaded). Relocation happens because an executable doesn't exist in isolation—it must co-exist with other executables that are loaded in the same address space. Other than the main executable (the .exe file you launch when you run a program), every program has a number of additional executables loaded into its address space, regardless of whether it has DLLs of its own or not. The O.S. loads quite a few DLLs. Because multiple executables are loaded into each address space, we have a mixed collection of executables in each address space that wasn't necessarily planned for.
RVA (Relative Virtual Address): An offset from the module's base address.
Base Address: Each module (low-level binary code) is assigned a Base Address while being created. The linker assumes that the executable is going to be loaded at the base address. If it is, no relocation will take place. Else, the module is relocated if the module's base address space is already taken.
Relocations are important and are the reason why there are never ABSOLUTE addresses in executable headers, only in code. Whenever you have a pointer inside the executable header, it'll always be in the form of an RVA, which is just an offset(+0x00aabb) into that file. When the file is loaded (.exe) and assigned a Virtual Address, the loader calculates the real virtual addresses out of RVAs by adding the module's base address (where it was loaded) to an RVA.
The executable stores RVA — “offsets” instead of absolute addresses. When Windows loads the module, it adds the actual base address to the RVA to find the true memory address.
Image Sections are needed because different areas of the module image are treated differently by the memory manager when a module is loaded. A common division is to have a Code Section (e.g., the .text section), containing the executable code, and a Data Section, containing the initialized and uninitialized data. They contain the contents of any initialized variable anywhere in the program.
Section Alignment: The memory manager sets the access rights on memory pages in the different sections based on the memory settings in the section headers. Section alignment shows how sections are aligned when the executable is loaded in memory, and file alignment is how sections are aligned inside the PE file on disk (from memory).
Imports and Exports: These are the mechanisms that enable the dynamic linking process of executables described above. Consider an executable that references functions in other executables while it's being compiled and linked. The compiler and linker have no idea of the actual address of the imported functions. Only in runtime will this address be known. To solve this problem, the linker creates a special Import Table that lists all the functions imported by the current module by their names. The Import Table contains a list of modules that the module uses and the list of functions called within each of those modules. When the module is loaded, the loader loads every module listed in the Import Table and goes to find the address of the functions listed in each module. The addresses are found by going over the exporting module's Export Table, which contains the names and RVAs of every exported function. When the importing module needs to call into an imported function, the calling code typically looks like this: Call [Some Address], where Some Address is a pointer into the executable's Import Address Table (IAT). When the module is linked, the IAT is nothing but a list of empty values. But when the module is loaded, the linker resolves each entry in the IAT to point to the actual function in the exporting module. This way, when the calling code is executed, Some Address will point to the actual address of the imported function.
PE Executables contain a list of special optional directories, which are essentially data structures that describe their contents. | Name | Associated Data Structure | | Export Directory | IMAGE_EXPORT_DIRECTORY | | Import Table | Image_Import_Descriptor | | Import Address Table (IAT) | A list of 32-bit pointers | | Resource Table | Image_Resource_Directory | | Base Relocation Table | Image_Base_Relocation | | Debugging Information | Image_Debug_Directory | | Thread Local Storage (TLS) Directory | Image_TLS_Directory | | Load Configuration Table | Image_Load_Config_Directory | | Bound Import Table | Image_Bound_Import_Descriptor | | Delay Import Descriptor | Image_Delay_Load_Descriptor |
An Exception is a special condition in a program that initializes a special function called an Exception Handler. The exception handler either deals with the exception, corrects the problem, or terminates the program if the exception cannot be resolved.
The O.S. provides a mechanism for distributing exceptions to applications in an organized manner, where each thread is assigned an Exception-Handler list (that deals with exceptions). This list is stored in the Thread Information Block (TIB) data structure, which is available from user mode. The TIB is stored in a regular, private-allocation, user-mode memory.
VBS is a security architecture that enhances the processor's natural privilege-based separation (User/Kernel) via the introduction of Virtual Trust Levels (VTLs), isolating access to memory, hardware, and the processor.
Windows Architecture -> Executive and Kernel
 Windows achieves portability across hardware architectures by using a Layered Design and by using the C Language. Windows is a Symmetric Multi-Processing (SMP) O.S.
The Executive is the upper layer of NTOSKRNL.EXE. The Kernel is the lower layer. The Executive contains Base OS Services and is the internal component that exports the documented OS API to the Object Manager.
| Executive Component | Role |
|---|---|
| Configuration Manager | Responsible for implementing and managing the system registry. |
| Process Manager | Creates and terminates processes and threads. |
| Security Reference Monitor (SRM) | Enforces security policies on the local computer. |
| I/O Manager | Implements device-dependent I/O and is responsible for dispatching to the appropriate device drivers. |
| Memory Manager | Implements Virtual Memory, a scheme providing a large private address space for each process. |
| Power Manager | Coordinates power events and generates power management I/O notifications to device drivers. |
| Cache Manager | Improves performance of file-based I/O by causing recently referenced disk data to reside in memory. |
| Plug & Play Manager | Determines what drivers are required to support a particular device and loads those, retaining the hardware resource requirements for each device during enumeration. |
Executive Support Functions: The Executive contains four main groups of support functions that are used by the Executive Components: Object Manager, Run Time Library Functions, Executive Support Routines, and Asynchronous Local Procedure Call (ALPC).
The Kernel provides fundamental mechanisms used by the Executive components and low-level hardware architecture.
Kernel Objects : Help the kernel control CPU processing and support the creation of Executive objects. Most Executive-level Objects encapsulate one or more kernel objects, incorporating their defined attributes. Control Objects, Async Procedural Call (APC) Object, Deferred Procedure Call (DPC) Object, Interrupt Object, Dispatcher Object.
Kernel Processor Control Region (KPCR) : A data structure used to store processor-specific data (e.g., the processor's Interrupt Dispatch Table, Task State Segment, and Global Descriptor Table).
Kernel Process Control Block (KPRCB) : An embedded data structure inside the KPCR containing: Scheduling Info, Dispatcher Database, DPC Queue, Time Accounting Info, Cache Size, and Processor Stats.
I/O Manager : Manages device-independent I/O operations and is responsible for dispatching I/O requests to the appropriate device drivers.
Device Drivers : Includes hardware device drivers, translating user I/O function calls into specific hardware requests. HAL (Hardware Abstraction Layer) : Abstracts and isolates the kernel, drivers, and Executive from platform-specific hardware differences (e.g., differences in motherboards).
The HAL is a loadable kernel-mode module that provides a low-level interface to the hardware platform on which Windows is running. It hides hardware-dependent details, multi-processor mechanisms, and any functions that are both architecture-specific and machine-dependent.
I/O channels implemented with Windows can be divided into two groups: kernel-level and high-level.
The I/O system is a combination of kernel components that manage the device drivers running in the system and the communication between applications and device drivers. Device drivers register with the I/O System, which enables applications to communicate with them and make generic or device-specific requests to or from the device. The I/O System is responsible for relaying such requests from the application to the device drivers that are responsible for performing the operation. The I/O system is layered, which means that for each device, there can be multiple device drivers stacked on top of each other.
DEVICE DRIVERS Device Drivers are loadable kernel-mode modules that interface between the I/O Manager and the relevant hardware. Drivers enable Windows to interact with various types of hardware, including displays, storage, smartcard readers, and human input devices. They are also used to monitor network traffic and file I/O by antivirus software (and by Sysinternals utilities such as Procmon and Procexp!). And, of course, they are also used by malware, particularly rootkits. They run in Kernel Mode in one of three contexts:
WDK (Windows Driver Kit): Aimed at developers of device drivers. WSDK (Windows Software Development Kit): Aimed at developers of Windows-supported software/applications.
Windows Driver Model (WDM) Perspective According to the Windows Driver Model (WDM) perspective, there are three kinds of drivers:
Windows Driver Foundation (WDF) The Windows Driver Foundation (WDF) simplifies Windows driver development by providing two frameworks:
| Process Name | Process ID (PID) | Notes | | Idle Process | 0 | (1 thread per CPU) to account for idle CPU time. | | System Process | 4 | Contains the majority of kernel-mode system threads and handles core Executive services. | | Secure System Process | N/A | Contains the address space of the Secure Kernel (VTL 1), if running. | | Memory Compression Process | N/A | Contains the compressed working set of user-mode processes. | | Session Manager (smss.exe) | N/A | Process that creates sessions and the initial processes for service hosts. | | Logon Process (winlogon.exe) | N/A | Handles interactive user logon/logoff. | | Local Security Auth Server (lsass.exe) | N/A | Local Security Authority Server (LSA). | | Local Security Auth Server (lsaiso.exe) | N/A | Isolated LSA Trustlet (if Credential Guard is enabled). |
To understand how these processes are related, it's helpful to view the process tree (parent/child relationship between processes). Viewing which process created which helps understand where each process is from. To understand this correctly, perform a BOOT TRACE, by enabling boot logging in Process Monitor. Using Process Monitor enables you to see processes that have since terminated.
Non-Standard System Processes
System Process (PID 4)
MiniMAL Processes (Memory Compression / Secure System Process)
The Minimal Flag is set on certain system processes (like the Memory Compression Process and the Secure System Process if VBS is enabled).
Pico Processes
Pico Provider Control allows the emulation of the behavior of a completely different Operating System kernel. To support the existence of Pico Processes on the system, a provider must be present and registered with the kernel. On Windows systems with the optional WSL (Windows Subsystem for Linux) component enabled, a core driver called Lxss.sys serves as a stub driver (provider) until another driver, Lxcore.sys, loads a bit later and takes over the pico provider responsibilities. When a Pico Provider calls the registration API, it receives a set of function pointers to create and manage pico processes. The provider can now create fully custom processes and threads for which it controls the critical starting state, segment registers, and associated data. This alone would not allow the ability to emulate another Operating System. A second set of function pointers is, therefore, transmitted from the provider to the kernel, which serves as callbacks whenever certain activities or interactions will be performed by a pico thread or process. These include:
Trustlets are regular Windows Portable Executables ($\text{PE}$) files that contain some IUM-specific properties and can import only a limited set of Windows System DLLs due to the restricted number of system calls that are available to them. The IUM-specific system DLL is jumbase.dll, which provides the base IUM system API. This library ends up calling into jumaal.dll (the VTL 1 version of NTDLL.DLL). They are signed with a certificate that contains the Isolated User Mode EKU ($\text{1.3.6.1.4.1.311.10.3.37}$). Trustlet Policy Metadata includes various options for configuring how "accessible" the Trustlet will be from VTL 0. This is described by a structure present at the _JumPolicyMetadata export and contains a Version Number. This serves as metadata for the Secure Kernel to implement policy settings around permitting $\text{VTL 0}$ (Kernel) access to the Trustlet (e.g., allowing debugging, crash dumps, Event Tracing, and other capability support). Trustlet Attributes are used to authenticate that the caller truly wants to create a Trustlet, as well as to verify that the Trustlet the caller thinks is executing is actually the Trustlet being executed. This is done by embedding a Trustlet Identifier in the attribute, which must match the Trustlet ID contained in the metadata. The benefits of running as a Trustlet include access to privileged and protected Secure System Calls offered by the Secure Kernel. As the Secure Kernel attempts to minimize its attack surface and exposure, it provides only a subset of all of the System Calls that a normal kernel ($\text{VTL 0}$) application can use. These system calls are the strict minimum necessary for compatibility with the system calls that Trustlets can use, as well as the specific services required to support the RPC Runtime Library ($\text{Rpcrt.dll}$) and ETW Tracing, including the following groups:
The Session Manager (smss.exe) is the first user-mode process created in the system, launched by the kernel-mode system thread that performs the final phase of initialization of the Executive & KERNEL.
The Windows Initialization Process (wininit.exe) also marks itself and its main thread as Critical, thereby treating certain errors as fatal.
Windows services run in noninteractive, user-mode processes that can be configured to start independently of any user logging on, and that are controlled through a standard interface with the Service Control Manager. Multiple services can be configured to share a single process. A common example of this can be seen in Svchost.exe (Host Process for Windows Services), which is specifically designed to host multiple services implemented in separate DLLs. Services are configured in the subkeys of HKLM\System\CurrentControlSet\Services.
The Winlogon tab displays entries that hook into Winlogon.exe, which manages the Windows interactive-logon user interface. Introduced in Windows Vista, the Credential Provider interface manages the user authentication interface. Today, Windows includes many credential providers that handle password, PIN, picture-password, smartcard, and biometric logon. The Winlogon process handles interactive user logons & logoffs. It is notified that a User Logon is required when the user enters the Secure Attention Sequence (SAS) keystroke combination: \text{Ctrl}+\text{Alt}+\text{Delete}.
(Client/Server Runtime Subsystem Services - CSRSS.exe)
The Windows boot sequence transitions from low-level firmware and boot loaders to the complex world of the Operating System's process structure.
The System process starts an instance of Smss.exe (the Session Manager), which remains running until system shutdown. That Smss.exe launches two new instances of Smss.exe, one in session 0 and one in session 1, which create processes in their respective sessions. Both of these instances end up exiting before a user logs on, so the initial Smss.exe always appears not to have child processes. The instance of Smss.exe in session 0 starts an instance of Csrss.exe (the “client-server runtime” Windows subsystem) in session 0 and Wininit.exe. Wininit.exe starts Services.exe (the Service Control Manager process) and Lsass.exe (the Local Security Authority subsystem). In session 1, Smss.exe starts a new instance of Csrss.exe and Winlogon.exe. Winlogon starts LogonUI.exe to prompt the interactive user for credentials, and then it starts Userinit.exe (which starts Explorer) after the user has authenticated. Both LogonUI and Userinit typically exit before the shell initializes and theuser can start Procexp. Most services are descendants of Services.exe; Services.exe does not host any services itself.
Process Initialization Sequence A description of the steps taken by the system in an average process creation sequence.
NTDLL.DLL contains two function types:
The role of an Environment Subsystem is to expose a subset of the bare Windows Executive system services to application programs. Each Executable Image ($\text{.exe}$) is bound to one and only one subsystem, indicated in the $\text{PE}$ Image header. When an Image is run, the process creation routine examines the subsystem type and notifies the proper subsystem of the new process. The libraries that programs link to do not call Windows kernel services directly. Instead, their high-level function calls are routed through one or more Subsystem DLLs (the API libraries), which then make the documented native system calls (e.g., through $\text{ntdll.dll}$). Subsystems are started by the Session Manager ($\text{smss.exe}$).
The Win32 API and Subsystem DLLs
The $\text{Win32}$ Subsystem Image is the crucial primary environment for most applications. Its functionality is exposed to user processes via a set of core DLLs often referred to as $\text{Win32}$ Subsystem Libraries. These are loaded into virtually every $\text{Win32}$ user-mode process: DLL Name Primary Role in the Win32 API kernel32.dll Core APIs. Fundamental library for most $\text{Win32}$ functions, including those for process creation and memory management. advapi32.dll Advanced APIs. Functions related to security (like access control, tokens) and Service Management. user32.dll User Interface. Manages high-level GUI constructs like windows, menus, and user input, and communicates with the kernel component $\text{Win32k.sys}$. gdi32.dll Graphics. Provides the GDI (Graphics Device Interface) functions for drawing graphics, text, and managing fonts, also communicating with $\text{Win32k.sys}$.
The Win32 Subsystem Implementation (Kernel and User Components)
The $\text{Win32}$ Subsystem is the component responsible for every aspect of the Windows User Interface. It is composed of both kernel and user components:
The Client/Server Runtime Subsystem ($\text{CSRSS.EXE}$)
The Client/Server Runtime Subsystem Process ($\text{CSRSS.EXE}$) is a persistent server process that provides shared services to $\text{Win32}$ client applications.
The main confusion stems from three related but distinct layers:
Standard Windows applications using the CreateProcess (or its internal CreateProcessInternal) API cannot directly create processes that use the native subsystem image type (which typically includes system processes like the initial boot process or certain driver-loading processes). The high-level Windows API is designed to create standard Win32 user-mode processes, To bypass this restriction and allow certain system-level components to create a native process, the native library, Ntdll.dll, provides the RtlCreateUserProcess helper function. This function is essentially a user-mode wrapper that calls the lower-level, non-public kernel-mode function NtCreateUserProcess to successfully create a process with the native subsystem type. As its name suggests, NtCreateUserProcess is used for the creation of user-mode processes [there is a function with the same name (NtCreateUserProcess), part of the Executive; Kernel Mode]
The Windows API provides several functions for creating a process:
Protected Processes add significant access limitations to the access rights that other processes on the system can request, even when the process is running as a system privileged user. The Operating System will allow a process to be protected only if the Image file has been digitally signed with a special Windows Media Certificate. The Audio, Video, Graphics Processes, Windows Error Reporting ($\text{WER}$), and the System process itself are protected to preserve integrity. $\text{wmplayer.exe}$ is a protected process because protected music content can be decoded through it. At the kernel level, support for protected processes is twofold. The bulk of process creation occurs in Kernel Mode to avoid Injection Attacks. Protected processes have special bits set in their $\text{EPROCESS}$ structure—"Protection Locks"—that modify the behavior of security-related routines in the Process Manager to deny certain access rights that would normally be granted to Administrators. The only access rights that are granted for protected processes are PROCESS_QUERY_INFORMATION, PROCESS_TERMINATE, and PROCESS_SUSPEND_RESUME. An extension to the protected process model was introduced, called Protected Process Light ($\text{PPL}$), which adds an additional layer to the quality of being protected: ATTRIBUTE VALUES. The different Signers have different Trust Levels, which in turn results in certain $\text{PPL}$ processes being more or less protected than others. Standard protected processes are now also differentiated based on the Signer Value. The various recognized Signers also define which access rights are denied to lesser protected processes. Protection Levels are defined by the Signer Value. The $\text{WinTcb}$ (Windows Trusted Computing Base Signer), used for the System process, is leveraged to protect critical processes that the kernel has intimate knowledge of. The power of a process is measured by its Protection Level: $\text{Protected Processes}$ $>$ $\text{PPLs}$ $>$ $\text{Standard Processes}$. Higher-value signer processes have access to lower-level protected processes. The protection level of a process also impacts which DLLs it will be allowed to load, effectively preventing a legitimate protected process from being coerced into loading a malicious third-party library, which would then execute with the same protection level as the process. A check is implemented by granting each process a "Signature Level," which is stored in the SignatureLevel field of the $\text{EPROCESS}$ structure. Through an internal lookup table, it finds a corresponding "DLL Signature Level," stored as SECTION_SIGNATURE_LEVEL in $\text{EPROCESS}$. Any DLL loading into the process will be checked by the Code Integrity Component in the same way the main executable is verified. Therefore, a process with "WinTcb" as its executable signer will only load "Windows" or higher signed DLLs. If you run Process Explorer and select the Protection check box in the Process Image Tab to view the Protection Column: if you select a protected process to look at the lower part to view DLLs, you will see nothing. This is because Process Explorer uses a User Mode API to query the loaded modules, which requires access that's not granted for protected processes. Exception: $\text{Process Explorer}$ will show the list of loaded kernel modules (drivers) since these are not DLLs within the process address space. One possible way malware can attack a system is by injecting code inside a process, or better, injecting code specifically inside an Anti-Malware Service and thus tamper with or disable its functions. If, however, the AM service could run as a Protected Process Light ($\text{PPL}$), no code injection or process termination would be allowed, meaning that the AM software would be protected from attack. To enable this, the AM kernel driver needs Early-Launch Anti-Malware ($\text{ELAM}$), which is granted by Microsoft (after proper verification of the software's publisher). ELAM CERTIFICATE INFO is a custom resource section in the AM executable file, loaded once the ELAM is installed and loaded. Once the Code Integrity System recognizes any file signed with such a special certificate, it permits the process to request a $\text{PPL}$ of PS_PROTECTED_ANTIMALWARE_LIGHT ($\text{0x31}$).
Creating a Windows process consists of several stages carried out in three parts of the Operating System:
Once NtCreateUserProcess returns a success code, the necessary Executive process and thread objects have been created, and CreateProcessInternalW then performs subsequent operations related to Windows Subsystem-specific initialization to finish initializing the process. Among many of these operations:
A process can exit gracefully by calling the ExitProcess function. The process startup code for the first thread calls ExitProcess on the process's behalf when the thread returns from its main function. Graceful Termination means that DLLs loaded into the process get a chance to do some work by getting notified of the process exit using a call to their DllMain function with the DLL_PROCESS_DETACH reason.
Most of the actual initialization work is done outside the kernel by the Image Loader, internally referred to as LDR, which lives in the User-Mode system DLL ($\text{NTDLL.DLL}$). What makes it special is the guarantee that it will always be present in the running process (i.e., $\text{NTDLL}$ is always loaded). LDR is the first piece of code to run in user mode as part of a new process. Although the loader runs before the actual application code, its initialization tasks are hidden. A program typically does interact with its interfaces during the runtime of a program via loading/unloading of DLLs. The tasks performed by LDR are critical:
To prevent security risks associated with DLL Preload Attacks (or Binary Planting), Windows checks directories in a specific order to find the DLL file it needs. The traditional "DLL Name Resolution & Redirection Search Path" is a list of locations that is searched sequentially for a file with a matching name. To mitigate the security risks associated with this behavior, Safe Search Mode was introduced to the path search component. Under Safe Search Mode, the current directory is moved behind the three primary system directories, resulting in the following search order:
DLL Name Redirection is Windows' way of intercepting or re-routing loading to a different file or location.
The loader maintains a list of all modules that have been loaded by a process—the "Loaded Modules Database". This information is stored in the $\text{PEB}$ (Process Environment Block) in a substructure identified by LDR and called PEB_LDR_DATA. The routine maintains three doubly linked lists containing structures called Loader Data Table Entries ($\text{LDR_DATA_TABLE_ENTRY}$) that store information about each module. The kernel also employs its own loader for drivers and dependent DLLs, with a similar loader entry structure called KLDR_DATA_TABLE_ENTRY instead. The kernel-mode loader has its own database of such entries, which is directly accessible through the PsActiveModuleList global data variable. To dump the kernel's module database, you can use the kernel debugger command: dt nt!_KLDR_DATA_TABLE_ENTRY nt!PsActiveModuleList.
The Image Loader (LDR), which is the first piece of User-Mode code to run, performs critical steps to get the application ready:
Once all imports are loaded ($\text{LdrInitState} \rightarrow 2$), the process proceeds through final initialization steps ($\text{LdrInitState} \rightarrow 3, 4$):
SWITCHBACK: A Compatibility Time Machine
Switchback is a Compatibility Time Machine for old apps. When Microsoft improves or fixes APIs, those changes might accidentally break old programs that relied on the old or buggy behavior.
API Sets: Modularity for Windows
There is a much more pervasive redirection mechanism used in Windows for all applications called API Sets. Its purpose is to enable fine-grained API categorization of Windows APIs into Sub-DLLs instead of having large multi-purpose DLLs that span nearly thousands of APIs that might not be needed on all types of Windows systems today and in the future. API Sets are about Modularity. Instead of one huge toolbox for every job (Kernel32.dll), Windows split it into smaller boxes labeled api-ms-win-core-file-l1-1-0.dll or api-ms-win-core-registry-l1-1-0.dll such that embedded systems can remove parts not required. This helps Windows refactor internal DLLs without breaking compatibility. The mapping of these Virtual "API Set" DLLs to their real ones (like Kernelbase.dll) is defined in ApiSetSchema.dll, which is loaded at process startup. If an app says it imports api-ms-win-core-file-l1-1-0.dll, Windows checks the schema and redirects it to the real DLL (Kernel32.dll or Kernelbase.dll).
Jobs, Nested Jobs, & Windows Containers
Jobs
A Job is a nameable, securable, shareable kernel object that allows control of one or more processes as a group, allowing groups of processes to be managed and manipulated as a unit. A process's association with a Job object can't be broken, and all processes created by the process (its descendants) are associated with the same Job object. The Job object records basic accounting information for all processes associated with the Job. The following are some of the CPU, memory, Disk, and I/O-related limits you can specify for a Job:
Starting with Windows 8 and Server 2012, a process can be associated with multiple Jobs, effectively creating a hierarchy known as Nested Jobs, where a child Job holds a subset of processes of its parent Job. Once a process is added to more than one Job, the system tries to form a hierarchy, if possible. A current restriction is that Jobs cannot form a hierarchy if any of them set User-Interface limits. Job limits for a child Job cannot be more permissive than its parent, but they can be more restrictive.
Jobs can be associated with an I/O Completion Port Object, which other threads might be waiting for. This allows interested parties (typically the Job creator) to monitor for limit violations and events that would affect the Job's security (e.g., a new process being created or abnormally exiting). Any notification that targets the I/O Completion Port of a Job will be sent to the Job and all its ancestors (the Job itself does not have to have the I/O Completion Port for the notification to be sent to its ancestors). You can view unnamed Jobs with the kernel debugger command $\rightarrow$ !job or dt nt!_ejob.
Windows Containers (Server Silos)—unlike Hyper-V Containers, which leverage a full virtualized environment—provide a second "instance" of all User-Mode components while running on top of the same kernel and drivers. At the cost of some security, this provides a much more lightweight container environment which Microsoft Windows uses to implement containerization at the OS level, similarly to Linux namespaces and cgroups but adapted for the NT Kernel. For simplicity, this is a Docker-like container environment on Windows, but instead of full virtualization, it uses a deep isolation layer built into the Windows Kernel. Therefore, Windows Containers fill the same role as Docker but for Windows-based apps (e.g., $\text{IIS}$ server, .NET, COM+ server, $\text{WCF}$). Containers share the same kernel but have an isolated User-Mode Environment. When you create a Silo (Sandboxed OS Session), inside that Silo, processes think they're in their own kernel, even though they share the same host kernel. This isolation is handled by new kernel features, including:
Silos, Nested Jobs, & Windows Containers
Silo: The Isolation Boundary
A Silo represents an isolation boundary in the Windows Kernel where each container gets its own logical OS environment (processes, registry, $\text{LSA}$, networking, file system). Silos are a feature of Job Objects; in practice, a Silo is a hybrid Job Object. This results in the Silo Flag being set inside the $\text{EJOB}$ object, and the allocation of the SLS (Silo Local Storage) slots are triggered by the Job creation. The CreateJobObject API, specifically the SetInformationJobObject API, is used with the JobObjectCreateSiloInformation class to initiate the creation of a Silo. A Silo can actually host two types of silos: App Silos and Server Silos.
The first element that defines a Server Silo is the existence of a custom Object Manager Namespace. All application-visible named objects (files, registry keys, events, mutexes, $\text{RPC}$ ports, and more) reside in a Root Namespace, which allows applications to create, locate, and share these objects among themselves. The ability for a Server Silo to have its own Root Namespace means that all access to any named object can be controlled in three ways:
Each Server Silo gets its own copy of certain Kernel State which is stored and tracked using the Silo Context Mechanism. A Silo Context refers to a storage slot inside the kernel that holds data specific to that container. When a new Server Silo (container) is created:
What happens with the Network driver that runs on the Host itself? Windows defines a "Root Host Silo". Even though the host system ($\text{Session 0}$) isn't a container, it pretends to be one and will be represented internally by the global structure PspHostSiloGlobals. Every time the kernel asks, "What's the current Silo context?" and finds a NULL, it just defaults to the Host's Silo context. This ensures all code paths—both for containers and the Host—can use the same logic.
Silo Monitors is a notification or registration mechanism built into the Windows kernel that lets drivers "subscribe" to Silo lifecycle events. Drivers can register as silo monitors using the following APIs: PsRegisterSiloMonitor, PsStartSiloMonitor, and PsUnregisterSiloMonitor. When you register, the kernel immediately informs you of:
The Simplest Creation function in user-mode is CreateThread. This function creates a thread in the current process, accepting the following arguments:
The target process handle must be obtained with enough access rights to allow such an operation. Protected processes cannot be injected in this way, as handles to such processes are obtained with limited rights.
Note: The implementation of CreateThread & CreateRemoteThread simply calls CreateRemoteThreadEx with the appropriate defaults. CreateRemoteThreadEx adds the capability to provide an attribute list (such as security or extended parameters). If all goes well, CreateRemoteThreadEx eventually calls NtCreateThreadEx in NTdll, thus making the usual transition to kernel mode, where execution continues in the executive routine NtCreateThreadEx. From there the kernel-mode part of thread creation occurs, which calls PspCreateThread to create a thread object. PsCreateSystemThread is useful for drivers that need independent work to be processed within the system process – not associated with any particular user process. It creates a thread in Kernel mode directly. A Windows thread is represented by an Executive Thread Object which encapsulates the ETHREAD structure. It contains a KTHREAD structure as its first member (Thread Control Block - TCB). The ETHREAD structure and other structures point to addresses in the system address space, except the Thread Environment Block (TEB), which exists in the User process address space (similar to Process Environment Block - PEB) because user-mode components need access to it. The Windows Subsystem process (CSRSS) maintains a parallel structure for each thread created by a Windows System application called "CSR_THREAD" for threads that have called a Windows Subsystem user/GDI function. The kernel-mode layer (Win32k.sys) maintains a per-Thread data structure (W32THREAD) that is pointed to by the KTHREAD structure. This points to a layer violation in standard kernel's abstraction architecture. The executive, higher level, graphics related Win32k thread structure is pointed to by KTHREAD’s Tcb.Win32Thread field, not ETHREAD, this is in opposite to the Win32k process structure pointed to by the EPROCESS not KPROCESS. You can use kernel debugger dt command to display the internal structure of ETHREAD and KTHREAD. Such as dt nt!_ETHREAD and dt nt!_KTHREAD, where dt nt!_ETHREAD Tcb = dt nt!_KTHREAD. The dt (dump type) command interprets memory at the given address according to the type definition (EPROCESS, KPROCESS, ETHREAD, KTHREAD, etc.) loaded from the process's database symbols. It's purely symbolic memory interpretation and inspecting raw fields manually. Meanwhile, the kernel debugger !thread or !process command is a debugger extension command that reads, formats, and interprets internal kernel structures by using Debugger Engine (DbgEng) API calls to inspect kernel memory. It performs higher-level logic. Some key elements of the information the kernel debugger displays can't be displayed by any other utility. These include: internal structure addresses, priority details, stack info, Pending I/O Request List, List of objects the thread is waiting for. To display process/thread information, use either the !process or !thread with the address of a thread object to display a specific process or thread. The threads shown using the !process command. Each thread shows its address (ETHREAD) which can be passed to the !thread command to get more information regarding a specific thread. The TEB can be viewed using the !TEB. The command can be used on its own to dump the TEB for the current thread examined using !thread thread_addr of the debugger, or with a TEB address of a thread to get it for an arbitrary thread. In the case of a kernel debugger, the current process must be set before issuing the command with a TEB address so that the correct process/thread context is used.
The prefix like Nt!, Win32k!, Csrss! doesn't mean a call is made to that module. Instead, it tells WinDbg or kernel debugger which symbol module the type or symbol belongs to, where Nt! refers to symbols from NTOSKRNL.exe. Therefore, dt nt!_EPROCESS means "Interpret memory at this address as an EPROCESS structure defined in ntoskrnl". Here, the nt! points WinDbg's symbol engine to the module that defines _EPROCESS, also dt csrss!_CSR_THREAD means "Interpret the memory address as a CSR_THREAD structure defined in CSRSS". They are just symbol module qualifiers. Only !process / !thread address is interpreted by WinDbg as dt nt!_EPROCESS / dt nt!_ETHREAD internally, as it knows that processes / threads in kernel space are represented by the _EPROCESS / _ETHREAD structure. A thread's life cycle starts when a process creates a new thread in one of the following ways:
User-mode debuggers allow you to attach to a process and display the user stack for a thread. Process Explorer, however, shows both the user's and kernel stack in one click of a button. You can view the kernel thread stacks using WinDbg in local kernel debugging mode. To view the stack of another thread, use ~n s command. To switch the debugger to another thread, use the ~n command, where n is the thread number.
Protected processes have several limitations in terms of which access rights will be granted, even to the user with the highest privileges on the system. These limitations also apply to threads inside such a process. Only four permissions are granted to prevent hijacking of a protected process: QueryLimitedInformation, SetLimitedInformation, Suspend, Resume. Even Process Explorer doesn't show the Win32 thread start address. Instead of displaying the standard thread client wrapper, you get an error while trying to view the stack because Process Explorer needs to read the virtual memory inside the protected process, which it can't do. Although the dynamic properties, the I/O & memory properties are not shown for protected processes.
Windows implements a priority-driven Preemptive Scheduling System. Certain high priority threads ready to run might be restricted by the processors on which they might be allowed/preferred to run on. Processor Affinity: By default, threads can run only on processors within the processor group associated with the process. Developers can alter processor affinity by using the appropriate API or by setting an affinity mask in the PE Image headers. You can also use tools to change affinity at run time. After a thread is selected to run, it runs for an amount of time called Quantum. A Quantum is the length of time a thread is allowed to run before another thread at the same priority level is given a turn to run. The Quantum value can vary due to:
Priority Levels & Base Priority
Each Process is assigned a Base Priority Class, that defines its base scheduling priority. This is set during process creation or adjusted dynamically through SetPriorityClass() API OR Task Manager / Process Explorer. Each THREAD within a process has Relative Priority Deltas – an adjustment to the process's Base Level. A Thread's effective base priority = Process Base Priority + Thread Relative Priority Delta. When Relative priorities reach extremes (+15/-15) they are saturated, not offset.
PROCESS PRIORITY CLASS (PspPriorityTable) $\times$ THREAD RELATIVE PRIORITY DELTAS
| Process Class | Priority Base | Thread Relative Deltas |
|---|---|---|
| Real Time (4) | 24 | Highest (+2) |
| High (3) | 13 | Above Normal (+1) |
| Above Normal (6) | 10 | Normal (0) |
| Normal (2) | 8 | Below Normal (-1) |
| Below Normal (5) | 6 | Lowest (-2) |
| Idle Time (1) | 4 | Idle (-15) |
| Critical (8) | 6 | |
| You can raise (or lower) thread priorities within the dynamic range. However, you must have the Increase Scheduling Priority privilege (SeIncreaseBasePriorityPrivilege) to enter Real-Time. | ||
| Once a process has entered the Real-Time range, all its Threads (+ Idle) must run at one of the Real-Time priority levels. It's impossible to run Real-Time threads with the same process at one of the dynamic priority levels. |
Processor Cycles / Clock cycles $\rightarrow$ Clock Intervals / Clock ticks per second. To make scheduling decisions, the kernel maintains a set of data structures collectively known as the Dispatcher Database, which is found in the Kernel Processor Control Block (KPCR). This database keeps track of which threads are ready to run. Thread Dispatcher Concurrency: A multiprocessor system has per-processor dispatcher queues and shared processor group queues. Each CPU can check its non-shared ready queue for the next thread to run without having to lock the system-wide ready queues. Use dt nt!_KPRCB to view its fields. The Dispatcher Ready Queues (ReadListHead in KSHARED_READY_QUEUE) contain threads in the ready state awaiting execution. There is one queue for each of the 32 priority levels. To speed up the selection of which thread to run / preempt , Windows maintains a 32-bit Bitmask (also called Bitmask) called the Ready Summary. Each bit is set to indicate one or more threads in the ready queue for that priority level. Instead of scanning each ready list to see whether it is empty or not , a single bit scan is performed to find the highest priority bit set. Regardless of the number of threads in the ready queue, this operation takes a constant time.
A QUANTUM is the amount of time a thread is permitted to run before Windows checks to see if another thread at the same priority level is waiting to run. A thread may run for another quantum if there are no other threads at its priority level or higher waiting to run on completion of its first Quantum. It represents an estimate of what the number of CPU clock cycles the thread has consumed should be to determine when its turn would be given up. It equals an equivalent number of clock intervals (clock ticks). Each process has a quantum reset value in the PCB used when creating new threads inside the process & duplicated in the TCB , which is then used when giving a thread a new quantum target. As a thread runs, clock cycles are charged at different times/events, e.g. context switches, interrupts, and certain scheduling decisions. If at a clock interval timer interrupt, the number of clock cycles charged has reached (or passed) the quantum target, a quantum end processing is triggered. A context switch occurs to the next (same or higher priority level thread) in the Ready Queue. To change the thread quantum for all processes, you can choose only one of two settings (Quantum Configuration):
(In Performance Options)
Variable Quantum: Windows sets the maximum possible priority level to foreground threads. The Priority Separation Value determines the priority boost that the scheduler will apply to foreground threads , which is thus paired with an appropriate extension of Quantum. For each extra priority level, another quantum is given to the thread. Thus, when a window is brought into the foreground (FG) on a client system , all the threads in the process containing the thread that owns a FG Window have their quantum tripled. Threads in the FG process run with a quantum of "18 clock ticks" , whereas threads in other processes have a default client quantum of "6 clock ticks". In this way, when you switch away from a CPU-intensive process , the FG process will get proportionally more of the CPU cycles. Assuming the thread priorities are the same in both Background & Foreground processes. The Win32 Priority Separation Registry Key ($\text{HKLM}\backslash\text{SYSTEM}\backslash\text{CurrentControlSet}\backslash\text{Control}\backslash\text{PriorityControl}$) controls quantum settings which specify relative length of thread quantum (short/long), Variable/Fixed & priority separation. This determines the quantum index used when variable quantums are enabled. It consists of 6 bits divided into flags.
Date: [Date: Insert Current Date]
PRIORITY BOOSTS: The Windows Scheduler periodically adjusts the current (dynamic/variable) priority of threads. It does so to decrease various latencies & increase responsiveness – to respond faster to events threads are waiting on. Also to prevent starvation and priority inversion scenarios. Here are some of the boosted scenarios:
| Event Type | Short Quantum Index (Client) | Long Quantum Index (Server) |
|---|---|---|
| I/O Completion | Variable: 1, 2, 4, 6 | Variable: 1, 2, 4, 6 |
| Scheduler Dispatcher Events | 1, 2 | 1, 2 |
| User Interface (UI) Interaction / Input | 2 | 2 |
| Waiting on an ERESOURCE | 12 | 12 |
| Ready to run but not run for some time (Starvation) | 15 | 15 |
| Windows gives a temporary priority boost upon completion of certain I/O Operations to that threads that were waiting for an I/O have more of a chance to run right away & process whatever was being waited on. | ||
| Recommended boost values can be found in the Windows Driver kit header files. The actual value for the boost is up to the Driver. It's the device driver that specifies the boost when it completes an I/O Request on its call to the kernel function IoCompleteRequest. I/O Requests to devices warranting better responsiveness have higher boost values. | ||
| Unwait Boosts attempt to decrease the latency between a thread waking up due to an object being signaled and the thread actually beginning its execution to process the Unwait. It's desirable that a thread that wakes up from a waiting state would be able to run as soon as possible. | ||
| Some Dispatcher objects don't have boosts associated with them. For example, when a timer is set on an EXPRESS timer, or when a process is signaled, no boost is applied. | ||
| Priority Inversion |
When a thread attempts to acquire an Executive Resource (ERESOURCE) that's already owned "exclusively" by another thread, it must enter a wait state until the other thread has released the resource. To limit deadlocks, the executive performs the wait in 500ms intervals. At the end of these 500ms, if the resource is still owned, the executive attempts to implement priority elevation by acquiring the dispatcher lock, boosting the owning thread(s) to 15, resetting its Quantum, and performing another wait. Because ERESOURCE can be either "shared/exclusive", the kernel first boosts the exclusive owner & then checks for shared owners & boosts all of them. When the waiting thread enters the wait state again, the hope is that the scheduler will schedule one of the ERESOURCE owner threads, which will have enough time to complete its work & release the resource. It's not perfect as this would cause a surge of high-priority threads on the system, all with full Quantum. Whenever a thread in the FG process completes a wait operation on a kernel object, the kernel boosts its Current Priority Level (PL) by the current value of PspPrioritySeparation. This reflects the quantum-table index used to select quantums for the threads in the FG apps. It's also used as a priority boost value to improve responsiveness of interactive apps. Threads that own Windows receive an additional boost of 2 when they wake up because of Windowing activity, e.g. arrival of Windows messages. The Windowing system (Win32k.sys) applies this boost when it calls KeSetEvent to set an event used to wake up a GUI Thread. You can see the system apply its boost of 2 for GUI threads that wake up to process window messages by monitoring the current priority of a GUI App & moving the mouse across the window.
PRIORITY INVERSION: A scenario where a low-priority thread (PL 7) running prevents a high-priority thread (PL 14) from accessing a resource (Resource A), because the low-priority thread owns the resource. The low-priority thread never runs enough to free Resource A. AutoBoost resolves such a scenario by tracking locks and owners and boosting the appropriate thread so that some forward progress can be made.
Windows includes a generic CPU Starvation-relief mechanism called the 'Balance-Set Manager'. This is a system thread that scans the ready queues for any thread that has been in the Ready state for approx 4 secs. It then boosts such a thread's priority to 15 & sets the quantum target to an equivalent CPU clock cycle count of 3 quantum units. After the quantum expires, the thread's priority decays immediately to its original base priority. If the thread hasn't finished & a high PL Thread is ready to run, it decays & returns to Ready. To disable boosting, call SetThreadPriorityBoost (FALSE). This sets the Disable Boost flag in the KTHREAD. Boosting is also disabled if the kernel realizes that the thread has actually exhausted its quantum (but the clock interrupt didn't fire to confirm it) and it has come out of a wait that lasted less than 2 clock ticks.
Priority Recomputation (Removing Boosts) happens on non-Real-time threads (not 16-30). This is done by taking the thread's current priority, subtracting its foreground boost, subtracting its unwait boost (The combination of these last 2 subtraction items is the Priority Decrement), and finally subtracting 1. This new priority is then compared with the base priority of the thread. The new priority is capped at the base priority, and any existing priority decrement is zeroed out. The AutoBoost idea is to track lock owners & lock waiters in such a way that would allow boosting the appropriate thread's priority to allow threads to make forward progress. The lock info is stored in a status array of KLOCK_ENTRY objects inside the KTHREAD structure. Each KLOCK_ENTRY maintains 2 binary trees:
Date: [Date: Insert Current Date] A thread's context is its volatile state. A typical context switch requires saving & reloading of the following parts:
TERMINATION: A Thread finishes running/execution by returning from its main routine, or it's killed by TerminateThread. It moves from Running to Terminated state. If no open handles on the process/thread object, the thread is removed from the process's thread list. The ETHREAD & associated data structures are deallocated & released to the pool.
IDLE THREADS: Each CPU/processor has its own dedicated idle thread. On a multi-processor system, one CPU can be executing a thread while another CPU might have no threads to execute. When no runnable threads are available to run on a CPU, Windows dispatches that CPU's idle thread. The Idle thread & process are special because they are represented by EPROCESS/KPROCESS & ETHREAD/KTHREAD structures , but they are not executive manager processes & thread objects. Nor is the idle process on the system process list. The !pcr (processor control region) command , displays a subset of info from the KPRCB. It takes a simple numeric argument which is the number of the CPU whose PCR is to be displayed. The boot processor is processor 0. !pcr 0. The Current Thread & Idle Thread Next Thread are different pointers and exist differently for each CPU/KPRCB. The Process ID, Thread ID, Client ID, PEB & TEB pointers are 0. The Idle Process has no user-mode address space. Its threads execute no user-mode code. They have no need of various data required to manage the user-mode environment.
Every Thread has a Suspend Count, which is incremented by suspension and decremented by resuming. If a thread's Suspend Count is 0, it is free to execute, otherwise it will not execute. Freezing is a mechanism by which processes enter a suspended state that can't be changed by calling ResumeThread on threads in the process. This happens when a windowed App goes to the background. A flag in the KTHREAD structure indicates a thread is frozen. For a thread to be able to execute, its Suspend Count must be 0 and the frozen flag must be clear (not set). Deep freeze adds another constraint : Newly created threads in the process can't execute as well. For example, if a call to CreateRemoteThreadEx is used to create a new thread in a deep frozen process, the thread will be frozen before actually starting.
THREAD SELECTION: Picking the next thread to run. The Scheduler calls KiSelectSchedulableThread to find a Ready state thread to run when:
KiSelectReadyThreadEx checks for ready threads. If a ready thread is not found, the Idle Scheduler is selected for execution. The logical processor may also be interested in immediately running the next ready thread or performing another action if one isn't available, such as when a context switch to the foreground process occurs. Whenever the idle thread runs, it checks whether idle scheduling has been enabled. If so, it begins scanning other processors' ready queues for threads it can run by calling KiSearchForNewThread. The run-time cost associated with this operation is not charged as idle thread time, but instead charged as Interrupt DPC time charged to the processor. So the Idle Scheduling time is considered as system time. Windows attempts to schedule the highest PL runnable threads on all available CPUs, guaranteeing running one of the available highest PL Threads somewhere. With shared Ready Queues $\rightarrow$ Threads with no affinity restrictions , the guarantee is stronger. Each shared group of processors is running at least one of the highest priority threads. There is a per-CPU list of threads in the Deferred Ready state. These threads represent threads that are ready to run but have not yet been readied for execution. The actual ready operation has been deferred to a more appropriate time. The Deferred Ready Thread list is processed by KiProcessDeferredReady. It does this by calling KiDeferredReadyThread for each thread on the list to perform modifications to process/thread Affinity, Priority (Including Boost), or Quantum values. These could all cause the thread to run immediately , to be put on the ready list of the processor , or if the processor is unavailable, to be potentially put on a different processor's defined ready list, in a standby state, or immediately executed.
AFFINITY: Each thread has an affinity mask that specifies the processors on which the thread is allowed to run. The thread affinity mask is inherited from the process affinity mask. By default, all processes begin with an affinity mask that is equal to the set of all active processors on their assigned Group Affinity. The system is free to schedule all threads on any available processor within the group assigned to the process. To optimize throughput, or partition workloads to a specific set of processors , applications can choose the affinity by calling SetThreadAffinityMask or SetProcessAffinityMask or using Task Manager or ProcExp's Set Affinity. Also, the PE executable provides a command-line interface to these functions, by specifying an affinity mask in the Image header. Windows won't move a running thread that could run on a different processor from one processor to a second processor to then permit a thread with an affinity mask for the first processor to run on the first processor. Therefore, changing affinity masks for a thread/process can result in them getting less CPU time than they normally would, because Windows is restricted from running the thread on certain processors due to Affinity settings. CPU Sets is a form of Affinity that you can set for use by the system as a whole (Including system thread activity), processes, and even individual threads. System threads are protected from external affinity changes.
Introduced in Windows 8 and Server 2012.
Soft AFFINITY: Managed by an algorithm that tracks processor usage, the IDEAL PROCESSOR. Each thread has three CPU numbers stored in the kernel thread control block : Ideal Processor, Last Processor, Next Processor. The ideal processor for a thread is chosen when a thread is created using a seed in the process control block. The seed is incremented each time a thread is created so that the Ideal Processor for each new thread in the process rotates through the available processors on the system. The "next" ideal processor is selected from the hyperthreading set, such that threads are spread evenly across the Physical Processors. The above explanation is for a Simultaneous Multi-threading Multi-processor system. Meanwhile, on NUMA systems where processors are grouped into Nodes , when a process is created, an ideal node for that process is selected. The first process is assigned to node 0, the second process to node 1, and so on. Then the ideal processors for the threads in the process are chosen from the process's ideal node. The ideal processor for the first thread in a process is assigned to the first processor in the node. As more threads are created in processes with the same ideal node , the next processor is used for the next thread's ideal processor and so on within the same node. Regardless of the underlying scenario and various possibilities, threads are mostly put on their Ideal Processor's Per-processor ready queues , guaranteeing the consistency of the Algorithms that determine how a logical processor picks a thread to run when there are idle processors versus when there are no idle processors.
Thread Based Scheduling attempts to fairly share the processor(s) amongst competing threads of the same priority only. It doesn't account for higher-level concerns such as the distribution of threads to users. This is problematic in Terminal-Services Environments , where dozens of users compete for CPU time such that a single high-priority thread from a given user has the potential to starve threads from other users on the system. Group-Based Scheduling is built around the concept of a Kernel Scheduling Group , which maintains a policy, its scheduling parameters, and a list of Kernel Scheduling Control Blocks (KSCBs), one per-processor.
DFSS (Dynamic Fair-Share Scheduling) is a mechanism that can be used to fairly distribute CPU time amongst sessions running on a machine , preventing one session from monopolizing the CPU if some threads running under that session have a relatively high priority and run a lot. It's enabled by default on a Windows Server system that has the Remote Desktop role. It can be configured on Client systems too. The last phase of System Init $\rightarrow$ Registry Hive Initialized by Smss $\rightarrow$ PsBootPhaseComplete calls PspIsDFSSEnabled (either DFSS/LEGACY). For DFSS to be enabled: EnableCpuQuota must be Non-Zero in both:
WORKER FACTORIES (User-Thread Pool). The Scheduling-Group Infrastructure can be used in a more granular fashion by using a CPU Rate Limit on a Job Object. One of the limitations you can place on a Job is a CPU Rate Control, which is done by calling SetInformationJobObject with JobObjectCpuRateControlInformation as the job info class and a structure type of JOBOBJECT_CPU_RATE_CONTROL_INFORMATION containing the actual data. The structure contains a set of flags that enable you to apply one of the three settings to limit CPU Time:
DYNAMIC PROCESSOR ADDITION: Desktop machines require shutting down the PC to make any sort of hardware changes to the process or core count. Today, some server systems cannot afford the downtime that CPU replacement/addition normally requires. To address this requirement, the latest generation of some system motherboards support the addition of processors while the machine is running. The ACPI BIOS and related hardware on the machine have been built to be aware of this need , but Operating System participation is required for full support. To support the features $\rightarrow$ the Hardware Abstraction Layer (HAL) is involved in the process , which notifies the kernel of a new processor on the system via the KeStartDynamicProcessor function. This routine does similar work to that performed when the system detects more than 1 processor at startup & needs to initialize the structures related to them. However, other Executive parts of the kernel are also called. The processor features need to be updated for the new processor to match the rest of the system (e.g. Hyper-V). The initialization sequence completes with the notification of the Windows Hardware Error Architecture (WHEA) component that a new processor is online. Device Drivers are also notified via a default executive callback object. Once drivers are notified, the final kernel component called is the Plug and Play Manager , which adds the processor to the system's device node and rebalances Interrupts so that the new processor can handle Interrupts that were already registered for other processors. Applications should not take advantage of a dynamically added processor by default (they must request it). Why? A sudden change of affinity can have potentially breaking changes for an running App, especially going from a single-processor $\rightarrow$ multi-processor environment. As part of KeStartDynamicProcessor, a new step has been added after Interrupts are rebalanced : calling the Process Manager to perform affinity updates through PspUpdateActiveProcessAffinity.
WORKER FACTORIES are the internal mechanism used to implement User Thread Pools (previously NT thread pool API). One issue with the old implementation was that only one thread pool could be created in a process and also the implementation itself was in user mode (in Ntdll.dll). However, now NTdll merely provides the interfaces / high-level APIs required for interacting with the worker factory kernel code. The kernel thread pool functionality in Windows is managed by an Object Manager type called ExWorkerFactory , as well as 4 native (NT) system calls for managing the factory and its workers and 2 Query/Set native calls & a Wait call. These calls provide user-mode code with a handle to the ExWorkerFactory Object, which contains information. The Worker Factory Implementation is responsible for allocating worker threads (or calling the given user-mode worker thread entry point) , maintaining a Min/Max thread count (allowing for permanent/dynamic worker pools) , as well as other accounting info. A worker factory will create a new thread if all conditions below are met:
I/O Completion Ports (KQUEUE): When creating a worker factory, an I/O Completion Port must have already been created by user mode and the handle needs to be passed in. It is through this I/O Completion Port that the user-mode implementation will queue and wait for work. The ReleaseWorkerFactory call (which queues work) is a wrapper around IoSetCompletionEx, which increases pending work , while the wait call is a wrapper around IoRemoveIoCompletion. Both routines call into the kernel Queue. The job of the worker factory code is to manage either a persistent, static, or dynamic thread pool , wrap the I/O Completion Port model into interfaces that try to prevent stalled worker threads by auto creating dynamic threads , simplify global cleanup/termination operations during a factory shutdown request & block new requests.
Every process and thread starts here — the NT executive level (in ntoskrnl.exe).
_EPROCESS → Represents a process in the kernel. It stores core attributes like address space, handle table, access tokens, and thread lists.
_ETHREAD → Represents a thread in the kernel. It links to its parent _EPROCESS, its TEB (Thread Environment Block) in user mode, and scheduling information.
_EPROCESS and _ETHREAD are the canonical representations.
These are managed by the NT kernel itself (the “nt!” world).
Now, when a process starts, CSRSS (Client/Server Runtime Subsystem) — the Windows user-mode subsystem manager — is notified. CSRSS maintains its own bookkeeping of processes and threads that are part of the Windows Subsystem.
_CSR_PROCESS → Mirrors _EPROCESS from the kernel’s perspective but in user mode inside csrss.exe. It holds info like console handles, process flags, API port handles, etc.
_CSR_THREAD → Mirrors _ETHREAD in user mode. It tracks per-thread state, such as Win32 API message handling and communication with csrss.exe.
It creates _CSR_PROCESS and _CSR_THREAD objects only for processes that register with the Windows subsystem, i.e., Win32 processes.
These are user-mode mirror records of kernel processes/threads. They’re not copies of the same memory — just bookkeeping that lets CSRSS handle:
Console I/O
Thread creation notifications
Exception dispatching
Exit handling
Window message loops before GUI initialization.
These are not duplicates, but parallel tracking structures — the subsystem’s shadow copies of process/thread metadata.
Every GUI-capable or Win32 process has a corresponding CSR_PROCESS and CSR_THREAD maintained by csrss.exe.
When a process loads the Win32 API DLLs (user32.dll, gdi32.dll), it becomes a GUI process. That triggers win32k.sys (the kernel graphics and window manager) to attach graphical context.
Win32k allocates _W32PROCESS and _W32THREAD structures in kernel space and links them via pointers in _EPROCESS / _ETHREAD.
_W32PROCESS → The kernel-mode structure in win32k.sys representing the process’s GUI state. Contains info like window station, desktop handles, GDI handle tables, etc.
_W32THREAD → Represents a thread’s GUI state: message queue, input focus, window handles, etc.
Those structures carry:
These structures live in kernel space (win32k.sys) but are logically associated with their _EPROCESS / _ETHREAD counterparts.
So the _EPROCESS is always there. Then:
The executive adds user-visible and subsystem logic; the kernel manages scheduling and synchronization.
The _KPROCESS is the Process Control Block (PCB) embedded within _EPROCESS, and the _KTHREAD is the Thread Control Block (TCB) embedded within _ETHREAD.
They’re the “kernel dispatcher objects” nested inside the “executive objects.”
The prefix K means Kernel Dispatcher Object — it’s the minimal, scheduler-visible part of a process or thread.
So:
Windows uses a layered object model where executive objects “wrap” kernel dispatcher objects.
➤ _EPROCESS (Executive-level process)
+0x098 Pcb : _KPROCESS
(offset varies by version)
That means every process is built around a KPROCESS.
➤ _ETHREAD (Executive-level thread)
+0x000 Tcb : _KTHREAD
(often the first field!)
NT was designed as a layered kernel:
So:
_KPROCESS and _KTHREAD are what the kernel dispatcher and scheduler see. _EPROCESS and _ETHREAD are what the executive and object manager see.
The executive layer extends the kernel layer.
When a thread is scheduled:
The rest of _EPROCESS — handles, tokens, image info — are managed by the executive, not the scheduler.
When Windows creates an executive object like _EPROCESS or _ETHREAD, it allocates a single contiguous memory block large enough to hold the entire structure, including its embedded substructures (like _KPROCESS and _KTHREAD).
That’s why, when you dump the memory around the address of _EPROCESS, you’ll see field offsets that increase linearly, e.g.:
nt!_EPROCESS
+0x000 Pcb : _KPROCESS
+0x2d0 ProcessLock : _EX_PUSH_LOCK
+0x2d8 UniqueProcessId : Ptr64 Void
+0x2e0 ActiveProcessLinks : _LIST_ENTRY
...
So if _EPROCESS begins at (say) 0xFFFFA20A34C3B080, then:
It’s literally like a book chapter: each substructure occupies its own segment within the continuous memory page for that object.
Here’s the key distinction that explains what you’re seeing:
| Field Type | Example | Memory Layout | Description |
|---|---|---|---|
| Embedded Structure | _EPROCESS.Pcb : _KPROCESS | Occupies part of the same contiguous memory | No pointer indirection — data lives directly inside the parent object. |
| Pointer to Another Structure | _EPROCESS.ThreadListHead → _ETHREAD list | Stores only the pointer (address) | The actual target is elsewhere in memory. |
| So: |
Let’s visualize this for a single process object:
EPROCESS @ 0xFFFFA20A34C3B080
│
├── KPROCESS (PCB)
│ [0x0000 - 0x02CF]
│
├── ProcessLock
│ [0x02D0 - 0x02D7]
│
├── UniqueProcessId
│ [0x02D8 - 0x02DF]
│
├── ActiveProcessLinks
│ [0x02E0 - 0x02EF]
│
├── Token
│ [0x0350 - 0x0357]
│
└── ...
[continues up to ~0x065AB depending on version]
Within that space:
ETHREAD @ 0xFFFFA20A36A2A080
│
├── KTHREAD (TCB)
│ [0x0000 - 0x01FF]
│
├── CreateTime
│ [0x0200 - 0x0207]
│
├── ExitTime
│ [0x0208 - 0x020F]
│
├── Cid (Client ID)
│ [0x0210 - 0x0217]
│
└── ...
So when you dump memory in WinDbg: 0: kd> dt nt!_ETHREAD <address> …the offsets you see correspond directly to byte ranges in that contiguous allocation.
If you wrote this in C, it would literally look like:
typedef struct _EPROCESS {
KPROCESS Pcb; // occupies first bytes
EX_PUSH_LOCK ProcessLock; // follows directly in memory
PVOID UniqueProcessId;
LIST_ENTRY ActiveProcessLinks;
// ...
} EPROCESS;
When this struct is allocated:
That’s why the debugger output appears like “book pages” — it’s the raw in-memory layout of that composite structure. These structures live in non-paged pool or paged pool memory (depending on type). When the kernel creates a process/thread:
So it’s one block (like a “book”), not one page.
When you dump the memory region (e.g., !pool, !poolfind, or memory window view), you might see the structure’s members at offset-like addresses:
_EPROCESS +0x000 Pcb : _KPROCESS +0x160 ProcessLock : _EX_PUSH_LOCK +0x168 UniqueProcessId : Ptr64 Void ...
These offsets make it look like EPROCESS “contains” a _KPROCESS at +0x0. That’s correct — _EPROCESS literally embeds _KPROCESS as its first field. But these offsets don’t correspond to virtual pages. They are just field offsets within the same allocated block.
The Sysinternals web site was created in 1996 by Mark Russinovich to host his advanced system utilities and technical information. Whether you’re an IT Pro or a developer, you’ll find Sysinternals utilities to help you manage, troubleshoot and diagnose your Windows systems and applications. https://docs.microsoft.com/en-us/sysinternals/
Unlike Task Manager and all other process/processor monitoring tools, Process Explorer uses the clock cycle counter designed for thread run-time accounting (described later in this chapter) instead of the clock interval timer, so you will see a significantly different view of CPU consumption using Process Explorer. This is because many threads run for such a short time that they are seldom (if ever) the currently running thread when the clock interval timer interrupt occurs. As a result, they are not charged for much of their CPU time, leading clock-based tools to perceive a CPU usage of 0 percent. On the other hand, the total number of clock cycles represents the actual number of processor cycles that each thread in the process accrued. It is independent of the clock interval timer’s resolution because the count is maintained internally by the processor at each cycle and updated by Windows at each interrupt entry . (A final accumulation is done before a context switch. Think of clock-based tools as a security camera taking one photo every second — if a thief runs in and out between photos, you’ll miss them. Process Explorer is like a motion sensor that tracks every little movement — it knows exactly when and how much activity happened.
AUTOSTARTS is the term I use to refer to software that runs automatically without being intentionally started by a user. This type of software includes drivers and services that start when the computer is booted; applications, utilities, and shell extensions that start when a user logs on; and browser extensions that load when Internet Explorer is started. Over 200 locations in the file system and registry allow autostarts to be configured on x64 versions of Windows. These locations are often referred to as Autostart Extensibility Points, or ASEPs. As malware has become more sophisticated and difficult to identify, its use of ASEPs has become more sophisticated as well, malware often leverages rootkits, which subvert the integrity of the operating system. Rootkits intercept and modify system calls, lying to software that uses documented system interfaces about the state of the system. Rootkits can hide the presence of registry keys and values, files and directories, processes, sockets, user accounts, and more, or they can make software believe something exists when it doesn’t. Some telltale signs that can point to malware: ■ Entries with a well-known publisher such as Microsoft that fail signature verification. (Unfortunately, not all software published by Microsoft is signed.) ■ Entries with an image path pointing to a DLL or EXE file that is missing Description or Publisher information (unless the target file is not found). ■ A common Windows component that is launched from an unusual or nonstandard location—for example, svchost.exe or another service launching from C:\Windows or C:\Windows\SysWOW64 (instead of from System32) or from C:\System Volume Information. ■ Entries with names that can be mistaken for common Windows components, such as those with slight misspellings—for example,“Isass.exe” with a capital “I” instead of a lower-case “L”, “scvhost.exe” instead of “svchost.exe,” or “iexplorer.exe” with the extra “r” at the end. ■ Entries for which the file date and time of the launched program correspond to when problems were first noticed or a breach is discovered to have occurred. ■ Disabling or deleting an entry, pressing F5 to refresh the display, and finding the entry still present and enabled. Malware will often monitor its ASEPs and put them back if they get removed.
AUTORUNS utility to expose as many autostarts as we could identify, and to make it easy to disable or remove those autostarts. The information that Autoruns exposes can be discovered manually if you know where to look in the registry and file system. Autoruns automates that task, scanning a large number of ASEPs in a few seconds, verifying entries, and making it easier to identify entries with suspicious characteristics, such as the lack of a digital signature, or that are flagged as suspicious by VirusTotal. Windows tracks the last write time for registry keys but not for individual registry values, the “last modified” time for a registry ASEP location will be for the key and might not reflect when a specific entry was changed. AutorunsC is a console-mode version of Autoruns that outputs results to its standard output. It is designed primarily for use in scripts. Its purpose is data collection only: it cannot disable or delete any autostart entries. The command-line options are listed below. They let you capture all autostarts or just specific categories, verify digital signatures, query VirusTotal, omit Microsoft entries, specify a user account for which to capture autostarts or capture all user accounts’ autostarts, and output results as comma-separated or tab-separated values (CSV) or as XML. If you don’t specify any options, AutorunsC outputs just the Logon entries without signature verification and in an indented list format designed for human reading. To capture other ASEPs, add the –a option followed by one or more letters indicating the ASEP categories of interest, or * to capture all ASEP categories.
The Boot Execute are Windows native-mode executables that are started by the Session Manager (Smss.exe) during system boot. BootExecute typically includes tasks, such as hard-drive verification and repair (Autochk.exe), that cannot be performed while Windows is running
AppInit The idea behind AppInit DLLs surely seemed like a good idea to the software engineers who incorporated it into Windows NT 3.1. Specify one or more DLLs in the Appinit_Dlls registry key, and those DLLs will be loaded into every process that loads User32.dll (that is, virtually all user-mode Windows processes). Well, what could go wrong with that? ■ The AppInit DLLs are loaded into the process during User32’s initialization—that is, while its DllMain function is executing. Developers are explicitly told not to load other DLLs within a DllMain. It can lead to deadlocks and out-of-order loads, which can lead to application crashes. And yet here, the AppInit DLL “feature” does exactly that. And yes, that has led to deadlock and application crashes.5 ■ A DLL that automatically gets loaded into every process on the computer sounds like a winner if you are writing malware. Although AppInit has been used in legitimate (but misguided) software, it is frequently used by malware. Because of these problems, AppInit DLLs are deprecated and disabled by default in Windows Vista and newer. For purposes of backward compatibility, it is possible to re-enable AppInit DLL functionality, but doing so is strongly discouraged. To ensure that AppInit DLLs have not been re-enabled, verify that the LoadAppInit_DLLs DWORD value is 0 in HKLM\Software\Microsoft\Windows NT\ CurrentVersion\Windows and in HKLM\Software\Wow6432Node\Microsoft\Windows NT\ CurrentVersion\Windows.
KnownDLLs KnownDLLs helps improve system performance by ensuring that all Windows processes use the same version of certain DLLs, rather than choose their own from various file locations. During startup, the Session Manager maps the DLLs listed in HKLM\System\CurrentControlSet\Control\Session Manager\KnownDlls into memory as named section objects. When a new process is loaded and needs to map these DLLs, it uses the existing sections rather than searching the file system for another version of the DLL. The Autoruns KnownDLLs tab should contain only verifiable Windows DLLs. On 64-bit versions of Windows, the KnownDLLs tab lists one ASEP, but file entries are duplicated for both 32-bit and 64-bit versions of the DLLs, in directories specified by the DllDirectory and DllDirectory32 values in the registry key. Note that the Windows-On-Windows-64 (WOW64) support DLLs are present only in the System32 directory and Autoruns will report “file not found” for the corresponding SysWOW64 directory entries. This is normal.
Image hijacks Image hijacks is the term I use for ASEPs that run a different program from the one you specify and expect to be running. The Image Hijacks tab displays four types of these redirections: ■ exefile Changes to the association of the .exe or .cmd file types with an executable command. The file-association user interfaces in Windows have never exposed a way to change the association of the .exe or .cmd file types, but they can be changed in the registry. Note that there are per-user and systemwide versions of these ASEPs. ■ htmlfile Changes to the association of the .htm or .html file types with an executable command. Some malware that hijacks these ASEPs can come into play when you open an HTML file. Verify that the executable command is a legitimate browser. ■ Command Processor\Autorun A command line that is executed whenever a new Cmd.exe instance is launched. The command runs within the context of the new Cmd.exe in- stance. There is a per-user and systemwide variant, as well as a separate version for the 32-bit Cmd.exe on 64-bit Windows. ■ Image File Execution Options (IFEO) Subkeys of this registry location (and its echo in the 64-bit versions of Windows) are used for a number of internal and undocumented purposes. One purpose for IFEO subkeys that has been documented is the ability to specify an alternate program to start whenever a particular application is launched. By creating a subkey named for the file name of the original program and a “Debugger” value within that key that specifies an executable path to an alternate program, the alternate program is started instead and receives the original program path and command line on its command line. The original purpose of this mechanism was for the alternate program to be a debugger and for the new process to be started by that debugger, rather than having a debugger attach to the process later, after its startup code had already run. However, there is no requirement that the alternate program actually be a debugger, nor that it even look at the command line passed to it. In fact, this mechanism is how Process Explorer replaces Task Manager.
The following lists the Logon ASEP locations that Autoruns inspects on a particular instance of an x64 version of Windows 10. The Startup directory in the “all users” Start menu %ALLUSERSPROFILE%\Microsoft\Windows\Start Menu\Programs\Startup
The Startup directory in the user’s Start menu
%APPDATA%\Microsoft\Windows\Start Menu\Programs\Startup
Per-user ASEPs under HKCU\Software
HKCU\Software\Microsoft\Windows\CurrentVersion\Run
HKCU\Software\Microsoft\Windows\CurrentVersion\RunOnce
HKCU\Software\Microsoft\Windows NT\CurrentVersion\Terminal Server\Install\Software\Microsoft\Windows
CurrentVersion\Run
HKCU\Software\Microsoft\Windows NT\CurrentVersion\Terminal Server\Install\Software\Microsoft\Windows
CurrentVersion\Runonce
HKCU\Software\Microsoft\Windows NT\CurrentVersion\Terminal Server\Install\Software\Microsoft\Windows
CurrentVersion\RunonceEx
HKCU\Software\Microsoft\Windows NT\CurrentVersion\Windows\Load
HKCU\Software\Microsoft\Windows NT\CurrentVersion\Windows\Run
HKCU\Software\Microsoft\Windows NT\CurrentVersion\Winlogon\Shell
Per-user ASEPs under HKCU\Software—64-bit only
HKCU\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Run
HKCU\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\RunOnce
Per-user ASEPs under HKCU\Software intended to be controlled through Group Policy
HKCU\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer\Run
HKCU\Software\Microsoft\Windows\CurrentVersion\Policies\System\Shell
HKCU\Software\Policies\Microsoft\Windows\System\Scripts\Logon
HKCU\Software\Policies\Microsoft\Windows\System\Scripts\Logoff
Systemwide ASEPs in the registry
HKLM\Software\Microsoft\Windows\CurrentVersion\Run
HKLM\Software\Microsoft\Windows\CurrentVersion\RunOnce
HKLM\Software\Microsoft\Windows\CurrentVersion\RunOnceEx
HKLM\Software\Microsoft\Active Setup\Installed Components
HKLM\Software\Microsoft\Windows NT\CurrentVersion\Terminal Server\Install\Software\Microsoft\Windows
CurrentVersion\Run
HKLM\Software\Microsoft\Windows NT\CurrentVersion\Terminal Server\Install\Software\Microsoft\Windows
CurrentVersion\Runonce
HKLM\Software\Microsoft\Windows NT\CurrentVersion\Terminal Server\Install\Software\Microsoft\Windows
CurrentVersion\RunonceEx
HKLM\Software\Microsoft\Windows NT\CurrentVersion\Winlogon\IconServiceLib
HKLM\Software\Microsoft\Windows NT\CurrentVersion\Winlogon\AlternateShells\AvailableShells
HKLM\Software\Microsoft\Windows NT\CurrentVersion\Winlogon\AppSetup
HKLM\Software\Microsoft\Windows NT\CurrentVersion\Winlogon\Shell
HKLM\Software\Microsoft\Windows NT\CurrentVersion\Winlogon\Taskman
HKLM\Software\Microsoft\Windows NT\CurrentVersion\Winlogon\Userinit
HKLM\Software\Microsoft\Windows NT\CurrentVersion\Winlogon\VmApplet
HKLM\System\CurrentControlSet\Control\SafeBoot\AlternateShell
HKLM\System\CurrentControlSet\Control\Terminal Server\Wds\rdpwd\StartupPrograms
HKLM\System\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp\InitialProgram
Systemwide ASEPs in the registry, intended to be controlled through Group Policy
HKLM\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer\Run
HKLM\Software\Microsoft\Windows\CurrentVersion\Policies\System\Shell
HKLM\Software\Policies\Microsoft\Windows\System\Scripts\Logon
HKLM\Software\Policies\Microsoft\Windows\System\Scripts\Logoff
HKLM\Software\Policies\Microsoft\Windows\System\Scripts\Startup
HKLM\Software\Policies\Microsoft\Windows\System\Scripts\Shutdown
HKLM\Software\Microsoft\Windows\CurrentVersion\Group Policy\Scripts\Startup
HKLM\Software\Microsoft\Windows\CurrentVersion\Group Policy\Scripts\Shutdown
Systemwide ASEPs in the registry—64-bit only
HKLM\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Run
HKLM\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\RunOnce
HKLM\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\RunOnceEx
HKLM\Software\Wow6432Node\Microsoft\Active Setup\Installed Components
Systemwide ActiveSync ASEPs in the registry
HKLM\Software\Microsoft\Windows CE Services\AutoStartOnConnect
HKLM\Software\Microsoft\Windows CE Services\AutoStartOnDisconnect
Systemwide ActiveSync ASEPs in the registry—64-bit only
HKLM\Software\Wow6432Node\Microsoft\Windows CE Services\AutoStartOnConnect
HKLM\Software\Wow6432Node\Microsoft\Windows CE Services\AutoStartOnDisconnect
Per-user ASEPs under HKCU\Software HKCU\Software\Classes*\ShellEx\ContextMenuHandlers HKCU\Software\Classes*\ShellEx\PropertySheetHandlers HKCU\Software\Classes\AllFileSystemObjects\ShellEx\ContextMenuHandlers HKCU\Software\Classes\AllFileSystemObjects\ShellEx\DragDropHandlers HKCU\Software\Classes\AllFileSystemObjects\ShellEx\PropertySheetHandlers HKCU\Software\Classes\Clsid{AB8902B4-09CA-4bb6-B78D-A8F59079A8D5}\Inprocserver32 HKCU\Software\Classes\Directory\Background\ShellEx\ContextMenuHandlers HKCU\Software\Classes\Directory\ShellEx\ContextMenuHandlers HKCU\Software\Classes\Directory\Shellex\CopyHookHandlers HKCU\Software\Classes\Directory\Shellex\DragDropHandlers HKCU\Software\Classes\Directory\Shellex\PropertySheetHandlers HKCU\Software\Classes\Drive\ShellEx\ContextMenuHandlers HKCU\Software\Classes\Folder\Shellex\ColumnHandlers HKCU\Software\Classes\Folder\ShellEx\ContextMenuHandlers HKCU\Software\Classes\Folder\ShellEx\DragDropHandlers HKCU\Software\Classes\Folder\ShellEx\ExtShellFolderViews HKCU\Software\Classes\Folder\ShellEx\PropertySheetHandlers HKCU\Software\Classes\Protocols\Filter HKCU\Software\Classes\Protocols\Handler HKCU\Software\Microsoft\Ctf\LangBarAddin HKCU\Software\Microsoft\Internet Explorer\Desktop\Components HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\ShellIconOverlayIdentifiers HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\ShellServiceObjects HKCU\Software\Microsoft\Windows\CurrentVersion\ShellServiceObjectDelayLoad HKLM\Software\Classes*\ShellEx\ContextMenuHandlers HKLM\Software\Classes*\ShellEx\PropertySheetHandlers HKLM\Software\Classes\AllFileSystemObjects\ShellEx\ContextMenuHandlers HKLM\Software\Classes\AllFileSystemObjects\ShellEx\DragDropHandlers HKLM\Software\Classes\AllFileSystemObjects\ShellEx\PropertySheetHandlers HKLM\Software\Classes\Directory\Background\ShellEx\ContextMenuHandlers HKLM\Software\Classes\Directory\ShellEx\ContextMenuHandlers HKLM\Software\Classes\Directory\Shellex\CopyHookHandlers HKLM\Software\Classes\Directory\Shellex\DragDropHandlers HKLM\Software\Classes\Directory\Shellex\PropertySheetHandlers HKLM\Software\Classes\Drive\ShellEx\ContextMenuHandlers HKLM\Software\Classes\Folder\Shellex\ColumnHandlers HKLM\Software\Classes\Folder\ShellEx\ContextMenuHandlers HKLM\Software\Classes\Folder\ShellEx\DragDropHandlers HKLM\Software\Classes\Folder\ShellEx\ExtShellFolderViews HKLM\Software\Classes\Folder\ShellEx\PropertySheetHandlers HKLM\Software\Classes\Protocols\Filter HKLM\Software\Classes\Protocols\Handler HKLM\Software\Microsoft\Ctf\LangBarAddin HKLM\Software\Microsoft\Windows\CurrentVersion\Explorer\SharedTaskScheduler HKLM\Software\Microsoft\Windows\CurrentVersion\Explorer\ShellExecuteHooks HKLM\Software\Microsoft\Windows\CurrentVersion\Explorer\ShellIconOverlayIdentifiers HKLM\Software\Microsoft\Windows\CurrentVersion\Explorer\ShellServiceObjects HKLM\Software\Microsoft\Windows\CurrentVersion\ShellServiceObjectDelayLoad Systemwide ASEPs in the registry—64-bit only HKLM\Software\Wow6432Node\Classes*\ShellEx\ContextMenuHandlers HKLM\Software\Wow6432Node\Classes*\ShellEx\PropertySheetHandlers HKLM\Software\Wow6432Node\Classes\AllFileSystemObjects\ShellEx\ContextMenuHandlers HKLM\Software\Wow6432Node\Classes\AllFileSystemObjects\ShellEx\DragDropHandlers HKLM\Software\Wow6432Node\Classes\AllFileSystemObjects\ShellEx\PropertySheetHandlers HKLM\Software\Wow6432Node\Classes\Directory\Background\ShellEx\ContextMenuHandlers HKLM\Software\Wow6432Node\Classes\Directory\ShellEx\ContextMenuHandlers HKLM\Software\Wow6432Node\Classes\Directory\Shellex\CopyHookHandlers HKLM\Software\Wow6432Node\Classes\Directory\Shellex\DragDropHandlers HKLM\Software\Wow6432Node\Classes\Directory\Shellex\PropertySheetHandlers HKLM\Software\Wow6432Node\Classes\Drive\ShellEx\ContextMenuHandlers HKLM\Software\Wow6432Node\Classes\Folder\Shellex\ColumnHandlers HKLM\Software\Wow6432Node\Classes\Folder\ShellEx\ContextMenuHandlers HKLM\Software\Wow6432Node\Classes\Folder\ShellEx\DragDropHandlers HKLM\Software\Wow6432Node\Classes\Folder\ShellEx\ExtShellFolderViews HKLM\Software\Wow6432Node\Classes\Folder\ShellEx\PropertySheetHandlers HKLM\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Explorer\SharedTaskScheduler HKLM\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Explorer\ShellExecuteHooks HKLM\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Explorer\ShellIconOverlayIdentifiers HKLM\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Explorer\ShellServiceObjects HKLM\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\ShellServiceObjectDelayLoad instance of an x64 version of Windows 10. Per-user ASEPs under HKCU\Software HKCU\Software\Microsoft\Internet Explorer\Explorer Bars HKCU\Software\Microsoft\Internet Explorer\Extensions HKCU\Software\Microsoft\Internet Explorer\UrlSearchHooks Systemwide ASEPs in the registry HKLM\Software\Microsoft\Internet Explorer\Explorer Bars HKLM\Software\Microsoft\Internet Explorer\Extensions HKLM\Software\Microsoft\Internet Explorer\Toolbar HKLM\Software\Microsoft\Windows\CurrentVersion\Explorer\Browser Helper Objects Per-user and systemwide ASEPs in the registry—64-bit only HKCU\Software\Wow6432Node\Microsoft\Internet Explorer\Explorer Bars HKCU\Software\Wow6432Node\Microsoft\Internet Explorer\Extensions HKLM\Software\Wow6432Node\Microsoft\Internet Explorer\Explorer Bars HKLM\Software\Wow6432Node\Microsoft\Internet Explorer\Extensions HKLM\Software\Wow6432Node\Microsoft\Internet Explorer\Toolbar HKLM\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Explorer\Browser Helper Objects
The following list specifies the registry keys that are shown on the Winlogon tab. Per-user specification of the screen saver HKCU\Control Panel\Desktop\Scrnsave.exe Per-user specification of the screen saver, controlled by Group Policy HKCU\Software\Policies\Microsoft\Windows\Control Panel\Desktop\Scrnsave.exe Group Policy Client-Side Extensions (CSEs) HKLM\Software\Microsoft\Windows NT\CurrentVersion\Winlogon\GPExtensions HKLM\Software\Wow6432Node\Microsoft\Windows NT\CurrentVersion\Winlogon\GPExtensions Credential provider ASEPs HKLM\Software\Microsoft\Windows\CurrentVersion\Authentication\Credential Provider Filters HKLM\Software\Microsoft\Windows\CurrentVersion\Authentication\Credential Providers HKLM\Software\Microsoft\Windows\CurrentVersion\Authentication\PLAP Providers Systemwide identification of a program to verify successful boot HKLM\System\CurrentControlSet\Control\BootVerificationProgram\ImagePath ASEP for custom setup and deployment tasks HKLM\System\Setup\CmdLine
(This ASEP isn’t truly related to the LSA, except that, like the LSA, it represents security-related functionality.) Keys inspected for Authentication Providers HKLM\System\CurrentControlSet\Control\Lsa\Authentication Packages HKLM\System\CurrentControlSet\Control\Lsa\Notification Packages HKLM\System\CurrentControlSet\Control\Lsa\Security Packages HKLM\System\CurrentControlSet\Control\Lsa\OSConfig\Security Packages Keys inspected for Registered Cryptographic Providers HKLM\System\CurrentControlSet\Control\SecurityProviders\SecurityProviders
The Office tab lists add-ins and plug-ins registered to hook into documented interfaces for Access, Excel, Outlook, PowerPoint, and Word. On 64-bit Windows, Office add-ins can be registered to run in 32-bit or 64-bit Office versions. 32-bit add-ins are registered in Wow6432Node subkeys on 64-bit Windows. Keys inspected under both HKLM and HKCU \Software\Microsoft\Office\Access\Addins \Software\Microsoft\Office\Excel\Addins \Software\Microsoft\Office\Outlook\Addins \Software\Microsoft\Office\PowerPoint\Addins \Software\Microsoft\Office\Word\Addins Keys inspected under both HKLM and HKCU on 64-bit Windows \Software\Wow6432Node\Microsoft\Office\Access\Addins \Software\Wow6432Node\Microsoft\Office\Excel\Addins \Software\Wow6432Node\Microsoft\Office\Outlook\Addins \Software\Wow6432Node\Microsoft\Office\PowerPoint\Addins \Software\Wow6432Node\Microsoft\Office\Word\Addins Registry locations inspected for EXE file hijacks HKCU\Software\Classes\Exefile\Shell\Open\Command(Default) HKCU\Software\Classes.exe HKCU\Software\Classes.cmd HKLM\Software\Classes\Exefile\Shell\Open\Command(Default) HKLM\Software\Classes.exe HKLM\Software\Classes.cmd Registry locations inspected for htmlfile hijacks HKCU\Software\Classes\Htmlfile\Shell\Open\Command(Default) HKLM\Software\Classes\Htmlfile\Shell\Open\Command(Default) Command processor autorun keys HKCU\Software\Microsoft\Command Processor\Autorun HKLM\Software\Microsoft\Command Processor\Autorun HKLM\Software\Wow6432Node\Microsoft\Command Processor\Autorun Keys inspected for Image File Execution Options hijacks HKLM\Software\Microsoft\Windows NT\CurrentVersion\Image File Execution Options HKLM\Software\Wow6432Node\Microsoft\Windows NT\CurrentVersion\Image File Execution Options
%SystemDrive%/hiberfil.sys hiberfil.sys, better known as the Windows hibernation file contains a compressed memory image from the previous boot. Microsoft Windows systems use this in order to provide faster boot-up times, however, we can use this file in our case for some memory forensics
On Windows, the password hash is normally stored in the SAM file at %SystemRoot%\System32\config. C:\Windows\System32\config
The web directories sit at C:\xampp\htdocs, which is common for an XAMPP deployment on Windows. There is an inetpub directory at the root of C:. That’s the directory IIS typically runs from
powershell -ep bypass -> load a powershell shell with execution policy bypassed
DLLs are shared system libraries utilized in system processes. These are commonly subjected to hijacking and other side-loading attacks, making them a key target for forensics.
The file system used in modern versions of Windows is the New Technology File System or simply NTFS. Before NTFS, there was FAT16/FAT32 (File Allocation Table) and HPFS (High Performance File System). NTFS is known as a journaling file system. In case of a failure, the file system can automatically repair the folders/files on disk using information stored in a log file. This function is not possible with FAT.
"Trusted Platform Module (TPM) technology is designed to provide hardware-based, security-related functions. A TPM chip is a secure crypto-processor that is designed to carry out cryptographic operations. The chip includes multiple physical security mechanisms to make it tamper-resistant, and malicious software is unable to tamper with the security functions of the TPM".
BitLocker Drive Encryption is a data protection feature that integrates with the operating system and addresses the threats of data theft or exposure from lost, stolen, or inappropriately decommissioned computers".
On devices with TPM installed, BitLocker offers the best protection.
Per Microsoft, "BitLocker provides the most protection when used with a Trusted Platform Module (TPM) version 1.2 or later. The TPM is a hardware component installed in many newer computers by the computer manufacturers. It works with BitLocker to help protect user data and to ensure that a computer has not been tampered with while the system was offline"
Alternate Data Streams (ADS) is a file attribute specific to Windows NTFS (New Technology File System). Every file has at least one data stream ($DATA), and ADS allows files to contain more than one stream of data. Natively Window Explorer doesn't display ADS to the user. There are 3rd party executables that can be used to view this data, but Powershell gives you the ability to view ADS for files. In this system a file is built up from a couple of attributes, one of them is $Data, aka the data attribute. Looking at the regular data stream of a text file there is no mystery. It simply contains the text inside the text file. But that is only the primary data stream which is sometimes referred to as the unnamed data stream since the name string of this attribute is empty ( “” ) . So any data stream that has a name is considered alternate.
Syntax for using powershell to read ADS streams >> Get-Item -path {path to file} -stream {name of stream} Syntax for using powershell to add streams to a file >> Set-Item -path {path to file} -stream {name of stream} Syntax for using powershell to remove ADS from a file >> Remove-Item -path {path to file} -stream {name of stream}
If you want to search a directory or drive for ADS you can use this command in the root of the target: gci -recurse | % { gi $_.FullName -stream * } | where stream -ne ':$Data'
Local User and Group Management >> Right-click on the Start Menu and click Run. Type lusrmgr.msc User Account Control (UAC) is a fundamental component of Microsoft's overall security vision. UAC helps mitigate the impact of malware.
The System Configuration utility/panel (MSConfig) is for advanced troubleshooting, and its main purpose is to help diagnose startup issues. https://docs.microsoft.com/en-us/troubleshoot/windows-client/performance/system-configuration-utility-troubleshoot-configuration-errors The normal startup option is the Windows default. This option enables Windows to start in normal mode together with all programs, services, and device drivers loaded. The diagnostic startup option enables Windows to determine which basic device drivers and software to load when you start Windows. When you use this option, the system temporarily disables some Microsoft services. The selective startup option enables you to select the programs and services that you want the computer to load when you restart the computer. You can select from the following options: Load system services, Load startup items, Use original boot configuration Below are tools available through the System Configuration
The Computer Management (compmgmt) utility has three primary sections: System Tools, Storage, and Services and Applications.
WMI Control configures and controls the Windows Management Instrumentation (WMI) service. "WMI allows scripting languages (such as VBScript or Windows PowerShell) to manage Microsoft Windows personal computers and servers, both locally and remotely. Microsoft also provides a command-line interface to WMI called Windows Management Instrumentation Command-line (WMIC)." Note: The WMIC tool is deprecated in Windows 10, version 21H1. Windows PowerShell supersedes this tool for WMI.
System Information (msinfo32) tool "Windows includes a tool called Microsoft System Information (Msinfo32.exe). This tool gathers information about your computer and displays a comprehensive view of your hardware, system components, and software environment, which you can use to diagnose computer issues."
Environment variables store information about the operating system environment. This information includes details such as the operating system path, the number of processors used by the operating system, and the location of temporary folders. The environment variables store data that is used by the operating system and other programs. For example, the WINDIR environment variable contains the location of the Windows installation directory. Programs can query the value of this variable to determine where Windows operating system files are located"
Resource Monitor (resmon) "Resource Monitor displays per-process and aggregate CPU, memory, disk, and network usage information, in addition to providing details about which processes are using individual file handles and modules. Advanced filtering allows users to isolate the data related to one or more processes (either applications or services), start, stop, pause, and resume services, and close unresponsive applications from the user interface. It also includes a process analysis feature that can help identify deadlocked processes and file locking conflicts so that the user can attempt to resolve the conflict instead of closing an application and potentially losing data."
Windows Command Prompt (cmd.exe) Unlike Unix Based Systems, the man page for Windows CMD commands can be accessed using {cmd} /? Or {cmd} help An A-Z Index of Windows CMD commands https://ss64.com/nt/
The Windows Registry (regedit) or reg /? at the Command Prompt more at >> https://docs.microsoft.com/en-us/troubleshoot/windows-server/performance/windows-registry-advanced-users is a central hierarchical database used to store information necessary to configure the system for one or more users, applications, and hardware devices. The registry contains information that Windows continually references during operation, such as: Profiles for each user, Applications installed on the computer and the types of documents that each can create, Property sheet settings for folders and application icons, What hardware exists on the system, The ports that are being used. There are various ways to view/edit the registry. One way is to use the Registry Editor (regedit). A registry hive is a group of keys, subkeys, and values in the registry that has a set of supporting files that contain backups of its data.
https://microsoft.fandom.com/wiki/Windows_Registry
List of Main Windows Registry Hives and Their Abbreviations: HKLM - HKEY_LOCAL_MACHINE Stores settings that are specific to the local computer. This hive contains information about the hardware, software, and preferences on the system. It affects all users on the computer. HKCU - HKEY_CURRENT_USER Contains configuration information for Windows and software settings specific to the currently logged-in user. Each user on the system has their own HKCU hive. HKCR - HKEY_CLASSES_ROOT A subset of HKLM\Software and HKCU\Software combined. It includes information about registered applications, such as file associations and OLE Object Class IDs. This helps Windows determine which programs to run when a specific type of file is accessed. HKU - HKEY_USERS Contains all the user profiles loaded on the machine. HKCU is actually a subkey of HKU, representing the current user profile in use. HKCC - HKEY_CURRENT_CONFIG Contains information gathered at runtime; data stored here is not permanently stored on disk, but rather generated at boot time. It relates to the configuration of the PC's hardware.
A command line interface (CLI) is a command screen or text interface called a shell that allows users to interact with a program. A useful tool for understanding commands is explainshell.com.
On BSD-based Unix systems, you may encounter different types of terminals:
/dev/ttyX): An actual virtual keyboard/screen pair./dev/pts/X): A software-made fake TTY that pretends to be a keyboard/screen.If you encounter an error indicating that a GPG key has expired or is invalid, you may need to update the key for the repository.
Download the updated key:
wget -q -O - https://archive.kali.org/archive-key.asc | sudo apt-key add -
Update and upgrade again:
sudo apt update
sudo apt full-upgrade -y
Python scripts can be made directly executable, similar to shell scripts.
To do this, add a "shebang" line at the very beginning of the script and give the file executable permissions. The #! must be the first two characters of the file.
#!/usr/bin/env python3
This line tells the system to use the python3 interpreter, assuming it is in the user's PATH. On some platforms, this first line must end with a Unix-style line ending (\n), not a Windows (\r\n) line ending. The hash character (#) is used to start a comment in Python.
Give the script executable permissions using the chmod command:
chmod +x myscript.py
On Windows, there is no "executable mode." The Python installer automatically associates .py files with python.exe, so double-clicking a file will run it as a script. If the extension is .pyw, the console window that normally appears is suppressed.
You can list the allowed (and forbidden) commands for a user.
sudo -l
If no command is specified, the -l (list) option will list the allowed commands for the invoking user on the current host. If a command is specified and permitted, the fully-qualified path to the command is displayed along with any command line arguments. If a command is specified but not allowed, sudo will exit with a status value of 1. If the -l option is specified with an l argument (-ll), or if -l is specified multiple times, a longer list format is used.
A shebang (#!) is a character sequence at the beginning of a script that specifies the path to the interpreter for executing it. It does not signify a binary file. For example: #!/bin/sh, #!/bin/zsh, or #!/bin/bash.
Bash is a scripting language that runs within the terminal on most Linux distros, as well as macOS. Shell scripts are a sequence of Bash commands within a file, combined to achieve more complex tasks than simple one-liners. They are especially useful for automating system administration tasks such as backups.
Please note that for variables to work, you cannot leave a space between the variable name, the
=sign, and the value. Variable names also cannot have spaces. You must add a$to the front of a variable name to use it, similar to JavaScript template literals${variableName}but without the curly braces.
Debugging is an important part of programming. Bash has built-in features to simplify this process. To debug the syntax of a script, you can run it with bash -x:
bash -x ./fileName.sh
This command outputs each command before it is executed, prefixed with a + sign, followed by the command's output. This makes it easy to spot where you have gone wrong. You can also debug a specific section of a script by inserting set -x before the section and set +x after it.
The following is a process for interacting with an Amazon S3 bucket using the AWS CLI, uploading a PHP shell to execute remote commands, and setting up a reverse shell. The files stored in an S3 bucket are called S3 objects.
You can interact with an S3 bucket using the awscli utility. It can be installed and configured on Linux using the following command:
apt install awscli && aws configure
Listing S3 Buckets:
aws --endpoint=http://s3.Server.AWS s3 ls
This lists all S3 buckets available at the specified endpoint.
Listing Objects in a Bucket:
aws --endpoint=http://s3.Server.AWS s3 ls s3://Server.AWS
Unrestricted file upload vulnerabilities occur when a web server allows users to upload files without sufficient validation. If an attacker can upload an executable script (like a .php file) and then browse to it, the server may execute that script.
System administrators should monitor for:
www-data spawning bash or sh).netstat or ss).Netcat is a networking utility for reading from and writing to network connections using TCP or UDP. It is often used for debugging network issues.
nc -lvnp [port]
-l: Listen-v: Verbose-n: No DNS lookup (IPs only)-p: PortThe grep command searches for patterns in text.
This command searches for the pattern "passw" in all files and directories recursively, starting from the current directory.
grep -ri 'passw' *
-r: Recursively searches subdirectories.-i: Ignores case (case-insensitive search).This command concatenates all files in the current directory into a single stream and then searches that stream for the pattern "passw".
cat * | grep -i passw*
The grep -ri 'passw' * command is generally more efficient and reliable for searching through files and directories, as it inherently handles directories and binary files without issue. In contrast, cat * | grep ... can generate errors if cat tries to read directories or non-text files.
The find command is useful for searching the target system for important information.
find . -name flag1.txt: Find the file named flag1.txt in the current directory.find /home -name flag1.txt: Find the file named flag1.txt in the /home directory.find / -type d -name config: Find the directory named config under /.find /home -user frank: Find all files for user frank under /home.find / -type f -perm 0777: Find files with 777 permissions.find / -perm a=x: Find executable files.find / -mtime 10: Find files that were modified in the last 10 days.find / -atime 10: Find files that were accessed in the last 10 days.find / -cmin -60: Find files changed within the last hour (60 minutes).find / -amin -60: Find files accessed within the last hour (60 minutes).find / -size 50M: Find files with a 50MB size. This can also be used with + (larger than) and - (smaller than).The find command can generate errors that make the output hard to read. You can redirect errors to /dev/null for a cleaner output.
find . -type f -name "search" 2>/dev/nullfind . -type d -name "search" 2>/dev/nullfind / -writable -type d 2>/dev/null: Find world-writable folders.find / -perm -222 -type d 2>/dev/null: Find world-writable folders.find / -perm -o w -type d 2>/dev/null: Find world-writable folders.find / -perm -o x -type d 2>/dev/null: Find world-executable folders.find / -perm -o r -type d 2>/dev/null: Find world-readable folders.Commonly noted as SUID (Set owner User ID), this special permission allows a file to execute as the user who owns it, regardless of the user running the command. This can be used to escalate privileges.
find / -perm -u=s -type f 2>/dev/null: Find files with the SUID bit set.The -type flag filters by file type:
b: block specialc: character speciald: directoryf: regular filel: symbolic linkp: FIFOs: socketThe strings command makes it possible to view the human-readable characters within any file. Its main purpose is to help determine the file type, but it can also be used to extract text.
The chmod (change file mode) utility modifies the file mode bits (permissions) of files and directories. It can also be used to modify Access Control Lists (ACLs).
Permissions are grouped into user, group, and other.
r: readablew: writablex: executable-: empty permissiond: directoryPermissions can also be represented numerically:
4: read2: write1: executeThe chown (change owner) utility modifies the user and/or group ownership of a file.
Displays one-line manual page descriptions.
Searches the manual page names and descriptions.
Formats and displays the on-line reference manual pages.
Locates a command.
Puts the current working directory onto a stack and allows you to return to it later.
Updates the database used by the locate command.
A command-line text editor that can interpret and compile many programming languages. It takes an optional filename argument.
A standard program for recognizing the type of data contained in a computer file.
Displays the value of a symbolic link.
Displays information about a file, such as size, permissions, and modification times. Read, write, or execute permissions are not required, but all directories in the path must be searchable.
Allows you to download files from the web via HTTP. You provide the address of the resource you wish to download.
The ps utility displays information about running processes.
ps -ax | grep <application_name>
This command reveals the processes associated with a running application.
The ping command is used to test whether a connection to a remote resource is possible by sending ICMP ECHO_REQUEST packets. It can also be used to determine the IP address of a server. Packets are transmitted via ICMP (type 8 for request, type 0 for response). Pinging localhost or 127.0.0.1 can help diagnose network card failures, while pinging a domain name can help resolve DNS issues.
Resolves and displays network statistics such as current network connections and port activities.
netstat -a: Shows all listening ports and established connections.netstat -at or netstat -au: Lists TCP or UDP protocols respectively.netstat -l: Lists ports in "listening" mode.netstat -s: Lists network usage statistics by protocol.netstat -tp: Lists connections with the service name and PID information.netstat -i: Shows interface statistics.netstat -ano: A common usage that displays all sockets, does not resolve names, and displays timers.Commands used to view and manage network interface information.
ipconfig (Windows)ifconfig (older Linux/macOS)ip a / ip addr (modern Linux)arp -a (displays the ARP table)Time-to-live (TTL) is a value for the period of time that a packet should exist on a network before being discarded. It is a counter or timestamp embedded in each packet. When the predefined timespan or event count expires, the packet is either discarded or revalidated. In networking, TTL prevents data packets from circulating indefinitely and helps determine how long a packet has been in circulation.
You can start a tcpdump listener to capture packets. The following command listens for ICMP traffic, which is used by ping.
sudo tcpdump ip proto \\icmp -i <interfaceName>
The traceroute command resolves the route that data packets take from a local network to an internet destination, providing more information than ping. It works by sending packets with a low TTL to elicit ICMP Time Exceeded messages from intermediate hops.
traceroute <destination> (operates over UDP by default)tracert <destination> (operates over ICMP by default)The whois utility looks up registration records for domain names and IP addresses from databases maintained by Network Information Centers (NICs).
Note: You may need to install
whoisbefore using it. On Debian-based systems, this can be done withsudo apt update && sudo apt-get install whois.
nslookup (Name Server Look Up) finds the IP address of a domain name.
The syntax is nslookup [-type=RECORD] [DOMAIN_NAME] [SERVER].
type: The record type to query (e.g., A for IPv4, AAAA for IPv6).DOMAIN_NAME: The domain to look up.SERVER: The DNS server to query (e.g., Cloudflare 1.1.1.1, Google 8.8.8.8, Quad9 9.9.9.9).dig (Domain Information Groper) is a flexible tool for interrogating DNS name servers. It's useful for viewing the TTL (Time To Live) of a DNS record, which indicates how long the record should be cached.
The syntax is dig @server name type.
@server: The name or IP address of the name server to query.name: The name of the resource record to look up.type: The type of query (e.g., ANY, A, MX, SIG). If omitted, dig performs a lookup for an A record.The host utility is a simple tool for performing DNS lookups, converting names to IP addresses and vice versa.
The syntax is host {name} [server].
name: The domain name or IP address to look up.server: (Optional) The name or IP address of a specific name server to query instead of the system default.The process of converting source code into an executable involves compilers (like GNU) turning text-based scripts into binary scripts.
The chmod command changes file modes or permissions.
chmod +perm fileName or chmod -perm fileName+ adds a permission, - removes it.r (read), w (write), and x (execute).The chown command changes the user and/or group ownership of a file.
A system daemon like systemd (or launchd on macOS) is one of the first processes started at boot. Other programs are started as child processes of the daemon. The OS uses namespaces to isolate processes from each other, splitting up system resources like CPU and RAM for security.
The systemctl command allows you to interact with the systemd process. The equivalent on macOS is launchctl.
systemctl [option] [service]start, stop, enable (start at boot), disable.The ps utility displays information about your active processes. Processes are the programs running on your machine, managed by the kernel. Each process has a Process ID (PID).
The top command provides a real-time, sorted list of system processes and their statistics, which refreshes automatically.
LXD is a management API for LXC containers. A user in the local lxd group can instantly escalate their privileges to root on the host OS, regardless of sudo rights. This vulnerability can be exploited by using a custom image to mount the host's root filesystem. The exploit involves building a custom Alpine image, transferring it to the target, and using it to spawn a privileged container.
For more details, see:
The simplified steps are:
/mnt/root).&: The ampersand operator allows you to run a command in the background of your terminal. You can also use Ctrl + Z to send a running process to the background.fg: The foreground command brings a backgrounded process back to the foreground.&&: Combines multiple commands, executing the next command only if the previous one succeeds.>: Redirects the output of a command to a file, overwriting the file's contents.>>: Appends the output of a command to a file.;: Separates commands to be run in sequence, regardless of whether the previous command succeeds or fails.| (pipe): Allows separate processes to communicate. The output of the command on the left is used as the input for the command on the right.
Redirection operators are used to control where a command's output is sent (stdout and stderr) and where it gets its input from (stdin).
0: stdin (standard input)1: stdout (standard output)2: stderr (standard error)The n>&m syntax redirects file descriptor n to the same location as file descriptor m. If n is omitted, it defaults to 1 (stdout).
>&: Redirects both stdout and stderr to a file.>&2: Redirects stdout to stderr.2>&1: Redirects stderr to wherever stdout is currently going.2>: Redirects stderr to a file.&>: Redirects both stdout and stderr to a file (a common shorthand).0>&1: Redirects stdin to wherever stdout is currently directed.<>: Opens a file for both reading and writing on stdin.crontab is used to schedule and manage cron jobs (automated tasks). A crontab is a special file with formatting that the cron process recognizes to execute each line.
| Value | Description |
|---|---|
| MIN | Minute (0-59) |
| HOUR | Hour (0-23) |
| DOM | Day of the month (1-31) |
| MON | Month (1-12) |
| DOW | Day of the week (0-6) |
| CMD | Command to be executed |
The crontab file is structured as follows:
# ┌───────────── minute (0 - 59)
# │ ┌───────────── hour (0 - 23)
# │ │ ┌───────────── day of the month (1 - 31)
# │ │ │ ┌───────────── month (1 - 12)
# │ │ │ │ ┌───────────── day of the week (0 - 6) (Sunday to Saturday)
# │ │ │ │ │
# * * * * * <command to execute>
# Use @reboot to run a command once at boot.
@reboot /path/to/script.sh
You can edit the crontab file with crontab -e.
/etc/cron.allow: If this file exists, a user must be listed in it to use cron jobs./etc/cron.deny: If cron.allow does not exist, a user must not be listed in this file to use cron jobs./: The root directory of the entire file system hierarchy./bin: Essential command binaries for all users./sbin: System binaries, typically used by the system administrator./boot: Contains all files needed for the OS to boot./dev: Device files, including terminals and hardware./etc: Host-specific, system-wide configuration files. The /etc/hosts file is used to resolve a hostname to an IP address before querying DNS. You can add an entry like this:
sudo echo "IP_ADDRESS FQDN" | sudo tee -a /etc/hosts
/home: Users' home directories./lib: System libraries required by binaries in /bin and /sbin./media & /mnt: Mount points for removable media and temporary filesystems./opt: Optional application software packages./proc: A virtual filesystem providing process and kernel information as files./root: The home directory for the root user./run: A temporary filesystem that stores volatile runtime data./srv: Site-specific data served by the system (e.g., for web or FTP servers)./sys: A virtual filesystem for interacting with the kernel./tmp: Temporary files that are often not preserved between reboots./usr: User utilities and applications./var: Variable data, such as logs (/var/log), that changes as the system runs..conf or .config: Files that often contain application configurations and sensitive information.The /etc/passwd file stores essential user account information required during login. It is a plain text file that contains a list of the system’s accounts. It should have general read permission, but write access must be limited to the root account.
The file contains one entry per line for each user, with seven fields separated by a colon (:):
TestUser:x:0:0:root:/root:/bin/bash
x indicates the encrypted password is stored in /etc/shadow.0 is for root./bin/bash).PATH is an environmental variable that specifies the directories containing executable programs. When a user runs a command, the shell searches these directories to find the corresponding executable.
To view the current PATH:
echo $PATH
To add a directory (like /bin or the current directory .) to the PATH:
export PATH=/bin:$PATH
export PATH=.:$PATH
GTFOBins is a curated list of Unix binaries that can be used to bypass local security restrictions in misconfigured systems. The project collects legitimate functions of Unix binaries that can be abused for tasks like breaking out of restricted shells, escalating privileges, transferring files, and spawning shells.
A Landscape Server is a systems management tool by Canonical for managing fleets of Ubuntu computers from a centralized web interface or API.
To prevent unnecessary attention in public, Kali Undercover mode changes the look and feel of your Kali desktop to resemble Windows 10.
kali-undercover
The apt command is part of the APT suite of tools for managing software packages and sources.
apt update: Fetches the latest information about available packages.apt-get upgrade: Upgrades installed packages.apt-get dist-upgrade or apt full-upgrade: Upgrades the core operating system as well as packages.apt-get clean: Cleans the local repository of retrieved package files.apt-get install -f: Fixes broken dependencies.dpkg --configure -a: Configures all unpackaged packages.dpkg -i <software.deb>: Installs a Debian package.git clone <url>: Clones a repository from a version control system like GitHub.A fancy interface for the Python interpreter with features like in-line syntax highlighting, autocomplete, and auto-indentation.
Python provides a simple http.server module that turns your computer into a web server to serve files from the directory you run it in.
python3 -m http.server
OpenSSL is a cryptography toolkit for SSL/TLS. It can be used for creating keys, certificates, digests, and for encryption/decryption.
scp (secure copy) allows you to securely transfer files between two computers using the SSH protocol for authentication and encryption.
sftp is a file transfer client with an FTP-like command interface that also uses SSH.
sshd is the SSH daemon that runs on the server, listening for client connections.
service ssh start, service ssh stop, service ssh restartsudo launchctl load -w /System/Library/LaunchDaemons/ssh.plistStart-Service sshd| Syntax | Visible in Terminal (stdout/stderr) | Visible in File (stdout/stderr) | Existing File |
|---|---|---|---|
> | no / yes | yes / no | overwrite |
>> | no / yes | yes / no | append |
2> | yes / no | no / yes | overwrite |
2>> | yes / no | no / yes | append |
&> | no / no | yes / yes | overwrite |
&>> | no / no | yes / yes | append |
| ` | tee` | yes / yes | yes / no |
| ` | tee -a` | yes / yes | yes / no |
| ` | & tee` | yes / yes | yes / yes |
| ` | & tee -a` | yes / yes | yes / yes |
QEMU is an emulator and virtualizer. For example, it can be used to virtualize Windows on an M1 Mac. See this MacRumors thread for details.
Network Controllers provide a centralized GUI to monitor and configure multiple network devices. However, they can be vulnerable to attacks like MAC address spoofing, which can poison switch forwarding tables or ARP tables.
Scapy is a powerful packet manipulation tool. In the context of ARP poisoning:
hwsrc: Sender hardware address (SHA)psrc: Sender protocol address (SPA)hwdst: Target hardware address (THA)pdst: Target protocol address (TPA)Broadcasting to FF:FF:FF:FF:FF:FF delivers a packet to all stations on the local network.
sr : Send and receive packets at layer 3
sr1 : Send packets at layer 3 and return only the first answer
srp : Send and receive packets at layer 2
srp1 : Send and receive packets at layer 2 and return only the first answer
arpcachepoison : Poison target's cache with (your MAC,victim's IP) couple
To use netfilterqueue with Python, you need to install it:
apt-get install build-essential python-dev libnetfilter-queue-dev
pip3 install -U git+https://github.com/kti/python-netfilterqueue
To send packets to the queue, use iptables:
iptables -I INPUT -d 192.168.0.0/24 -j NFQUEUE --queue-num 1
Chisel is a fast TCP/UDP tunnel, transported over HTTP, secured via SSH.
chisel server -p 8000 --reverse
./chisel client 10.10.14.55:8000 R:8001:127.0.0.1:8000