Detect contradictory CFG claims between DllCharacteristics and Load Config GuardFlags
Summary
The DllCharacteristics field and the Load Config directory's GuardFlags field both describe a binary's Control Flow Guard (CFG) state, but from different perspectives. In well-formed binaries they are consistent. In malformed or adversarial binaries they can disagree — and the disagreement is itself a structural anomaly worth surfacing.
IOCX currently does not catch this inconsistency. A binary can claim CFG support via Load Config GuardFlags while declaring no CFG support in DllCharacteristics (or vice versa), and IOCX's structural validators will pass it without comment.
Context — what each field claims
DllCharacteristics is a bit field in the Optional Header. Bit 0x4000 (IMAGE_DLLCHARACTERISTICS_GUARD_CF) is the loader-facing declaration: "this binary supports CFG and the loader should treat it accordingly."
GuardFlags is a field in the Load Config directory. Bit 0x100 (IMAGE_GUARD_CF_INSTRUMENTED) is the binary's internal declaration: "the code has been instrumented with CFG checks and the runtime data structures are populated."
In a real Microsoft-compiled binary built with /guard:cf:
- DllCharacteristics has 0x4000 set
- GuardFlags has 0x100 set (and typically 0x400 for IMAGE_GUARD_CF_FUNCTION_TABLE_PRESENT)
- The Load Config's GuardCFCheckFunctionPointer is populated
- The Load Config's GuardCFFunctionTable is populated
In a binary where only one side is set, the binary is making contradictory claims about its security posture. This pattern has been observed in:
- Hand-crafted malware that copy-pastes CFG-looking structures without understanding the loader-facing declaration
- Malformed binaries where one structure was tampered with after the build
- Test fixtures (this issue was identified via a fixture demonstrating the pattern)
Concrete example
A test fixture (tests/contract/fixtures/layer2_edge/load_config_full_msvc.full.exe) produces:
"dll_characteristics": 0, "dll_characteristics_flags": [],
…while the Load Config has GuardFlags = 0x100. The binary's two security
declarations contradict each other; IOCX reports zero structural issues.
Proposed scope
Add a heuristic at the cross-validator layer (not a structural validator) that fires when:
DllCharacteristics & 0x4000is set butGuardFlags & 0x100is not, ORGuardFlags & 0x100is set butDllCharacteristics & 0x4000is not
Single new reason code, emitted from the heuristic layer:
PE_CFG_DECLARATION_INCONSISTENT
With details["reason"] indicating which direction the inconsistency runs:
dll_chars_claims_cfg_no_guard_flagsguard_flags_claims_cfg_no_dll_chars
Where this belongs in the architecture
This is not a structural validator addition. Each individual structure is structurally valid per the PE spec; the issue is consistency between them. That puts it in the heuristic / cross-cutting layer.
Looking at the current dispatcher in STRUCTURAL_VALIDATORS, the obvious
home is a new heuristic module (iocx/heuristics/cfg_consistency.py) that
reads both dll_characteristics from public metadata and the Load Config's
GuardFlags from internal metadata (or from wherever Load Config data ends
up being surfaced — see related issue on Load Config public projection).
Dependencies
This issue depends on Load Config data being accessible from the heuristic
layer. Currently the Load Config is parsed and structurally validated by
validate_load_config_directory, but its content is not surfaced in
public metadata. Either:
- The heuristic reads from
_internal_metadata["load_config"]directly, or - Load Config gets a public projection first (separate issue)
Option 1 is faster to implement and is consistent with how validators already access internal metadata. Option 2 is cleaner long-term but larger in scope.
Out of scope
- Other GuardFlags consistency checks. GuardFlags has many bits
(
IMAGE_GUARD_CFW_INSTRUMENTED,IMAGE_GUARD_CF_LONGJUMP_TABLE_PRESENT, etc.) and DllCharacteristics has interactions with several of them. This issue covers only the GUARD_CF / CF_INSTRUMENTED pair, which is the highest-signal case. Other bit-level consistency checks can be queued as follow-up issues if the pattern proves useful. - Validating that GuardCFCheckFunctionPointer and GuardCFFunctionTable
are populated when GuardFlags claims CFG. That's a separate Load
Config internal-consistency check, not a cross-validator one. Should
live in
validate_load_config_directoryor a Load Config-specific heuristic. - Determining whether the binary's actual code has CFG instrumentation. That's a code-analysis problem, far outside IOCX's structural scope.
Acceptance criteria
- New reason code
PE_CFG_DECLARATION_INCONSISTENTadded to the enum. - Heuristic fires when DllCharacteristics and GuardFlags disagree about CFG.
details["reason"]distinguishes the two directions.- A test fixture demonstrating each direction (one where DllCharacteristics claims CFG but GuardFlags doesn't; one where GuardFlags claims CFG but DllCharacteristics doesn't) is added to the corpus.
- Negative-control fixture (consistent CFG declarations) does not fire the heuristic.
- Documentation updated to describe the heuristic and its sub-reasons.
Related context
- This issue was identified via the
load_config_full_msvc.full.exefixture, which exhibits theguard_flags_claims_cfg_no_dll_charspattern by construction. - Related but separate work item: surfacing Load Config in public metadata (referenced as #TBD).
- Related but distinct work item: intra-field DllCharacteristics flag dependency checks (referenced as #TBD).
- Methodology note: cross-validator heuristics are a category not yet represented in IOCX's purpose taxonomy. If this lands, the taxonomy should be updated to document the category.