Chapter 2: Vulnerability Classes
This chapter documents the main classes of vulnerabilities found in operating systems and applications, with a particular emphasis on the context of kernel and low-level systems. Each entry includes a technical description, real-world case studies, impact, and applicable mitigations.
Objective: To understand the primary classes of memory corruption vulnerabilities and their real-world impact.
Recommended Reading Resources: - "The Art of Software Security Assessment" by Mark Dowd, John McDonald, Justin Schuh - Chapter 5: Memory Corruption - Memory Corruption: Examples, Impact, and 4 Ways to Prevent It - Microsoft Security Research: Memory Safety - Google Project Zero Blog - Recent findings on memory corruption
2.1. 1.1 Fundamentals of Memory Corruption
Memory corruption continues to be one of the most critical and prevalent classes of vulnerabilities in software written in C/C++. Despite decades of security research, these bugs persist due to the inherent complexity of manual memory management.
Key Concepts: - What is memory corruption and why does it matter? Memory corruption occurs when a program modifies memory in unintended ways, allowing attackers to alter the program's state and potentially gain execution control. - Stack: A memory region for local variables and return addresses. Its LIFO (Last-In-First-Out) structure makes it vulnerable to overflows that can overwrite return addresses. - Heap: A dynamic memory region managed by the allocator (malloc/free). Heap metadata and adjacent objects can be corrupted by overflows. - Memory Lifecycle: Allocation → Usage → Deallocation. Errors in any phase can lead to vulnerabilities.
2.1.1. 1.1.1 Stack Buffer Overflow
General Description
A stack buffer overflow occurs when a program writes more data to a buffer located on the stack than it can hold. This causes the overwriting of adjacent memory, including critical data such as return addresses, potentially allowing the program's execution to be redirected.
Attack Mechanics:
STACK LAYOUT
+-------------------------+
| [High Addresses] |
| +-----------------+ |
| | Return | <--- Overwritten by attacker
| | Address | |
| +-----------------+ |
| | Saved Frame | <--- Also corrupted
| | Pointer | |
| +-----------------+ |
| | Local | |
| | Variables | |
| +-----------------+ |
| | Buffer[64] | <--- Overflow occurs here
| | | |
| +-----------------+ |
| [Low Addresses] |
+-------------------------+
Case Study: CVE-2024-27130 — QNAP QTS/QuTS Hero
| Field | Detail |
|---|---|
| Affected Product | QNAP QTS and QuTS hero |
| Type | Stack Buffer Overflow |
| Vector | Web administration interface |
| Severity | Critical |
| PoC Available | github.com/watchtowrlabs/CVE-2024-27130 |
The Bug
The QNAP QTS and QuTS hero operating systems contained multiple buffer copy vulnerabilities where insecure functions like strcpy() were used to copy user-supplied input to fixed-size buffers on the stack without proper size validation. The vulnerabilities affected the web administration interface and file handling components.
The Attack (Step-by-Step)
- Reconnaissance: Attacker identifies a vulnerable endpoint in the web administration interface.
- Preparation: Construction of a payload with oversized input.
- Exploitation: Sending a specially crafted request with data that exceeds the buffer size.
- Corruption: The unverified data overflows the stack buffer, overwriting:
- Adjacent local variables
- Saved frame pointer
- Return address
- Execution Control: When the function returns, the execution flow is redirected to attacker-controlled code.
Impact
- Remote code execution with the privileges of the QNAP service (typically root).
- Complete control of the NAS device, allowing:
- Access to all stored data
- Pivoting to other network resources
- Installation of persistent backdoors
- Critical risk for enterprise infrastructure where NAS devices store sensitive data.
Mitigation
QNAP released QTS 5.1.7.2770 build 20240520 and QuTS hero h5.1.7.2770 build 20240520 in May 2024:
- Replacement of insecure string copy functions (strcpy, sprintf) with bounds-checking alternatives (strncpy, snprintf).
- Implementation of additional input validation.
- Enablement of compiler protections (stack canaries).
Observations
Stack overflows are still common in: - Embedded devices with legacy C/C++ code. - NAS systems with internet-exposed administration interfaces. - Applications that have not adopted modern secure APIs.
They are particularly dangerous when: - They provide the initial entry point for sophisticated attack chains against enterprise infrastructure. - They do not have compiler protections enabled (ASLR, DEP, stack canaries).
2.1.2. 1.1.2 Use-After-Free / UAF
General Description
A Use-After-Free (UAF) 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 previously resided.
Bug Mechanics:
UAF LIFECYCLE
+--------------------------------+
| 1. ALLOCATION |
| obj = malloc(sizeof(Object)); |
| obj->vtable = &legitimate_vtable; |
| |
| 2. LEGITIMATE USE |
| obj->method(); // Call function via vtable |
| |
| 3. DEALLOCATION |
| free(obj); // Memory freed, but... |
| // The 'obj' pointer still exists! |
| |
| 4. REALLOCATION (by attacker) |
| attacker_data = malloc(sizeof(Object)); |
| // Same size → can get the same location |
| attacker_data->vtable = &malicious_vtable; |
| |
| 5. USE-AFTER-FREE |
| obj->method(); // Calls attacker's function! |
+--------------------------------+
Case Study: CVE-2024-2883 — Chrome ANGLE
| Field | Detail |
|---|---|
| Affected Product | Google Chrome (ANGLE component) |
| Type | Use-After-Free |
| Vector | Malicious web page |
| Severity | Critical |
| Exploitable Code | Yes, without user interaction |
The Bug
The ANGLE (Almost Native Graphics Layer Engine) component of Google Chrome, 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 being referenced by pending graphics operations, leaving dangling pointers to freed graphics objects.
The Attack (Step-by-Step)
- Environment Preparation:
- Attacker creates a malicious HTML page with WebGL JavaScript code.
- The code manipulates the creation and destruction of graphics contexts.
- Triggering the Bug:
javascript // Simplified concept (not the actual exploit): let ctx = canvas.getContext('webgl'); // Start asynchronous graphics operation ctx.bindBuffer(ctx.ARRAY_BUFFER, buffer); // Destroy context while operation is pending ctx = null; // Garbage collection frees the context // but pending operation still has a reference - Heap Feng-Shui:
- Use heap spray techniques to control allocations.
- Allocate objects of the same size as the freed object.
- Place attacker-controlled data in the freed location.
- Exploitation:
- When ANGLE code uses the dangling pointer, it accesses the attacker's data.
- The attacker places a fake object with a malicious vtable.
- The next virtual method call executes the attacker's code.
Impact
- Remote code execution via a malicious web page with NO user interaction other than visiting the page.
- By placing a fake object in the freed memory, the attacker can hijack the control flow.
- Execute arbitrary code in the renderer process.
- Can be chained with sandbox escape exploits for full system compromise.
Mitigation
Google Chrome 123.0.6312.86 (released March 2024) fixed the vulnerability: - Implementation of proper lifetime management for graphics objects. - Added reference counting to prevent premature destruction of objects still in use. - Additional validation before using pointers to graphics objects.
Observations
UAF vulnerabilities are particularly dangerous in: - Browsers: Complex C++ applications where object lifetimes are difficult to track. - Graphics Subsystems: ANGLE, Skia, and similar handle untrusted content and have complex state management. - Code with Asynchronous Callbacks: Where the order of execution is difficult to predict.
They are a favorite target of advanced attackers because: - They offer fine-grained control over program execution. - They are difficult to detect with static analysis. - Modern mitigations (ASLR) can be bypassed with heap manipulation techniques.
2.1.3. 1.1.3 Heap Buffer Overflow
General Description
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 allocator later processes the corrupted structures.
Heap Overflow Mechanics:
HEAP LAYOUT
+----------------------------------+
| +----------------------------+ |
| | Chunk Header (metadata) | |
| +----------------------------+ |
| | Vulnerable Buffer [100] | |
| | | |
| | ══════════════════════════ | <--- Boundary
| | OVERFLOW →→→→→→→→→→→→→→→→→→ |
| +----------------------------+ |
| +----------------------------+ |
| | Chunk Header (CORRUPTED) | <--- Corruption
| +----------------------------+ |
| | Adjacent Object | |
| | - vtable * | <--- Or object
| | - function_ptr | corruption
| | - data fields | |
| +----------------------------+ |
+----------------------------------+
Case Study: CVE-2023-4863 — libWebP
| Field | Detail |
|---|---|
| Affected Product | libWebP (Chrome, Firefox, Edge, multiple apps) |
| Type | Heap Buffer Overflow |
| Vector | Malicious WebP image |
| Severity | Critical |
| PoC Available | github.com/mistymntncop/CVE-2023-4863 |
The Bug
The libWebP library, used by Chrome, Firefox, Edge, and many other applications to process WebP images, contained a heap overflow in the BuildHuffmanTable() function. When parsing specially crafted WebP images with malformed Huffman coding data, the function wrote beyond the boundaries of the allocated buffer.
The Attack (Step-by-Step)
- Input Vector:
- Attacker embeds a malicious WebP image on a web page.
- Or sends it via messaging applications (WhatsApp, Telegram, Signal).
- Or includes it in a document (email, Word, PDF).
- Trigger:
- The victim's browser/application attempts to decode the image.
- The WebP parser processes malformed Huffman data.
BuildHuffmanTable()calculates an incorrect table size.
- Exploitation:
- The overflow corrupts heap metadata.
- Or corrupts adjacent objects with function pointers.
- The attacker controls the overflow data to achieve primitives.
- Result:
- Arbitrary code execution in the process context.
- In browsers: code executes in the renderer process.
Impact
- Remote code execution without user interaction other than viewing a web page or opening an image.
- Zero-day actively exploited before its public disclosure (September 2023).
- Billions of devices affected across multiple platforms:
- Windows, macOS, Linux (desktop)
- Android, iOS (mobile)
- Any software using libWebP (Electron apps, etc.)
Why This Vulnerability is Emblematic:
- Supply Chain Risk: A bug in libWebP affected dozens of major applications.
- Ubiquity of Images: Images are processed automatically and are ubiquitous.
- Modern Heap Techniques: Attackers combined the heap overflow with ASLR bypass techniques.
Mitigation
- libWebP 1.3.2 (September 2023): Corrected bounds checking in
BuildHuffmanTable(). - Chrome 116.0.5845.187: Emergency patch.
- Firefox 117.0.1: Emergency patch.
- Other affected software released coordinated updates.
Observations
Heap overflows in image parsers are particularly dangerous because: - Images are processed automatically without user confirmation. - They are routinely shared and considered “safe.” - Image parsers optimize for performance, sometimes sacrificing security checks. - The complexity of compression formats (Huffman, LZW, etc.) introduces bugs.
2.1.4. 1.1.4 Out-of-Bounds Read / Info Leak
General Description
An Out-of-Bounds (OOB) Read occurs when a program reads memory past the boundaries of a buffer without modifying it. Although it does not allow direct writing, it is frequently used to: - Leak pointers to bypass ASLR/KASLR. - Expose object metadata to build more powerful primitives. - Reveal kernel memory layout for reliable exploitation.
Role in Exploit Chains:
TYPICAL EXPLOIT CHAIN
+--------------------------------+
| 1. OOB READ (Info Leak) | <--- Leak kernel addresses
| └─────────┬─────────┘ |
| │ |
| ▼ |
| 2. KASLR BYPASS | <--- Calculate real addresses
| └─────────┬─────────┘ |
| │ |
| ▼ |
| 3. WRITE PRIMITIVE | <--- Another vulnerability (UAF, overflow)
| └─────────┬─────────┘ |
| │ |
| ▼ |
| 4. CODE EXECUTION | <--- Write to a known location
+--------------------------------+
Case Study: CVE-2024-53108 — Linux AMDGPU Display Driver
| Field | Detail |
|---|---|
| Affected Product | Linux Kernel (AMD Display driver) |
| Type | Out-of-Bounds Read (slab-out-of-bounds) |
| Vector | Malicious EDID/display data |
| Severity | Medium-High |
| Patch Diff | git.kernel.org |
The Bug
In the AMD display driver of the Linux kernel, the EDID/VSDB (Video Specification Database) parsing path had insufficient bounds checking when extracting capability identifiers. When processing EDID data with manipulated length fields, the driver would read beyond the boundaries of the allocated EDID buffer.
The bug was detected by KASAN (Kernel AddressSanitizer), which reported a slab-out-of-bounds access during the extraction of display data.
The Attack
A maliciously crafted EDID/display data stream could: 1. Trigger an OOB read in kernel space. 2. Expose kernel memory contents (including pointers). 3. Provide information to bypass KASLR. 4. Be chained with another write vulnerability for full exploitation.
Impact
- Information disclosure: Exposure of kernel memory content.
- Potential system instability: Reading invalid memory can cause an oops.
- Exploitation enabler: Usable to bypass KASLR in more complex exploit chains.
Why OOB Reads Matter:
In kernel contexts: - KASLR is a fundamental mitigation against exploitation. - Without an info leak, a blind write fails - the attacker needs to know where to write. - OOB reads are the first step in most modern kernel exploits.
Mitigation
Kernel updates adjusted the length validation: - Verify that bLength is >= the minimum expected size. - Validate offsets before accessing fields. - Ensure that all reads remain within the boundaries of the EDID buffer.
Observations
Pure OOB reads are valuable for building reliable exploit chains: - They provide the necessary information to bypass ASLR/KASLR. - They are frequently the first stage of multi-step exploits. - In the kernel, defeating KASLR is pivotal for reliable exploitation.
2.1.5. 1.1.5 Uninitialized Memory Use
General Description
Using stack/heap/pool memory before it is initialized can expose residual contents from previous operations. These contents may include: - Previous pointers (kernel addresses for bypassing KASLR). - Capability flags (for privilege escalation). - Structure fields (for type confusion).
Why It's Dangerous:
// Vulnerable code - uninitialized variable
void vulnerable_function(struct netlink_msg *msg) {
struct nft_pipapo_match *m; // <--- UNINITIALIZED
// If some code path does not assign 'm'...
if (some_condition(msg)) {
m = find_match(msg);
}
// ... but 'm' is used unconditionally
copy_to_user(response, &m, sizeof(m)); // <--- Leaks residual stack data
}
Case Study: CVE-2024-26581 — Linux Kernel Netfilter
| Field | Detail |
|---|---|
| Affected Product | Linux Kernel (netfilter subsystem) |
| Type | Uninitialized Variable Use |
| Vector | Local netlink messages |
| Severity | High |
| PoC Available | sploitus.com/exploit?id=A4D521EE-225F-57D5-8C31-9F1C86D066B6 |
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 its use.
The uninitialized stack variable could contain residual data from previous function calls, including kernel pointers and sensitive memory addresses.
The Attack (Step-by-Step)
- Obtain Capabilities:
- Attacker is in an unprivileged user namespace.
- User namespaces grant CAP_NET_ADMIN (default on Ubuntu, Debian).
- Trigger the Bug:
- Send specific netlink messages for nf_tables configuration.
- Cause the code path with the uninitialized variable to be executed.
- The variable is read and copied back to user space.
- Collect Information:
- Repeat the trigger multiple times.
- Analyze the returned data.
- Extract kernel addresses (heap, stack, code).
- Exploit with Information:
- Use the leaked addresses to bypass KASLR.
- Combine with another netfilter write vulnerability.
- Achieve full privilege escalation (LPE chain).
Impact
- Information disclosure → KASLR bypass.
- Leaked kernel addresses allow for reliable exploitation of other vulnerabilities.
- Particularly dangerous when combined with other netfilter bugs for full LPE chains.
The Danger of the Combo: Netfilter + User Namespaces
Many Linux distributions allow unprivileged user namespaces by default: - Ubuntu: Enabled by default. - Debian: Enabled by default. - Fedora: Enabled by default.
This means that CAP_NET_ADMIN is available to unprivileged users, making netfilter bugs exploitable without root privileges.
Mitigation
Linux kernel 6.8-rc1 (February 2024):
- Added proper initialization: struct nft_pipapo_match *m = NULL;
- Enabled designated initializers for stack structures.
- Enabled stricter compiler warnings (-Wuninitialized) for netfilter.
Observations
Uninitialized memory reads are often the first stage in exploit chains: - They provide entropy reductions to bypass modern mitigations. - They are particularly valuable in kernel exploitation where KASLR is essential. - The combination of unprivileged user namespaces and netfilter leaks makes this class of vulnerability accessible to local attackers without requiring root privileges.
2.1.6. 1.1.6 Reference Counting Bugs
General Description
Reference counting errors occur when there are incorrect increments/decrements or overflows in counters that control the lifetime of objects (file systems, networking, drivers). These bugs can lead to: - Premature free: Object freed while references still exist → UAF - Memory leak: Object never freed → memory exhaustion - Double-free: Excessive decrement → heap corruption
Reference Counting Mechanics:
REFERENCE COUNTING MANAGEMENT
CORRECT:
┌─────────┐ ┌─────────┐ ┌─────────┐
│ ref = 1 │ ──► │ ref = 2 │ ──► │ ref = 1 │ ──► free()
│ (alloc) │ │ (add) │ │ (drop) │
└─────────┘ └─────────┘ └─────────┘
BUG - PREMATURE FREE:
┌─────────┐ ┌─────────┐ ┌─────────┐
│ ref = 1 │ ──► │ ref = 0 │ ──► │ USE │ ← UAF!
│ (alloc) │ │ (drop) │ │ (bug) │
└─────────┘ └─────────┘ └─────────┘
BUG - REFCOUNT OVERFLOW:
┌─────────┐ ┌─────────┐ ┌─────────┐
│ ref=MAX │ ──► │ ref = 0 │ ──► │ free() │ ← Still in use!
│ │ │(overflow)│ │ (wrong) │
└─────────┘ └─────────┘ └─────────┘
Case Study: CVE-2022-32250 — Linux Netfilter nf_tables
| Field | Detail |
|---|---|
| Affected Product | Linux Kernel (nf_tables) |
| Type | Reference Counting Error → UAF |
| Vector | Unprivileged user namespaces |
| Severity | Critical |
| Public Exploit | github.com/theori-io/CVE-2022-32250-exploit |
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 check for NFT_STATEFUL_EXPR failed to properly track the lifetimes of expression objects during rule updates, leading to premature destruction of objects while references still existed.
The Attack (Step-by-Step)
- Environment Setup:
- Attacker creates an unprivileged user namespace.
- This grants CAP_NET_ADMIN within the namespace.
- Allows manipulation of nf_tables rules.
- Triggering the Bug:
- Create stateful expressions in nf_tables rules.
- Modify rules in specific sequences.
- Cause the kernel to incorrectly decrement the refcount.
- UAF Condition:
- The kernel frees an expression object.
- Another reference to the object still exists.
- The code continues to use the dangling pointer.
- Exploitation:
- Use heap spray techniques to reclaim the freed memory.
- Place attacker-controlled data at the location.
- Use the dangling pointer to achieve arbitrary read/write.
- Privilege Escalation:
- Modify process credentials (task_struct->cred).
- Or overwrite kernel function pointers.
- Gain root from an unprivileged user.
Impact
- Local privilege escalation from any user to root on systems that allow unprivileged namespaces.
- The UAF primitive can be exploited for arbitrary kernel memory read/write.
- Affected Linux kernels from 4.1 (2015) to 5.18.1 (2022) - over 7 years of vulnerability.
- The public exploit makes this vulnerability particularly dangerous.
Affected Distributions (namespaces enabled by default): - Ubuntu - Debian - Fedora - And many others
Mitigation
Linux kernel 5.18.2+ corrected the reference counting logic: - Added explicit refcount increments/decrements at the appropriate points in the code. - Ensured proper lifetime tracking during rule operations. - Added additional validations on stateful expressions.
Observations
Reference counting bugs: - Are subtle: Can lead to premature free conditions → use-after-free. - Or refcount overflow → free while references remain. - Are particularly dangerous in kernel code where object lifetime management is critical. - Accessibility via unprivileged user namespaces made this vulnerability particularly impactful for local privilege escalation.
2.1.7. 1.1.7 NULL Pointer Dereference
General Description
Dereferencing a NULL pointer in privileged code. While modern systems typically prevent NULL page mapping in user space (mitigating historical privilege escalation techniques), NULL pointer dereferences in the kernel remain a significant source of vulnerabilities for: - Denial of Service (immediate kernel panic) - Information Disclosure (in some contexts) - Privilege Escalation (in specific legacy configurations)
Mitigation Evolution:
EVOLUTION OF PROTECTIONS AGAINST NULL DEREF
BEFORE (Linux < 2.6.23):
┌─────────────────────────────────────────────────────┐
│ User space could map page 0 │
│ NULL deref → Execute attacker code → ROOT │
└─────────────────────────────────────────────────────┘
AFTER (Modern Linux with mmap_min_addr):
┌─────────────────────────────────────────────────────┐
│ Page 0 cannot be mapped by user │
│ NULL deref → Kernel Panic → DoS (but not RCE) │
└─────────────────────────────────────────────────────┘
/proc/sys/vm/mmap_min_addr = 65536 (typical)
Case Study: CVE-2023-52434 — Linux SMB Client
| Field | Detail |
|---|---|
| Affected Product | Linux Kernel (SMB/CIFS client) |
| Type | NULL Pointer Dereference |
| Vector | Malicious SMB server |
| Severity | High (CVSS 8.0) |
| Attack Vector | Adjacent network |
The Bug
The Linux kernel's SMB 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 contexts with invalid offsets could cause the kernel to access unmapped memory addresses, triggering a NULL pointer dereference.
The Attack (Step-by-Step)
- Input Vector:
- Malicious or compromised SMB server on the network.
- Or man-in-the-middle attack modifying SMB responses.
- Trigger:
- Server sends SMB2_CREATE responses with invalid create context structures.
- Offsets point outside of valid data.
- Or lengths calculate to NULL addresses.
- Crash:
- Linux client attempts to mount the share or access files.
- Kernel parses malformed contexts without bounds checking.
- Access to invalid address → kernel panic.
- Result:
BUG: unable to handle page fault for address: ffff8881178d8cc3 #PF: supervisor read access in kernel mode ... Call Trace: smb2_parse_contexts+0x...
Impact
- Denial of service affecting Linux kernels from 5.3 to 6.7-rc5.
- The NULL pointer dereference caused an immediate kernel panic.
- Any user with permission to mount SMB shares could trigger the vulnerability.
- Exploitable in multi-user environments where SMB mounting is allowed.
Exploitation Contexts: - Corporate network: Malicious user sets up a fake SMB server. - Public WiFi: Attacker performs MITM on SMB connections. - Compromised network: Legitimate SMB server is compromised and sends malicious responses.
Mitigation
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. - Verify that lengths do not exceed buffer limits. - Ensure all pointer arithmetic remains within allocated bounds.
Observations
NULL pointer dereferences in network protocol parsers are particularly dangerous because: - They can be triggered remotely by malicious servers. - Or through MITM attacks modifying network traffic. - While modern kernel protections prevent NULL page mapping (mitigating historical RCE), the DoS impact remains critical for availability.
2.1.8. 1.1.8 Memory Corruption Conclusions
Key Findings:
- 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: Every real-world example shows attackers bypassing multiple protection mechanisms (DEP, ASLR, CET, XFG, safe-linking).
- Modern mitigations raise the bar but do not eliminate the 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 (improper bounds checking, lifetime management) but require different exploitation techniques.
- Legacy components remain vulnerable: Years-old vulnerabilities in office parsers and file handlers continue to be exploited due to slow patching cycles.
Discussion Questions:
- What commonalities do you see across the covered memory corruption vulnerability classes?
- Why do memory corruption vulnerabilities persist despite decades of research into memory-safe languages?
- How do 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?
2.2. 1.2 Logical Vulnerabilities and Race Conditions
Logical vulnerabilities do not involve memory corruption but can be equally dangerous. This section covers race conditions, TOCTOU bugs, double-fetch, authentication flaws, arbitrary write primitives, and misuse of synchronization.
Reading Resources: - "Web Application Security, 2nd Edition" by Andrew Hoffman - Chapter 18: "Business Logic Vulnerabilities" - Portswigger Logic Flaws - Time-of-check Time-of-use (TOCTOU) Vulnerabilities - Microsoft: Avoiding Race Conditions
2.2.1. 1.2.1 Race Conditions
General Description
A race condition occurs when software behavior 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: Checking a file's permissions, then opening it (attacker swaps the file between check and open).
- Double-Fetch: Kernel reads user-mode memory twice; the attacker modifies it between reads.
- Synchronization Primitives: Missing or incorrect use of locks, mutexes, or atomic operations.
Case Study: CVE-2024-26218 — Windows Kernel TOCTOU
| Field | Detail |
|---|---|
| Affected Product | Windows Kernel |
| Type | TOCTOU Race Condition |
| Vector | Local |
| Severity | High (CVSS 7.7) |
The Bug
A Time-of-Check Time-of-Use race condition in the Windows Kernel allowed an attacker to exploit a timing window between the validation and use of kernel resources. The vulnerability occurred when the kernel checked permissions or resource states but did not perform the subsequent operation atomically, allowing a racing thread to modify the resource state between check and use.
The Attack (Step-by-Step)
TOCTOU ATTACK
KERNEL ATTACKER
────── ────────
│ │
│ 1. Check resource permissions │
│ result: OK │
│ ║ │
│ ║ ═══════════════════ │
│ ║ RACE WINDOW │ 2. Modify
│ ║ │ resource state
│ ║ ═══════════════════ │
│ ▼ │
│ 3. Use resource (now │
│ modified by attacker) │
│ │
│ 4. RESULT: Privilege Escalation │
Impact
- Local privilege escalation from a low-privileged user to SYSTEM.
- Affected Windows 10, Windows 11, and Windows Server 2019/2022.
- Patched in April 2024 (Microsoft Patch Tuesday).
Why It's Hard to Fix:
Race conditions require: - Atomic check-and-use operations. - Proper locking mechanisms across complex kernel subsystems. - Defensive copying to ensure the verified state matches the used state. - Many kernel operations assume sequential execution without considering concurrent modification.
Mitigation
Microsoft implemented: - Atomic check-and-use operations. - Appropriate locking mechanisms for shared resources. - Defensive copying to ensure verified/used state consistency.
Observations
Race conditions are difficult to reproduce but provide reliable exploitation when timing is controlled. They require a deep understanding of the target system's concurrency model.
2.2.2. 1.2.2 TOCTOU (Time-of-Check Time-of-Use) Vulnerabilities
General Description
TOCTOU is a specific type of race condition where there is a gap between checking a condition and using the result. During that gap, the condition can change, invalidating the check.
Classic Example — Symlink Attacks:
// Vulnerable program
1. if (access("/tmp/important_file", W_OK) == 0) { // CHECK
// [RACE WINDOW] Attacker: ln -s /etc/passwd /tmp/important_file
2. fd = open("/tmp/important_file", O_WRONLY); // USE
write(fd, data, size); // Writes to /etc/passwd!
}
Real-World Impact:
- Privilege Escalation: TOCTOU bugs in privileged programs allow unprivileged users to modify protected files.
- Security Check Bypass: Authentication or authorization checks can be bypassed if the resource changes between check and use.
- Data Corruption: Unexpected file modifications can corrupt the system state.
Case Study: CVE-2025-11001/11002 — 7-Zip Symlink Path Traversal
| Field | Detail |
|---|---|
| Affected Product | 7-Zip |
| Type | TOCTOU / Path Traversal via Symlink |
| Vector | Malicious ZIP file |
| Severity | High |
The Bug
Improper validation of symlink targets in ZIP extraction allowed directory traversal via malicious symlinks, enabling writes outside the intended extraction directory.
The Attack:
- Malicious File Preparation:
- Attacker creates a specially crafted ZIP/RAR file.
- Includes a symlink:
link.txt -> ../../../etc/cron.d/malicious. - Includes a file
link.txtwith malicious content.
- Extraction:
- User extracts the file to
/home/user/downloads/. - 7-Zip creates a symlink pointing outside the directory.
- It then writes content to the symlink.
- User extracts the file to
- Result:
- File is written to
/etc/cron.d/malicious. - Code execution as root when cron processes the file.
- File is written to
Impact
- Arbitrary file write leading to potential RCE in the user's context.
- Depending on the target directory (e.g.,
~/.bashrc,/etc/cron.d/,~/.ssh/authorized_keys), it can allow privilege escalation. - Affects all users who extract files from untrusted sources.
Mitigation
The updates addressed: - Validation of conversion and symlink logic during extraction. - Verification that destination paths remain within the extraction directory. - Rejection of symlinks pointing outside the extraction context.
Observations
TOCTOU vulnerabilities in file parsers are particularly dangerous because users frequently extract files from untrusted sources without additional verification.
2.2.3. 1.2.3 Double-Fetch Vulnerabilities
General Description
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 the kernel code to operate on inconsistent data.
Mechanics:
DOUBLE-FETCH VULNERABILITY
KERNEL USER SPACE (Attacker)
────── ─────────────────────────
│ │
│ 1. First read │
│ value = *userptr │
│ (validate: value == 1) │
│ ║ │
│ ║ ════════════════ │
│ ║ WINDOW │ 2. *userptr = 999
│ ║ ════════════════ │
│ ▼ │
│ 3. Second read │
│ use *userptr │
│ (now it's 999!) │
│ │
│ 4. Bug: code uses │
│ unvalidated value (999) │
Case Study: CVE-2023-4155 — Linux KVM AMD SEV Double-Fetch
| Field | Detail |
|---|---|
| Affected Product | Linux Kernel (KVM AMD SEV) |
| Type | Double-Fetch → Stack Overflow |
| Vector | Malicious VM guest |
| Severity | High |
The Bug
A double-fetch race condition in the KVM AMD Secure Encrypted Virtualization implementation of the Linux kernel. 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 the second read (use), causing inconsistent behavior.
The Attack (Step-by-Step)
- First Read: The hypervisor reads guest memory to validate the VMGEXIT reason code.
- Race Window: The attacker's vCPU thread modifies the guest memory containing the reason code.
- Second Read: The hypervisor reads the modified value and processes a different operation than the one validated.
- Result: Recursive invocation of the VMGEXIT handler, leading to a stack overflow.
Impact
- Denial of Service (DoS) via stack overflow in the hypervisor.
- In kernel configurations without stack guard pages (
CONFIG_VMAP_STACK), potential guest-to-host escape. - Affects virtualization environments with AMD SEV enabled.
Why It's Hard to Fix:
Double-fetches require: - Identifying all locations where hypervisor code reads guest memory multiple times. - Copying guest data to hypervisor memory once. - Operating on the stable copy. - Performance considerations make defensive copying expensive in hot virtualization paths.
Mitigation
The Linux kernel patches: - Added proper synchronization to ensure the VMGEXIT reason code is read once. - Stored the value in a local variable before validation and use. - Added checks to prevent recursive invocation of the handler.
Observations
Double-fetch vulnerabilities are particularly difficult to fix and particularly dangerous in hypervisor contexts where guest-to-host escape has a critical impact.
2.2.4. 1.2.4 Logical Flaws in Authentication
General Description
Bugs in the logical flow of authentication or authorization checks that allow attackers to bypass security boundaries without exploiting memory corruption.
Types of Logical Authentication Flaws:
| Type | Description | Example |
|---|---|---|
| Authentication Bypass | Accessing without credentials | Malformed requests bypass check |
| Vertical Escalation | User becomes admin | Role parameter manipulation |
| Horizontal Escalation | User A accesses B's data | IDOR (Insecure Direct Object Reference) |
| State Confusion | Inconsistent session state | Reusable reset tokens |
Case Study: CVE-2024-0012 — Palo Alto PAN-OS Authentication Bypass
| Field | Detail |
|---|---|
| Affected Product | Palo Alto Networks PAN-OS |
| Type | Authentication Bypass |
| Vector | Web administration interface |
| Severity | Critical |
| PoC Available | github.com/0xjessie21/CVE-2024-0012 |
The Bug
Palo Alto Networks' PAN-OS software contained an authentication bypass vulnerability in its web administration interface. The vulnerability allowed an unauthenticated attacker to completely bypass authentication checks and gain administrator privileges without providing any credentials.
The Attack:
- Attacker has network access to the PAN-OS web administration interface.
- Sends specially crafted requests that bypass the authentication logic.
- No credentials or user interaction are required.
- Attacker gains direct administrator access.
Impact
- Complete authentication bypass allowing unauthenticated remote attackers to gain PAN-OS administrator privileges.
- Enabled performing administrative actions:
- Manipulating firewall configurations.
- Creating rules to allow malicious traffic.
- Extracting configurations and credentials.
- Could be chained with other vulnerabilities like CVE-2024-9474 for further exploitation.
Mitigation
Palo Alto released patches in versions 10.2.12, 11.0.6, 11.1.5, and 11.2.4 (November 2024): - Corrected the authentication validation logic. - Recommended restricting access to the administration interface to only trusted internal IPs as a defense-in-depth measure.
Observations
Logical flaws in authentication and authorization can lead to: - Privilege escalation (user becomes admin). - Horizontal escalation (user A accesses user B's data). - Authentication bypass (access without credentials).
All without memory corruption. Missing checks, state confusion, parameter manipulation, and session management flaws are common patterns.
2.2.5. 1.2.5 Arbitrary Write (Write-What-Where)
General Description
An arbitrary write primitive allows the attacker to write a controlled value to a controlled address. This is one of the most powerful exploitation primitives, as it allows modifying any memory location.
Uses of Arbitrary Write:
ARBITRARY WRITE PRIMITIVES
1. OVERWRITE CREDENTIALS
task_struct->cred->uid = 0 → Become root
2. CORRUPT FUNCTION POINTERS
callback_ptr = &shellcode → Code execution
3. DISABLE PROTECTIONS
security_callback = NULL → Security bypass
4. MODIFY POLICIES
selinux_enforcing = 0 → Disable SELinux
Case Study: CVE-2024-21338 — Windows AppLocker Driver Arbitrary Function Call
| Field | Detail |
|---|---|
| Affected Product | Windows AppLocker driver (appid.sys) |
| Type | Arbitrary Function Call → Arbitrary Write |
| Vector | Local (local service or admin impersonation) |
| Severity | High |
| PoC Available | github.com/hakaioffsec/CVE-2024-21338 |
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.
The Attack (Step-by-Step)
- Gain Access:
- Attacker impersonates the local service account.
- Or has admin access that can impersonate.
- Send Malicious IOCTL:
- Send a specially crafted IOCTL request to
\Device\AppId. - Include malicious function pointers in the input buffer.
- Send a specially crafted IOCTL request to
- Exploit Gadget:
- Choose the correct gadget function.
- Perform a 64-bit copy to an arbitrary kernel address.
- Specific target:
PreviousModefield in the current thread's KTHREAD structure.
PreviousModeCorruption:- Corrupt
PreviousModetoKernelMode(0). - This bypasses kernel mode checks in syscalls like
NtReadVirtualMemoryandNtWriteVirtualMemory. - Grants arbitrary kernel read/write capabilities from user mode.
- Corrupt
- Post-Exploitation:
- Perform direct kernel object manipulation (DKOM).
- Disable security callbacks.
- Blind ETW telemetry.
- Suspend PPL-protected security processes.
Impact
This vulnerability was used by the sophisticated FudModule rootkit to: - Achieve local privilege escalation from local service (or admin via impersonation) to kernel-level arbitrary read/write. - Conduct a truly fileless kernel attack - no need to drop or load custom drivers. - Perform direct kernel object manipulation (DKOM). - Disable security callbacks. - Blind ETW telemetry. - Suspend PPL-protected security processes.
Why It's Significant:
This represents a sophisticated evolution beyond traditional BYOVD techniques. By exploiting a zero-day in a built-in Windows driver, attackers achieved a truly fileless kernel attack without needing to drop or load custom drivers.
Mitigation
Microsoft released patches in February 2024 (Patch Tuesday) that:
- Added an ExGetPreviousMode check to the IOCTL handler.
- Prevent user-mode initiated IOCTLs from triggering the arbitrary callback invocation.
Observations
The arbitrary write primitive (achieved via PreviousMode corruption) is a canonical technique for:
- Flipping privilege bits.
- Overwriting function pointers.
- Modifying 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.
2.2.6. 1.2.6 Locking/RCU Misuse
General Description
Incorrect lock ordering, missing locks, or misuse of RCU (Read-Copy-Update) leading to races on freed objects. These bugs occur in highly concurrent kernel code.
Common Patterns:
- Missing Lock: Accessing shared data without synchronization.
- Incorrect Lock Ordering: Deadlocks or races from inconsistent ordering.
- RCU Violations: Using an RCU-protected object outside a critical section.
- Premature Release: Dropping a lock before an operation completes.
Case Study: CVE-2023-32629 — Linux Netfilter nf_tables Race Condition
| Field | Detail |
|---|---|
| Affected Product | Linux Kernel (nf_tables) |
| Type | Race Condition from Improper Locking → UAF |
| Vector | Unprivileged user namespaces |
| Severity | High |
| PoC Available | github.com/ThrynSec/CVE-2023-32629-CVE-2023-2640-POC-Escalation |
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 was not properly synchronized, allowing for use-after-free conditions.
The Attack:
An attacker with CAP_NET_ADMIN capability (obtainable through unprivileged user namespaces in many distributions) could:
- Send concurrent netlink messages to manipulate nf_tables rules.
- Carefully time these operations across multiple threads.
- Trigger a window where one thread frees an object while another thread still holds a reference.
- Exploit the use-after-free condition for privilege escalation.
Impact
- Local privilege escalation from an 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).
Mitigation
Linux kernel 6.3.1: - Added proper locking mechanisms around the processing of nf_tables batch transactions. - Implemented reference counting to correctly track object lifetimes. - Ensured atomic operations for concurrent access to shared netfilter data structures.
Observations
Misuse of locking and RCU leads to reproducible UAF and memory corruption in hot paths like file systems, networking, and timers. Incorrect lock ordering, missing locks, and RCU violations are particularly dangerous in kernel code where concurrency is ubiquitous.
The netfilter subsystem continues to be a recurring source of such vulnerabilities due to its complexity and extensive use of concurrent data structures.
2.2.7. 1.2.7 Logical Vulnerabilities Conclusions
Key Findings:
- Logical vulnerabilities do not 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,
PreviousModecorruption, or RCU misuse, arbitrary kernel write enables privilege escalation, disabling security callbacks, and deploying rootkits. - User namespaces expand the 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 prone to races; 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
PreviousModecorruption) differ from traditional buffer overflow-based arbitrary write, and what advantages does it provide to attackers?
2.3. 1.3 Type Confusion and Integers
Type confusion vulnerabilities occur when a program processes an object as a different type than intended. Integer bugs include overflow, underflow, and truncation.
2.3.1. 1.3.1 Type Confusion in JIT
General Description
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.
Case Study: CVE-2024-7971 — V8 TurboFan Type Confusion
| Field | Detail |
|---|---|
| Affected Product | Google Chrome (V8 JavaScript Engine) |
| Type | Type Confusion in JIT |
| Vector | Malicious web page |
| Severity | Critical |
The Bug
TurboFan's CheckBounds elimination optimization incorrectly assumed array element types during JIT compilation. When encountering a polymorphic inline cache, TurboFan sometimes confused tagged pointers (Heap objects) with SMIs (Small Integers).
Impact
- Remote code execution via a malicious web page.
- Allowed creating a fake JSArray with a controlled backing store pointer.
- Out-of-bounds read/write capabilities.
- Escape from the V8 sandbox for shellcode execution.
Exploitation Context
Type confusion allowed building exploitation primitives: - addrof: Leak object addresses (information leak for ASLR bypass). - fakeobj: Create fake objects with a controlled structure. - arbitrary read/write: Out-of-bounds access to any memory location.
Mitigation
V8 patched the CheckBounds elimination logic to correctly track type information during optimization passes.
Observations
Browser exploitation is a high-value target. Type confusion in JIT compilers is a common vulnerability class, with new variants discovered regularly.
2.3.2. 1.3.2 Integer Overflow
General Description
Integer bugs include:
- Overflow: Exceeding the maximum value (e.g., INT_MAX + 1 wraps to INT_MIN).
- Underflow: Going below the minimum value (e.g., 0 - 1 becomes UINT_MAX for unsigned).
- Truncation: Losing data when converting from a larger to a smaller type.
Integer bugs frequently lead to memory corruption because integers are used for buffer sizes, loop counters, and array indices.
Case Study: CVE-2024-38063 — Windows TCP/IP Integer Underflow RCE
| Field | Detail |
|---|---|
| Affected Product | Windows TCP/IP Stack (tcpip.sys) |
| Type | Integer Underflow → RCE |
| Vector | Network IPv6 packets |
| Severity | Critical (CVSS 9.8) |
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 tcpip.sys driver performed arithmetic operations that could result in an integer underflow.
Impact
- Remote Code Execution with SYSTEM privileges on affected Windows systems.
- CVSS Score: 9.8 (Critical).
- Affected Windows 10, Windows 11, and Windows Server versions from 2008 to 2022.
- Potentially wormable (could spread automatically like SMBGhost).
Exploitation Context
- IPv6 packets with specific extension header configurations.
- Trigger the underflow in size calculations.
- The underflowed value wraps to a large unsigned integer.
- The kernel allocates a small buffer based on the wrapped value.
- A subsequent copy operation uses the original large size, causing a heap overflow.
- The heap overflow leads to kernel memory corruption and RCE.
Mitigation
Microsoft released patches in August 2024 that added proper bounds checking to IPv6 packet processing and corrected integer arithmetic operations to prevent underflow conditions.
Observations
This vulnerability demonstrates how integer underflow in network protocol parsers can lead to critical RCE vulnerabilities. The bug affected fundamental network code that processes untrusted network input, making it a prime target for wormable exploits similar to SMBGhost and EternalBlue.
2.3.3. 1.3.3 Parser Vulnerabilities
General Description
Parsers convert structured data (files, network protocols, etc.) into the program's internal representations. Their complexity makes them prime targets for fuzzing and exploitation.
Case Study: CVE-2024-47606 — GStreamer Signed-to-Unsigned Integer Underflow
| Field | Detail |
|---|---|
| Affected Product | GStreamer multimedia framework |
| Type | Signed-to-Unsigned Conversion → RCE |
| Vector | Malicious multimedia file |
| Severity | High |
The Bug
GStreamer contained a signed-to-unsigned integer conversion vulnerability in the qtdemux_parse_theora_extension function. A gint (signed integer) size variable underflowed to a negative value, which was then implicitly converted to a 64-bit unsigned integer, becoming a massive value.
Impact
- Remote code execution when processing malicious multimedia files.
- GStreamer is used by countless applications (GNOME, KDE, Firefox, Chrome, VLC derivatives).
- Multimedia files are commonly shared and processed automatically.
- Affects both desktop and embedded systems.
Exploitation Context
- A malicious multimedia file contains a Theora extension with crafted size fields.
- The function calculates the size using signed arithmetic.
- The calculation underflows (e.g., -6 or 0xFFFFFFFA in 32-bit representation).
- The 32-bit negative value is converted to a 64-bit unsigned integer → massive value.
- Only small bytes are allocated despite the huge requested size.
- A subsequent
memcpycopies large data into a small buffer. - The buffer overflow corrupts the
GstMapInfostructure. - Function pointer hijacking achieves RCE.
Mitigation
GStreamer 1.24.10 (December 2024) fixed the vulnerability by adding explicit checks for negative values before converting from signed to unsigned and by using safe integer arithmetic.
Observations
This is a textbook example of signed-to-unsigned conversion vulnerabilities (CWE-195). In C/C++, implicit conversions between signed and unsigned integers follow complex rules that developers often misinterpret. Negative signed integers become huge positive unsigned values when converted.
Case Study: CVE-2024-27316 — nghttp2 HTTP/2 CONTINUATION Frame DoS
| Field | Detail |
|---|---|
| Affected Product | nghttp2 HTTP/2 library |
| Type | Resource Exhaustion → DoS |
| Vector | Network HTTP/2 connection |
| Severity | High (CVSS 7.5) |
The Bug
The nghttp2 HTTP/2 library (used by Apache httpd, nginx, and many other servers) contained a vulnerability in its handling of CONTINUATION frames. The library failed to limit the total accumulated size of header data across CONTINUATION frames.
Impact
- Denial of Service via memory exhaustion.
- A single TCP connection could exhaust gigabytes of server memory.
- Very low bandwidth required from the attacker.
- Affected nghttp2, Apache HTTP Server, nginx, and others.
Exploitation Context
An attacker could establish an HTTP/2 connection and execute: 1. Send a valid HEADERS frame to initiate a new stream. 2. Send continuous CONTINUATION frames without setting the END_HEADERS flag. 3. Each CONTINUATION frame adds data to the accumulated header buffer. 4. The server allocates more memory for each received frame. 5. The process is repeated until the server's memory is exhausted.
Mitigation
nghttp2 v1.61.0 (April 2024) added a NGHTTP2_DEFAULT_MAX_HEADER_LIST_SIZE limit (64KB by default) for the total accumulated size of headers. Apache httpd 2.4.59 implemented the H2MaxHeaderListSize directive.
Observations
This vulnerability demonstrates that parsers must track resource consumption across related operations, not just individual ones. The attack is particularly effective because it exploits the protocol's legitimate mechanism.
2.4. 1.4 String and Format Vulnerabilities
Format string vulnerabilities occur when user-controlled data is passed as a format string argument to functions like printf, sprintf, and similar.
Case Study: CVE-2023-35086 — ASUS Router Format String RCE
| Field | Detail |
|---|---|
| Affected Product | ASUS RT-AX56U V2 and RT-AC86U routers |
| Type | Format String → RCE |
| Vector | Web administration interface |
| Severity | Critical |
The Bug
ASUS routers contained a format string vulnerability in their web administration interface (httpd daemon). The logmessage_normal function of the do_detwan_cgi module directly used user-controlled input as a format string when calling syslog().
Impact
- Remote code execution with root privileges.
- Allowed information leak to bypass ASLR.
- Enabled arbitrary memory write via the
%ndirective. - Complete compromise of the network device.
Exploitation Context
Stage 1 - Information Leak:
- Attacker sends an HTTP request with the format string: %p.%p.%p.%p.
- The router logs this to syslog, leaking stack addresses.
- The %p directives reveal the stack layout and defeat ASLR.
Stage 2 - Arbitrary Write:
- The attacker crafts a format string with the %n directive.
- Overwrites a function pointer or return address on the stack.
-. Redirects execution to attacker-controlled shellcode.
- Result: Remote Code Execution with root privileges.
Mitigation
ASUS firmware updates changed:
// Vulnerable:
syslog(LOG_INFO, user_input);
// Fixed:
syslog(LOG_INFO, " %s", user_input);
They also implemented input validation and enabled the -Wformat-security compiler warning.
Observations
Format string vulnerabilities in embedded devices and routers are particularly dangerous because the devices often run outdated firmware, many are exposed to the internet, and a compromise provides persistent access to networks.
2.5. 1.5 Driver and File System Vulnerabilities
Drivers and file systems represent a massive attack surface due to their complex interfaces with the kernel and their handling of untrusted input.
2.5.1. IOCTL/Syscall Handler Vulnerabilities
Case Study: CVE-2023-21768 — Windows AFD.sys Buffer Size Confusion
| Field | Detail |
|---|---|
| Affected Product | Windows AFD.sys (Ancillary Function Driver) |
| Type | Buffer Size Confusion |
| Vector | Local |
| Severity | High |
The Bug
The Windows Ancillary Function Driver (AFD.sys), which handles socket operations, had a buffer size confusion vulnerability in its IOCTL handler. When processing IOCTL_AFD_SELECT requests, the driver failed to properly validate the relationship between the user-provided buffer size and the actual structure size.
Impact
- Local privilege escalation from a standard user to SYSTEM.
- The OOB write primitive was used to corrupt adjacent kernel objects in the pool.
- Exploited in the wild before patching.
Exploitation Context
An attacker could call DeviceIoControl() with a specially crafted input buffer where the declared size did not match the actual data size. The driver allocated a buffer based on one size value but copied data based on another.
Mitigation
Microsoft KB5022845 added strict validation ensuring that the user-provided length matched the expected structure size, used ProbeForRead() to validate user pointers, and implemented additional bounds checking.
Observations
IOCTL/syscall handlers are common attack vectors due to size/boundary confusion, trust in user pointers without probing, and double-fetch issues.
2.5.2. File System Vulnerabilities
Case Study: CVE-2022-0847 — Dirty Pipe
| Field | Detail |
|---|---|
| Affected Product | Linux Kernel (pipe implementation) |
| Type | Logical Flaw → Arbitrary File Write |
| Vector | Local |
| Severity | Critical |
The Bug
The Linux kernel's pipe implementation failed to properly initialize the PIPE_BUF_FLAG_CAN_MERGE flag when splicing pages from the page cache into pipes. This allowed overwriting data in read-only files by splicing modified pages back.
Impact
- Local privilege escalation from any user to root by overwriting
/etc/passwdor other privileged files. - Extremely reliable exploitation requiring minimal permissions.
- Affected Linux kernels 5.8+ up to 5.16.11.
Exploitation Context
An attacker could:
1. Open a read-only file (e.g., /etc/passwd).
2. Use splice() to create a pipe containing pages from that file.
3. Modify the pipe buffer.
4. Splice back to overwrite the original file's contents.
Mitigation
Linux kernel 5.16.11+ properly initializes pipe buffer flags and prevents splicing back to read-only files.
Observations
Pipe and splice operations are complex kernel mechanisms with subtle state management requirements. Dirty Pipe demonstrated how initialization bugs can lead to powerful arbitrary file write primitives.
2.5.3. Bring Your Own Vulnerable Driver (BYOVD)
Case Study: Driver Abuse by Lazarus Group
| Field | Detail |
|---|---|
| Technique | BYOVD (Bring Your Own Vulnerable Driver) |
| Type | Legitimate Driver Abuse |
| Vector | Vulnerable signed driver |
| Usage | Advanced threat groups |
The Technique
Attackers drop a legitimate but vulnerable signed driver (e.g., old versions of ASUS, Gigabyte, or MSI drivers) that Windows will load due to its valid signature.
Impact
- Once loaded, the vulnerable driver provides arbitrary kernel read/write primitives through its IOCTL interface.
- Attackers use this to disable security features (PatchGuard, AV/EDR).
- Allows loading unsigned drivers or escalating privileges.
Exploitation Context
The BYOVD technique was widely used by groups like Lazarus before Microsoft expanded the Driver Blocklist. Advanced groups have shifted from BYOVD to direct zero-day kernel exploits after 2023 due to increased detection.
Mitigation
- Enable the Vulnerable Driver Blocklist (HVCI/Memory Integrity).
- Monitor for unusual driver loads.
- Implement application control policies.
Observations
While not a vulnerability per se, BYOVD is widely used in exploit chains and represents a significant risk of abuse of legitimate signed drivers.
2.6. 1.6 Impact Assessment and Classification
Understanding how to evaluate and classify vulnerabilities by their real-world impact and exploitability is fundamental for patch prioritization and incident response.
2.6.1. Impact Categories
Remote Code Execution (RCE) - Definition: An attacker can execute arbitrary code on the target system remotely. - Impact: Maximum severity - complete system compromise is possible. - Examples: CVE-2024-27130 (QNAP), CVE-2024-2883 (Chrome ANGLE), CVE-2023-4863 (libWebP)
Local Privilege Escalation (LPE) - Definition: An attacker with limited access can obtain higher privileges. - Impact: High severity - enables persistence, defense evasion, and lateral movement. - Examples: CVE-2024-26218 (Windows Kernel TOCTOU), CVE-2022-0847 (Dirty Pipe)
Information Disclosure - Definition: An attacker can read data they should not have access to. - Impact: Medium to High - often chained with other bugs to bypass ASLR. - Examples: Format string leaks, uninitialized memory reads.
Denial of Service (DoS) - Definition: An attacker can make a service unavailable without gaining code execution. - Impact: Low to Medium - interrupts availability without compromising confidentiality/integrity. - Examples: CVE-2024-27316 (HTTP/2 CONTINUATION), decompression bombs.
2.6.2. Exploitability Factors
| Factor | Low | High |
|---|---|---|
| Attack Complexity | Requires complex preparation | Exploitable repeatedly |
| with minimal effort | ||
| Attack Vector | Requires physical access | Exploitable remotely |
| over the network | ||
| Privileges Required | Requires administrative access | No authentication needed |
| User Interaction | Victim must perform an action | Completely automated |
2.6.3. CVSS Scoring System
Base Score Components (Intrinsic Qualities): - Attack Vector (AV): Network/Adjacent/Local/Physical - Attack Complexity (AC): Low/High - Privileges Required (PR): None/Low/High - User Interaction (UI): None/Required - Scope (S): Unchanged/Changed - Impact on Confidentiality (C), Integrity (I), Availability (A): None/Low/High
Score Ranges:
| Range | Severity |
|---|---|
| 0.0 | None |
| 0.1-3.9 | Low |
| 4.0-6.9 | Medium |
| 7.0-8.9 | High |
| 9.0-10.0 | Critical |
2.6.4. Chapter 1 Conclusions
- Memory corruption remains prevalent: Despite decades of research, memory corruption bugs continue to affect software, especially in C/C++ codebases.
- Defense-in-depth is essential: Every real-world example shows attackers bypassing multiple protection mechanisms (DEP, ASLR, CET, safe-linking).
- Modern mitigations raise the bar but do not eliminate the 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 (improper bounds checking, lifetime management) but require different exploitation techniques.
- Legacy components remain vulnerable: Years-old vulnerabilities in office parsers and file handlers continue to be exploited due to slow patching cycles.
- Logical vulnerabilities do not require memory corruption: Authentication bypasses, TOCTOU flaws, and arbitrary write primitives can be equally impactful.
- User namespaces expand the attack surface: Many kernel vulnerabilities become exploitable from unprivileged contexts when user namespaces grant capabilities like
CAP_NET_ADMIN.