iocx icon indicating copy to clipboard operation
iocx copied to clipboard

Heuristics for binaries that pass structural validation but cannot exist in the wild

Open malx-labs opened this issue 5 months ago • 0 comments

Summary

IOCX's structural validators check PE spec compliance. Binaries that pass structural validation are "well-formed PE files" by definition. But some binaries are well-formed AND impossible to encounter in the wild outside of adversarial or test contexts. IOCX currently has no mechanism to flag these "implausible-but-valid" binaries.

This issue proposes a heuristic layer that catches patterns indicating a binary was hand-crafted, generated by non-standard tooling, or constructed for testing purposes — distinct from structural malformation.

Context — why this matters

A binary with stack_reserve_size: 0 is structurally valid per the PE spec (the field is uint32_t and zero is a representable value). But the Windows loader will refuse to execute it — a thread needs stack space to run. So any binary with zero stack reserve is one of:

  • A test fixture (the construction tooling didn't fill in plausible values)
  • An adversarial sample (some malware packers strip non-essential fields)
  • A corrupted binary (a real binary that's been tampered with post-build)
  • A research artifact (someone deliberately exploring the loader's limits)

Distinguishing these is a triage question, not a structural one. But surfacing "this binary has a zero-stack-reserve that no real compiler would emit" is a useful signal for analysts and downstream tooling.

The same logic applies to several other fields where the PE spec is permissive but real-world tooling is consistent:

  • linker_version: "0.0" — no real linker emits this
  • os_version: "0.0" — no real linker emits this
  • subsystem_version: "0.0" — no real linker emits this
  • dll_characteristics: 0 — no real compiler emits this since Windows Vista's introduction of ASLR/DEP defaults
  • stack_commit_size: 0 — same reasoning as stack_reserve_size
  • heap_reserve_size: 0 — same reasoning
  • timestamp: 0 — possible (reproducible-build tooling sometimes zeroes this) but unusual without other reproducible-build markers

Proposed scope

Add a heuristic layer module (iocx/heuristics/implausible_fields.py) that checks the above fields and emits a single reason code with structured details listing the specific implausibilities found:

PE_FIELDS_IMPLAUSIBLE details: { "reasons": [ "zero_stack_reserve", "zero_dll_characteristics_post_vista", "zero_linker_version", "zero_os_version", ... ], "count": }

The heuristic does NOT fire for any single anomaly in isolation, but it DOES fire when multiple implausibility tags accumulate — the "no real binary has all of these zeroed" signal is stronger than any single field's.

A reasonable threshold might be 3 or more implausibility tags. Below that threshold, the heuristic stays silent (avoiding false positives on unusual but legitimate binaries).

What this is NOT

Important to be explicit so future maintainers don't expand the scope into territory it shouldn't cover:

  • Not a structural validator. Each individual field passes spec compliance. The heuristic is about plausibility, not validity.
  • Not a malware detector. "Implausible" doesn't mean "malicious." Many implausible binaries are test fixtures, research artifacts, or unusual tooling output.
  • Not a comprehensive realism check. This catches the obvious "no real binary has these all zero" cases. It does not (and should not) try to model the full distribution of real-world PE fields.
  • Not a signature-based check. The heuristic uses simple field-value rules. It does not maintain a database of "known good" binary patterns.

Where this belongs in the architecture

New heuristic module reading from the public metadata. This works because:

  • The heuristic doesn't need access to internal metadata.
  • The fields it checks are already exposed via requirement 1.
  • It can be developed in isolation from the structural validator suite.

The heuristic dispatcher (if one exists separate from the structural validator dispatcher) is the natural home. If heuristics currently piggyback on the structural dispatcher, this issue can decide whether to introduce a separate heuristic registration mechanism as part of its scope.

Threshold tuning

The 3-tag threshold is a starting point, not a researched figure. Worth empirical calibration:

  1. Run the heuristic against the existing fixture corpus and count how many fixtures fire it.
  2. Cross-reference with which fixtures are intentionally implausible (test fixtures) versus intentionally adversarial (malware samples) versus intentionally normal (negative controls).
  3. Choose the threshold that catches the test fixtures and adversarial samples while not firing on negative controls.

This calibration should be part of the issue's acceptance criteria, not deferred. A heuristic with an unjustified threshold is worse than no heuristic.

Out of scope

  • Time-based timestamp anomalies. Detecting "timestamp is in the future" or "timestamp predates the binary's earliest possible build" requires additional context (release dates of dependencies, etc.) that IOCX doesn't have. Could be a follow-up issue if proven useful.
  • Plausibility checks against compiler-specific patterns. Detecting "this looks like MinGW output" vs "this looks like MSVC output" would require maintaining compiler-fingerprint data. Out of scope; if needed, Rich Header analysis is a better avenue.
  • Cross-field plausibility. "SizeOfImage doesn't match the sum of section sizes" is a structural check, not a plausibility one. Belongs in the structural validator layer if not already covered.
  • Intra-field flag dependency checks. DllCharacteristics bits have internal dependencies (e.g., HIGH_ENTROPY_VA requires DYNAMIC_BASE); those are tracked separately (referenced as #TBD).

Acceptance criteria

  1. New reason code PE_FIELDS_IMPLAUSIBLE added to the enum.
  2. Heuristic module implemented with the rules described above.
  3. Threshold empirically calibrated against the existing fixture corpus and documented (with calibration data in the methodology document).
  4. Detail payload structure documented as part of the reason-codes reference.
  5. At least one fixture demonstrating each implausibility tag added to the corpus.
  6. Negative-control fixture (a binary with realistic values across all checked fields) added to confirm the heuristic does not false-positive.
  7. Methodology document updated to describe the "implausibility heuristic" as a distinct purpose category from structural validation.

Related context

  • This issue was identified via the load_config_full_msvc.full.exe fixture, which exhibits multiple implausibility tags simultaneously (zero_dll_characteristics, zero_stack_reserve, zero_linker_version, etc.).
  • The methodology angle is interesting independent of the implementation: this is the first heuristic in IOCX whose purpose is "did a real compiler emit this?" rather than "is this spec-compliant?" That distinction is worth documenting explicitly in the methodology paper.
  • Related work items: cross-validator CFG consistency (#TBD), intra-field DllCharacteristics flag dependencies (#TBD).

malx-labs avatar Jun 30 '26 08:06 malx-labs