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)

Merge PR #102: feat: 支持漏洞关联多条流量证据

Autumn-27028d9bd25cc9
diff --cc db/schema.sql
index a0e284a,15d076b..4ff5483
--- a/db/schema.sql
+++ b/db/schema.sql
@@@ -1063,38 -1058,39 +1063,71 @@@ CREATE INDEX IF NOT EXISTS idx_findings
-- 「按资产」视图靠 asset_ids @> '[<id>]' 反查发现,没有这个 GIN 索引就是全表扫。
CREATE INDEX IF NOT EXISTS idx_findings_asset_ids ON findings USING GIN(asset_ids jsonb_path_ops);
+-- 手动复测属于独立会话;结论与原漏洞处置状态分开保存。
+CREATE TABLE IF NOT EXISTS finding_retests (
+ id BIGSERIAL PRIMARY KEY,
+ finding_id BIGINT NOT NULL REFERENCES findings(id) ON DELETE CASCADE,
+ conversation_id BIGINT UNIQUE REFERENCES conversations(id) ON DELETE SET NULL,
+ status TEXT NOT NULL DEFAULT 'pending' CHECK (status IN ('pending','running','completed','failed','stopped')),
+ verdict TEXT NOT NULL DEFAULT '' CHECK (verdict IN ('','reproduced','fixed','inconclusive')),
+ notes TEXT NOT NULL DEFAULT '',
+ snapshot JSONB NOT NULL,
+ summary TEXT NOT NULL DEFAULT '',
+ evidence TEXT NOT NULL DEFAULT '',
+ error TEXT NOT NULL DEFAULT '',
+ created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
+ started_at TIMESTAMPTZ,
+ finished_at TIMESTAMPTZ
+);
+CREATE INDEX IF NOT EXISTS idx_finding_retests_history ON finding_retests(finding_id, id DESC);
+CREATE UNIQUE INDEX IF NOT EXISTS idx_finding_retests_active ON finding_retests(finding_id)
+ WHERE status IN ('pending','running');
+
+-- 删除会话保留复测记录,同时解除尚未结束的复测占用。
+CREATE OR REPLACE FUNCTION stop_deleted_conversation_retest() RETURNS trigger LANGUAGE plpgsql AS $$
+BEGIN
+ UPDATE finding_retests SET status='stopped', error='复测会话已删除', finished_at=now()
+ WHERE conversation_id=OLD.id AND status IN ('pending','running');
+ RETURN OLD;
+END;
+$$;
+DROP TRIGGER IF EXISTS trg_conversation_retest_delete ON conversations;
+CREATE TRIGGER trg_conversation_retest_delete BEFORE DELETE ON conversations
+ FOR EACH ROW EXECUTE FUNCTION stop_deleted_conversation_retest();
+
+ ALTER TABLE findings ADD COLUMN IF NOT EXISTS evidence_version BIGINT NOT NULL DEFAULT 0;
+ ALTER TABLE findings ADD COLUMN IF NOT EXISTS report_evidence_version BIGINT NOT NULL DEFAULT 0;
+
+ CREATE TABLE IF NOT EXISTS traffic_evidence_snapshots (
+ id TEXT PRIMARY KEY,
+ source_traffic_id TEXT NOT NULL,
+ captured_at BIGINT NOT NULL,
+ url TEXT NOT NULL,
+ method TEXT NOT NULL,
+ status INTEGER NOT NULL,
+ content_type TEXT NOT NULL DEFAULT '',
+ req_head TEXT NOT NULL,
+ resp_head TEXT NOT NULL,
+ req_hash TEXT NOT NULL,
+ resp_hash TEXT NOT NULL,
+ req_len BIGINT NOT NULL,
+ resp_len BIGINT NOT NULL,
+ unreferenced_at TIMESTAMPTZ,
+ created_at TIMESTAMPTZ NOT NULL DEFAULT now()
+ );
+ CREATE TABLE IF NOT EXISTS finding_traffic_bindings (
+ id BIGSERIAL PRIMARY KEY,
+ finding_id BIGINT NOT NULL REFERENCES findings(id) ON DELETE CASCADE,
+ snapshot_id TEXT NOT NULL REFERENCES traffic_evidence_snapshots(id),
+ role TEXT NOT NULL DEFAULT 'supporting',
+ note TEXT NOT NULL DEFAULT '',
+ position INTEGER NOT NULL,
+ created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
+ UNIQUE(finding_id, snapshot_id)
+ );
+ CREATE INDEX IF NOT EXISTS idx_finding_traffic_order ON finding_traffic_bindings(finding_id, position, id);
+ CREATE INDEX IF NOT EXISTS idx_finding_traffic_snapshot ON finding_traffic_bindings(snapshot_id);
+
-- =====================================================================
-- M. 后端日志持久化
-- =====================================================================
diff --cc server/server.go
index 9d549ee,e45d3c1..3aff826
--- a/server/server.go
+++ b/server/server.go
@@@ -220,9 -220,7 +220,10 @@@ func New(ctx context.Context, m *Manage
wireTools(m.pg, domainReg) // 内置工具表:按 agent 过滤 + 覆盖描述/schema + 注入默认值
seedPrompts(m.pg) // 内置 agent 默认提示词正文播种进 agent_prompts(仅空时)
s.seedOrchestrationTools() // P2 跨任务编排工具 seed 进 tools 表(可按 agent 绑定)
+ if err := s.seedFindingRetester(); err != nil {
+ log.Printf("[retester] seed: %v", err)
+ }
+ go s.evidenceStore().RunGC(s.ctx)
s.seedPythonInterpreter() // 自定义脚本工具:开机检测 python 解释器入库(仅空时)
go newScheduler(s).Run(s.ctx) // P3 触发器调度(定时/finding/目标事件),仅自定义 agent
// Fill the tool cache for any enabled MCP that has none yet (notably the
diff --cc web/src/app/(main)/function/findings/_components/findings-table.tsx
index 9f1aae6,b331bf6..17ca1c5
--- a/web/src/app/(main)/function/findings/_components/findings-table.tsx
+++ b/web/src/app/(main)/function/findings/_components/findings-table.tsx
@@@ -212,9 -206,10 +213,10 @@@ export function FindingsTable(
<span className="truncate font-medium">{f.name || f.vulnclass || "未分类"}</span>
)}
<span className="truncate text-xs text-muted-foreground">{f.summary}</span>
+ <Badge variant="outline">流量证据 {f.traffic_count ?? 0} 条</Badge>
</div>
</TableCell>
- <TableCell className="w-52">
+ <TableCell>
{f.assets && f.assets.length > 0 ? (
<div className="flex flex-wrap gap-1">
{f.assets.slice(0, 3).map((a) => (
diff --cc web/src/app/(main)/function/findings/detail/page.tsx
index 27e4c04,4068850..d40f962
--- a/web/src/app/(main)/function/findings/detail/page.tsx
+++ b/web/src/app/(main)/function/findings/detail/page.tsx
@@@ -1,13 -1,18 +1,19 @@@
"use client";
import * as React from "react";
+
import Link from "next/link";
import { useSearchParams } from "next/navigation";
- import { toast } from "sonner";
+
import { ArrowLeftIcon, ArrowUpRightIcon, ShieldAlertIcon } from "lucide-react";
+ import { toast } from "sonner";
- import { SidebarTrigger } from "@/components/ui/sidebar";
- import { Separator } from "@/components/ui/separator";
+ import { CopyButton } from "@/components/copy-button";
++import { FindingRetestPanel } from "@/components/finding-retest-panel";
+ import { FindingTrafficPanel } from "@/components/finding-traffic-panel";
+ import { Markdown } from "@/components/markdown";
+ import { StatusBadge } from "@/components/status-badge";
+ import { Alert, AlertDescription } from "@/components/ui/alert";
import { Badge } from "@/components/ui/badge";
import { Button } from "@/components/ui/button";
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
@@@ -190,12 -167,9 +169,10 @@@ function FindingDetailInner()
<CardTitle className="text-sm">摘要</CardTitle>
</CardHeader>
<CardContent>
- <p className="text-sm leading-relaxed whitespace-pre-wrap">
- {finding.summary || "(无摘要)"}
- </p>
+ <p className="text-sm leading-relaxed whitespace-pre-wrap">{finding.summary || "(无摘要)"}</p>
</CardContent>
</Card>
+ <FindingRetestPanel key={id} findingId={id} readOnly={finding.inherited} onCompleted={load} />
<Card>
<CardHeader>
<CardTitle className="text-sm">证据 / PoC</CardTitle>
diff --cc web/src/lib/api.ts
index e35ef30,a45ff1f..ef32d8d
--- a/web/src/lib/api.ts
+++ b/web/src/lib/api.ts
@@@ -38,9 -37,10 +39,11 @@@ import type
FindingStats,
FindingStatus,
FindingsPage,
+ FindingTraffic,
+ FindingTrafficDetail,
IntentAsset,
InterceptApprovalRow,
+ InterceptDetail,
InterceptPending,
InterceptRule,
JudgeConfig,
diff --cc web/src/lib/types.ts
index a8385b3,339c2b7..6fac143
--- a/web/src/lib/types.ts
+++ b/web/src/lib/types.ts
@@@ -1272,30 -1252,53 +1277,81 @@@ export interface LLMTask
count: number;
}
+// Immutable review snapshot plus separately recorded execution outcome.
+export interface InterceptAudit {
+ run_id?: string;
+ tool_use_id?: string;
+ correlation: "exact" | "ambiguous" | "unavailable";
+ input_digest: string;
+ user_message: string;
+ user_truncated?: boolean;
+ context: { kind: string; tool?: string; tool_use_id?: string; text: string; is_error?: boolean; truncated?: boolean }[] | null;
+ context_truncated?: boolean;
+ captured_at: string;
+ model_fallback?: boolean;
+ initial_action: "allow" | "ask" | "deny";
+ initial_reason: string;
+ effective_action?: "allow" | "deny";
+ decision_reason?: string;
+ rule_name?: string;
+ config_digest?: string;
+ profile_id?: number;
+ execution_status: "not_started" | "not_executed" | "awaiting_result" | "succeeded" | "failed" | "unknown";
+ output?: string;
+ output_truncated?: boolean;
+ execution_ended_at?: string;
+}
+export interface InterceptDetail extends InterceptApprovalRow {
+ audit: InterceptAudit | null;
+}
++
+ export type TrafficEvidenceRole = "baseline" | "proof" | "verification" | "supporting";
+ export interface TrafficEvidenceRef {
+ traffic_id: string;
+ role?: TrafficEvidenceRole;
+ note?: string;
+ }
+ export interface TrafficEvidenceSnapshot {
+ id: string;
+ source_traffic_id: string;
+ captured_at: number;
+ url: string;
+ method: string;
+ status: number;
+ content_type: string;
+ req_head?: string;
+ resp_head?: string;
+ req_hash: string;
+ resp_hash: string;
+ req_len: number;
+ resp_len: number;
+ }
+ export interface FindingTrafficBinding {
+ id: string;
+ finding_id: string;
+ snapshot_id: string;
+ role: TrafficEvidenceRole;
+ note: string;
+ position: number;
+ created_at: string;
+ snapshot: TrafficEvidenceSnapshot;
+ }
+ export interface FindingTraffic {
+ finding_id: string;
+ version: number;
+ report_version: number;
+ bindings: FindingTrafficBinding[];
+ }
+ export interface EvidenceBodyPreview {
+ content: string;
+ offset: number;
+ total: number;
+ next_offset: number;
+ truncated: boolean;
+ binary: boolean;
+ }
+ export interface FindingTrafficDetail {
+ binding: FindingTrafficBinding;
+ request: EvidenceBodyPreview;
+ response: EvidenceBodyPreview;
+ }