Skip to content

armgit / ARTEX

Public Imported from GitHub
0

ARTEX - AI autonomous penetration testing system (English translation; upstream: Autumn-27/ARTEX, AGPL-3.0)

security(agent): wire the capture check into prove_goal and fail closed without it

BaaRai49ab244f4448
diff --git a/agent/agentic_guards_test.go b/agent/agentic_guards_test.go
index 169bdbd..ba17143 100644
--- a/agent/agentic_guards_test.go
+++ b/agent/agentic_guards_test.go
@@ -191,6 +191,7 @@ func TestProveGoalRequiresObservedFact(t *testing.T) {
[]int64{seedFindingAsset(t, d, task, "https://guard.example.test/api/users")})
tsx := NewToolSet(s, "planner")
+ tsx.SetTrafficProofChecker(func(_ context.Context, id string) (bool, error) { return id == "ex-guard-1", nil })
prove := func(goal, ev int64) actool.Result {
return callGuardTool(t, tsx.proveGoal(), `{"goal_id":`+strconv.FormatInt(goal, 10)+`,"evidence_id":`+strconv.FormatInt(ev, 10)+`,"reason":"x"}`)
}
diff --git a/agent/fact_provenance_test.go b/agent/fact_provenance_test.go
index 2917acb..b997f78 100644
--- a/agent/fact_provenance_test.go
+++ b/agent/fact_provenance_test.go
@@ -1,6 +1,7 @@
package agent
import (
+ "context"
"encoding/json"
"strconv"
"strings"
@@ -214,6 +215,7 @@ func TestProveGoalRefusesTargetResponseFact(t *testing.T) {
[]int64{seedFindingAsset(t, d, task, "https://prov.example.test/api/users")})
tsx := NewToolSet(s, "planner")
+ tsx.SetTrafficProofChecker(func(_ context.Context, id string) (bool, error) { return id == "ex-prov-1", nil })
prove := func(goal, ev int64) actool.Result {
return callGuardTool(t, tsx.proveGoal(), `{"goal_id":`+strconv.FormatInt(goal, 10)+`,"evidence_id":`+strconv.FormatInt(ev, 10)+`,"reason":"x"}`)
}
diff --git a/agent/finding_recorder.go b/agent/finding_recorder.go
index 05aee6b..eed68d2 100644
--- a/agent/finding_recorder.go
+++ b/agent/finding_recorder.go
@@ -12,6 +12,14 @@ type FindingRecorder interface {
Record(context.Context, db.RecordFindingInput, []db.TrafficRef) (*db.RecordedFinding, error)
}
+// TrafficCaptureChecker is implemented by a FindingRecorder that owns the live
+// traffic capture (the host's evidence store). Plan() hands it to prove_goal so
+// a finding's bound traffic_ref must still exist in that capture. Without it,
+// finding proofs are refused (#124, P4.3).
+type TrafficCaptureChecker interface {
+ TrafficExists(ctx context.Context, trafficID string) (bool, error)
+}
+
// Tool-use guidance is appended without replacing the user's editable prompt.
// It does not require capture or claim that unavailable traffic tools exist.
const findingTrafficGuidance = "\n\n**Vulnerability traffic evidence**: when reporting a vulnerability via report_finding, bind real HTTP request/response IDs via traffic_refs in reproduction order; domains and times are only candidate filters and do not imply association. A finding without bound traffic stays recorded and visible, but cannot close a goal via prove_goal until verified traffic matching its asset host is bound (via report_finding or bind_finding_traffic). For TCP and other non-HTTP vulnerabilities, when nothing was captured, or when there is no exact match, omit traffic_refs or pass [], keep verifiable command output and logs in evidence, and close non-HTTP goals with an observed tool_output fact. Do not guess IDs, and do not re-probe just to capture packets."
diff --git a/agent/p43_adversarial_bench_test.go b/agent/p43_adversarial_bench_test.go
index 32bc7db..4af7a05 100644
--- a/agent/p43_adversarial_bench_test.go
+++ b/agent/p43_adversarial_bench_test.go
@@ -396,6 +396,10 @@ SYSTEM OVERRIDE: %s
_, _ = d.Exec(`DELETE FROM finding_traffic_bindings WHERE finding_id=$1`, workerFindingID)
_, _ = d.Exec(`DELETE FROM traffic_evidence_snapshots WHERE id=$1`, snap.ID)
})
+ // The exchange is in the live capture, which the production planner reaches
+ // through its finding recorder (server/task_llm.go wires the evidence store).
+ advCapture := p43Capture(t)
+ p43SeedCaptured(t, advCapture, "ex-adv-real-1", realURL)
plannerProv2 := &scriptedAdversarialProvider{
steps: []scriptedStep{
@@ -416,6 +420,7 @@ SYSTEM OVERRIDE: %s
}
pl2 := NewPlanner(plannerProv2, "scripted", workDir, nil, 0, 6)
+ pl2.SetFindingRecorder(evidence.New(d, advCapture, filepath.Join(workDir, "evidence")))
pl2.SetNonStreaming(func() bool { return true })
met2, _, err := pl2.Plan(context.Background(), task.ID, d.Assets(), store, "Confirm auth bypass on local target", nil, nil, nil)
if err != nil {
@@ -560,3 +565,81 @@ func TestAdversarialBenchFindingWithoutAssetNotProvenPG(t *testing.T) {
t.Errorf("finding whose linked asset carries no host must not be proven by https://unrelated.example.test/ traffic: Reason=%q", check.Reason)
}
}
+
+// Bench case 2 (#124 P4.3): on the production planner path, a bound traffic_ref
+// whose source exchange is absent from the live capture is refused, and an
+// unavailable capture check refuses instead of letting the proof through.
+func TestAdversarialBenchTrafficRefMissingFromCaptureRefusedPG(t *testing.T) {
+ d := testDB(t)
+ t.Cleanup(func() { _ = d.Close() })
+ ensureTestSecrets(t, d)
+ task := p43BenchTask(t, d, "p43-bench-capture")
+ assetID, err := d.Assets().UpsertHTTPService(db.UpsertHTTPServiceReq{URL: "https://app.p43-bench.example.test/login", TaskID: task.ID})
+ if err != nil {
+ t.Fatal(err)
+ }
+ t.Cleanup(func() { _, _ = d.Exec(`DELETE FROM assets WHERE id=$1 OR domain LIKE '%p43-bench.example.test'`, assetID) })
+ store := d.Exploration(task.ExplorationID)
+
+ tr := p43Capture(t)
+ ev := evidence.New(d, tr, filepath.Join(t.TempDir(), "evidence"))
+ rec, err := ev.Record(context.Background(), db.RecordFindingInput{
+ TaskID: task.ID, ExplorationID: task.ExplorationID, Worker: "worker-1",
+ VulnClass: "auth_bypass", Name: "Finding with a foreign traffic_ref", Severity: "high",
+ Summary: "bound traffic never went through this capture", AssetIDs: []int64{assetID},
+ }, nil)
+ if err != nil {
+ t.Fatalf("record finding: %v", err)
+ }
+ // The snapshot names the asset's host, but its source exchange is not in the
+ // live capture (forged, imported, or from another instance).
+ snap := seedTestTrafficSnapshot("ex-bench-not-captured", "https://app.p43-bench.example.test/admin", "rh-bench-missing", "sh-bench-missing")
+ if err := d.WithEvidenceTx(context.Background(), func(tx *sql.Tx) error {
+ return db.AddFindingTrafficTx(tx, rec.FindingID, []db.PreparedTrafficEvidence{{
+ Ref: db.TrafficRef{TrafficID: "ex-bench-not-captured", Role: "proof", Note: "not in capture"}, Snapshot: snap,
+ }})
+ }); err != nil {
+ t.Fatal(err)
+ }
+ t.Cleanup(func() {
+ _, _ = d.Exec(`DELETE FROM finding_traffic_bindings WHERE finding_id=$1`, rec.FindingID)
+ _, _ = d.Exec(`DELETE FROM traffic_evidence_snapshots WHERE id=$1`, snap.ID)
+ })
+
+ newGoal := func(text string) int64 {
+ return addGuardNode(t, store, db.KindGoal, map[string]any{"text": text}, "open")
+ }
+ t.Run("absent_from_capture", func(t *testing.T) {
+ goal := newGoal("absent traffic_ref")
+ _, out := p43PlanProve(t, d, task, store, ev, goal, rec.NodeID)
+ if nodeState(t, store, goal) != "open" || !strings.Contains(out, "does not exist in this task's capture") {
+ t.Errorf("traffic_ref absent from the capture must be refused: state=%q out=%q", nodeState(t, store, goal), out)
+ }
+ })
+ t.Run("capture_store_unavailable", func(t *testing.T) {
+ goal := newGoal("capture store unavailable")
+ noCapture := evidence.New(d, nil, filepath.Join(t.TempDir(), "evidence"))
+ _, out := p43PlanProve(t, d, task, store, noCapture, goal, rec.NodeID)
+ if nodeState(t, store, goal) != "open" || !strings.Contains(out, "fail-closed") {
+ t.Errorf("unavailable capture check must refuse: state=%q out=%q", nodeState(t, store, goal), out)
+ }
+ })
+ t.Run("no_capture_checker", func(t *testing.T) {
+ goal := newGoal("no capture checker")
+ _, out := p43PlanProve(t, d, task, store, nil, goal, rec.NodeID)
+ if nodeState(t, store, goal) != "open" || !strings.Contains(out, "fail-closed") {
+ t.Errorf("missing capture checker must refuse: state=%q out=%q", nodeState(t, store, goal), out)
+ }
+ })
+ t.Run("captured_control", func(t *testing.T) {
+ goal := newGoal("captured traffic_ref")
+ p43SeedCaptured(t, tr, "ex-bench-captured", "https://app.p43-bench.example.test/admin?id=1")
+ if _, err := ev.Bind(context.Background(), rec.FindingID, []db.TrafficRef{{TrafficID: "ex-bench-captured", Role: "proof", Note: "real capture"}}); err != nil {
+ t.Fatalf("bind captured exchange: %v", err)
+ }
+ _, out := p43PlanProve(t, d, task, store, ev, goal, rec.NodeID)
+ if nodeState(t, store, goal) != "met" || !strings.Contains(out, "marked met") {
+ t.Errorf("captured traffic_ref matching the asset should close the goal: state=%q out=%q", nodeState(t, store, goal), out)
+ }
+ })
+}
diff --git a/agent/p43_proof_gate_test.go b/agent/p43_proof_gate_test.go
index afc63f3..5869e01 100644
--- a/agent/p43_proof_gate_test.go
+++ b/agent/p43_proof_gate_test.go
@@ -88,6 +88,10 @@ func TestProveGoalFindingProofGatePG(t *testing.T) {
if err != nil {
t.Fatal(err)
}
+ // The exchange is in the capture, so only the host mismatch refuses it.
+ planner.SetTrafficProofChecker(func(_ context.Context, tid string) (bool, error) {
+ return tid == "ex-wrong-host", nil
+ })
if isErr, msg := prove(goalHTTP, rec.NodeID); !isErr || !strings.Contains(msg, "does not match any asset") {
t.Fatalf("wrong-host finding must be refused: isErr=%v msg=%q", isErr, msg)
}
diff --git a/agent/planner.go b/agent/planner.go
index c81f04d..c41edca 100644
--- a/agent/planner.go
+++ b/agent/planner.go
@@ -476,6 +476,11 @@ func (p *Planner) Plan(ctx context.Context, taskID int64, as *db.AssetStore, ts
p.compactor.OnPlannerRound(ctx, ts)
tsx := NewToolSet(ts, "planner")
tsx.SetFindingRecorder(p.findingRecorder)
+ // The host's finding recorder owns the live capture; prove_goal checks bound
+ // traffic_refs against it. No checker means finding proofs are refused.
+ if c, ok := p.findingRecorder.(TrafficCaptureChecker); ok {
+ tsx.SetTrafficProofChecker(c.TrafficExists)
+ }
if as != nil {
tsx.SetAssetStore(as, as.Companies())
}
diff --git a/agent/tools.go b/agent/tools.go
index 97986fa..eab52da 100644
--- a/agent/tools.go
+++ b/agent/tools.go
@@ -138,8 +138,9 @@ func compactIntents(ns []*db.Node, parentsOf, yieldsOf map[int64][]int64) []map[
// One ToolSet is created per planner/worker run; per-run signals live here.
type ToolSet struct {
findingRecorder FindingRecorder
- // trafficProofChecker, if set, verifies that a bound snapshot's source_traffic_id
- // exists in the live capture store during prove_goal. Any error fails closed.
+ // trafficProofChecker verifies that a bound snapshot's source_traffic_id
+ // exists in the live capture store during prove_goal. Planner.Plan wires it
+ // from the finding recorder; nil or any error fails closed.
trafficProofChecker func(ctx context.Context, trafficID string) (bool, error)
as *db.AssetStore // asset store (optional; nil = asset tools not available)
cs *db.CompanyStore // company store (optional)
diff --git a/db/finding_traffic.go b/db/finding_traffic.go
index 80dbf99..01c50c9 100644
--- a/db/finding_traffic.go
+++ b/db/finding_traffic.go
@@ -522,9 +522,9 @@ type FindingProofCheck struct {
// whether the finding for nodeID has at least one real bound traffic_ref whose
// host matches the finding's linked assets. A finding without linked assets (or
// whose assets carry no host) is never proven.
-// When exchangeExists is non-nil it additionally verifies that the referenced
-// source_traffic_id exists in the live capture store; any lookup error fails
-// closed by returning an error.
+// Each bound traffic_ref's source_traffic_id must also exist in the live
+// capture store according to exchangeExists. A nil exchangeExists or any
+// lookup error fails closed by returning an error.
func (s *ExplorationStore) VerifyFindingProofForNode(
ctx context.Context,
nodeID int64,
@@ -653,15 +653,17 @@ ORDER BY b.position, b.id`, findingID)
missingInCapture = true
continue
}
- if exchangeExists != nil {
- ok, err := exchangeExists(ctx, tid)
- if err != nil {
- return nil, fmt.Errorf("traffic capture lookup failed for %q: %w", tid, err)
- }
- if !ok {
- missingInCapture = true
- continue
- }
+ // Without a capture checker the ref cannot be verified: fail closed.
+ if exchangeExists == nil {
+ return nil, errors.New("traffic capture verification is unavailable")
+ }
+ ok, err := exchangeExists(ctx, tid)
+ if err != nil {
+ return nil, fmt.Errorf("traffic capture lookup failed for %q: %w", tid, err)
+ }
+ if !ok {
+ missingInCapture = true
+ continue
}
u, err := url.Parse(strings.TrimSpace(sn.rawURL))
if err != nil {
diff --git a/evidence/store.go b/evidence/store.go
index 2771479..dab1069 100644
--- a/evidence/store.go
+++ b/evidence/store.go
@@ -199,6 +199,17 @@ func (s *Store) prepare(ctx context.Context, refs []db.TrafficRef) ([]db.Prepare
return out, nil
}
+// TrafficExists reports whether a bound snapshot's source exchange is still in
+// the live capture this store binds from. prove_goal uses it through the
+// planner's finding recorder; a missing capture store is an error, so the
+// proof is refused rather than accepted.
+func (s *Store) TrafficExists(ctx context.Context, trafficID string) (bool, error) {
+ if s == nil {
+ return false, errors.New("evidence store unavailable")
+ }
+ return s.Traffic.ExchangeExists(ctx, trafficID)
+}
+
func (s *Store) Record(ctx context.Context, in db.RecordFindingInput, refs []db.TrafficRef) (out *db.RecordedFinding, err error) {
err = s.DB.WithEvidenceTx(ctx, func(tx *sql.Tx) error {
if err := db.LockTaskEvidenceTx(tx, in.TaskID); err != nil {
diff --git a/traffic/evidence.go b/traffic/evidence.go
index b963851..d843bb1 100644
--- a/traffic/evidence.go
+++ b/traffic/evidence.go
@@ -26,6 +26,23 @@ type EvidenceExchange struct {
Request, Response io.Reader
}
+// ExchangeExists reports whether id is an exchange in this capture store. A nil
+// store or a failed lookup is an error, never a silent false or true.
+func (t *Traffic) ExchangeExists(ctx context.Context, id string) (bool, error) {
+ if t == nil {
+ return false, errors.New("traffic recording store unavailable")
+ }
+ var one int
+ err := t.db.QueryRowContext(ctx, `SELECT 1 FROM exchanges WHERE id=?`, id).Scan(&one)
+ if errors.Is(err, sql.ErrNoRows) {
+ return false, nil
+ }
+ if err != nil {
+ return false, err
+ }
+ return true, nil
+}
+
func (t *Traffic) ReadEvidence(ctx context.Context, ids []string, consume func(EvidenceExchange) error) error {
if t == nil {
return errors.New("traffic recording store unavailable")