SKILL: Week 1: Vulnerability Classes with Real-World Examples
Metadata
Description
Exploit development curriculum covering core vulnerability classes with real-world CVE case studies: stack/heap buffer overflows, use-after-free, integer overflows, format strings, type confusion, and race conditions. Use when learning or teaching vuln classes, researching specific CVE patterns, or building exploit dev knowledge.
Trigger Phrases
Use this skill when the conversation involves any of:
vulnerability classes, buffer overflow, use-after-free, UAF, heap overflow, stack overflow, type confusion, integer overflow, format string, memory corruption, CVE case study, exploit development, Day 1-7
Instructions for Claude
When this skill is active:
- Load and apply the full methodology below as your operational checklist
- Follow steps in order unless the user specifies otherwise
- For each technique, consider applicability to the current target/context
- Track which checklist items have been completed
- Suggest next steps based on findings
Full Methodology
Week 1: Vulnerability Classes with Real-World Examples
Course Overview
created by AnotherOne from @Pwn3rzs Telegram channel.
This document is Week 1 of a multi‑week exploit development course, focusing on core vulnerability classes and real‑world exploitation context.
Next Week we'll focus on using fuzzing to identify new vulnerabilites and in week 3 we'll focus on using patch diffing to find n-days
Day 1: Memory Corruption Fundamentals
- Goal: Understand primary memory corruption vulnerability classes and their real-world impact.
- Activities:
- Reading:
- Online Resources:
- Concepts:
- What is memory corruption and why does it matter?
- Understanding the stack, heap, and their differences
- The lifecycle of memory: allocation → use → deallocation
Stack Buffer Overflow
What It Is: A stack overflow occurs when a program writes more data to a buffer located on the stack than it can hold, causing adjacent memory to be overwritten. This can corrupt important data like return addresses, allowing attackers to redirect program execution.
Case Study - CVE-2024-27130 (QNAP QTS/QuTS hero Stack Overflow):
- The Bug: QNAP's QTS and QuTS hero operating systems contained multiple buffer copy vulnerabilities where unsafe functions like
strcpy() were used to copy user-supplied input into fixed-size stack buffers without proper size validation. The vulnerabilities affected the web administration interface and file handling components. POC
- The Attack: An authenticated remote attacker could send specially crafted requests with oversized input to vulnerable endpoints. The unchecked data would overflow stack buffers, corrupting adjacent memory including return addresses and saved frame pointers.
- The Impact: Remote code execution with the privileges of the QNAP system service. The attacker could gain complete control over the NAS device, accessing stored data, pivoting to other network resources, or installing persistent backdoors.
- The Fix: QNAP released QTS 5.1.7.2770 build 20240520 and QuTS hero h5.1.7.2770 build 20240520 in May 2024, replacing unsafe string copy functions with bounds-checked alternatives and implementing additional input validation.
- Why It Matters: Stack overflows remain common in embedded devices and NAS systems running legacy C/C++ code. They're particularly dangerous in internet-facing administration interfaces and often provide the initial foothold for sophisticated attack chains against enterprise infrastructure.
Use-After-Free (UAF)
What It Is: A use-after-free vulnerability occurs when a program continues to use a pointer after the memory it points to has been freed. This creates a "dangling pointer" that can be exploited by carefully controlling heap allocations to place attacker-controlled data where the freed object once lived.
Case Study - CVE-2024-2883 (Chrome ANGLE Use-After-Free):
- The Bug: Google Chrome's ANGLE (Almost Native Graphics Layer Engine) component, which translates OpenGL ES API calls to DirectX, Vulkan, or native OpenGL, contained a use-after-free vulnerability. The bug occurred when WebGL contexts were destroyed while still referenced by pending graphics operations, leaving dangling pointers to freed graphics objects.
- The Attack: An attacker could create a malicious HTML page with specially crafted WebGL JavaScript code that triggered rapid creation and destruction of graphics contexts. By carefully timing these operations, the attacker could cause ANGLE to reference already-freed memory. Using heap spray and heap feng-shui techniques, the attacker could control the contents of the freed memory region.
- The Impact: Remote code execution via a crafted web page with no user interaction beyond visiting the page. By placing a fake object in the freed memory location, the attacker could hijack control flow and execute arbitrary code in the renderer process. This could be chained with sandbox escape exploits for full system compromise.
- The Fix: Google Chrome 123.0.6312.86 (released March 2024) fixed the vulnerability by implementing proper lifetime management for graphics objects and adding reference counting to prevent premature destruction of objects still in use.
- Why It Matters: UAF vulnerabilities are particularly dangerous in browsers and complex C++ applications where object lifetimes are difficult to track. Graphics subsystems like ANGLE are attractive targets because they handle untrusted content and have complex state management. They're a favorite target for advanced attackers because they offer fine-grained control over program execution.
Heap Buffer Overflow
What It Is: Similar to stack overflows, heap overflows occur when a program writes beyond the boundaries of a dynamically allocated buffer on the heap. Instead of corrupting stack frames, heap overflows typically corrupt heap metadata or adjacent objects, leading to memory corruption when the heap allocator later processes the corrupted structures.
Case Study - CVE-2023-4863 (libWebP Heap Buffer Overflow):
- The Bug: The libWebP library, used by Chrome, Firefox, Edge, and many other applications for processing WebP images, contained a heap buffer overflow in the
BuildHuffmanTable() function. When parsing specially crafted WebP images with malformed Huffman coding data, the function would write beyond the allocated buffer boundaries. POC
- The Attack: An attacker could embed a malicious WebP image in a web page or send it via messaging apps. When the victim's browser or application attempted to decode the image, the overflow would occur. The attacker could control the overflow data to corrupt heap metadata and adjacent objects.
- The Impact: Remote code execution with no user interaction beyond viewing a web page or opening an image. Exploited as a zero-day in the wild before public disclosure. The vulnerability affected billions of devices across multiple platforms (Windows, macOS, Linux, Android, iOS).
- The Fix: libWebP 1.3.2 (September 2023) fixed the bounds checking in
BuildHuffmanTable(). Chrome 116.0.5845.187, Firefox 117.0.1, and other affected software released emergency patches.
- Why It Matters: Heap buffer overflows in image parsers are particularly dangerous because images are ubiquitous and processed automatically. This vulnerability demonstrated the supply chain risk of widely-used libraries - a single bug in libWebP affected dozens of major applications. Modern heap exploitation techniques can bypass ASLR and other protections when combined with information leaks.
Out-of-Bounds Read (Info Leak)
What It Is: Reading past buffer bounds without modifying memory. Frequently used to leak pointers, object metadata, and kernel layout to defeat KASLR and build arbitrary read/write primitives.
Case Study - CVE-2024-53108 (Linux AMDGPU Display Driver OOB Read):
- The Bug: In the AMD display driver’s EDID/VSDB parsing path, insufficient bounds checking allowed out-of-bounds reads when extracting identifiers, leading to slab-out-of-bounds access under KASAN.
- The Attack: A crafted display/EDID data stream could trigger an OOB read in kernel space. While not directly granting write primitives, the info leak can expose kernel memory contents and aid in bypassing KASLR.
- The Impact: Information disclosure and potential system instability.
- The Fix: Kernel updates tightened length validation within the AMD display capability parsing logic to ensure all reads stay within EDID buffer bounds. DIFF
- Why It Matters: Pure OOB reads are valuable for building reliable exploit chains (e.g., pairing with separate write primitives), especially in kernel contexts where defeating KASLR is pivotal.
Uninitialized Memory Use
What It Is: Using stack/heap/pool memory before it is initialized. Contents may include stale pointers, capability flags, or structure fields.
Case Study - CVE-2024-26581 (Linux Kernel Netfilter Uninitialized Variable):
- The Bug: The Linux kernel's netfilter subsystem contained an uninitialized variable vulnerability in the
nf_tables component. When processing netlink messages to configure firewall rules, the nft_pipapo_walk() function failed to initialize a local variable before use. The uninitialized stack variable could contain residual data from previous function calls, including kernel pointers and sensitive memory addresses. POC
- The Attack: An attacker with
CAP_NET_ADMIN capability (obtainable via unprivileged user namespaces on many distributions) could trigger specific netfilter operations that caused the uninitialized variable to be read and copied back to userspace through netlink responses. By repeatedly triggering the vulnerable code path and analyzing returned data, an attacker could extract kernel memory contents including heap/stack addresses.
- The Impact: Information disclosure leading to KASLR (Kernel Address Space Layout Randomization) bypass. The leaked kernel addresses could then be used to reliably exploit other kernel vulnerabilities, turning potential denial-of-service bugs into privilege escalation or code execution. This vulnerability was particularly dangerous when combined with other netfilter bugs for full LPE chains.
- The Fix: Linux kernel 6.8-rc1 (February 2024) added proper initialization of the variable using designated initializers:
struct nft_pipapo_match *m = NULL; and added explicit zero-initialization for stack structures. Additionally, the patch enabled stricter compiler warnings (-Wuninitialized) for the netfilter subsystem.
- Why It Matters: Uninitialized memory reads are frequently the first stage in exploit chains, providing the entropy reductions needed to bypass modern mitigations like KASLR. They're particularly valuable in kernel exploitation where defeating ASLR is essential for reliable exploitation. The combination of unprivileged user namespaces granting
CAP_NET_ADMIN and uninitialized memory leaks in netfilter makes this class of vulnerability accessible to local attackers without requiring root privileges.
Reference Counting Bugs
What It Is: Incorrect increments/decrements or overflows in reference counters controlling object lifetime (filesystems, networking, drivers).
Case Study - CVE-2022-32250 (Linux Netfilter nf_tables Use-After-Free):
- The Bug: The Linux kernel's netfilter subsystem (
net/netfilter/nf_tables_api.c) had a reference counting error in the nf_tables component. An incorrect NFT_STATEFUL_EXPR check failed to properly track expression object lifetimes during rule updates, leading to premature object destruction while references still existed.
- The Attack: A local attacker with the ability to create user/network namespaces (unprivileged on many distributions) could manipulate nf_tables firewall rules to trigger the reference counting bug. By creating and modifying stateful expressions in specific sequences, the attacker could cause the kernel to free an object while it was still being referenced, creating a use-after-free condition.
- The Impact: Local privilege escalation from any user to root on systems allowing unprivileged namespaces (default on Ubuntu, Debian, and others). The UAF primitive could be exploited for arbitrary kernel memory read/write, typically used to modify credentials or overwrite function pointers. Affected Linux kernels from 4.1 (2015) through 5.18.1 (2022). Public exploit available.
- The Fix: Linux kernel 5.18.2+ corrected the reference counting logic for stateful expressions, ensuring proper lifetime tracking during rule operations. The patch added explicit reference count increments/decrements at the appropriate points in the code path.
- Why It Matters: Reference counting bugs are subtle and can lead to premature free → use-after-free conditions, or refcount overflow → free while references remain. They're particularly dangerous in kernel code where object lifetime management is critical. The accessibility via unprivileged user namespaces made this vulnerability particularly impactful for local privilege escalation.
NULL Pointer Dereference
What It Is: Dereferencing a NULL pointer in privileged code. While modern systems typically prevent user-space mapping of NULL pages, kernel NULL pointer dereferences remain a significant source of denial-of-service vulnerabilities and can occasionally enable privilege escalation in specific contexts.
Case Study - CVE-2023-52434 (Linux SMB Client NULL Pointer Dereference):
- The Bug: The Linux kernel's SMB (CIFS) client implementation contained a NULL pointer dereference vulnerability in the
smb2_parse_contexts() function. When parsing server responses during SMB2/SMB3 connection establishment, the code failed to properly validate offsets and lengths of create context structures before dereferencing pointers. Malformed create contexts with invalid offsets could cause the kernel to access unmapped memory addresses, triggering a NULL pointer dereference.
- The Attack: A malicious or compromised SMB server could send crafted SMB2_CREATE responses with invalid create context structures. When a Linux client attempted to mount the share or access files, the kernel would parse these malformed contexts without proper bounds checking. The vulnerability was triggered during the mount operation or file access, requiring only that a user attempt to connect to the malicious server.
- The Impact: Denial of service affecting Linux kernels from 5.3 through 6.7-rc5. The NULL pointer dereference caused an immediate kernel panic with the error "unable to handle page fault for address: ffff8881178d8cc3" in the
smb2_parse_contexts() function. Any user with permission to mount SMB shares could trigger the vulnerability, making it exploitable in multi-user environments. CVSS Score: 8.0 (High) with attack vector: Adjacent Network, requiring low privileges and no user interaction.
- The Fix: Linux kernel patches (versions 5.4.277, 5.10.211, 5.15.150, 6.1.80, and 6.6.8+) added comprehensive validation of create context offsets and lengths before dereferencing. The patches ensure all pointer arithmetic stays within allocated buffer boundaries during SMB protocol parsing.
- Why It Matters: NULL pointer dereferences in network protocol parsers are particularly dangerous because they can be triggered remotely by malicious servers or through man-in-the-middle attacks. While modern kernel protections prevent NULL page mapping (mitigating historical privilege escalation techniques), the DoS impact remains critical for availability.
Key Takeaways
- Memory corruption remains prevalent: Despite decades of security research, memory corruption bugs continue to plague software, especially in C/C++ codebases.
- Defense-in-depth is essential: Each real-world example shows attackers bypassing multiple protection mechanisms (DEP, ASLR, CET, XFG, safe-linking).
- Modern mitigations raise the bar but don't eliminate risk: While technologies like CET shadow stack and safe-linking make exploitation harder, determined attackers continue to find bypasses.
- Root causes are similar, but contexts differ: Stack, heap, and UAF bugs share common root causes (inadequate bounds checking, lifetime management) but require different exploitation techniques.
- Legacy components remain vulnerable: Years-old vulnerabilities in office parsers and archive handlers continue to be exploited due to slow patching.
Discussion Questions
- What commonalities do you see across the memory corruption vulnerability classes covered today?
- Why do memory corruption vulnerabilities persist despite decades of research into memory-safe languages?
- How do the exploitation techniques differ between stack, heap, and UAF vulnerabilities?
- What defense mechanisms were bypassed in each example, and what does that tell us about the current state of exploit mitigation?
- How do reference counting bugs lead to use-after-free conditions, and why are they particularly difficult to detect?
- What role do information leaks (like OOB reads and uninitialized memory) play in modern exploit chains?
Day 2: Logic Vulnerabilities and Race Conditions
- Goal: Understand logic vulnerabilities that don't involve memory corruption but can be equally dangerous.
- Activities:
- Reading:
- "Web Application Security, 2nd Edition" by Andrew Hoffman - Chapter 18: "Business Logic Vulnerabilities"
- Portswigger Logic Flaws
- Online Resources:
- Concepts:
- Race conditions and their causes
- TOCTOU (Time-of-Check Time-of-Use) vulnerabilities
- Double-fetch vulnerabilities
- Logic flaws in authentication and authorization
Race Conditions
What It Is: A race condition occurs when the behavior of software depends on the relative timing of events, such as the order in which threads execute. When multiple threads or processes access shared resources without proper synchronization, an attacker can manipulate the timing to cause unexpected behavior.
Common Patterns:
- File System Race Conditions: Check a file's permissions, then open it (attacker swaps the file between check and open).
- Double-Fetch: Kernel reads user-mode memory twice, attacker modifies it between reads.
- Synchronization Primitives: Missing or incorrect use of locks, mutexes, or atomic operations.
Real-World Context - Windows TOCTOU Race Condition (CVE-2024-26218):
- The Bug Pattern: A Time-of-Check Time-of-Use (TOCTOU) race condition in the Windows Kernel allowed an attacker to exploit a timing window between validation and usage of kernel resources. The vulnerability occurred when the kernel checked permissions or resource states but didn't atomically perform the subsequent operation, allowing a racing thread to modify the resource state between check and use.
- The Attack:
- Check Phase: Kernel validates resource permissions/state (e.g., file access rights, object ownership).
- Race Window: Attacker's thread modifies the resource state (e.g., replaces object, changes permissions).
- Use Phase: Kernel operates on the now-modified resource, assuming the original validated state.
- Result: Privilege escalation by operating on resources with elevated privileges.
- The Impact: Local privilege escalation from low-privileged user to SYSTEM. CVSS Score: 7.7 (HIGH). Affected Windows 10, Windows 11, and Windows Server 2019/2022 systems. Patched in April 2024 (Microsoft Patch Tuesday).
- Why It's Hard to Fix: Requires atomic check-and-use operations, proper locking mechanisms across complex kernel subsystems, or defensive copying to ensure the checked state matches the used state. Many kernel operations assume sequential execution without considering concurrent modification.
Time-of-Check Time-of-Use (TOCTOU)
What It Is: TOCTOU is a specific type of race condition where there's a gap between checking a condition and using the result. During that gap, the condition can change, invalidating the check.
Classic Example - Symbolic Link Attacks:
1. Program checks if /tmp/important_file is safe to write
2. [RACE WINDOW] Attacker creates symlink: /tmp/important_file -> /etc/passwd
3. Program writes to /tmp/important_file (now actually /etc/passwd)
Real-World Impact:
- Privilege Escalation: TOCTOU bugs in privileged programs can allow unprivileged users to modify protected files.
- Bypass Security Checks: Authentication or authorization checks can be circumvented if the resource changes between check and use.
- Data Corruption: Unexpected file modifications can corrupt system state.
Recent Example - 7-Zip Symlink Path Traversal (CVE-2025-11001/11002):
- The Bug: Improper validation of symlink targets in ZIP extraction allowed directory traversal via crafted symlinks, enabling writes outside the intended extraction directory.
- The Attack: A malicious archive embeds symlinks that resolve to sensitive paths; when extracted, files are written to arbitrary locations, enabling code execution scenarios depending on target path.
- The Impact: Arbitrary file write leading to potential RCE in user context.
- The Fix: Updates addressed symlink conversion and validation logic during extraction to prevent traversal outside the destination directory.
Double-Fetch Vulnerabilities
What It Is: A double-fetch occurs when kernel code reads user-mode memory twice, assuming it won't change between reads. An attacker with multiple threads can modify the memory after the first read but before the second, causing kernel code to operate on inconsistent data.
Case Study - CVE-2023-4155 (Linux KVM AMD SEV Double-Fetch):
- The Bug: A double-fetch race condition in the Linux kernel's KVM (Kernel-based Virtual Machine) AMD Secure Encrypted Virtualization (SEV) implementation. KVM guests using SEV-ES or SEV-SNP with multiple vCPUs could trigger the vulnerability by manipulating shared guest memory that the hypervisor reads twice without proper synchronization.
- The Bug Pattern: The
VMGEXIT handler in the hypervisor read guest-controlled memory to determine which operation to perform. An attacker could modify this memory between the first read (validation) and second read (usage), causing inconsistent behavior.
- The Attack:
- First Read: Hypervisor reads guest memory to validate the VMGEXIT reason code.
- Race Window: Attacker's vCPU thread modifies the guest memory containing the reason code.
- Second Read: Hypervisor reads the modified value and processes a different operation than validated.
- Result: Recursive invocation of the
VMGEXIT handler, leading to stack overflow.
- The Impact: Denial of service (DoS) via stack overflow in hypervisor. In kernel configurations without stack guard pages (
CONFIG_VMAP_STACK), potential guest-to-host escape.
- The Fix: Linux kernel patches added proper synchronization to ensure the VMGEXIT reason code is read once and stored in a local variable, preventing the double-fetch condition. Added checks to prevent recursive handler invocation.
- Why It's Hard to Fix: Requires identifying all locations where hypervisor code reads guest memory multiple times, copying guest data into hypervisor memory once, and operating on the stable copy. Performance considerations make defensive copying expensive in virtualization hot paths.
Logic Flaws in Authentication and Authorization
What It Is: Bugs in the logical flow of authentication or authorization checks that allow attackers to bypass security boundaries without exploiting memory corruption.
Case Study - CVE-2024-0012 (Palo Alto PAN-OS Authentication Bypass):
- The Bug: Palo Alto Networks PAN-OS software contained an authentication bypass vulnerability in its management web interface. The vulnerability allowed an unauthenticated attacker to bypass authentication checks entirely and gain administrator privileges without providing any credentials.POC
- The Attack: An attacker with network access to the PAN-OS management web interface could send specially crafted requests that bypassed authentication logic. No credentials or user interaction were required—the attacker could directly gain administrator access by exploiting the flaw in the authentication validation code.
- The Impact: Complete authentication bypass allowing unauthenticated remote attackers to gain PAN-OS administrator privileges. This enabled attackers to perform administrative actions, tamper with firewall configurations, extract sensitive data, or chain with other vulnerabilities like CVE-2024-9474 for further exploitation.
- The Fix: Palo Alto released patches in versions 10.2.12, 11.0.6, 11.1.5, and 11.2.4 (November 2024) that corrected the authentication validation logic. Additionally, Palo Alto recommended restricting management interface access to only trusted internal IP addresses as a defense-in-depth measure.
- Why It Matters: Logic flaws in authentication and authorization can lead to privilege escalation (user becomes admin), horizontal privilege escalation (user A accesses user B's data), or authentication bypass (access without credentials) - all without memory corruption. Missing checks, state confusion, parameter tampering, and session management flaws are common patterns. This vulnerability demonstrates how authentication logic flaws in network devices can provide complete system compromise without requiring memory corruption exploitation.
Arbitrary Write (Write-What-Where)
What It Is: The attacker can write a controlled value to a controlled address.
Case Study - CVE-2024-21338 (Windows AppLocker Driver Arbitrary Function Call → Arbitrary Write):
- The Bug: The Windows AppLocker driver (appid.sys) contained a vulnerability in its IOCTL handler (control code
0x22A018) that allowed an attacker with local service privileges to call arbitrary kernel function pointers with controlled arguments. The IOCTL was designed to accept kernel function pointers for file operations but remained accessible from user space without proper validation. POC
- The Attack: An attacker could impersonate the local service account and send a specially crafted IOCTL request to
\Device\AppId with malicious function pointers. By choosing the right gadget function, the attacker could perform a 64-bit copy to an arbitrary kernel address - specifically targeting the PreviousMode field in the current thread's KTHREAD structure. Corrupting PreviousMode to KernelMode (0) bypasses kernel-mode checks in syscalls like NtReadVirtualMemory and NtWriteVirtualMemory, granting arbitrary kernel read/write capabilities from user mode.
- The Impact: Local privilege escalation from local service (or admin via impersonation) to kernel-level arbitrary read/write. This primitive enabled the sophisticated FudModule rootkit to perform direct kernel object manipulation (DKOM), disable security callbacks, blind ETW telemetry, and suspend PPL-protected security processes.
- The Fix: Microsoft released patches in February 2024 (Patch Tuesday) that added an
ExGetPreviousMode check to the IOCTL handler, preventing user-mode initiated IOCTLs from triggering the arbitrary callback invocation.
- Why It Matters: This represents a sophisticated evolution beyond traditional BYOVD (Bring Your Own Vulnerable Driver) techniques. By exploiting a zero-day in a built-in Windows driver, attackers achieved a truly fileless kernel attack with no need to drop or load custom drivers. The arbitrary write primitive (achieved via PreviousMode corruption) is a canonical technique to flip privilege bits, overwrite function pointers, or modify security policy data. This case demonstrates how IOCTL handlers with insufficient input validation can provide powerful primitives for kernel exploitation, especially when they accept function pointers or allow object confusion.
Locking/RCU Misuse
What It Is: Incorrect lock ordering, missing locks, or misuse of RCU leading to races on freed objects.
Case Study - CVE-2023-32629 (Linux Netfilter nf_tables Race Condition):
- The Bug: The Linux kernel's netfilter nf_tables subsystem contained a race condition vulnerability due to improper locking when handling batch operations. The vulnerability occurred in the transaction handling code where concurrent access to nf_tables objects wasn't properly synchronized, allowing use-after-free conditions.POC
- The Attack: An attacker with
CAP_NET_ADMIN capability (obtainable through unprivileged user namespaces on many distributions) could exploit the race by sending concurrent netlink messages to manipulate nf_tables rules. By carefully timing these operations across multiple threads, the attacker could trigger a window where one thread frees an object while another thread still holds a reference to it.
- The Impact: Local privilege escalation from unprivileged user to root on systems with unprivileged user namespaces enabled (default on Ubuntu, Debian, Fedora, and others). The use-after-free primitive could be exploited to gain arbitrary kernel read/write capabilities, typically used to modify process credentials or overwrite kernel function pointers. Affected Linux kernels prior to version 6.3.1 (May 2023).
- The Fix: Linux kernel 6.3.1 added proper locking mechanisms around nf_tables batch transaction processing, implemented reference counting to track object lifetimes correctly, and ensured atomic operations for concurrent access to shared netfilter data structures.
- Why It Matters: Locking and RCU misuse leads to reproducible UAF and memory corruption in hot paths like filesystems, networking, and timers. Incorrect lock ordering, missing locks, and RCU violations are particularly dangerous in kernel code where concurrency is pervasive. The netfilter subsystem continues to be a recurring source of such vulnerabilities due to its complexity and extensive use of concurrent data structures.
Key Takeaways
- Logic vulnerabilities don't require memory corruption: Authentication bypasses, TOCTOU flaws, and arbitrary write primitives can be as impactful as traditional memory corruption.
- Concurrency bugs enable sophisticated exploits: Double-fetch, race conditions and locking misuse are difficult to reproduce but provide reliable exploitation when timing is controlled.
- Arbitrary write is the ultimate primitive: Whether achieved through IOCTL handlers, PreviousMode corruption, or RCU misuse, arbitrary kernel write enables privilege escalation, security callback disabling, and rootkit deployment.
- User namespaces expand attack surface: Many kernel vulnerabilities (netfilter, io_uring) become exploitable from unprivileged contexts when user namespaces grant capabilities like
CAP_NET_ADMIN.
- Defense requires atomic operations: TOCTOU vulnerabilities demonstrate that check-then-use patterns are inherently racy; atomic check-and-use operations, proper locking, and defensive copying are essential.
Discussion Questions
- How do double-fetch vulnerabilities differ from traditional TOCTOU race conditions and what makes them particularly dangerous in hypervisor contexts?
- Compare the exploitation complexity of authentication logic flaws versus kernel race conditions Which provides more reliable exploitation and why?
- How does the arbitrary write primitive achieved in CVE-2024-21338 (via PreviousMode corruption) differ from traditional buffer overflow-based arbitrary write, and what advantages does it provide to attackers?
- What role do user namespaces play in the exploitability of kernel bugs like CVE-2023-32629, and should distributions reconsider their default unprivileged namespace policies?
Day 3: Type Confusion, Integer, Parser Vulnerabilities
- Goal: Understand how type mismatches and integer arithmetic errors lead to exploitable conditions.
- Activities:
- Reading:
- Online Resources:
- Concepts:
- Type systems and type safety
- JIT compilation and type confusion
- Integer overflow, underflow, and truncation
- Signed/unsigned confusion
Type Confusion Vulnerabilities
What It Is: Type confusion occurs when a program processes an object as a different type than intended. This can happen in dynamically-typed languages, during unsafe type casts, or in JIT compilers that make incorrect assumptions about object types.
Why They're Dangerous:
- Objects of different types have different memory layouts
- Treating Type A as Type B can expose internal pointers, corrupt metadata, or provide arbitrary read/write primitives
- In JIT compilers, type confusion can bypass sandbox protections
Real-World Example - CVE-2024-7971 (V8 TurboFan Type Confusion):
Background: V8 is the JavaScript engine powering Chrome, Edge, and Node.js. TurboFan is V8's optimizing JIT compiler that converts JavaScript to highly-optimized machine code based on runtime type information.
The Bug: TurboFan's CheckBounds elimination optimization incorrectly assumed array element types during JIT compilation. When encountering a polymorphic inline cache (an optimization for code that handles multiple types), TurboFan sometimes confused tagged pointers (Heap objects) with SMI (Small Integers, V8's immediate integer representation).POC
The Attack:
Type Confusion Setup: Craft JavaScript with polymorphic inline cache that triggers speculative optimization on mixed SMI/HeapNumber array.
// Simplified concept (not actual exploit):
let arr = [1, 2, 3]; // SMI array
arr[0] = 1.5; // Now mixed SMI and HeapNumber
// TurboFan optimizes assuming one type, confusion occurs
Primitive Construction: The type confusion allowed creating a fake JSArray with a controlled backing store pointer.
Memory Corruption: By corrupting the length field of the fake array, the attacker achieved out-of-bounds read/write capabilities.
Sandbox Escape: Pivot to WASM RWX (read-write-execute) page for shellcode execution, bypassing V8's sandbox.
Mitigations Bypassed:
- V8 Sandbox (Pointer Compression): The V8 sandbox isolates JavaScript objects from native memory. The attacker bypassed this using pointer compression primitives.
- CFI (Control-Flow Integrity): JIT-generated code is often exempt from CFI checks, allowing the attacker to execute arbitrary code.
The Fix: V8 patched the CheckBounds elimination logic to correctly track type information during optimization passes.
Why It Matters: Browser exploitation is a high-value target for attackers. Type confusion in JIT compilers is a common vulnerability class, with new variants discovered regularly.
JIT Compiler Exploitation Concepts
Background on JIT Compilation:
- JIT compilers observe runtime behavior and generate optimized machine code
- They make assumptions based on type inference and profiling
- When assumptions are violated but the compiler doesn't properly handle it, bugs occur
Common JIT Vulnerability Patterns:
- Type Confusion: Incorrect type inference leading to wrong optimizations
- Bounds Check Elimination: Removing safety checks based on incorrect assumptions
- Register Allocation Bugs: Incorrect register usage leading to data corruption
- Inline Cache Poisoning: Manipulating cached type information
Exploitation Primitives Built from Type Confusion:
- addrof: Leak object addresses (information leak for ASLR bypass)
- fakeobj: Create fake objects with controlled structure (type confusion)
- arbitrary read/write: Out-of-bounds access to any memory location
- code execution: Pivot to RWX pages or corrupt code pointers
Integer Overflow, Underflow, and Truncation
What They Are:
- Overflow: Exceeding maximum value (e.g.,
INT_MAX + 1 wraps to INT_MIN)
- Underflow: Going below minimum value (e.g.,
0 - 1 becomes UINT_MAX for unsigned)
- Truncation: Losing data when converting larger to smaller type (e.g.,
(uint32_t)0x100000000 becomes 0)
Why They're Dangerous:
Integer bugs often lead to memory corruption because integers are used for:
- Buffer sizes in memory allocation
- Loop counters and array indices
- Length checks and bounds validation
Common Exploitation Pattern:
// Vulnerable code pattern:
size_t size = user_controlled_value1 + user_controlled_value2; // Overflow!
char *buf = malloc(size); // Allocates small buffer due to wrap-around
memcpy(buf, user_data, original_large_size); // Heap overflow
Case Study - CVE-2024-38063 (Windows TCP/IP Integer Underflow RCE):
- The Bug: The Windows TCP/IP stack contained a critical integer underflow vulnerability in its IPv6 packet processing code. When handling specially crafted IPv6 packets with malformed extension headers, the TCP/IP driver (tcpip.sys) performed arithmetic operations that could result in an integer underflow, leading to out-of-bounds memory access. The vulnerability occurred during IPv6 packet reassembly when calculating buffer sizes for packet fragments.
- The Attack: A remote unauthenticated attacker could send specially crafted IPv6 packets to a vulnerable Windows system over the network. The malformed packets would trigger the integer underflow during packet reassembly or extension header processing, causing a buffer overfl
…(truncated)
1---2name: skill-week-1-vulnerability-classes-with-real-world-examples3description: Skill Week 1 Vulnerability Classes With Real World Examples4---5# SKILL: Week 1: Vulnerability Classes with Real-World Examples
6
7## Metadata
8- **Skill Name**: vulnerability-classes
9- **Folder**: offensive-vuln-classes
10- **Source**: https://github.com/SnailSploit/offensive-checklist/blob/main/1-vulnerability-classes.md
11
12## Description
13Exploit development curriculum covering core vulnerability classes with real-world CVE case studies: stack/heap buffer overflows, use-after-free, integer overflows, format strings, type confusion, and race conditions. Use when learning or teaching vuln classes, researching specific CVE patterns, or building exploit dev knowledge.
14
15## Trigger Phrases
16Use this skill when the conversation involves any of:
17`vulnerability classes, buffer overflow, use-after-free, UAF, heap overflow, stack overflow, type confusion, integer overflow, format string, memory corruption, CVE case study, exploit development, Day 1-7`
18
19## Instructions for Claude
20
21When this skill is active:
221. Load and apply the full methodology below as your operational checklist
232. Follow steps in order unless the user specifies otherwise
243. For each technique, consider applicability to the current target/context
254. Track which checklist items have been completed
265. Suggest next steps based on findings
27
28---
29
30## Full Methodology
31
32# Week 1: Vulnerability Classes with Real-World Examples
33
34## Course Overview
35
36_created by AnotherOne from @Pwn3rzs Telegram channel_.
37
38This document is Week 1 of a multi‑week exploit development course, focusing on core vulnerability classes and real‑world exploitation context.
39
40Next Week we'll focus on using fuzzing to identify new vulnerabilites and in week 3 we'll focus on using patch diffing to find n-days
41
42## Day 1: Memory Corruption Fundamentals
43
44- **Goal**: Understand primary memory corruption vulnerability classes and their real-world impact.
45- **Activities**:
46 - _Reading_:
47 - "The Art of Software Security Assessment" by Mark Dowd, John McDonald, Justin Schuh - Chapter 5: Memory Corruption
48 - [Memory Corruption: Examples, Impact, and 4 Ways to Prevent It](https://sternumiot.com/iot-blog/memory-corruption-examples-impact-and-4-ways-to-prevent-it/)
49 - _Online Resources_:
50 - [Microsoft Security Research: Memory Safety](https://www.microsoft.com/en-us/research/project/checked-c/)
51 - [Google Project Zero Blog](https://googleprojectzero.blogspot.com/) - Read recent memory corruption findings
52 - _Concepts_:
53 - What is memory corruption and why does it matter?
54 - Understanding the stack, heap, and their differences
55 - The lifecycle of memory: allocation → use → deallocation
56
57### Stack Buffer Overflow
58
59**What It Is**: A stack overflow occurs when a program writes more data to a buffer located on the stack than it can hold, causing adjacent memory to be overwritten. This can corrupt important data like return addresses, allowing attackers to redirect program execution.
60
61**Case Study - CVE-2024-27130 (QNAP QTS/QuTS hero Stack Overflow)**:
62
63- **The Bug**: QNAP's QTS and QuTS hero operating systems contained multiple buffer copy vulnerabilities where unsafe functions like `strcpy()` were used to copy user-supplied input into fixed-size stack buffers without proper size validation. The vulnerabilities affected the web administration interface and file handling components. [POC](https://github.com/watchtowrlabs/CVE-2024-27130)
64- **The Attack**: An authenticated remote attacker could send specially crafted requests with oversized input to vulnerable endpoints. The unchecked data would overflow stack buffers, corrupting adjacent memory including return addresses and saved frame pointers.
65- **The Impact**: Remote code execution with the privileges of the QNAP system service. The attacker could gain complete control over the NAS device, accessing stored data, pivoting to other network resources, or installing persistent backdoors.
66- **The Fix**: QNAP released QTS 5.1.7.2770 build 20240520 and QuTS hero h5.1.7.2770 build 20240520 in May 2024, replacing unsafe string copy functions with bounds-checked alternatives and implementing additional input validation.
67- **Why It Matters**: Stack overflows remain common in embedded devices and NAS systems running legacy C/C++ code. They're particularly dangerous in internet-facing administration interfaces and often provide the initial foothold for sophisticated attack chains against enterprise infrastructure.
68
69### Use-After-Free (UAF)
70
71**What It Is**: A use-after-free vulnerability occurs when a program continues to use a pointer after the memory it points to has been freed. This creates a "dangling pointer" that can be exploited by carefully controlling heap allocations to place attacker-controlled data where the freed object once lived.
72
73**Case Study - CVE-2024-2883 (Chrome ANGLE Use-After-Free)**:
74
75- **The Bug**: Google Chrome's ANGLE (Almost Native Graphics Layer Engine) component, which translates OpenGL ES API calls to DirectX, Vulkan, or native OpenGL, contained a use-after-free vulnerability. The bug occurred when WebGL contexts were destroyed while still referenced by pending graphics operations, leaving dangling pointers to freed graphics objects.
76- **The Attack**: An attacker could create a malicious HTML page with specially crafted WebGL JavaScript code that triggered rapid creation and destruction of graphics contexts. By carefully timing these operations, the attacker could cause ANGLE to reference already-freed memory. Using heap spray and heap feng-shui techniques, the attacker could control the contents of the freed memory region.
77- **The Impact**: Remote code execution via a crafted web page with no user interaction beyond visiting the page. By placing a fake object in the freed memory location, the attacker could hijack control flow and execute arbitrary code in the renderer process. This could be chained with sandbox escape exploits for full system compromise.
78- **The Fix**: Google Chrome 123.0.6312.86 (released March 2024) fixed the vulnerability by implementing proper lifetime management for graphics objects and adding reference counting to prevent premature destruction of objects still in use.
79- **Why It Matters**: UAF vulnerabilities are particularly dangerous in browsers and complex C++ applications where object lifetimes are difficult to track. Graphics subsystems like ANGLE are attractive targets because they handle untrusted content and have complex state management. They're a favorite target for advanced attackers because they offer fine-grained control over program execution.
80
81### Heap Buffer Overflow
82
83**What It Is**: Similar to stack overflows, heap overflows occur when a program writes beyond the boundaries of a dynamically allocated buffer on the heap. Instead of corrupting stack frames, heap overflows typically corrupt heap metadata or adjacent objects, leading to memory corruption when the heap allocator later processes the corrupted structures.
84
85**Case Study - CVE-2023-4863 (libWebP Heap Buffer Overflow)**:
86
87- **The Bug**: The libWebP library, used by Chrome, Firefox, Edge, and many other applications for processing WebP images, contained a heap buffer overflow in the `BuildHuffmanTable()` function. When parsing specially crafted WebP images with malformed Huffman coding data, the function would write beyond the allocated buffer boundaries. [POC](https://github.com/mistymntncop/CVE-2023-4863)
88- **The Attack**: An attacker could embed a malicious WebP image in a web page or send it via messaging apps. When the victim's browser or application attempted to decode the image, the overflow would occur. The attacker could control the overflow data to corrupt heap metadata and adjacent objects.
89- **The Impact**: Remote code execution with no user interaction beyond viewing a web page or opening an image. Exploited as a zero-day in the wild before public disclosure. The vulnerability affected billions of devices across multiple platforms (Windows, macOS, Linux, Android, iOS).
90- **The Fix**: libWebP 1.3.2 (September 2023) fixed the bounds checking in `BuildHuffmanTable()`. Chrome 116.0.5845.187, Firefox 117.0.1, and other affected software released emergency patches.
91- **Why It Matters**: Heap buffer overflows in image parsers are particularly dangerous because images are ubiquitous and processed automatically. This vulnerability demonstrated the supply chain risk of widely-used libraries - a single bug in libWebP affected dozens of major applications. Modern heap exploitation techniques can bypass ASLR and other protections when combined with information leaks.
92
93### Out-of-Bounds Read (Info Leak)
94
95**What It Is**: Reading past buffer bounds without modifying memory. Frequently used to leak pointers, object metadata, and kernel layout to defeat KASLR and build arbitrary read/write primitives.
96
97**Case Study - CVE-2024-53108 (Linux AMDGPU Display Driver OOB Read)**:
98
99- **The Bug**: In the AMD display driver’s EDID/VSDB parsing path, insufficient bounds checking allowed out-of-bounds reads when extracting identifiers, leading to slab-out-of-bounds access under KASAN.
100- **The Attack**: A crafted display/EDID data stream could trigger an OOB read in kernel space. While not directly granting write primitives, the info leak can expose kernel memory contents and aid in bypassing KASLR.
101- **The Impact**: Information disclosure and potential system instability.
102- **The Fix**: Kernel updates tightened length validation within the AMD display capability parsing logic to ensure all reads stay within EDID buffer bounds. [DIFF](https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/diff/?id=16dd2825c23530f2259fc671960a3a65d2af69bd)
103- **Why It Matters**: Pure OOB reads are valuable for building reliable exploit chains (e.g., pairing with separate write primitives), especially in kernel contexts where defeating KASLR is pivotal.
104
105### Uninitialized Memory Use
106
107**What It Is**: Using stack/heap/pool memory before it is initialized. Contents may include stale pointers, capability flags, or structure fields.
108
109**Case Study - CVE-2024-26581 (Linux Kernel Netfilter Uninitialized Variable)**:
110
111- **The Bug**: The Linux kernel's netfilter subsystem contained an uninitialized variable vulnerability in the `nf_tables` component. When processing netlink messages to configure firewall rules, the `nft_pipapo_walk()` function failed to initialize a local variable before use. The uninitialized stack variable could contain residual data from previous function calls, including kernel pointers and sensitive memory addresses. [POC](https://sploitus.com/exploit?id=A4D521EE-225F-57D5-8C31-9F1C86D066B6)
112- **The Attack**: An attacker with `CAP_NET_ADMIN` capability (obtainable via unprivileged user namespaces on many distributions) could trigger specific netfilter operations that caused the uninitialized variable to be read and copied back to userspace through netlink responses. By repeatedly triggering the vulnerable code path and analyzing returned data, an attacker could extract kernel memory contents including heap/stack addresses.
113- **The Impact**: Information disclosure leading to KASLR (Kernel Address Space Layout Randomization) bypass. The leaked kernel addresses could then be used to reliably exploit other kernel vulnerabilities, turning potential denial-of-service bugs into privilege escalation or code execution. This vulnerability was particularly dangerous when combined with other netfilter bugs for full LPE chains.
114- **The Fix**: Linux kernel 6.8-rc1 (February 2024) added proper initialization of the variable using designated initializers: `struct nft_pipapo_match *m = NULL;` and added explicit zero-initialization for stack structures. Additionally, the patch enabled stricter compiler warnings (`-Wuninitialized`) for the netfilter subsystem.
115- **Why It Matters**: Uninitialized memory reads are frequently the first stage in exploit chains, providing the entropy reductions needed to bypass modern mitigations like KASLR. They're particularly valuable in kernel exploitation where defeating ASLR is essential for reliable exploitation. The combination of unprivileged user namespaces granting `CAP_NET_ADMIN` and uninitialized memory leaks in netfilter makes this class of vulnerability accessible to local attackers without requiring root privileges.
116
117### Reference Counting Bugs
118
119**What It Is**: Incorrect increments/decrements or overflows in reference counters controlling object lifetime (filesystems, networking, drivers).
120
121**Case Study - CVE-2022-32250 (Linux Netfilter nf_tables Use-After-Free)**:
122
123- **The Bug**: The Linux kernel's netfilter subsystem (`net/netfilter/nf_tables_api.c`) had a reference counting error in the nf_tables component. An incorrect `NFT_STATEFUL_EXPR` check failed to properly track expression object lifetimes during rule updates, leading to premature object destruction while references still existed.
124- **The Attack**: A local attacker with the ability to create user/network namespaces (unprivileged on many distributions) could manipulate nf_tables firewall rules to trigger the reference counting bug. By creating and modifying stateful expressions in specific sequences, the attacker could cause the kernel to free an object while it was still being referenced, creating a use-after-free condition.
125- **The Impact**: Local privilege escalation from any user to root on systems allowing unprivileged namespaces (default on Ubuntu, Debian, and others). The UAF primitive could be exploited for arbitrary kernel memory read/write, typically used to modify credentials or overwrite function pointers. Affected Linux kernels from 4.1 (2015) through 5.18.1 (2022). [Public exploit available](https://github.com/theori-io/CVE-2022-32250-exploit).
126- **The Fix**: Linux kernel 5.18.2+ corrected the reference counting logic for stateful expressions, ensuring proper lifetime tracking during rule operations. The patch added explicit reference count increments/decrements at the appropriate points in the code path.
127- **Why It Matters**: Reference counting bugs are subtle and can lead to premature free → use-after-free conditions, or refcount overflow → free while references remain. They're particularly dangerous in kernel code where object lifetime management is critical. The accessibility via unprivileged user namespaces made this vulnerability particularly impactful for local privilege escalation.
128
129### NULL Pointer Dereference
130
131**What It Is**: Dereferencing a NULL pointer in privileged code. While modern systems typically prevent user-space mapping of NULL pages, kernel NULL pointer dereferences remain a significant source of denial-of-service vulnerabilities and can occasionally enable privilege escalation in specific contexts.
132
133**Case Study - CVE-2023-52434 (Linux SMB Client NULL Pointer Dereference)**:
134
135- **The Bug**: The Linux kernel's SMB (CIFS) client implementation contained a NULL pointer dereference vulnerability in the `smb2_parse_contexts()` function. When parsing server responses during SMB2/SMB3 connection establishment, the code failed to properly validate offsets and lengths of create context structures before dereferencing pointers. Malformed create contexts with invalid offsets could cause the kernel to access unmapped memory addresses, triggering a NULL pointer dereference.
136- **The Attack**: A malicious or compromised SMB server could send crafted SMB2_CREATE responses with invalid create context structures. When a Linux client attempted to mount the share or access files, the kernel would parse these malformed contexts without proper bounds checking. The vulnerability was triggered during the mount operation or file access, requiring only that a user attempt to connect to the malicious server.
137- **The Impact**: Denial of service affecting Linux kernels from 5.3 through 6.7-rc5. The NULL pointer dereference caused an immediate kernel panic with the error "unable to handle page fault for address: ffff8881178d8cc3" in the `smb2_parse_contexts()` function. Any user with permission to mount SMB shares could trigger the vulnerability, making it exploitable in multi-user environments. CVSS Score: 8.0 (High) with attack vector: Adjacent Network, requiring low privileges and no user interaction.
138- **The Fix**: Linux kernel patches (versions 5.4.277, 5.10.211, 5.15.150, 6.1.80, and 6.6.8+) added comprehensive validation of create context offsets and lengths before dereferencing. The patches ensure all pointer arithmetic stays within allocated buffer boundaries during SMB protocol parsing.
139- **Why It Matters**: NULL pointer dereferences in network protocol parsers are particularly dangerous because they can be triggered remotely by malicious servers or through man-in-the-middle attacks. While modern kernel protections prevent NULL page mapping (mitigating historical privilege escalation techniques), the DoS impact remains critical for availability.
140
141### Key Takeaways
142
1431. **Memory corruption remains prevalent**: Despite decades of security research, memory corruption bugs continue to plague software, especially in C/C++ codebases.
1442. **Defense-in-depth is essential**: Each real-world example shows attackers bypassing multiple protection mechanisms (DEP, ASLR, CET, XFG, safe-linking).
1453. **Modern mitigations raise the bar but don't eliminate risk**: While technologies like CET shadow stack and safe-linking make exploitation harder, determined attackers continue to find bypasses.
1464. **Root causes are similar, but contexts differ**: Stack, heap, and UAF bugs share common root causes (inadequate bounds checking, lifetime management) but require different exploitation techniques.
1475. **Legacy components remain vulnerable**: Years-old vulnerabilities in office parsers and archive handlers continue to be exploited due to slow patching.
148
149### Discussion Questions
150
1511. What commonalities do you see across the memory corruption vulnerability classes covered today?
1522. Why do memory corruption vulnerabilities persist despite decades of research into memory-safe languages?
1533. How do the exploitation techniques differ between stack, heap, and UAF vulnerabilities?
1544. What defense mechanisms were bypassed in each example, and what does that tell us about the current state of exploit mitigation?
1555. How do reference counting bugs lead to use-after-free conditions, and why are they particularly difficult to detect?
1566. What role do information leaks (like OOB reads and uninitialized memory) play in modern exploit chains?
157
158## Day 2: Logic Vulnerabilities and Race Conditions
159
160- **Goal**: Understand logic vulnerabilities that don't involve memory corruption but can be equally dangerous.
161- **Activities**:
162 - _Reading_:
163 - "Web Application Security, 2nd Edition" by Andrew Hoffman - Chapter 18: "Business Logic Vulnerabilities"
164 - [Portswigger Logic Flaws](https://portswigger.net/web-security/logic-flaws)
165 - _Online Resources_:
166 - [Time-of-check Time-of-use (TOCTOU) Vulnerabilities](https://en.wikipedia.org/wiki/Time-of-check_to_time-of-use)
167 - [Microsoft: Avoiding Race Conditions](https://learn.microsoft.com/en-us/windows/win32/sync/synchronization-and-multiprocessor-issues)
168 - _Concepts_:
169 - Race conditions and their causes
170 - TOCTOU (Time-of-Check Time-of-Use) vulnerabilities
171 - Double-fetch vulnerabilities
172 - Logic flaws in authentication and authorization
173
174### Race Conditions
175
176**What It Is**: A race condition occurs when the behavior of software depends on the relative timing of events, such as the order in which threads execute. When multiple threads or processes access shared resources without proper synchronization, an attacker can manipulate the timing to cause unexpected behavior.
177
178**Common Patterns**:
179
1801. **File System Race Conditions**: Check a file's permissions, then open it (attacker swaps the file between check and open).
1812. **Double-Fetch**: Kernel reads user-mode memory twice, attacker modifies it between reads.
1823. **Synchronization Primitives**: Missing or incorrect use of locks, mutexes, or atomic operations.
183
184**Real-World Context - Windows TOCTOU Race Condition (CVE-2024-26218)**:
185
186- **The Bug Pattern**: A Time-of-Check Time-of-Use (TOCTOU) race condition in the Windows Kernel allowed an attacker to exploit a timing window between validation and usage of kernel resources. The vulnerability occurred when the kernel checked permissions or resource states but didn't atomically perform the subsequent operation, allowing a racing thread to modify the resource state between check and use.
187- **The Attack**:
188 1. **Check Phase**: Kernel validates resource permissions/state (e.g., file access rights, object ownership).
189 2. **Race Window**: Attacker's thread modifies the resource state (e.g., replaces object, changes permissions).
190 3. **Use Phase**: Kernel operates on the now-modified resource, assuming the original validated state.
191 4. **Result**: Privilege escalation by operating on resources with elevated privileges.
192- **The Impact**: Local privilege escalation from low-privileged user to SYSTEM. CVSS Score: 7.7 (HIGH). Affected Windows 10, Windows 11, and Windows Server 2019/2022 systems. Patched in April 2024 (Microsoft Patch Tuesday).
193- **Why It's Hard to Fix**: Requires atomic check-and-use operations, proper locking mechanisms across complex kernel subsystems, or defensive copying to ensure the checked state matches the used state. Many kernel operations assume sequential execution without considering concurrent modification.
194
195### Time-of-Check Time-of-Use (TOCTOU)
196
197**What It Is**: TOCTOU is a specific type of race condition where there's a gap between checking a condition and using the result. During that gap, the condition can change, invalidating the check.
198
199**Classic Example - Symbolic Link Attacks**:
200
201```
2021. Program checks if /tmp/important_file is safe to write
2032. [RACE WINDOW] Attacker creates symlink: /tmp/important_file -> /etc/passwd
2043. Program writes to /tmp/important_file (now actually /etc/passwd)
205```
206
207**Real-World Impact**:
208
209- **Privilege Escalation**: TOCTOU bugs in privileged programs can allow unprivileged users to modify protected files.
210- **Bypass Security Checks**: Authentication or authorization checks can be circumvented if the resource changes between check and use.
211- **Data Corruption**: Unexpected file modifications can corrupt system state.
212
213**Recent Example - 7-Zip Symlink Path Traversal (CVE-2025-11001/11002)**:
214
215- **The Bug**: Improper validation of symlink targets in ZIP extraction allowed directory traversal via crafted symlinks, enabling writes outside the intended extraction directory.
216- **The Attack**: A malicious archive embeds symlinks that resolve to sensitive paths; when extracted, files are written to arbitrary locations, enabling code execution scenarios depending on target path.
217- **The Impact**: Arbitrary file write leading to potential RCE in user context.
218- **The Fix**: Updates addressed symlink conversion and validation logic during extraction to prevent traversal outside the destination directory.
219
220### Double-Fetch Vulnerabilities
221
222**What It Is**: A double-fetch occurs when kernel code reads user-mode memory twice, assuming it won't change between reads. An attacker with multiple threads can modify the memory after the first read but before the second, causing kernel code to operate on inconsistent data.
223
224**Case Study - CVE-2023-4155 (Linux KVM AMD SEV Double-Fetch)**:
225
226- **The Bug**: A double-fetch race condition in the Linux kernel's KVM (Kernel-based Virtual Machine) AMD Secure Encrypted Virtualization (SEV) implementation. KVM guests using SEV-ES or SEV-SNP with multiple vCPUs could trigger the vulnerability by manipulating shared guest memory that the hypervisor reads twice without proper synchronization.
227- **The Bug Pattern**: The `VMGEXIT` handler in the hypervisor read guest-controlled memory to determine which operation to perform. An attacker could modify this memory between the first read (validation) and second read (usage), causing inconsistent behavior.
228- **The Attack**:
229 1. **First Read**: Hypervisor reads guest memory to validate the VMGEXIT reason code.
230 2. **Race Window**: Attacker's vCPU thread modifies the guest memory containing the reason code.
231 3. **Second Read**: Hypervisor reads the modified value and processes a different operation than validated.
232 4. **Result**: Recursive invocation of the `VMGEXIT` handler, leading to stack overflow.
233- **The Impact**: Denial of service (DoS) via stack overflow in hypervisor. In kernel configurations without stack guard pages (`CONFIG_VMAP_STACK`), potential guest-to-host escape.
234- **The Fix**: Linux kernel patches added proper synchronization to ensure the VMGEXIT reason code is read once and stored in a local variable, preventing the double-fetch condition. Added checks to prevent recursive handler invocation.
235- **Why It's Hard to Fix**: Requires identifying all locations where hypervisor code reads guest memory multiple times, copying guest data into hypervisor memory once, and operating on the stable copy. Performance considerations make defensive copying expensive in virtualization hot paths.
236
237### Logic Flaws in Authentication and Authorization
238
239**What It Is**: Bugs in the logical flow of authentication or authorization checks that allow attackers to bypass security boundaries without exploiting memory corruption.
240
241**Case Study - CVE-2024-0012 (Palo Alto PAN-OS Authentication Bypass)**:
242
243- **The Bug**: Palo Alto Networks PAN-OS software contained an authentication bypass vulnerability in its management web interface. The vulnerability allowed an unauthenticated attacker to bypass authentication checks entirely and gain administrator privileges without providing any credentials.[POC](https://github.com/0xjessie21/CVE-2024-0012)
244- **The Attack**: An attacker with network access to the PAN-OS management web interface could send specially crafted requests that bypassed authentication logic. No credentials or user interaction were required—the attacker could directly gain administrator access by exploiting the flaw in the authentication validation code.
245- **The Impact**: Complete authentication bypass allowing unauthenticated remote attackers to gain PAN-OS administrator privileges. This enabled attackers to perform administrative actions, tamper with firewall configurations, extract sensitive data, or chain with other vulnerabilities like CVE-2024-9474 for further exploitation.
246- **The Fix**: Palo Alto released patches in versions 10.2.12, 11.0.6, 11.1.5, and 11.2.4 (November 2024) that corrected the authentication validation logic. Additionally, Palo Alto recommended restricting management interface access to only trusted internal IP addresses as a defense-in-depth measure.
247- **Why It Matters**: Logic flaws in authentication and authorization can lead to privilege escalation (user becomes admin), horizontal privilege escalation (user A accesses user B's data), or authentication bypass (access without credentials) - all without memory corruption. Missing checks, state confusion, parameter tampering, and session management flaws are common patterns. This vulnerability demonstrates how authentication logic flaws in network devices can provide complete system compromise without requiring memory corruption exploitation.
248
249### Arbitrary Write (Write-What-Where)
250
251**What It Is**: The attacker can write a controlled value to a controlled address.
252
253**Case Study - CVE-2024-21338 (Windows AppLocker Driver Arbitrary Function Call → Arbitrary Write)**:
254
255- **The Bug**: The Windows AppLocker driver (appid.sys) contained a vulnerability in its IOCTL handler (control code `0x22A018`) that allowed an attacker with local service privileges to call arbitrary kernel function pointers with controlled arguments. The IOCTL was designed to accept kernel function pointers for file operations but remained accessible from user space without proper validation. [POC](https://github.com/hakaioffsec/CVE-2024-21338)
256- **The Attack**: An attacker could impersonate the local service account and send a specially crafted IOCTL request to `\Device\AppId` with malicious function pointers. By choosing the right gadget function, the attacker could perform a 64-bit copy to an arbitrary kernel address - specifically targeting the `PreviousMode` field in the current thread's `KTHREAD` structure. Corrupting `PreviousMode` to `KernelMode` (0) bypasses kernel-mode checks in syscalls like `NtReadVirtualMemory` and `NtWriteVirtualMemory`, granting arbitrary kernel read/write capabilities from user mode.
257- **The Impact**: Local privilege escalation from local service (or admin via impersonation) to kernel-level arbitrary read/write. This primitive enabled the sophisticated FudModule rootkit to perform direct kernel object manipulation (DKOM), disable security callbacks, blind ETW telemetry, and suspend PPL-protected security processes.
258- **The Fix**: Microsoft released patches in February 2024 (Patch Tuesday) that added an `ExGetPreviousMode` check to the IOCTL handler, preventing user-mode initiated IOCTLs from triggering the arbitrary callback invocation.
259- **Why It Matters**: This represents a sophisticated evolution beyond traditional BYOVD (Bring Your Own Vulnerable Driver) techniques. By exploiting a zero-day in a built-in Windows driver, attackers achieved a truly fileless kernel attack with no need to drop or load custom drivers. The arbitrary write primitive (achieved via PreviousMode corruption) is a canonical technique to flip privilege bits, overwrite function pointers, or modify security policy data. This case demonstrates how IOCTL handlers with insufficient input validation can provide powerful primitives for kernel exploitation, especially when they accept function pointers or allow object confusion.
260
261### Locking/RCU Misuse
262
263**What It Is**: Incorrect lock ordering, missing locks, or misuse of RCU leading to races on freed objects.
264
265**Case Study - CVE-2023-32629 (Linux Netfilter nf_tables Race Condition)**:
266
267- **The Bug**: The Linux kernel's netfilter nf_tables subsystem contained a race condition vulnerability due to improper locking when handling batch operations. The vulnerability occurred in the transaction handling code where concurrent access to nf_tables objects wasn't properly synchronized, allowing use-after-free conditions.[POC](https://github.com/ThrynSec/CVE-2023-32629-CVE-2023-2640---POC-Escalation)
268- **The Attack**: An attacker with `CAP_NET_ADMIN` capability (obtainable through unprivileged user namespaces on many distributions) could exploit the race by sending concurrent netlink messages to manipulate nf_tables rules. By carefully timing these operations across multiple threads, the attacker could trigger a window where one thread frees an object while another thread still holds a reference to it.
269- **The Impact**: Local privilege escalation from unprivileged user to root on systems with unprivileged user namespaces enabled (default on Ubuntu, Debian, Fedora, and others). The use-after-free primitive could be exploited to gain arbitrary kernel read/write capabilities, typically used to modify process credentials or overwrite kernel function pointers. Affected Linux kernels prior to version 6.3.1 (May 2023).
270- **The Fix**: Linux kernel 6.3.1 added proper locking mechanisms around nf_tables batch transaction processing, implemented reference counting to track object lifetimes correctly, and ensured atomic operations for concurrent access to shared netfilter data structures.
271- **Why It Matters**: Locking and RCU misuse leads to reproducible UAF and memory corruption in hot paths like filesystems, networking, and timers. Incorrect lock ordering, missing locks, and RCU violations are particularly dangerous in kernel code where concurrency is pervasive. The netfilter subsystem continues to be a recurring source of such vulnerabilities due to its complexity and extensive use of concurrent data structures.
272
273### Key Takeaways
274
2751. **Logic vulnerabilities don't require memory corruption**: Authentication bypasses, TOCTOU flaws, and arbitrary write primitives can be as impactful as traditional memory corruption.
2762. **Concurrency bugs enable sophisticated exploits**: Double-fetch, race conditions and locking misuse are difficult to reproduce but provide reliable exploitation when timing is controlled.
2773. **Arbitrary write is the ultimate primitive**: Whether achieved through IOCTL handlers, PreviousMode corruption, or RCU misuse, arbitrary kernel write enables privilege escalation, security callback disabling, and rootkit deployment.
2784. **User namespaces expand attack surface**: Many kernel vulnerabilities (netfilter, io_uring) become exploitable from unprivileged contexts when user namespaces grant capabilities like `CAP_NET_ADMIN`.
2795. **Defense requires atomic operations**: TOCTOU vulnerabilities demonstrate that check-then-use patterns are inherently racy; atomic check-and-use operations, proper locking, and defensive copying are essential.
280
281### Discussion Questions
282
2831. How do double-fetch vulnerabilities differ from traditional TOCTOU race conditions and what makes them particularly dangerous in hypervisor contexts?
2842. Compare the exploitation complexity of authentication logic flaws versus kernel race conditions Which provides more reliable exploitation and why?
2853. How does the arbitrary write primitive achieved in CVE-2024-21338 (via PreviousMode corruption) differ from traditional buffer overflow-based arbitrary write, and what advantages does it provide to attackers?
2864. What role do user namespaces play in the exploitability of kernel bugs like CVE-2023-32629, and should distributions reconsider their default unprivileged namespace policies?
287
288## Day 3: Type Confusion, Integer, Parser Vulnerabilities
289
290- **Goal**: Understand how type mismatches and integer arithmetic errors lead to exploitable conditions.
291- **Activities**:
292 - _Reading_:
293 - "A Guide to Kernel Exploitation" by Enrico Perla and Massimiliano Oldani - Chapter 2: "a Taxonomy of Kernel Vulnerabilities"
294 - [CWE-190: Integer Overflow or Wraparound](https://cwe.mitre.org/data/definitions/190.html)
295 - [CWE-843: Type Confusion](https://cwe.mitre.org/data/definitions/843.html)
296 - _Online Resources_:
297 - [Understanding Type Confusion Vulnerabilities](https://hackingportal.github.io/Type_Confusion/type_confusion.html)
298 - [Type Confusion in Kernel Driver](https://whiteknightlabs.com/2025/07/08/understanding-type-confusion-in-kernel-driver/)
299 - _Concepts_:
300 - Type systems and type safety
301 - JIT compilation and type confusion
302 - Integer overflow, underflow, and truncation
303 - Signed/unsigned confusion
304
305### Type Confusion Vulnerabilities
306
307**What It Is**: Type confusion occurs when a program processes an object as a different type than intended. This can happen in dynamically-typed languages, during unsafe type casts, or in JIT compilers that make incorrect assumptions about object types.
308
309**Why They're Dangerous**:
310
311- Objects of different types have different memory layouts
312- Treating Type A as Type B can expose internal pointers, corrupt metadata, or provide arbitrary read/write primitives
313- In JIT compilers, type confusion can bypass sandbox protections
314
315**Real-World Example - CVE-2024-7971 (V8 TurboFan Type Confusion)**:
316
317**Background**: V8 is the JavaScript engine powering Chrome, Edge, and Node.js. TurboFan is V8's optimizing JIT compiler that converts JavaScript to highly-optimized machine code based on runtime type information.
318
319**The Bug**: TurboFan's `CheckBounds` elimination optimization incorrectly assumed array element types during JIT compilation. When encountering a polymorphic inline cache (an optimization for code that handles multiple types), TurboFan sometimes confused tagged pointers (Heap objects) with SMI (Small Integers, V8's immediate integer representation).[POC](https://github.com/mistymntncop/CVE-2024-7971)
320
321**The Attack**:
322
3231. **Type Confusion Setup**: Craft JavaScript with polymorphic inline cache that triggers speculative optimization on mixed `SMI`/`HeapNumber` array.
324
325 ```javascript
326 // Simplified concept (not actual exploit):
327 let arr = [1, 2, 3]; // SMI array
328 arr[0] = 1.5; // Now mixed SMI and HeapNumber
329 // TurboFan optimizes assuming one type, confusion occurs
330 ```
331
3322. **Primitive Construction**: The type confusion allowed creating a fake JSArray with a controlled backing store pointer.
333
3343. **Memory Corruption**: By corrupting the `length` field of the fake array, the attacker achieved out-of-bounds read/write capabilities.
335
3364. **Sandbox Escape**: Pivot to WASM RWX (read-write-execute) page for shellcode execution, bypassing V8's sandbox.
337
338**Mitigations Bypassed**:
339
340- **V8 Sandbox (Pointer Compression)**: The V8 sandbox isolates JavaScript objects from native memory. The attacker bypassed this using pointer compression primitives.
341- **CFI (Control-Flow Integrity)**: JIT-generated code is often exempt from CFI checks, allowing the attacker to execute arbitrary code.
342
343**The Fix**: V8 patched the `CheckBounds` elimination logic to correctly track type information during optimization passes.
344
345**Why It Matters**: Browser exploitation is a high-value target for attackers. Type confusion in JIT compilers is a common vulnerability class, with new variants discovered regularly.
346
347### JIT Compiler Exploitation Concepts
348
349**Background on JIT Compilation**:
350
351- JIT compilers observe runtime behavior and generate optimized machine code
352- They make assumptions based on type inference and profiling
353- When assumptions are violated but the compiler doesn't properly handle it, bugs occur
354
355**Common JIT Vulnerability Patterns**:
356
3571. **Type Confusion**: Incorrect type inference leading to wrong optimizations
3582. **Bounds Check Elimination**: Removing safety checks based on incorrect assumptions
3593. **Register Allocation Bugs**: Incorrect register usage leading to data corruption
3604. **Inline Cache Poisoning**: Manipulating cached type information
361
362**Exploitation Primitives Built from Type Confusion**:
363
364- **addrof**: Leak object addresses (information leak for ASLR bypass)
365- **fakeobj**: Create fake objects with controlled structure (type confusion)
366- **arbitrary read/write**: Out-of-bounds access to any memory location
367- **code execution**: Pivot to RWX pages or corrupt code pointers
368
369### Integer Overflow, Underflow, and Truncation
370
371**What They Are**:
372
373- **Overflow**: Exceeding maximum value (e.g., `INT_MAX + 1` wraps to `INT_MIN`)
374- **Underflow**: Going below minimum value (e.g., `0 - 1` becomes `UINT_MAX` for unsigned)
375- **Truncation**: Losing data when converting larger to smaller type (e.g., `(uint32_t)0x100000000` becomes `0`)
376
377**Why They're Dangerous**:
378Integer bugs often lead to memory corruption because integers are used for:
379
380- Buffer sizes in memory allocation
381- Loop counters and array indices
382- Length checks and bounds validation
383
384**Common Exploitation Pattern**:
385
386```c
387// Vulnerable code pattern:
388size_t size = user_controlled_value1 + user_controlled_value2; // Overflow!
389char *buf = malloc(size); // Allocates small buffer due to wrap-around
390memcpy(buf, user_data, original_large_size); // Heap overflow
391```
392
393**Case Study - CVE-2024-38063 (Windows TCP/IP Integer Underflow RCE)**:
394
395- **The Bug**: The Windows TCP/IP stack contained a critical integer underflow vulnerability in its IPv6 packet processing code. When handling specially crafted IPv6 packets with malformed extension headers, the TCP/IP driver (tcpip.sys) performed arithmetic operations that could result in an integer underflow, leading to out-of-bounds memory access. The vulnerability occurred during IPv6 packet reassembly when calculating buffer sizes for packet fragments.
396- **The Attack**: A remote unauthenticated attacker could send specially crafted IPv6 packets to a vulnerable Windows system over the network. The malformed packets would trigger the integer underflow during packet reassembly or extension header processing, causing a buffer overfl
397
398…(truncated)