← ./resources / blog

Process and Thread Structure: The PEB and TEB Explained

The Process Environment Block and Thread Environment Block are user-mode bookkeeping structures that explain how a Windows process sees itself. They are invaluable to debuggers, incident responders, and reverse engineers, but they are not authoritative security boundaries. That distinction makes them both useful and easy to misuse.

A process is more than an executable

Windows represents a process through kernel objects, an address space, a primary token, handle tables, and one or more threads. The kernel maintains the authoritative process state; user mode has supporting structures that let libraries and applications work efficiently. The PEB is generally process-scoped user-mode state. The TEB is per-thread user-mode state. Each thread has its own TEB and points back to its process's PEB.

One process, one PEB, many TEBsProcesskernel: EPROCESS, token,handles, virtual memoryPEBloader + process stateThread ATEBstackTLSThread BTEBstackTLSThread CTEBstackTLSPreemptive Cyber Security
Figure 1. The PEB describes user-mode process context; every thread receives its own TEB, stack, and thread-local state.

The PEB: a map for user-mode runtime code

The PEB contains fields used by the loader and runtimes, including a pointer to loader data, process parameters such as command line and current directory, heap-related state, and flags. The loader data contains linked lists of modules that have been registered through the normal loading path. Debuggers use this information to name images and unwind a process into something a human can understand.

That is a helpful convenience, not a source of truth. Layouts are undocumented implementation details and can differ by Windows version, architecture, and process type. Security tools should use supported APIs where possible and defensive tooling should validate information against independent views of memory and kernel-maintained state.

The TEB: state that belongs to one thread

A TEB holds the thread's stack bounds, thread-local storage (TLS) data, error-state storage used by Win32 APIs, and a pointer to the PEB. On x64 Windows, the CPU's segment-based thread context gives user-mode code efficient access to thread-local data; on 32-bit Windows, the mechanism differs. The important operational point is not the offset of any field, but the ownership model: a process with ten threads has ten distinct TEBs and stacks, while it shares one PEB.

Module inventory: use more than one sourcePEB loader listfast, user-modeVirtual memorymapped image regionsKernel / EDRimage-load eventsDisk + signatureprovenancevalidated module inventoryreconcile differencesPreemptive Cyber Security
Figure 2. The PEB is valuable evidence, but defenders should reconcile it with memory mappings, signed files, and telemetry.

Security significance: visibility is not integrity

Malware and some offensive tooling have historically tried to reduce user-mode visibility by altering bookkeeping structures or by loading code outside the normal loader path. Those tactics do not erase memory mappings, file artifacts, thread starts, or kernel and EDR telemetry. Conversely, a suspicious PEB list alone is not proof of malicious activity: protected processes, compatibility layers, and security products can produce unusual-looking state. Treat discrepancies as investigation leads and corroborate them.

Related vulnerability lessons

CVE-2023-36033, a Windows DWM Core Library elevation-of-privilege vulnerability, and CVE-2024-30051, a Windows DWM Core Library elevation-of-privilege vulnerability exploited in the wild, demonstrate the real objective behind many local Windows exploits: cross a privilege boundary and execute with more authority. PEB and TEB inspection does not remediate these flaws, but it helps responders understand the affected process, loaded modules, command line, and thread context during triage. Patch management remains the primary control for the CVEs themselves.

A safe analyst workflow

  1. Use a disposable VM. Take a snapshot, use a known-good test executable, and avoid experimenting on production endpoints.
  2. Observe a process. Microsoft Process Explorer shows image paths, command lines, handles, threads, and loaded modules without depending solely on one internal structure.
  3. Capture evidence. Use Volatility 3 against an authorized memory image to enumerate processes, DLLs, and thread indicators. Preserve hashes and acquisition metadata.
  4. Reconcile sources. Compare module listings with memory regions, image-load telemetry, parent-child process relationships, signatures, and expected software inventory.
  5. Escalate carefully. An unexplained executable region, unsigned image, anomalous thread start, or telemetry gap deserves deeper incident-response review, not an automatic conclusion.

What to record during triage

  • Process ID, parent, command line, token integrity level, and executable hash.
  • Thread count, start addresses, stack anomalies, and recently created threads.
  • Mapped images and private executable memory, reconciled with file provenance and image-load logs.
  • PEB-derived process parameters as supporting evidence, with the collection method and OS build noted.

Keep the abstraction honest

PEB and TEB data are immensely practical because Windows software relies on them. They are also writable user-mode memory, so an adversary in the process can attempt to mislead a naïve observer. The kernel's object model, page tables, trusted telemetry, and an acquired memory image give investigators independent angles. Good Windows triage asks what a structure says, then asks what other layers can confirm it.

Key takeaways

  • The PEB is per-process user-mode context; the TEB is per-thread context.
  • PEB loader lists help discovery but are not an authoritative module inventory.
  • Use supported tools and corroborate internal structures with memory, disk, and telemetry evidence.
  • Patch elevation-of-privilege CVEs and use process internals to improve investigation quality.
#windows-internals#peb#teb#memory-forensics
← All articlesAssess your Windows estate →