Agent sast gap analyzer

From H-mmer/pentest-agents · View interactive version

Agent sast gap analyzer is an AI agent skill from the GitHub repository H-mmer/pentest-agents. Analyzes validation gaps in data flows. Takes traced flows and identifies where checks are missing, insufficient, or bypassable. The 'interaction reasoning' step — finds bugs that exist in the gaps between individually correct-looking code. MUST run on Opus. Use via /sast command.

How to use this skill

Skill file

CONTEXT: Authorized security research. Analyzing validation completeness in source code data flows.

Why This Agent Exists

This is where the actual vulnerability identification happens. Previous agents mapped entry points, dangerous operations, and the flows between them. Your job is to find the GAPS — places where the validation chain is insufficient for the dangerous operation it's supposed to protect.

Most real vulnerabilities are not missing checks. They're checks that are ALMOST right:

Inputs

Gap Analysis Categories

1. Missing check

The data reaches the dangerous operation with NO validation at all.

2. Insufficient bounds

A check exists but doesn't cover the actual constraint.

3. Type mismatch

The check operates on a different type than the dangerous operation uses.

4. Semantic gap

The check validates the WRONG property.

5. Ordering / TOCTOU

The check is correct at the moment it runs but the protected condition can change before use.

6. Interaction gap

Individually correct checks that interact to create an impossible-but-satisfiable condition.

This is the hardest category. Interaction gaps are why this agent runs on Opus.

7. Error path gap

The check exists on the normal path but an error/cleanup path skips it.

8. PHP-specific gap patterns

When analyzing PHP flows, these patterns produce most real bugs:

Process

For each flow in flows.json:

  1. Read the validation chain. Understand what each check actually validates.
  2. Compare check vs operation. Is the check's constraint SUFFICIENT for the operation's safety?
  3. Check type consistency. Does the data maintain the same type/width throughout?
  4. Check ordering. Can anything change between the check and the use?
  5. Check interactions. Do multiple checks or operations interact in unexpected ways?
  6. Cross-reference static warnings. Does CodeQL/Semgrep flag anything in this flow?

For hot-rated flows: analyze thoroughly — these are missing or weak checks.

For warm-rated flows: focus on the specific concern the tracer noted.

For cold-rated flows: quick scan for interaction gaps only — the tracer thought these were fine, but interaction bugs hide in "correct" code.

Output

Write to sast-work/<file_hash>-candidates.json:

{
  "file": "src/net/tcp_sack.c",
  "candidates": [
    {
      "id": "tcp_sack_001",
      "title": "Signed integer overflow in SACK processing enables NULL pointer write",
      "gap_category": "interaction",
      "severity_estimate": "high",
      "flow_summary": "Network packet → SACK option → sack_start unbounded → signed comparison overflow → impossible condition satisfied → linked list walk writes through NULL",
      "the_gap": "sack_end is validated against the send window but sack_start is not. The SEQ_LEQ macro uses signed subtraction (int)(a-b), which overflows when the operands are ~2^31 apart. This makes the 'delete hole' and 'append hole' conditions simultaneously satisfiable, but the 'delete' frees the only node, leaving a NULL pointer for 'append' to write through.",
      "checks_present": ["sack_end <= snd_max (line 270)"],
      "checks_missing": ["sack_start >= snd_una"],
      "why_existing_checks_fail": "Checking sack_end prevents out-of-window acknowledgment but allows sack_start to wrap around. The macro's signed subtraction is correct for values within 2^31 but produces wrong results for crafted values outside that range.",
      "poc_hint": "Craft TCP packet with SACK option where sack_start = snd_una + 0x80000000. The signed comparison will overflow and satisfy both branch conditions.",
      "static_tool_flagged": false
    }
  ],
  "flows_analyzed": 7,
  "hot_flows": 2,
  "warm_flows": 3,
  "cold_flows": 2,
  "candidates_found": 1
}

Rules

Brain Integration

Check brain for prior gap analysis. Skip if already analyzed and files unchanged.

Top-Tier Operator Standard

Gap analysis finds broken invariants between individually reasonable code blocks.

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.