bugx-cli 0.1.0 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +193 -185
- package/core/README.md +2 -2
- package/core/agent/README.md +2 -1
- package/core/agent/agent_artifacts.py +8 -6
- package/core/agent/agent_eval.py +136 -54
- package/core/agent/agent_execution.py +218 -52
- package/core/agent/agent_orchestrator.py +14 -8
- package/core/agent/agent_targets.py +8 -2
- package/core/agent/feature_baseline.py +150 -0
- package/core/assets/README.md +3 -2
- package/core/assets/axe-core/LICENSE-3RD-PARTY.txt +66 -0
- package/core/assets/axe-core/LICENSE.txt +362 -0
- package/core/assets/axe-core/UPSTREAM.md +10 -0
- package/core/assets/axe-core/axe.min.js +12 -0
- package/core/assets/bugx-hero-en.svg +74 -0
- package/core/assets/bugx-hero-zh.svg +74 -0
- package/core/assets/bugx-social-preview.svg +71 -0
- package/core/assets/bugx-wechat-group.png +0 -0
- package/core/assets/codex.png +0 -0
- package/core/assets/dsh.png +0 -0
- package/core/assets/webui-chatgpt.jpg +0 -0
- package/core/assets/webui-session.jpg +0 -0
- package/core/assets/webui-skills.jpg +0 -0
- package/core/assets/webui-studio.jpg +0 -0
- package/core/assets/webui-zcode.jpg +0 -0
- package/core/assets/zcode.png +0 -0
- package/core/audit_packs/README.md +2 -0
- package/core/audit_packs/pitfalls/auth_crypto.json +64 -0
- package/core/audit_packs/pitfalls/file_ssrf_cmd.json +64 -0
- package/core/audit_packs/pitfalls/go_backend.json +66 -0
- package/core/audit_packs/pitfalls/java_spring.json +64 -0
- package/core/audit_packs/pitfalls/js_ts_web.json +67 -0
- package/core/audit_packs/pitfalls/python_web.json +82 -0
- package/core/autonomous_cve/SPEC.md +1 -1
- package/core/autonomous_cve/attack_graph_store.py +152 -106
- package/core/autonomous_cve/behavior_graph.py +8 -2
- package/core/autonomous_cve/verifier.py +4 -1
- package/core/bugx.md +1 -1
- package/core/bugx_paths.py +43 -8
- package/core/cli-help.txt +66 -0
- package/core/cloud_sync/SPEC.md +1 -1
- package/core/cloud_sync/cloud_client.py +81 -11
- package/core/cloud_sync/cloud_onboard.py +42 -1
- package/core/cloud_sync/consent.py +33 -3
- package/core/cloud_sync/flywheel_client.py +186 -15
- package/core/cloud_sync/network_transport.py +24 -3
- package/core/cloud_sync/sensitive_filter.py +2 -2
- package/core/cloud_sync/sync_push.py +12 -10
- package/core/contracts/AGENT_GUIDE.md +6 -9
- package/core/contracts/README.md +2 -2
- package/core/contracts/bugx-runtime-contract.md +1 -1
- package/core/contracts/bugx-worker.md +1 -1
- package/core/contracts/engine_gap_contracts.py +86 -3
- package/core/coverage/coverage_discovery.py +599 -29
- package/core/coverage/coverage_evidence.py +47 -0
- package/core/coverage/coverage_forensics.py +9 -0
- package/core/coverage/coverage_validate.py +6 -1
- package/core/dev_harness/SPEC.md +1 -1
- package/core/engine-integrity.json +670 -442
- package/core/fuzzing/concurrency_fuzzer.py +53 -0
- package/core/fuzzing/differential_oracle.py +562 -27
- package/core/fuzzing/fuzz_input.py +109 -6
- package/core/fuzzing/stateful_fuzzer.py +72 -0
- package/core/governance/secret_redactor.py +22 -10
- package/core/host_acp/SPEC.md +1 -1
- package/core/host_acp/__init__.py +4 -4
- package/core/host_acp/claude.py +59 -1
- package/core/host_acp/cline.py +64 -1
- package/core/host_acp/codex.py +56 -1
- package/core/host_acp/dsh.py +59 -1
- package/core/host_acp/opencode.py +56 -1
- package/core/host_acp/pi.py +59 -1
- package/core/host_acp/zcode.py +59 -1
- package/core/host_runtime/SPEC.md +1 -1
- package/core/host_runtime/adapters.py +1 -1
- package/core/host_runtime/cline.py +13 -0
- package/core/host_runtime/host_evaluators.py +44 -4
- package/core/host_runtime/host_probe.py +1 -1
- package/core/host_runtime/host_provider_arbitrator.py +116 -62
- package/core/host_runtime/host_registry.py +15 -8
- package/core/host_runtime/mcp_registry_gate.py +12 -1
- package/core/host_runtime/pi.py +102 -0
- package/core/host_runtime/provider_facts.py +66 -0
- package/core/hosts/SPEC.md +1 -1
- package/core/hosts/__init__.py +6 -2
- package/core/hosts/_dsh_usage.py +1 -1
- package/core/hosts/base.py +32 -4
- package/core/hosts/claude.py +55 -0
- package/core/hosts/cline.py +6 -2
- package/core/hosts/codex.py +58 -0
- package/core/hosts/dsh.py +9 -1
- package/core/hosts/opencode.py +6 -6
- package/core/hosts/pi.py +159 -2
- package/core/infra/README.md +4 -2
- package/core/infra/__init__.py +2 -0
- package/core/infra/build_info.py +22 -3
- package/core/infra/client_metadata.py +1 -1
- package/core/infra/json_utils.py +22 -0
- package/core/launch_phases/README.md +6 -3
- package/core/launch_phases/SPEC.md +1 -1
- package/core/launch_phases/common.py +21 -2
- package/core/launch_phases/finding_confirm_phase.py +170 -5
- package/core/launch_phases/finding_settlement.py +188 -1
- package/core/launch_phases/judge_phase.py +69 -12
- package/core/launch_phases/orchestrator_controls.py +11 -7
- package/core/launch_phases/post_coverage_sync.py +9 -2
- package/core/launch_phases/post_phase.py +144 -8
- package/core/launch_phases/post_receipt.py +12 -1
- package/core/launch_phases/pre_phase.py +3 -3
- package/core/launch_phases/pre_recon_scout.py +66 -36
- package/core/launch_phases/pre_state_builder.py +23 -176
- package/core/launch_phases/report_sharing.py +3 -7
- package/core/launch_phases/round_orchestrator.py +129 -58
- package/core/launch_phases/semantic_recon.py +545 -0
- package/core/launch_phases/session_runtime.py +56 -9
- package/core/launch_phases/startup_gates.py +36 -8
- package/core/launch_phases/startup_interaction.py +68 -12
- package/core/launch_phases/startup_version_gate.py +13 -3
- package/core/launch_phases/supervisor_bridge.py +46 -17
- package/core/launch_phases/supervisor_coverage.py +8 -2
- package/core/launch_phases/supervisor_degraded.py +1 -9
- package/core/launch_phases/verify_loop.py +767 -0
- package/core/launch_phases/worker_barriers.py +15 -5
- package/core/launch_phases/worker_orchestrator.py +105 -25
- package/core/launch_phases/worker_prior.py +115 -0
- package/core/ledger/README.md +2 -1
- package/core/ledger/SPEC.md +1 -1
- package/core/ledger/_facade.py +2 -1
- package/core/ledger/archive_ops.py +60 -2
- package/core/ledger/cli.py +6 -1
- package/core/ledger/export_ops.py +6 -1
- package/core/ledger/finding_confirmation.py +48 -6
- package/core/ledger/finding_lifecycle.py +428 -5
- package/core/ledger/finding_verification.py +555 -10
- package/core/ledger/fp_ledger.py +255 -0
- package/core/ledger/incidents.py +10 -4
- package/core/ledger/patterns.py +10 -7
- package/core/ledger/receipt_contract.py +17 -1
- package/core/ledger/sync_ops.py +21 -16
- package/core/ledger/tool_experience.py +2 -1
- package/core/ledger/verify_life.py +88 -17
- package/core/locales/en-US.json +2 -2
- package/core/locales/zh-CN.json +2 -2
- package/core/mcp_handlers/SPEC.md +1 -1
- package/core/mcp_handlers/base.py +23 -3
- package/core/mcp_handlers/channel_lifecycle.py +85 -30
- package/core/mcp_handlers/retrieval_handlers.py +11 -1
- package/core/mcp_handlers/rpc_server.py +6 -1
- package/core/mcp_handlers/supervisor_handlers.py +32 -6
- package/core/mcp_handlers/tool_table.py +15 -0
- package/core/mcp_runtime_support/environment.py +0 -38
- package/core/mcp_runtime_support/verifier.py +0 -52
- package/core/metadata.txt +2 -3
- package/core/planning/README.md +2 -1
- package/core/planning/domain_router.py +4 -2
- package/core/planning/dynamic_flow_analyzer.py +219 -14
- package/core/planning/judge_pipeline.py +87 -4
- package/core/planning/prompt_harness.py +57 -15
- package/core/planning/prompt_policy_engine.py +386 -0
- package/core/planning/spec_harvester.py +4 -4
- package/core/probes/INTERFACE.md +11 -1
- package/core/probes/SPEC.md +11 -1
- package/core/probes/__init__.py +46 -40
- package/core/probes/android_probe.py +177 -9
- package/core/probes/codebase_memory_probe.py +57 -0
- package/core/probes/desktop_probe.py +104 -0
- package/core/probes/differential_probe.py +99 -21
- package/core/probes/efficiency_probe.py +64 -0
- package/core/probes/ios_binary_probe.py +105 -1
- package/core/probes/memory_probe.py +66 -0
- package/core/probes/miniprogram_probe.py +75 -13
- package/core/probes/mobile_probe.py +215 -30
- package/core/probes/native_probe.py +88 -0
- package/core/probes/openwiki_probe.py +70 -0
- package/core/probes/pattern_probe.py +106 -0
- package/core/probes/platform_probe.py +81 -0
- package/core/probes/probe_registry.py +108 -7
- package/core/probes/sast_fixture_corpus.py +340 -0
- package/core/probes/sast_probe.py +553 -52
- package/core/probes/sast_rules.py +668 -28
- package/core/probes/sca_scanner.py +48 -0
- package/core/probes/ui_accessibility.py +149 -0
- package/core/probes/ui_audit.py +513 -0
- package/core/probes/ui_contract.py +273 -0
- package/core/probes/ui_evidence.py +212 -0
- package/core/probes/ui_measurements.py +314 -0
- package/core/probes/ui_repair.py +250 -0
- package/core/probes/ui_review.py +133 -0
- package/core/probes/ui_storybook.py +107 -0
- package/core/probes/ui_tokens.py +185 -0
- package/core/probes/ui_visual_diff.py +131 -0
- package/core/probes/web_probe.py +373 -18
- package/core/project_profiler/SPEC.md +1 -1
- package/core/project_profiler/arbitrator.py +6 -1
- package/core/project_profiler/detector.py +8 -1
- package/core/project_profiler/strategy.py +51 -15
- package/core/prompts/README.md +4 -2
- package/core/prompts/command_routing_en.md +2 -2
- package/core/prompts/command_routing_zh.md +2 -2
- package/core/prompts/policies/prompt_policies.json +101 -0
- package/core/prompts/stages/stage_repair.md +1 -1
- package/core/prompts/stages/stage_verify.defensive.md +42 -0
- package/core/prompts/stages/stage_verify.md +44 -0
- package/core/repair/README.md +1 -1
- package/core/repair/l7_repair_loop.py +1 -4
- package/core/repair/rsi_fixer.py +4 -4
- package/core/repair/rsi_loop.py +1 -3
- package/core/repair/rsi_repair.py +7 -7
- package/core/repair/rsi_scope.py +27 -8
- package/core/report_engine/SPEC.md +1 -1
- package/core/report_engine/attestation.py +8 -4
- package/core/report_engine/finding_report.py +2 -1
- package/core/report_engine/models.py +7 -9
- package/core/report_engine/report_share.py +0 -8
- package/core/report_engine/sast_bridge.py +2 -2
- package/core/report_engine/server.py +18 -8
- package/core/report_engine/web-conformance.md +123 -18
- package/core/report_engine/web_conformance.py +21 -52
- package/core/retrieval/README.md +2 -1
- package/core/retrieval/SPEC.md +1 -1
- package/core/retrieval/code_analyzer.py +50 -14
- package/core/retrieval/context_assembler.py +7 -1
- package/core/retrieval/knowledge_sync.py +108 -14
- package/core/retrieval/pitfall_packs.py +277 -0
- package/core/retrieval/symbol_index.py +25 -6
- package/core/retrieval/universal_code_matcher.py +234 -49
- package/core/runtime/README.md +1 -1
- package/core/runtime/bugx_logging.py +78 -7
- package/core/runtime/fixture_solidify.py +5 -10
- package/core/runtime/global_telemetry.py +20 -0
- package/core/runtime/incident_eval.py +1 -1
- package/core/runtime/model_runner.py +4 -41
- package/core/runtime/platform_adapter.py +2 -2
- package/core/runtime/prep_validate.py +4 -2
- package/core/runtime/project_settings.py +2 -1
- package/core/runtime/scenario_eval.py +50 -8
- package/core/skills/bugx_docs_mcp_server.py +3 -1
- package/core/skills/bugx_mcp_server.py +29 -2
- package/core/skills/tools_kb.py +1 -1
- package/core/supervisor/README.md +1 -1
- package/core/supervisor/SPEC.md +1 -1
- package/core/supervisor/budget_governor.py +503 -9
- package/core/supervisor/checkpoint_pipeline.py +248 -6
- package/core/supervisor/checkpoint_sync.py +13 -0
- package/core/supervisor/claim_events.py +1 -1
- package/core/supervisor/finding_workflow.py +22 -5
- package/core/supervisor/lease_manager.py +1 -1
- package/core/supervisor/lifecycle_blocks.py +6 -1
- package/core/supervisor/rejection_remedies.py +52 -5
- package/core/supervisor/serial_authorization.py +48 -4
- package/core/supervisor/task_scheduler.py +2 -2
- package/core/supervisor/worker_checkpoint.py +8 -1
- package/core/supervisor/worker_runtime.py +8 -2
- package/core/supervisor_types/worker_claim.py +9 -0
- package/core/webui/README.md +1 -1
- package/core/webui/SPEC.md +2 -1
- package/core/webui/adapters/claude.py +5 -1
- package/core/webui/adapters/cline.py +10 -2
- package/core/webui/adapters/codex.py +5 -1
- package/core/webui/adapters/dsh.py +5 -1
- package/core/webui/docs_session_service.py +2 -2
- package/core/webui/mcp_inspector.py +11 -7
- package/core/webui/static/00-base.css +1060 -0
- package/core/webui/static/01-monitoring.css +802 -0
- package/core/webui/static/02-header-actions.css +321 -0
- package/core/webui/static/03-trigger-popover.css +697 -0
- package/core/webui/static/04-composer.css +628 -0
- package/core/webui/static/05-skills-center.css +878 -0
- package/core/webui/static/06-mcp-center.css +623 -0
- package/core/webui/static/07-skill-detail.css +265 -0
- package/core/webui/static/08-files-management.css +167 -0
- package/core/webui/static/09-files-center.css +386 -0
- package/core/webui/static/10-icons.css +105 -0
- package/core/webui/static/11-project-options.css +185 -0
- package/core/webui/static/12-profile-tab.css +383 -0
- package/core/webui/static/design-tokens.css +113 -0
- package/core/webui/static/index.html +14 -1
- package/core/webui/workspace_service.py +1 -1
- package/docs/07_distribution/01_README_NPM.md +193 -185
- package/ecosystem/integrations/README.md +1 -1
- package/ecosystem/integrations/dsh/mcp/package.json +1 -1
- package/ecosystem/integrations/dsh/skills/bugx-dsh/SKILL.md +1 -1
- package/ecosystem/integrations/dsh/ui/package.json +1 -1
- package/ecosystem/integrations/opencode/bugx-mcp-manifest.json +4 -4
- package/ecosystem/integrations/opencode/mcp-lock.json +14 -6
- package/ecosystem/integrations/opencode/opencode.json +23 -12
- package/ecosystem/integrations/pi/extensions/bugx/manifest.json +1 -1
- package/ecosystem/integrations/qoder/connector-meta.json +1 -1
- package/ecosystem/integrations/workbuddy/connector-meta.json +1 -1
- package/ecosystem/integrations/workbuddy/skills/bugx/SKILL.md +1 -1
- package/ecosystem/plugins/bugx/.claude-plugin/plugin.json +1 -1
- package/ecosystem/plugins/bugx/.codex-plugin/plugin.json +1 -1
- package/ecosystem/plugins/bugx/.zcode-plugin/plugin.json +1 -1
- package/ecosystem/plugins/bugx/skills/bugx/SKILL.md +2 -2
- package/ecosystem/plugins/bugx/skills/bugx-dsh/SKILL.md +1 -1
- package/ecosystem/plugins/bugx/skills/bugx-opencode/SKILL.md +1 -1
- package/ecosystem/plugins/bugx/skills/bugx-zcode/SKILL.md +1 -1
- package/interfaces/bin/bugx.js +37 -0
- package/interfaces/cli/bugx_cli/__init__.py +4 -2
- package/interfaces/cli/bugx_cli/cli.py +172 -69
- package/interfaces/cli/bugx_cli/commands/advisory.py +1 -1
- package/interfaces/cli/bugx_cli/commands/agent.py +461 -134
- package/interfaces/cli/bugx_cli/commands/audit.py +10 -9
- package/interfaces/cli/bugx_cli/commands/autonomous.py +1 -1
- package/interfaces/cli/bugx_cli/commands/cloud.py +31 -22
- package/interfaces/cli/bugx_cli/commands/doctor.py +449 -204
- package/interfaces/cli/bugx_cli/commands/interaction.py +5 -1
- package/interfaces/cli/bugx_cli/commands/knowledge.py +5 -4
- package/interfaces/cli/bugx_cli/commands/lifecycle.py +3 -3
- package/interfaces/cli/bugx_cli/commands/plugin.py +58 -23
- package/interfaces/cli/bugx_cli/commands/plugin_claude.py +7 -7
- package/interfaces/cli/bugx_cli/commands/plugin_funide.py +2 -1
- package/interfaces/cli/bugx_cli/commands/plugin_zcode.py +1 -1
- package/interfaces/cli/bugx_cli/commands/project.py +6 -13
- package/interfaces/cli/bugx_cli/commands/report.py +2 -6
- package/interfaces/cli/bugx_cli/commands/system.py +524 -169
- package/interfaces/cli/bugx_cli/common.py +21 -15
- package/interfaces/cli/bugx_cli/host_adapters.py +29 -54
- package/interfaces/cli/bugx_cli/hosts/registry.py +8 -6
- package/interfaces/cli/bugx_cli/infra/ai_advisor.py +157 -27
- package/interfaces/cli/bugx_cli/infra/engine_installer.py +35 -16
- package/interfaces/cli/bugx_cli/infra/host_sync.py +11 -8
- package/interfaces/cli/bugx_cli/infra/mcp_advisor.py +76 -5
- package/interfaces/cli/bugx_cli/infra/security.py +13 -6
- package/package.json +30 -15
- package/pyproject.toml +60 -9
- package/scripts/ensure-python.mjs +7 -7
- package/scripts/sync-version.mjs +10 -21
- package/scripts/test-npm-wrapper.mjs +1 -1
- package/core/assets/bugx-hero-cn.png +0 -0
- package/core/assets/bugx-hero-en.png +0 -0
- package/core/webui/static/project-settings.css +0 -6458
- package/docs/07_distribution/README.md +0 -16
- package/docs/README.md +0 -121
- package/interfaces/README.md +0 -143
- package/interfaces/bin/README.md +0 -35
- package/interfaces/cli/README.md +0 -90
- package/scripts/README.md +0 -118
|
@@ -15,7 +15,15 @@ CLI 用法:
|
|
|
15
15
|
python3 differential_oracle.py verify \
|
|
16
16
|
--cmd 'python3 target.py {input}' \
|
|
17
17
|
--input /path/to/poc.json \
|
|
18
|
-
[--timeout 10] [--json] [--out report.json]
|
|
18
|
+
[--workspace /path/to/project] [--timeout 10] [--json] [--out report.json]
|
|
19
|
+
|
|
20
|
+
沙盒投递契约(DEF-1):提供 --workspace(或库调用传 workspace_root/allowed_root)时,
|
|
21
|
+
沙盒执行前会把 PoC 文本与命令模板中实际引用的文件/目录按相对布局复制进沙盒
|
|
22
|
+
(有文件数/字节硬预算)。引用来源有三类且统一经越界/存在性裁决:
|
|
23
|
+
① 引号字面量(runpy.run_path("app/admin.py"));② import 子句(from app import files);
|
|
24
|
+
③ **命令模板的裸 argv token**(python3 target.py {input} 中的 target.py)。
|
|
25
|
+
对引用到的单个文件同时捕获其父目录子树(跳过 .git/__pycache__ 等噪声目录),
|
|
26
|
+
保证被测目标源码自身的同级依赖在沙盒内可达;PoC 字节本身不改写。
|
|
19
27
|
"""
|
|
20
28
|
|
|
21
29
|
from __future__ import annotations
|
|
@@ -35,7 +43,6 @@ import hashlib
|
|
|
35
43
|
import json
|
|
36
44
|
import os
|
|
37
45
|
import re
|
|
38
|
-
import shlex
|
|
39
46
|
import shutil
|
|
40
47
|
import subprocess
|
|
41
48
|
import sys
|
|
@@ -50,13 +57,9 @@ if str(_CORE_DIR) not in sys.path:
|
|
|
50
57
|
sys.path.insert(0, str(_CORE_DIR))
|
|
51
58
|
|
|
52
59
|
from core.supervisor.worker_execution import run_bounded
|
|
60
|
+
from core.fuzzing.fuzz_input import split_argv as _split_argv_shared
|
|
53
61
|
|
|
54
62
|
SCHEMA_VERSION = 1
|
|
55
|
-
_SHELL_PUNCTUATION = ";&|<>`$()"
|
|
56
|
-
_SHELL_OPERATORS = frozenset({
|
|
57
|
-
";", "&", "&&", "|", "||", "<", ">", ">>", "<<", "<&", ">&",
|
|
58
|
-
"`", "$(", "(", ")",
|
|
59
|
-
})
|
|
60
63
|
|
|
61
64
|
|
|
62
65
|
class DifferentialOracleError(ValueError):
|
|
@@ -73,6 +76,8 @@ class RunResult:
|
|
|
73
76
|
timed_out: bool = False
|
|
74
77
|
infrastructure_error: bool = False
|
|
75
78
|
infrastructure_reason: str = ""
|
|
79
|
+
# DEF-1: 沙盒内被测目标源码投递收据(仅 workspace_root 提供时非空)。
|
|
80
|
+
provisioning: dict[str, Any] | None = None
|
|
76
81
|
|
|
77
82
|
|
|
78
83
|
_INFRASTRUCTURE_PATTERNS = (
|
|
@@ -120,6 +125,331 @@ def _temporary_input(content: str, *, suffix: str = ".tmp") -> Path:
|
|
|
120
125
|
return Path(handle.name)
|
|
121
126
|
|
|
122
127
|
|
|
128
|
+
# --- DEF-1 修复:沙盒内被测目标源码投递 -------------------------------------
|
|
129
|
+
# 沙盒 cwd 是全新临时目录,PoC 模板引用的 workspace 相对路径(如
|
|
130
|
+
# runpy.run_path("app/admin.py"))此前必然 FileNotFoundError → 全部 INFRA_ERROR,
|
|
131
|
+
# deterministic dual-run 确认链路被结构性切断。修复方式是按 PoC/命令模板中
|
|
132
|
+
# 实际引用(引号字面量)且真实存在于 workspace 根内的文件/目录,按原相对
|
|
133
|
+
# 布局复制进沙盒——PoC 字节本身不改写(保住 input_sha256 证据链),只复制
|
|
134
|
+
# 引用到的路径,绝不镜像全仓(沙盒隔离保持),双跑共享同一份投递计划以
|
|
135
|
+
# 维持确定性裁决语义。
|
|
136
|
+
_QUOTED_LITERAL_RE = re.compile(r"['\"]([^'\"\n]{1,1024})['\"]")
|
|
137
|
+
# DEF-1 缺口1:import 型 PoC(``from app import files`` / ``import app.admin``)
|
|
138
|
+
# 没有任何引号路径字面量,只靠引号提取会得到空投递计划 → 沙箱缺被测包 →
|
|
139
|
+
# 双跑同指纹 ModuleNotFoundError。除引号字面量外,把 import 语句中的点分
|
|
140
|
+
# 模块路径也提取为投递候选(仍经 _safe_workspace_member 真实存在 + 越界过滤)。
|
|
141
|
+
# 锚点覆盖三种 import 出现边界:行首(多行 -c 程序体)、分号后(一行式)、
|
|
142
|
+
# 引号后(``python3 -c "from x.y import z"`` 单引号包裹的一行式程序体——
|
|
143
|
+
# 引号字面量通道会把整段程序体当一个含空格 token 吃掉且无法解析为路径,
|
|
144
|
+
# 2026-11-18 dsh 第三批端到端实证该形态仍漏提取 → 沙箱 ModuleNotFoundError)。
|
|
145
|
+
_IMPORT_CLAUSE_RE = re.compile(
|
|
146
|
+
r"(?:^[ \t]*|[;\"'][ \t]*)(?:from[ \t]+([.\w]+)[ \t]+import\b|import[ \t]+([.\w]+(?:[ \t]*,[ \t]*[.\w]+)*))",
|
|
147
|
+
re.MULTILINE,
|
|
148
|
+
)
|
|
149
|
+
_DOTTED_MODULE_RE = re.compile(r"[A-Za-z_]\w*(?:\.[A-Za-z_]\w*)*")
|
|
150
|
+
# DEF-1 缺口2:模块缺失/导入失败类错误是沙箱执行环境问题(投递计划缺包、
|
|
151
|
+
# 解释器环境不完整),不是目标缺陷证据。双跑同指纹命中时不得升级为
|
|
152
|
+
# CONFIRMED_DETERMINISTIC(现有 _INFRASTRUCTURE_PATTERNS 不覆盖该形态)。
|
|
153
|
+
_STABLE_INFRA_SIGNATURE_RE = re.compile(
|
|
154
|
+
r"\bModuleNotFoundError\b|\bNo module named\b", re.IGNORECASE
|
|
155
|
+
)
|
|
156
|
+
_SANDBOX_PROVISION_MAX_FILES = 400
|
|
157
|
+
_SANDBOX_PROVISION_MAX_TOTAL_BYTES = 16 * 1024 * 1024
|
|
158
|
+
_SANDBOX_PROVISION_SCAN_BYTES = 1024 * 1024
|
|
159
|
+
_SANDBOX_PROVISION_REPORT_LIMIT = 50
|
|
160
|
+
# 目录子树捕获时跳过的噪声/巨型目录(VCS、缓存、依赖与引擎状态)。
|
|
161
|
+
_PROVISION_SKIP_DIR_NAMES = frozenset({
|
|
162
|
+
".git", "__pycache__", ".bugx", ".venv", "venv", "node_modules",
|
|
163
|
+
})
|
|
164
|
+
# plan 条目: (token, 引用路径, kind);kind: "file" 精确引用文件 / "dir" 引用目录
|
|
165
|
+
# 或引用文件的父目录捕获(覆盖目标源码自身未被 PoC 引用的同级依赖)。
|
|
166
|
+
_WorkspaceProvisionPlan = tuple[Path, list[tuple[str, Path, str]]]
|
|
167
|
+
|
|
168
|
+
|
|
169
|
+
def _workspace_reference_tokens(text: str) -> list[str]:
|
|
170
|
+
"""提取文本中去重后的 workspace 相对路径候选。
|
|
171
|
+
|
|
172
|
+
DEF-1 缺口1 扩展:除引号字面量外,同时提取 import 语句中的点分模块
|
|
173
|
+
路径(``from <pkg> import ...`` 的 ``<pkg>``、``import <pkg>.<mod>[, ...]``
|
|
174
|
+
的逐个模块名)。候选是否真实存在、是否越界仍由 ``_safe_workspace_member``
|
|
175
|
+
统一裁决;``runpy.run_path(...)`` 等带引号的调用形态已由引号字面量覆盖。
|
|
176
|
+
"""
|
|
177
|
+
if not text:
|
|
178
|
+
return []
|
|
179
|
+
tokens: list[str] = []
|
|
180
|
+
seen: set[str] = set()
|
|
181
|
+
|
|
182
|
+
def _add(raw: str | None) -> None:
|
|
183
|
+
token = (raw or "").strip()
|
|
184
|
+
if not token or token in seen:
|
|
185
|
+
return
|
|
186
|
+
seen.add(token)
|
|
187
|
+
tokens.append(token)
|
|
188
|
+
|
|
189
|
+
for match in _QUOTED_LITERAL_RE.finditer(text):
|
|
190
|
+
_add(match.group(1))
|
|
191
|
+
for match in _IMPORT_CLAUSE_RE.finditer(text):
|
|
192
|
+
_add(match.group(1))
|
|
193
|
+
for piece in (match.group(2) or "").split(","):
|
|
194
|
+
_add(piece)
|
|
195
|
+
return tokens
|
|
196
|
+
|
|
197
|
+
|
|
198
|
+
def _command_argv_reference_tokens(cmd_template: str) -> list[str]:
|
|
199
|
+
"""提取命令模板 argv 中的裸路径候选(DEF-1 缺口3,根治)。
|
|
200
|
+
|
|
201
|
+
文档自带 CLI 示例 ``--cmd 'python3 target.py {input}'`` 的目标脚本是裸 argv
|
|
202
|
+
token——既不在引号里也不是 import 子句,旧投递源(引号+import)提取为空,
|
|
203
|
+
沙盒缺少被测目标 → 双跑同指纹 FileNotFoundError → INFRA_ERROR,确定性确认
|
|
204
|
+
链路被结构性切断。本函数用仓库唯一 argv 解析器拆分命令模板,跳过解释器/运行
|
|
205
|
+
时标志与占位符参数,把其余 token 作为路径候选交给 ``_safe_workspace_member``
|
|
206
|
+
统一裁决(真实存在 + workspace 根内 + 非逃逸)。
|
|
207
|
+
|
|
208
|
+
只收录"疑似路径形态"的 token(含路径分隔符或常见脚本/源码扩展名),避免把
|
|
209
|
+
普通参数值(如 ``--level 3`` 的 ``3``)当候选误投;即便误收也会被
|
|
210
|
+
``_safe_workspace_member`` 的存在性检查过滤。模板解析失败时返回空列表,不在
|
|
211
|
+
投递阶段抛错——命令合法性由执行阶段 ``_split_argv`` 统一负责。
|
|
212
|
+
"""
|
|
213
|
+
if not cmd_template:
|
|
214
|
+
return []
|
|
215
|
+
try:
|
|
216
|
+
argv = _split_argv(cmd_template)
|
|
217
|
+
except DifferentialOracleError:
|
|
218
|
+
return []
|
|
219
|
+
path_like = re.compile(
|
|
220
|
+
r"(?:/|\\|\.(?:py|js|mjs|cjs|ts|tsx|sh|bash|rb|pl|php|java|go|rs|c|cpp|exe)$)",
|
|
221
|
+
re.IGNORECASE,
|
|
222
|
+
)
|
|
223
|
+
tokens: list[str] = []
|
|
224
|
+
for token in argv:
|
|
225
|
+
if not token or "{" in token or "}" in token:
|
|
226
|
+
continue
|
|
227
|
+
if token.startswith("-"):
|
|
228
|
+
continue
|
|
229
|
+
if not path_like.search(token):
|
|
230
|
+
continue
|
|
231
|
+
tokens.append(token)
|
|
232
|
+
return tokens
|
|
233
|
+
|
|
234
|
+
|
|
235
|
+
def _dotted_module_candidates(token: str) -> list[str]:
|
|
236
|
+
"""把 import 型点分模块路径展开为候选 workspace 相对路径。
|
|
237
|
+
|
|
238
|
+
``app.admin`` 依次尝试 ``app/admin.py``、``app/admin/__init__.py``、
|
|
239
|
+
``app/admin`` 目录,最后回退顶层包 ``app``——引用文件的父目录子树捕获
|
|
240
|
+
会把同级依赖一并投递,任一候选真实存在即可保证被测包在沙箱内可达。
|
|
241
|
+
非点分模块形状(含 ``/``、引号残留等)的 token 不展开,保持引号型
|
|
242
|
+
回归行为不变。
|
|
243
|
+
"""
|
|
244
|
+
if not _DOTTED_MODULE_RE.fullmatch(token):
|
|
245
|
+
return []
|
|
246
|
+
rel = token.replace(".", "/")
|
|
247
|
+
candidates = [f"{rel}.py", f"{rel}/__init__.py", rel]
|
|
248
|
+
top = token.split(".", 1)[0]
|
|
249
|
+
if top != token:
|
|
250
|
+
candidates.append(top)
|
|
251
|
+
return candidates
|
|
252
|
+
|
|
253
|
+
|
|
254
|
+
def _safe_workspace_member(workspace_root: Path, token: str) -> Path | None:
|
|
255
|
+
"""把引号字面量解析为严格位于 workspace 根内的真实文件/目录。
|
|
256
|
+
|
|
257
|
+
拒绝绝对路径、``..`` 越界与符号链接逃逸;返回未解析的引用路径以便
|
|
258
|
+
沙盒内按 PoC 所见布局落盘(内容复制仍经解析后的真实文件)。
|
|
259
|
+
"""
|
|
260
|
+
if not token or "\x00" in token or len(token) > 512:
|
|
261
|
+
return None
|
|
262
|
+
try:
|
|
263
|
+
candidate = Path(token)
|
|
264
|
+
except (OSError, ValueError):
|
|
265
|
+
return None
|
|
266
|
+
if candidate.is_absolute() or not candidate.parts:
|
|
267
|
+
return None
|
|
268
|
+
if any(part == ".." for part in candidate.parts):
|
|
269
|
+
return None
|
|
270
|
+
target = workspace_root / candidate
|
|
271
|
+
try:
|
|
272
|
+
resolved = target.resolve(strict=False)
|
|
273
|
+
resolved.relative_to(workspace_root)
|
|
274
|
+
except (OSError, ValueError):
|
|
275
|
+
return None
|
|
276
|
+
if resolved == workspace_root:
|
|
277
|
+
return None
|
|
278
|
+
if not (resolved.is_file() or resolved.is_dir()):
|
|
279
|
+
return None
|
|
280
|
+
return target
|
|
281
|
+
|
|
282
|
+
|
|
283
|
+
def _plan_workspace_provisioning(
|
|
284
|
+
texts: list[str],
|
|
285
|
+
workspace_root: Path | None,
|
|
286
|
+
*,
|
|
287
|
+
cmd_template: str | None = None,
|
|
288
|
+
) -> _WorkspaceProvisionPlan | None:
|
|
289
|
+
"""构建沙盒投递计划:PoC/命令模板引用且存在于 workspace 根内的路径集合。
|
|
290
|
+
|
|
291
|
+
三类引用源统一进 ``seen_tokens`` 去重后由 ``_safe_workspace_member`` 裁决:
|
|
292
|
+
① texts 中的引号字面量 + import 子句(``_workspace_reference_tokens``);
|
|
293
|
+
② ``cmd_template`` 的裸 argv 路径 token(DEF-1 缺口3;runpy 形态的 CLI 示例)。
|
|
294
|
+
|
|
295
|
+
对引用到的单个文件,同时捕获其父目录子树(有界预算 + 噪声目录跳过):
|
|
296
|
+
被测目标源码自身的同级依赖(admin.py 读 payload.txt、包内 import 兄弟
|
|
297
|
+
模块)随父目录一并投递,多文件目标在沙盒内可达。``workspace_root`` 为
|
|
298
|
+
None 时返回 None(保持旧的 workspace-blind 行为,调用方零破坏)。
|
|
299
|
+
"""
|
|
300
|
+
if workspace_root is None:
|
|
301
|
+
return None
|
|
302
|
+
root = Path(workspace_root).expanduser().resolve()
|
|
303
|
+
members: list[tuple[str, Path, str]] = []
|
|
304
|
+
seen_tokens: set[str] = set()
|
|
305
|
+
seen_targets: set[Path] = set()
|
|
306
|
+
sources: list[tuple[str, bool]] = [(text, False) for text in texts]
|
|
307
|
+
if cmd_template:
|
|
308
|
+
sources.append((cmd_template, True))
|
|
309
|
+
for text, is_command in sources:
|
|
310
|
+
if not text:
|
|
311
|
+
continue
|
|
312
|
+
scan = text[:_SANDBOX_PROVISION_SCAN_BYTES]
|
|
313
|
+
tokens = _workspace_reference_tokens(scan)
|
|
314
|
+
if is_command:
|
|
315
|
+
tokens = tokens + _command_argv_reference_tokens(scan)
|
|
316
|
+
for token in tokens:
|
|
317
|
+
if token in seen_tokens:
|
|
318
|
+
continue
|
|
319
|
+
seen_tokens.add(token)
|
|
320
|
+
member = _safe_workspace_member(root, token)
|
|
321
|
+
if member is None:
|
|
322
|
+
# DEF-1 缺口1:import 型点分模块路径(如 app / app.admin)按
|
|
323
|
+
# 候选相对路径逐个解析,仍走同一 _safe_workspace_member 过滤。
|
|
324
|
+
for candidate in _dotted_module_candidates(token):
|
|
325
|
+
member = _safe_workspace_member(root, candidate)
|
|
326
|
+
if member is not None:
|
|
327
|
+
break
|
|
328
|
+
if member is None:
|
|
329
|
+
continue
|
|
330
|
+
resolved_key = member.resolve(strict=False)
|
|
331
|
+
if resolved_key in seen_targets:
|
|
332
|
+
continue
|
|
333
|
+
seen_targets.add(resolved_key)
|
|
334
|
+
if member.is_dir():
|
|
335
|
+
members.append((token, member, "dir"))
|
|
336
|
+
continue
|
|
337
|
+
members.append((token, member, "file"))
|
|
338
|
+
# 父目录捕获:引用文件的同级依赖一并投递(引用根级文件时父目录
|
|
339
|
+
# 即 workspace 根,受文件数/字节硬预算约束并记录截断收据)。
|
|
340
|
+
capture_dir = member.parent
|
|
341
|
+
resolved_capture = capture_dir.resolve(strict=False)
|
|
342
|
+
if resolved_capture not in seen_targets:
|
|
343
|
+
seen_targets.add(resolved_capture)
|
|
344
|
+
members.append((f"{token}::parent", capture_dir, "dir"))
|
|
345
|
+
return root, members
|
|
346
|
+
|
|
347
|
+
|
|
348
|
+
def _apply_sandbox_provisioning(
|
|
349
|
+
sandbox_path: Path,
|
|
350
|
+
provision_plan: _WorkspaceProvisionPlan,
|
|
351
|
+
reserved_path: Path | None = None,
|
|
352
|
+
) -> dict[str, Any]:
|
|
353
|
+
"""把投递计划中的 workspace 文件/目录按相对布局复制进沙盒(有界预算)。
|
|
354
|
+
|
|
355
|
+
``reserved_path``(沙盒内的 {input} 文件)不可被投递覆盖,否则会在
|
|
356
|
+
内容分歧时破坏被裁决的 PoC 证据。
|
|
357
|
+
"""
|
|
358
|
+
root, members = provision_plan
|
|
359
|
+
file_count = 0
|
|
360
|
+
total_bytes = 0
|
|
361
|
+
truncated = False
|
|
362
|
+
skipped = 0
|
|
363
|
+
copied_files: list[str] = []
|
|
364
|
+
copied_dirs: list[str] = []
|
|
365
|
+
copied_dests: set[Path] = set()
|
|
366
|
+
|
|
367
|
+
def _over_budget(size: int) -> bool:
|
|
368
|
+
return (
|
|
369
|
+
file_count >= _SANDBOX_PROVISION_MAX_FILES
|
|
370
|
+
or total_bytes + size > _SANDBOX_PROVISION_MAX_TOTAL_BYTES
|
|
371
|
+
)
|
|
372
|
+
|
|
373
|
+
for _token, member, kind in members:
|
|
374
|
+
if truncated:
|
|
375
|
+
break
|
|
376
|
+
rel = member.relative_to(root)
|
|
377
|
+
if kind == "dir" or member.is_dir():
|
|
378
|
+
dest_dir = sandbox_path / rel
|
|
379
|
+
try:
|
|
380
|
+
dest_dir.mkdir(parents=True, exist_ok=True)
|
|
381
|
+
except OSError:
|
|
382
|
+
skipped += 1
|
|
383
|
+
continue
|
|
384
|
+
copied_dirs.append(rel.as_posix())
|
|
385
|
+
for entry in sorted(
|
|
386
|
+
p for p in member.rglob("*")
|
|
387
|
+
if not any(part in _PROVISION_SKIP_DIR_NAMES for part in p.parts)
|
|
388
|
+
):
|
|
389
|
+
try:
|
|
390
|
+
if not entry.is_file():
|
|
391
|
+
continue
|
|
392
|
+
resolved_entry = entry.resolve(strict=False)
|
|
393
|
+
resolved_entry.relative_to(root)
|
|
394
|
+
size = entry.stat().st_size
|
|
395
|
+
except (OSError, ValueError):
|
|
396
|
+
skipped += 1
|
|
397
|
+
continue
|
|
398
|
+
dest_file = sandbox_path / entry.relative_to(root)
|
|
399
|
+
if dest_file in copied_dests:
|
|
400
|
+
continue
|
|
401
|
+
if reserved_path is not None and dest_file == reserved_path:
|
|
402
|
+
skipped += 1
|
|
403
|
+
continue
|
|
404
|
+
if _over_budget(size):
|
|
405
|
+
truncated = True
|
|
406
|
+
break
|
|
407
|
+
try:
|
|
408
|
+
dest_file.parent.mkdir(parents=True, exist_ok=True)
|
|
409
|
+
shutil.copy2(entry, dest_file)
|
|
410
|
+
except OSError:
|
|
411
|
+
skipped += 1
|
|
412
|
+
continue
|
|
413
|
+
copied_dests.add(dest_file)
|
|
414
|
+
file_count += 1
|
|
415
|
+
total_bytes += size
|
|
416
|
+
if len(copied_files) < _SANDBOX_PROVISION_REPORT_LIMIT:
|
|
417
|
+
copied_files.append(entry.relative_to(root).as_posix())
|
|
418
|
+
elif member.is_file():
|
|
419
|
+
dest_file = sandbox_path / rel
|
|
420
|
+
if dest_file in copied_dests:
|
|
421
|
+
continue
|
|
422
|
+
if reserved_path is not None and dest_file == reserved_path:
|
|
423
|
+
skipped += 1
|
|
424
|
+
continue
|
|
425
|
+
try:
|
|
426
|
+
size = member.stat().st_size
|
|
427
|
+
except OSError:
|
|
428
|
+
skipped += 1
|
|
429
|
+
continue
|
|
430
|
+
if _over_budget(size):
|
|
431
|
+
truncated = True
|
|
432
|
+
continue
|
|
433
|
+
try:
|
|
434
|
+
dest_file.parent.mkdir(parents=True, exist_ok=True)
|
|
435
|
+
shutil.copy2(member, dest_file)
|
|
436
|
+
except OSError:
|
|
437
|
+
skipped += 1
|
|
438
|
+
continue
|
|
439
|
+
copied_dests.add(dest_file)
|
|
440
|
+
file_count += 1
|
|
441
|
+
total_bytes += size
|
|
442
|
+
copied_files.append(rel.as_posix())
|
|
443
|
+
return {
|
|
444
|
+
"copied_files": copied_files,
|
|
445
|
+
"copied_dirs": copied_dirs[:_SANDBOX_PROVISION_REPORT_LIMIT],
|
|
446
|
+
"file_count": file_count,
|
|
447
|
+
"total_bytes": total_bytes,
|
|
448
|
+
"truncated": truncated,
|
|
449
|
+
"skipped": skipped,
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
|
|
123
453
|
def _materialize_poc_input(
|
|
124
454
|
poc_input: Any,
|
|
125
455
|
*,
|
|
@@ -225,19 +555,14 @@ def extract_crash_signature(exit_code: int, stderr: str, stdout: str) -> str:
|
|
|
225
555
|
|
|
226
556
|
|
|
227
557
|
def _split_argv(template: str) -> list[str]:
|
|
228
|
-
"""
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
if not argv:
|
|
237
|
-
raise DifferentialOracleError("命令模板不能为空")
|
|
238
|
-
if any(token in _SHELL_OPERATORS for token in argv):
|
|
239
|
-
raise DifferentialOracleError("命令包含 shell 运算符;为确保纯净沙盒隔离,请传纯 argv 格式")
|
|
240
|
-
return argv
|
|
558
|
+
"""复用全仓 argv 解析器,仅适配本模块的异常契约。"""
|
|
559
|
+
return _split_argv_shared(
|
|
560
|
+
template,
|
|
561
|
+
error_type=DifferentialOracleError,
|
|
562
|
+
parse_error_prefix="命令模板无法解析",
|
|
563
|
+
empty_message="命令模板不能为空",
|
|
564
|
+
operator_message="命令包含 shell 运算符;为确保纯净沙盒隔离,请传纯 argv 格式",
|
|
565
|
+
)
|
|
241
566
|
|
|
242
567
|
|
|
243
568
|
def _execute_in_sandbox(
|
|
@@ -246,6 +571,7 @@ def _execute_in_sandbox(
|
|
|
246
571
|
input_filename: str,
|
|
247
572
|
timeout: float = 10.0,
|
|
248
573
|
accepted_exits: set[int] | None = None,
|
|
574
|
+
provision_plan: _WorkspaceProvisionPlan | None = None,
|
|
249
575
|
) -> RunResult:
|
|
250
576
|
"""在全新的独立临时目录沙盒中执行单次目标命令。"""
|
|
251
577
|
with tempfile.TemporaryDirectory(prefix="bugx-oracle-sandbox-") as sandbox_dir:
|
|
@@ -253,6 +579,14 @@ def _execute_in_sandbox(
|
|
|
253
579
|
sandbox_input = sandbox_path / input_filename
|
|
254
580
|
sandbox_input.write_bytes(input_content)
|
|
255
581
|
|
|
582
|
+
# DEF-1:执行前把 PoC 引用的被测目标源码投递进沙盒,否则引用
|
|
583
|
+
# workspace 相对路径的 PoC 必然 FileNotFoundError → 全 INFRA_ERROR。
|
|
584
|
+
provisioning_summary: dict[str, Any] | None = None
|
|
585
|
+
if provision_plan is not None:
|
|
586
|
+
provisioning_summary = _apply_sandbox_provisioning(
|
|
587
|
+
sandbox_path, provision_plan, reserved_path=sandbox_input,
|
|
588
|
+
)
|
|
589
|
+
|
|
256
590
|
argv = _split_argv(cmd_template)
|
|
257
591
|
rendered_argv = [
|
|
258
592
|
arg.replace("{input}", str(sandbox_input)) for arg in argv
|
|
@@ -302,7 +636,32 @@ def _execute_in_sandbox(
|
|
|
302
636
|
timed_out=timed_out,
|
|
303
637
|
infrastructure_error=infrastructure_reason is not None,
|
|
304
638
|
infrastructure_reason=infrastructure_reason or "",
|
|
639
|
+
provisioning=provisioning_summary,
|
|
640
|
+
)
|
|
641
|
+
|
|
642
|
+
|
|
643
|
+
def _stable_infra_signature_reason(res1: RunResult, res2: RunResult) -> str | None:
|
|
644
|
+
"""DEF-1 缺口2:双跑同指纹且命中基础设施模式时返回降级理由。
|
|
645
|
+
|
|
646
|
+
复用现有 ``_infrastructure_failure_reason`` 分类器语义,并补上其未覆盖的
|
|
647
|
+
模块缺失/导入失败形态(``ModuleNotFoundError: No module named 'app'``)。
|
|
648
|
+
仅在两侧归一化签名完全一致(稳定复现的环境错误)时生效;签名分歧、
|
|
649
|
+
单侧偶发的路径维持原有 FLAKY/CONFIRMED 裁决,判定语义不放宽——真实
|
|
650
|
+
缺陷(非 infra 签名)的双跑确定性复现仍然 CONFIRMED。
|
|
651
|
+
"""
|
|
652
|
+
if res1.normalized_signature != res2.normalized_signature:
|
|
653
|
+
return None
|
|
654
|
+
reason = _infrastructure_failure_reason(
|
|
655
|
+
exit_code=res1.exit_code, stderr=res1.stderr, stdout=res1.stdout,
|
|
656
|
+
)
|
|
657
|
+
if reason:
|
|
658
|
+
return reason
|
|
659
|
+
if _STABLE_INFRA_SIGNATURE_RE.search(res1.normalized_signature):
|
|
660
|
+
return (
|
|
661
|
+
f"stable same-fingerprint module/import failure: "
|
|
662
|
+
f"{res1.normalized_signature[:160]}"
|
|
305
663
|
)
|
|
664
|
+
return None
|
|
306
665
|
|
|
307
666
|
|
|
308
667
|
def verify_poc(
|
|
@@ -311,6 +670,7 @@ def verify_poc(
|
|
|
311
670
|
*,
|
|
312
671
|
timeout: float = 10.0,
|
|
313
672
|
accepted_exits: set[int] | None = None,
|
|
673
|
+
workspace_root: Path | None = None,
|
|
314
674
|
) -> dict[str, Any]:
|
|
315
675
|
"""快捷入口:验证单个 PoC 文件。"""
|
|
316
676
|
path, temp_file = _materialize_poc_input(poc_input)
|
|
@@ -320,6 +680,7 @@ def verify_poc(
|
|
|
320
680
|
input_path=path,
|
|
321
681
|
timeout=timeout,
|
|
322
682
|
accepted_exits=accepted_exits,
|
|
683
|
+
workspace_root=workspace_root,
|
|
323
684
|
)
|
|
324
685
|
finally:
|
|
325
686
|
if temp_file is not None and path.is_file():
|
|
@@ -334,6 +695,7 @@ def verify_red_blue_debate(
|
|
|
334
695
|
red_poc_path: Path,
|
|
335
696
|
blue_counter_template: str | None = None,
|
|
336
697
|
timeout: float = 30.0,
|
|
698
|
+
workspace_root: Path | None = None,
|
|
337
699
|
) -> dict[str, Any]:
|
|
338
700
|
"""DOC-137 2.0 / D137-07: 红蓝双 Agent 闭环对抗博弈与差分验证裁决器。
|
|
339
701
|
|
|
@@ -350,7 +712,15 @@ def verify_red_blue_debate(
|
|
|
350
712
|
|
|
351
713
|
# 1. Red 独立沙盒穿透验证(硬超时 <= timeout)
|
|
352
714
|
red_content = red_poc_path.read_bytes()
|
|
353
|
-
|
|
715
|
+
red_provision_plan = _plan_workspace_provisioning(
|
|
716
|
+
[cmd_template, red_content.decode("utf-8", errors="replace")],
|
|
717
|
+
workspace_root,
|
|
718
|
+
cmd_template=cmd_template,
|
|
719
|
+
)
|
|
720
|
+
red_res = _execute_in_sandbox(
|
|
721
|
+
cmd_template, red_content, red_poc_path.name,
|
|
722
|
+
timeout=min(timeout, 15.0), provision_plan=red_provision_plan,
|
|
723
|
+
)
|
|
354
724
|
if red_res.infrastructure_error:
|
|
355
725
|
return {
|
|
356
726
|
"schema_version": SCHEMA_VERSION,
|
|
@@ -388,6 +758,7 @@ def verify_red_blue_debate(
|
|
|
388
758
|
red_content,
|
|
389
759
|
red_poc_path.name,
|
|
390
760
|
timeout=min(timeout - (time.perf_counter() - start_t), 15.0),
|
|
761
|
+
provision_plan=red_provision_plan,
|
|
391
762
|
)
|
|
392
763
|
blue_timed_out = blue_res.timed_out
|
|
393
764
|
if blue_res.infrastructure_error:
|
|
@@ -429,7 +800,9 @@ def verify_red_blue_debate(
|
|
|
429
800
|
confirmed = False
|
|
430
801
|
else:
|
|
431
802
|
# 进行第二次沙盒验证以保证确定性
|
|
432
|
-
dual = run_differential_verification(
|
|
803
|
+
dual = run_differential_verification(
|
|
804
|
+
cmd_template, red_poc_path, timeout=10.0, workspace_root=workspace_root,
|
|
805
|
+
)
|
|
433
806
|
if dual["confirmed"]:
|
|
434
807
|
verdict = "CONFIRMED_DETERMINISTIC"
|
|
435
808
|
summary = f"Red 攻击真实有效且 Blue 无法反驳({blue_detail}),两次双跑确定性复现,确认为真实漏洞"
|
|
@@ -457,6 +830,7 @@ def run_differential_verification(
|
|
|
457
830
|
input_path: str | os.PathLike[str],
|
|
458
831
|
timeout: float = 10.0,
|
|
459
832
|
accepted_exits: set[int] | None = None,
|
|
833
|
+
workspace_root: Path | None = None,
|
|
460
834
|
) -> dict[str, Any]:
|
|
461
835
|
"""执行隔离双跑差分验证并产出判定结论与证据工件。"""
|
|
462
836
|
input_file = Path(input_path)
|
|
@@ -468,9 +842,23 @@ def run_differential_verification(
|
|
|
468
842
|
input_filename = input_file.name
|
|
469
843
|
expected_good_exits = accepted_exits or {0}
|
|
470
844
|
|
|
845
|
+
# DEF-1:双跑共享同一份沙盒投递计划(同源同布局),保证确定性裁决;
|
|
846
|
+
# workspace_root 为 None 时保持旧的 workspace-blind 行为。
|
|
847
|
+
provision_plan = _plan_workspace_provisioning(
|
|
848
|
+
[cmd_template, input_content.decode("utf-8", errors="replace")],
|
|
849
|
+
workspace_root,
|
|
850
|
+
cmd_template=cmd_template,
|
|
851
|
+
)
|
|
852
|
+
|
|
471
853
|
# 执行 Run 1 与 Run 2(两个完全独立的临时目录)
|
|
472
|
-
res1 = _execute_in_sandbox(
|
|
473
|
-
|
|
854
|
+
res1 = _execute_in_sandbox(
|
|
855
|
+
cmd_template, input_content, input_filename,
|
|
856
|
+
timeout=timeout, provision_plan=provision_plan,
|
|
857
|
+
)
|
|
858
|
+
res2 = _execute_in_sandbox(
|
|
859
|
+
cmd_template, input_content, input_filename,
|
|
860
|
+
timeout=timeout, provision_plan=provision_plan,
|
|
861
|
+
)
|
|
474
862
|
|
|
475
863
|
infrastructure_runs = [
|
|
476
864
|
result for result in (res1, res2) if result.infrastructure_error
|
|
@@ -499,7 +887,17 @@ def run_differential_verification(
|
|
|
499
887
|
summary = f"双跑行为分歧(Run 1 exit {res1.exit_code} vs Run 2 exit {res2.exit_code}),判定为偶发不稳定抖动"
|
|
500
888
|
else:
|
|
501
889
|
# 两次均失败,比较归一化签名是否吻合
|
|
502
|
-
|
|
890
|
+
# DEF-1 缺口2:同指纹但命中基础设施模式(含模块缺失/导入失败)时,
|
|
891
|
+
# 这是稳定环境错误而非目标缺陷证据,必须降级为 INFRA_ERROR,
|
|
892
|
+
# 绝不能升级 CONFIRMED_DETERMINISTIC(负对照门保持不变)。
|
|
893
|
+
stable_infra_reason = _stable_infra_signature_reason(res1, res2)
|
|
894
|
+
if stable_infra_reason is not None:
|
|
895
|
+
verdict = "INFRA_ERROR"
|
|
896
|
+
summary = (
|
|
897
|
+
"双跑同指纹但命中基础设施错误模式,拒绝把稳定环境错误升级为目标缺陷"
|
|
898
|
+
f": {stable_infra_reason}"
|
|
899
|
+
)
|
|
900
|
+
elif res1.exit_code == res2.exit_code and res1.normalized_signature == res2.normalized_signature:
|
|
503
901
|
verdict = "CONFIRMED_DETERMINISTIC"
|
|
504
902
|
summary = f"两次隔离沙盒独立复验一致崩溃(exit {res1.exit_code},签名: {res1.normalized_signature}),确认为真实确定性缺陷"
|
|
505
903
|
elif res1.exit_code == res2.exit_code:
|
|
@@ -509,7 +907,7 @@ def run_differential_verification(
|
|
|
509
907
|
verdict = "FLAKY_JITTER"
|
|
510
908
|
summary = f"两次双跑均报错但退出码分歧({res1.exit_code} != {res2.exit_code}),归类为不稳定用例"
|
|
511
909
|
|
|
512
|
-
|
|
910
|
+
report: dict[str, Any] = {
|
|
513
911
|
"schema_version": SCHEMA_VERSION,
|
|
514
912
|
"oracle_tier": "deterministic_dual_run",
|
|
515
913
|
"verdict": verdict,
|
|
@@ -541,6 +939,17 @@ def run_differential_verification(
|
|
|
541
939
|
],
|
|
542
940
|
"summary": summary,
|
|
543
941
|
}
|
|
942
|
+
if provision_plan is not None:
|
|
943
|
+
# DEF-1 收据:记录沙盒投递了哪些被测目标源码(证据可追溯,
|
|
944
|
+
# 且与 workspace-blind 调用路径字段级可区分)。
|
|
945
|
+
plan_root, plan_members = provision_plan
|
|
946
|
+
report["sandbox_provisioning"] = {
|
|
947
|
+
"workspace_root": str(plan_root),
|
|
948
|
+
"references": [token for token, _, _ in plan_members],
|
|
949
|
+
"run1": res1.provisioning,
|
|
950
|
+
"run2": res2.provisioning,
|
|
951
|
+
}
|
|
952
|
+
return report
|
|
544
953
|
|
|
545
954
|
|
|
546
955
|
def verify_differential_poc(
|
|
@@ -565,7 +974,13 @@ def verify_differential_poc(
|
|
|
565
974
|
) from exc
|
|
566
975
|
path = resolved_path
|
|
567
976
|
try:
|
|
568
|
-
|
|
977
|
+
# DEF-1 关键接线:allowed_root 之前只用于 PoC 路径越界校验,随后在
|
|
978
|
+
# verify_poc 边界被丢弃,导致沙盒从不投递被测目标源码;这里把根
|
|
979
|
+
# 目录传入双跑,让 PoC 引用的 workspace 相对路径在沙盒内真实可达。
|
|
980
|
+
return verify_poc(
|
|
981
|
+
cmd_template, path, timeout=timeout, accepted_exits=accepted_exits,
|
|
982
|
+
workspace_root=root,
|
|
983
|
+
)
|
|
569
984
|
finally:
|
|
570
985
|
if temp_file is not None and path.is_file():
|
|
571
986
|
try:
|
|
@@ -583,6 +998,10 @@ def parse_args(argv: list[str] | None = None) -> argparse.Namespace:
|
|
|
583
998
|
p_verify.add_argument("--input", type=Path, required=True, help="候选 PoC 输入文件")
|
|
584
999
|
p_verify.add_argument("--timeout", type=float, default=10.0, help="单次运行超时秒数(默认 10)")
|
|
585
1000
|
p_verify.add_argument("--accepted-exits", default="0", help="预期正常退出码(逗号分隔,默认 0)")
|
|
1001
|
+
p_verify.add_argument(
|
|
1002
|
+
"--workspace", type=Path, default=None,
|
|
1003
|
+
help="被测项目根目录;提供后把 PoC 引用的项目内文件投递进沙盒再双跑(DEF-1)",
|
|
1004
|
+
)
|
|
586
1005
|
p_verify.add_argument("--out", type=Path, default=None, help="输出报告 JSON 保存路径")
|
|
587
1006
|
p_verify.add_argument("--json", action="store_true", help="以 JSON 格式输出至 stdout")
|
|
588
1007
|
|
|
@@ -600,6 +1019,7 @@ def main(argv: list[str] | None = None) -> int:
|
|
|
600
1019
|
args.input,
|
|
601
1020
|
timeout=args.timeout,
|
|
602
1021
|
accepted_exits=accepted,
|
|
1022
|
+
workspace_root=args.workspace,
|
|
603
1023
|
)
|
|
604
1024
|
except DifferentialOracleError as exc:
|
|
605
1025
|
print(f"[differential_oracle] 错误: {exc}", file=sys.stderr)
|
|
@@ -625,5 +1045,120 @@ def main(argv: list[str] | None = None) -> int:
|
|
|
625
1045
|
return 0
|
|
626
1046
|
|
|
627
1047
|
|
|
1048
|
+
def is_available() -> tuple[bool, str]:
|
|
1049
|
+
"""降级契约:机械探活沙盒双跑前提(解释器 + 可写临时目录,零子进程)。"""
|
|
1050
|
+
if not sys.executable:
|
|
1051
|
+
return False, "缺少 Python 解释器;隔离沙盒双跑不可用"
|
|
1052
|
+
tmp = tempfile.gettempdir()
|
|
1053
|
+
if not os.path.isdir(tmp) or not os.access(tmp, os.W_OK):
|
|
1054
|
+
return False, f"沙盒临时目录不可写: {tmp}"
|
|
1055
|
+
return True, f"沙盒临时目录可用: {tmp}"
|
|
1056
|
+
|
|
1057
|
+
|
|
1058
|
+
def run_static_degraded(
|
|
1059
|
+
run1: Mapping[str, Any] | None = None,
|
|
1060
|
+
run2: Mapping[str, Any] | None = None,
|
|
1061
|
+
*,
|
|
1062
|
+
input_sha256: str | None = None,
|
|
1063
|
+
) -> dict[str, Any]:
|
|
1064
|
+
"""降级契约:沙盒双跑不可用时,仅对已记录输出做归一化签名静态裁决。
|
|
1065
|
+
|
|
1066
|
+
输出与成功路径(``run_differential_verification`` 的真实隔离双跑工件)
|
|
1067
|
+
字段级可区分:``status="degraded"`` + ``degraded=True`` + ``degraded_reason``、
|
|
1068
|
+
``oracle_tier="static_signature_only"``,且 ``confirmed`` 恒为 False——
|
|
1069
|
+
静态签名比对只能提供线索,绝不直接确认确定性缺陷。
|
|
1070
|
+
"""
|
|
1071
|
+
available, availability_detail = is_available()
|
|
1072
|
+
|
|
1073
|
+
def _normalize_recorded(run: Mapping[str, Any] | None) -> tuple[int, str, str] | None:
|
|
1074
|
+
if not isinstance(run, Mapping):
|
|
1075
|
+
return None
|
|
1076
|
+
exit_code = run.get("exit_code")
|
|
1077
|
+
if exit_code is None:
|
|
1078
|
+
return None
|
|
1079
|
+
stdout = run.get("stdout")
|
|
1080
|
+
stderr = run.get("stderr")
|
|
1081
|
+
stdout_text = (
|
|
1082
|
+
stdout.decode("utf-8", errors="replace")
|
|
1083
|
+
if isinstance(stdout, bytes) else str(stdout or "")
|
|
1084
|
+
)
|
|
1085
|
+
stderr_text = (
|
|
1086
|
+
stderr.decode("utf-8", errors="replace")
|
|
1087
|
+
if isinstance(stderr, bytes) else str(stderr or "")
|
|
1088
|
+
)
|
|
1089
|
+
try:
|
|
1090
|
+
return int(exit_code), stdout_text, stderr_text
|
|
1091
|
+
except (TypeError, ValueError):
|
|
1092
|
+
return None
|
|
1093
|
+
|
|
1094
|
+
side1 = _normalize_recorded(run1)
|
|
1095
|
+
side2 = _normalize_recorded(run2)
|
|
1096
|
+
if side1 is None or side2 is None:
|
|
1097
|
+
return {
|
|
1098
|
+
"schema_version": SCHEMA_VERSION,
|
|
1099
|
+
"success": False,
|
|
1100
|
+
"status": "degraded",
|
|
1101
|
+
"degraded": True,
|
|
1102
|
+
"degraded_reason": "dynamic_dual_run_unavailable",
|
|
1103
|
+
"oracle_tier": "static_signature_only",
|
|
1104
|
+
"verdict": "INSUFFICIENT_EVIDENCE",
|
|
1105
|
+
"confirmed": False,
|
|
1106
|
+
"input_sha256": input_sha256,
|
|
1107
|
+
"findings": [],
|
|
1108
|
+
"evidence": {
|
|
1109
|
+
"availability_detail": availability_detail,
|
|
1110
|
+
"recorded_runs_present": False,
|
|
1111
|
+
},
|
|
1112
|
+
"metadata": {
|
|
1113
|
+
"degraded_mode": "no_static_evidence_available",
|
|
1114
|
+
"sandbox_runs_executed": 0,
|
|
1115
|
+
},
|
|
1116
|
+
}
|
|
1117
|
+
signature1 = extract_crash_signature(side1[0], side1[2], side1[1])
|
|
1118
|
+
signature2 = extract_crash_signature(side2[0], side2[2], side2[1])
|
|
1119
|
+
if side1[0] != side2[0]:
|
|
1120
|
+
verdict = "FLAKY_JITTER"
|
|
1121
|
+
verdict_summary = (
|
|
1122
|
+
f"已记录双跑退出码分歧({side1[0]} != {side2[0]}),归类为不稳定用例"
|
|
1123
|
+
)
|
|
1124
|
+
elif signature1 == signature2:
|
|
1125
|
+
verdict = "DETERMINISTIC_SIGNATURE_MATCH"
|
|
1126
|
+
verdict_summary = (
|
|
1127
|
+
f"已记录双跑签名一致(exit {side1[0]},签名: {signature1});"
|
|
1128
|
+
"需真实沙盒双跑复验后才能确认确定性缺陷"
|
|
1129
|
+
)
|
|
1130
|
+
else:
|
|
1131
|
+
verdict = "SIGNATURE_MISMATCH_SAME_EXIT"
|
|
1132
|
+
verdict_summary = (
|
|
1133
|
+
f"已记录双跑退出码相同(exit {side1[0]})但归一化签名分歧,证据不足"
|
|
1134
|
+
)
|
|
1135
|
+
return {
|
|
1136
|
+
"schema_version": SCHEMA_VERSION,
|
|
1137
|
+
"success": True,
|
|
1138
|
+
"status": "degraded",
|
|
1139
|
+
"degraded": True,
|
|
1140
|
+
"degraded_reason": (
|
|
1141
|
+
"static_mode_forced" if available else "dynamic_dual_run_unavailable"
|
|
1142
|
+
),
|
|
1143
|
+
"oracle_tier": "static_signature_only",
|
|
1144
|
+
"verdict": verdict,
|
|
1145
|
+
"confirmed": False,
|
|
1146
|
+
"summary": verdict_summary,
|
|
1147
|
+
"input_sha256": input_sha256,
|
|
1148
|
+
"findings": [],
|
|
1149
|
+
"evidence": {
|
|
1150
|
+
"availability_detail": availability_detail,
|
|
1151
|
+
"recorded_runs_present": True,
|
|
1152
|
+
"signatures": [signature1, signature2],
|
|
1153
|
+
"exit_codes": [side1[0], side2[0]],
|
|
1154
|
+
},
|
|
1155
|
+
"metadata": {
|
|
1156
|
+
"degraded_mode": "recorded_output_signature_compare",
|
|
1157
|
+
"sandbox_runs_executed": 0,
|
|
1158
|
+
"fallback": "沙盒双跑不可用时只做签名线索裁决;正式确认必须重跑 run_differential_verification",
|
|
1159
|
+
},
|
|
1160
|
+
}
|
|
1161
|
+
|
|
1162
|
+
|
|
628
1163
|
if __name__ == "__main__":
|
|
629
1164
|
sys.exit(main())
|