Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Heuristic:416rehman DeepZero Dangerous API Detection

From Leeroopedia
Knowledge Sources
Domains Security_Research, Reverse_Engineering
Last Updated 2026-10-27 00:00 GMT

Overview

Heuristic scoring of driver dangerousness from PE import tables: flag IOCTL-surface APIs, physical-memory manipulation, process manipulation, and MSR I/O to prioritize which drivers are worth decompiling.

Description

The `PEIngest` processor parses PE headers with `lief` and inspects the import table for known-dangerous kernel-driver APIs. It computes a `priority_score` (0-10) based on which dangerous import categories are present: physical memory access (+3), process manipulation (+2), MSR/port I/O (+2), few sections (+1), and targeting modern OS versions (+3). It also records boolean indicators (`has_ioctl_surface`, `creates_device`, `creates_symlink`) and the list of `dangerous_imports`. This score feeds into the `TopKSelector` reduce stage to rank which drivers get decompiled and assessed first.

Usage

Use this heuristic when prioritizing which driver binaries to analyze in a BYOVD (bring-your-own-vulnerable-driver) research pipeline. Drivers with high `priority_score` (physical memory access + IOCTL surface + modern OS target) are the most likely to yield exploitable vulnerabilities and should be decompiled first.

The Insight (Rule of Thumb)

  • Action: After parsing PE imports, check the import set against three dangerous-API categories plus structural indicators.
  • Value:
    • Physical memory APIs (`MmMapIoSpace`, `ZwMapViewOfSection`, `ZwOpenSection`, `MmGetPhysicalAddress`) → +3.0
    • Process manipulation APIs (`PsLookupProcessByProcessId`, `ZwTerminateProcess`, `ZwOpenProcess`) → +2.0
    • MSR/port I/O APIs (`__readmsr`, `__writemsr`, `HalGetBusDataByOffset`, `HalSetBusDataByOffset`) → +2.0
    • Few sections (<=6) → +1.0 (small drivers are often shim/hijack targets)
    • Modern OS target (major OS version >=10) → +3.0
    • Score capped at 10.0
  • Trade-off: This is a heuristic — it may miss novel attack surfaces that don't use these classic APIs, or score packed/obfuscated binaries low. It is a prioritization filter, not a vulnerability detector.
  • Compatibility: Requires `lief >= 0.14.0` for PE parsing. Falls back gracefully (returns empty metadata) if lief is not installed.

Reasoning

Drivers that import physical-memory-mapping APIs (`MmMapIoSpace`) can directly read/write physical memory, which is a common BYOVD exploitation primitive. Process manipulation APIs enable privilege escalation. MSR I/O enables microcode or hardware register abuse. Drivers with few sections targeting modern OS versions (where signature enforcement is active) are prime BYOVD candidates because they are small attack surfaces that are still loadable. The weighted score reflects which indicators are most commonly associated with exploitable drivers.

Code Evidence

Dangerous API sets from `pe_ingest.py:218-240`:

dangerous_apis = {
    "MmMapIoSpace",
    "MmUnmapIoSpace",
    "ZwMapViewOfSection",
    "ZwOpenSection",
    "MmGetPhysicalAddress",
    "MmCopyVirtualMemory",
    "MmCopyMemory",
    "PsLookupProcessByProcessId",
    "ZwOpenProcess",
    "ZwTerminateProcess",
    "KeStackAttachProcess",
    "__readmsr",
    "__writemsr",
    "HalGetBusDataByOffset",
    "HalSetBusDataByOffset",
    "MmProbeAndLockPages",
    "IoAllocateMdl",
    "MmIsAddressValid",
    "ZwLoadDriver",
    "MmLoadSystemImage",
}
meta["dangerous_imports"] = sorted(func_set & dangerous_apis)

Scoring logic from `pe_ingest.py:249-284`:

score = 0.0
if meta["has_ioctl_surface"]:
    phys_mem = {"MmMapIoSpace", "ZwMapViewOfSection", "ZwOpenSection", "MmGetPhysicalAddress"}
    proc_manip = {"PsLookupProcessByProcessId", "ZwTerminateProcess", "ZwOpenProcess"}
    msr_io = {"__readmsr", "__writemsr", "HalGetBusDataByOffset", "HalSetBusDataByOffset"}

    if func_set & phys_mem:
        score += 3.0
    if func_set & proc_manip:
        score += 2.0
    if func_set & msr_io:
        score += 2.0
    if pe.header.numberof_sections <= 6:
        score += 1.0

try:
    if pe.optional_header.major_operating_system_version >= 10:
        score += 3.0
except AttributeError:
    pass

meta["priority_score"] = min(10.0, score)

IOCTL surface indicators from `pe_ingest.py:196-216`:

ioctl_indicators = {
    "IoCreateDevice",
    "IoCreateDeviceSecure",
    "IoCreateSymbolicLink",
    "IofCompleteRequest",
    "IoCompleteRequest",
    "WdfDeviceCreate",
    "WdfDeviceCreateSymbolicLink",
    "WdfIoQueueCreate",
    "WdfRequestComplete",
    "WdfDriverCreate",
    "NdisMRegisterMiniportDriver",
    "NdisFRegisterFilterDriver",
    "StorPortInitialize",
    "ScsiPortInitialize",
    "HidRegisterMinidriver",
    "IoRegisterDeviceInterface",
}
meta["has_ioctl_surface"] = bool(func_set & ioctl_indicators)
meta["creates_device"] = "IoCreateDevice" in func_set
meta["creates_symlink"] = "IoCreateSymbolicLink" in func_set

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment