bugx-cli 0.0.0-stage → 0.1.0
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/LICENSE +55 -0
- package/README.md +280 -2
- package/core/CATALOG.json +141 -0
- package/core/README.md +254 -0
- package/core/adapters/README.md +35 -0
- package/core/adapters/android-interaction.json +81 -0
- package/core/adapters/android.json +24 -0
- package/core/adapters/desktop-macos.json +20 -0
- package/core/adapters/ios-interaction.json +34 -0
- package/core/adapters/ios.json +23 -0
- package/core/adapters/memory-macos.json +24 -0
- package/core/agent/README.md +50 -0
- package/core/agent/__init__.py +146 -0
- package/core/agent/agent_artifacts.py +764 -0
- package/core/agent/agent_eval.py +1073 -0
- package/core/agent/agent_execution.py +552 -0
- package/core/agent/agent_orchestrator.py +1345 -0
- package/core/agent/agent_targets.py +871 -0
- package/core/agent/agent_workspace.py +770 -0
- package/core/assets/README.md +24 -0
- package/core/assets/bugx-avatar-1024.png +0 -0
- package/core/assets/bugx-avatar-512.png +0 -0
- package/core/assets/bugx-avatar-tight.svg +23 -0
- package/core/assets/bugx-avatar.svg +28 -0
- package/core/assets/bugx-hero-cn.png +0 -0
- package/core/assets/bugx-hero-en.png +0 -0
- package/core/assets/project-layout.md +42 -0
- package/core/audit_packs/README.md +37 -0
- package/core/audit_packs/data-audit/manifest.json +94 -0
- package/core/audit_packs/data-audit/stages/00-scope.md +14 -0
- package/core/audit_packs/data-audit/stages/10-schema-inventory.md +14 -0
- package/core/audit_packs/data-audit/stages/20-query-and-integrity.md +14 -0
- package/core/audit_packs/data-audit/stages/80-evidence-regression.md +14 -0
- package/core/audit_packs/desktop-audit/manifest.json +123 -0
- package/core/audit_packs/desktop-audit/stages/00-scope.md +15 -0
- package/core/audit_packs/desktop-audit/stages/10-process-model.md +14 -0
- package/core/audit_packs/desktop-audit/stages/20-package-integrity.md +15 -0
- package/core/audit_packs/desktop-audit/stages/30-ui-behavior.md +14 -0
- package/core/audit_packs/desktop-audit/stages/80-evidence-regression.md +15 -0
- package/core/audit_packs/memory-testing.md +227 -0
- package/core/audit_packs/mobile-audit/manifest.json +155 -0
- package/core/audit_packs/mobile-audit/modules/android.md +19 -0
- package/core/audit_packs/mobile-audit/modules/h5.md +18 -0
- package/core/audit_packs/mobile-audit/modules/ios.md +25 -0
- package/core/audit_packs/mobile-audit/modules/miniprogram.md +26 -0
- package/core/audit_packs/mobile-audit/modules/webview.md +18 -0
- package/core/audit_packs/mobile-audit/stages/00-scope.md +14 -0
- package/core/audit_packs/mobile-audit/stages/10-platform-inventory.md +14 -0
- package/core/audit_packs/mobile-audit/stages/20-masvs-static.md +20 -0
- package/core/audit_packs/mobile-audit/stages/30-component-exposure.md +14 -0
- package/core/audit_packs/mobile-audit/stages/40-device-behavior.md +14 -0
- package/core/audit_packs/mobile-audit/stages/80-evidence-regression.md +13 -0
- package/core/audit_packs/native-audit/manifest.json +127 -0
- package/core/audit_packs/native-audit/stages/00-scope.md +14 -0
- package/core/audit_packs/native-audit/stages/10-static-white-box.md +14 -0
- package/core/audit_packs/native-audit/stages/20-memory-concurrency.md +15 -0
- package/core/audit_packs/native-audit/stages/30-behavior-black-box.md +39 -0
- package/core/audit_packs/native-audit/stages/80-evidence-regression.md +14 -0
- package/core/audit_packs/platform-testing.md +174 -0
- package/core/audit_packs/web-audit/manifest.json +191 -0
- package/core/audit_packs/web-audit/modules/graphql.md +5 -0
- package/core/audit_packs/web-audit/modules/h5.md +18 -0
- package/core/audit_packs/web-audit/modules/multi-tenant.md +4 -0
- package/core/audit_packs/web-audit/modules/oauth.md +4 -0
- package/core/audit_packs/web-audit/modules/upload.md +4 -0
- package/core/audit_packs/web-audit/modules/websocket.md +4 -0
- package/core/audit_packs/web-audit/stages/00-scope.md +13 -0
- package/core/audit_packs/web-audit/stages/10-discovery.md +13 -0
- package/core/audit_packs/web-audit/stages/20-auth-session.md +13 -0
- package/core/audit_packs/web-audit/stages/30-authz-business.md +13 -0
- package/core/audit_packs/web-audit/stages/40-input-output.md +13 -0
- package/core/audit_packs/web-audit/stages/50-state-async.md +13 -0
- package/core/audit_packs/web-audit/stages/60-file-ssrf-deser.md +12 -0
- package/core/audit_packs/web-audit/stages/70-config-dependency.md +12 -0
- package/core/audit_packs/web-audit/stages/80-evidence-regression.md +12 -0
- package/core/autonomous_cve/INTERFACE.md +61 -0
- package/core/autonomous_cve/README.md +58 -0
- package/core/autonomous_cve/SPEC.md +25 -0
- package/core/autonomous_cve/__init__.py +109 -0
- package/core/autonomous_cve/attack_graph.py +1096 -0
- package/core/autonomous_cve/attack_graph_store.py +1822 -0
- package/core/autonomous_cve/audit_campaign.py +1232 -0
- package/core/autonomous_cve/behavior_graph.py +459 -0
- package/core/autonomous_cve/ghsa_advisories.py +174 -0
- package/core/autonomous_cve/models.py +93 -0
- package/core/autonomous_cve/mutator.py +87 -0
- package/core/autonomous_cve/patcher.py +126 -0
- package/core/autonomous_cve/scout.py +278 -0
- package/core/autonomous_cve/synthesizer.py +207 -0
- package/core/autonomous_cve/verifier.py +100 -0
- package/core/bugx.md +1299 -0
- package/core/bugx_paths.py +1846 -0
- package/core/cloud_sync/INTERFACE.md +32 -0
- package/core/cloud_sync/README.md +62 -0
- package/core/cloud_sync/SPEC.md +25 -0
- package/core/cloud_sync/__init__.py +23 -0
- package/core/cloud_sync/auto_sync.py +398 -0
- package/core/cloud_sync/cloud_client.py +1199 -0
- package/core/cloud_sync/cloud_onboard.py +702 -0
- package/core/cloud_sync/cloud_schema.py +648 -0
- package/core/cloud_sync/consent.py +81 -0
- package/core/cloud_sync/device_identity.py +307 -0
- package/core/cloud_sync/endpoint_router.py +415 -0
- package/core/cloud_sync/flywheel_client.py +760 -0
- package/core/cloud_sync/network_transport.py +275 -0
- package/core/cloud_sync/onboard_wizard.py +493 -0
- package/core/cloud_sync/sensitive_filter.py +285 -0
- package/core/cloud_sync/sync_pull.py +695 -0
- package/core/cloud_sync/sync_push.py +721 -0
- package/core/contracts/AGENT_GUIDE.md +362 -0
- package/core/contracts/README.md +34 -0
- package/core/contracts/bugx-blackbox.md +541 -0
- package/core/contracts/bugx-opencode.md +469 -0
- package/core/contracts/bugx-quick.md +44 -0
- package/core/contracts/bugx-runtime-contract.md +353 -0
- package/core/contracts/bugx-worker.md +470 -0
- package/core/contracts/engine_gap_contracts.py +390 -0
- package/core/coverage/README.md +70 -0
- package/core/coverage/__init__.py +106 -0
- package/core/coverage/coverage_ai_review.py +185 -0
- package/core/coverage/coverage_backfill.py +54 -0
- package/core/coverage/coverage_bootstrap.py +713 -0
- package/core/coverage/coverage_business.py +36 -0
- package/core/coverage/coverage_cli.py +715 -0
- package/core/coverage/coverage_discovery.py +859 -0
- package/core/coverage/coverage_evidence.py +977 -0
- package/core/coverage/coverage_forensics.py +115 -0
- package/core/coverage/coverage_gate.py +277 -0
- package/core/coverage/coverage_intelligence.py +734 -0
- package/core/coverage/coverage_manifest.py +396 -0
- package/core/coverage/coverage_platform.py +77 -0
- package/core/coverage/coverage_validate.py +236 -0
- package/core/coverage/module_coverage.py +157 -0
- package/core/dev_harness/INTERFACE.md +20 -0
- package/core/dev_harness/README.md +21 -0
- package/core/dev_harness/SPEC.md +25 -0
- package/core/dev_harness/__init__.py +5 -0
- package/core/dev_harness/interaction_preset.py +408 -0
- package/core/engine-integrity.json +2625 -0
- package/core/fuzzing/README.md +49 -0
- package/core/fuzzing/__init__.py +82 -0
- package/core/fuzzing/concurrency_fuzzer.py +382 -0
- package/core/fuzzing/differential_oracle.py +629 -0
- package/core/fuzzing/fuzz_input.py +1188 -0
- package/core/fuzzing/stateful_fuzzer.py +332 -0
- package/core/governance/README.md +61 -0
- package/core/governance/__init__.py +130 -0
- package/core/governance/capacity_planner.py +124 -0
- package/core/governance/dependency_lock.py +317 -0
- package/core/governance/goal_governor.py +754 -0
- package/core/governance/guide_budget.py +458 -0
- package/core/governance/lockdown.sh +50 -0
- package/core/governance/readonly_enforcer.py +154 -0
- package/core/governance/runtime_tool_gate.py +373 -0
- package/core/governance/secret_redactor.py +772 -0
- package/core/governance/token_budget.py +38 -0
- package/core/host_acp/INTERFACE.md +36 -0
- package/core/host_acp/README.md +51 -0
- package/core/host_acp/SPEC.md +25 -0
- package/core/host_acp/__init__.py +121 -0
- package/core/host_acp/base.py +111 -0
- package/core/host_acp/claude.py +41 -0
- package/core/host_acp/cline.py +235 -0
- package/core/host_acp/codex.py +245 -0
- package/core/host_acp/dsh.py +48 -0
- package/core/host_acp/opencode.py +154 -0
- package/core/host_acp/pi.py +36 -0
- package/core/host_acp/zcode.py +41 -0
- package/core/host_runtime/INTERFACE.md +24 -0
- package/core/host_runtime/README.md +62 -0
- package/core/host_runtime/SPEC.md +25 -0
- package/core/host_runtime/__init__.py +21 -0
- package/core/host_runtime/adapters.py +412 -0
- package/core/host_runtime/autonomous_runner.py +1152 -0
- package/core/host_runtime/cline.py +435 -0
- package/core/host_runtime/common.py +103 -0
- package/core/host_runtime/free_models.py +786 -0
- package/core/host_runtime/host_bootstrap.py +389 -0
- package/core/host_runtime/host_evaluators.py +721 -0
- package/core/host_runtime/host_probe.py +41 -0
- package/core/host_runtime/host_provider_arbitrator.py +777 -0
- package/core/host_runtime/host_registry.py +655 -0
- package/core/host_runtime/host_usage.py +127 -0
- package/core/host_runtime/mcp_process_tracker.py +509 -0
- package/core/host_runtime/mcp_registry_gate.py +368 -0
- package/core/hosts/INTERFACE.md +51 -0
- package/core/hosts/README.md +67 -0
- package/core/hosts/SPEC.md +25 -0
- package/core/hosts/__init__.py +136 -0
- package/core/hosts/_base_usage.py +152 -0
- package/core/hosts/_codex_usage.py +297 -0
- package/core/hosts/_dsh_usage.py +184 -0
- package/core/hosts/_mcp_toml.py +365 -0
- package/core/hosts/_zcode_usage.py +269 -0
- package/core/hosts/base.py +451 -0
- package/core/hosts/claude.py +157 -0
- package/core/hosts/cline.py +225 -0
- package/core/hosts/codex.py +948 -0
- package/core/hosts/dsh.py +518 -0
- package/core/hosts/opencode.py +358 -0
- package/core/hosts/pi.py +151 -0
- package/core/hosts/zcode.py +219 -0
- package/core/i18n.py +252 -0
- package/core/infra/README.md +39 -0
- package/core/infra/__init__.py +15 -0
- package/core/infra/build_info.py +86 -0
- package/core/infra/client_metadata.py +185 -0
- package/core/infra/python_runtime.py +540 -0
- package/core/infra/safe_xml.py +221 -0
- package/core/launch_bugx.py +118 -0
- package/core/launch_phases/INTERFACE.md +31 -0
- package/core/launch_phases/README.md +106 -0
- package/core/launch_phases/SPEC.md +25 -0
- package/core/launch_phases/__init__.py +29 -0
- package/core/launch_phases/candidate_revalidation.py +484 -0
- package/core/launch_phases/common.py +1041 -0
- package/core/launch_phases/finding_confirm_phase.py +387 -0
- package/core/launch_phases/finding_settlement.py +1245 -0
- package/core/launch_phases/findings_adjudication.py +666 -0
- package/core/launch_phases/findings_snapshot.py +357 -0
- package/core/launch_phases/judge_phase.py +791 -0
- package/core/launch_phases/lesson_context.py +536 -0
- package/core/launch_phases/lifecycle_reporter.py +627 -0
- package/core/launch_phases/orchestrator_controls.py +682 -0
- package/core/launch_phases/post_commit.py +567 -0
- package/core/launch_phases/post_coverage_sync.py +591 -0
- package/core/launch_phases/post_dry_run.py +817 -0
- package/core/launch_phases/post_observability.py +367 -0
- package/core/launch_phases/post_phase.py +1087 -0
- package/core/launch_phases/post_receipt.py +362 -0
- package/core/launch_phases/post_round_lifecycle.py +786 -0
- package/core/launch_phases/pre_phase.py +1029 -0
- package/core/launch_phases/pre_recon_scout.py +862 -0
- package/core/launch_phases/pre_state_builder.py +1286 -0
- package/core/launch_phases/report_sharing.py +414 -0
- package/core/launch_phases/round_orchestrator.py +1133 -0
- package/core/launch_phases/session_runtime.py +1623 -0
- package/core/launch_phases/startup_gates.py +1022 -0
- package/core/launch_phases/startup_interaction.py +947 -0
- package/core/launch_phases/startup_version_gate.py +873 -0
- package/core/launch_phases/supervisor_bridge.py +1224 -0
- package/core/launch_phases/supervisor_coverage.py +417 -0
- package/core/launch_phases/supervisor_degraded.py +1219 -0
- package/core/launch_phases/worker_barriers.py +414 -0
- package/core/launch_phases/worker_orchestrator.py +1166 -0
- package/core/launch_phases/worker_prior.py +749 -0
- package/core/ledger/INTERFACE.md +35 -0
- package/core/ledger/README.md +160 -0
- package/core/ledger/SPEC.md +25 -0
- package/core/ledger/__init__.py +67 -0
- package/core/ledger/_facade.py +226 -0
- package/core/ledger/archive_ops.py +572 -0
- package/core/ledger/auto_materialization.py +459 -0
- package/core/ledger/bug-log.md +22 -0
- package/core/ledger/cli.py +270 -0
- package/core/ledger/export_ops.py +549 -0
- package/core/ledger/finding_confirmation.py +1274 -0
- package/core/ledger/finding_io.py +299 -0
- package/core/ledger/finding_lifecycle.py +307 -0
- package/core/ledger/finding_verification.py +369 -0
- package/core/ledger/incidents.py +999 -0
- package/core/ledger/lesson-replay-cases.json +20 -0
- package/core/ledger/lesson_ledger.py +241 -0
- package/core/ledger/lesson_replay.py +272 -0
- package/core/ledger/life_ledger.py +668 -0
- package/core/ledger/mistake-book.md +130 -0
- package/core/ledger/patterns.py +681 -0
- package/core/ledger/receipt_contract.py +253 -0
- package/core/ledger/schema.py +1192 -0
- package/core/ledger/sync_ops.py +935 -0
- package/core/ledger/tool_experience.py +682 -0
- package/core/ledger/verify_life.py +1526 -0
- package/core/lesson-ledger.json +275 -0
- package/core/locales/README.md +19 -0
- package/core/locales/en-US.json +462 -0
- package/core/locales/zh-CN.json +462 -0
- package/core/mcp_handlers/INTERFACE.md +75 -0
- package/core/mcp_handlers/README.md +62 -0
- package/core/mcp_handlers/SPEC.md +25 -0
- package/core/mcp_handlers/__init__.py +128 -0
- package/core/mcp_handlers/base.py +697 -0
- package/core/mcp_handlers/channel_lifecycle.py +696 -0
- package/core/mcp_handlers/graph_handlers.py +222 -0
- package/core/mcp_handlers/knowledge_handlers.py +536 -0
- package/core/mcp_handlers/mining_handlers.py +586 -0
- package/core/mcp_handlers/resource_prompt_table.py +116 -0
- package/core/mcp_handlers/retrieval_handlers.py +239 -0
- package/core/mcp_handlers/rpc_server.py +465 -0
- package/core/mcp_handlers/supervisor_handlers.py +1435 -0
- package/core/mcp_handlers/telemetry_handlers.py +227 -0
- package/core/mcp_handlers/tool_table.py +1015 -0
- package/core/mcp_runtime_support/README.md +21 -0
- package/core/mcp_runtime_support/__init__.py +1 -0
- package/core/mcp_runtime_support/common.py +363 -0
- package/core/mcp_runtime_support/environment.py +605 -0
- package/core/mcp_runtime_support/verifier.py +810 -0
- package/core/metadata.txt +5 -0
- package/core/planning/README.md +157 -0
- package/core/planning/__init__.py +242 -0
- package/core/planning/capability_plan.py +187 -0
- package/core/planning/capability_planner.py +195 -0
- package/core/planning/domain_archetype.py +542 -0
- package/core/planning/domain_router.py +267 -0
- package/core/planning/dynamic_flow_analyzer.py +328 -0
- package/core/planning/impact_pruner.py +435 -0
- package/core/planning/intent_adjudicator.py +175 -0
- package/core/planning/judge_pipeline.py +1163 -0
- package/core/planning/logic_analysis.py +419 -0
- package/core/planning/prompt_harness.py +1702 -0
- package/core/planning/source_inspector.py +267 -0
- package/core/planning/spec_harvester.py +449 -0
- package/core/planning/target_sandbox_manager.py +573 -0
- package/core/planning/test_capability_verifier.py +1364 -0
- package/core/planning/tools-kb.md +38 -0
- package/core/planning/unit_kind.py +122 -0
- package/core/probes/INTERFACE.md +73 -0
- package/core/probes/README.md +51 -0
- package/core/probes/SPEC.md +26 -0
- package/core/probes/__init__.py +70 -0
- package/core/probes/android_probe.py +384 -0
- package/core/probes/base.py +147 -0
- package/core/probes/codebase_memory_probe.py +590 -0
- package/core/probes/desktop_probe.py +238 -0
- package/core/probes/differential_probe.py +356 -0
- package/core/probes/efficiency_probe.py +168 -0
- package/core/probes/ios_binary_probe.py +368 -0
- package/core/probes/memory_probe.py +326 -0
- package/core/probes/miniprogram_probe.py +323 -0
- package/core/probes/mobile_probe.py +281 -0
- package/core/probes/native_probe.py +214 -0
- package/core/probes/openwiki_probe.py +193 -0
- package/core/probes/pattern_probe.py +347 -0
- package/core/probes/platform_probe.py +343 -0
- package/core/probes/probe_registry.py +1669 -0
- package/core/probes/sast_probe.py +1009 -0
- package/core/probes/sast_rules.py +841 -0
- package/core/probes/sca_scanner.py +731 -0
- package/core/probes/web_probe.py +359 -0
- package/core/project_profiler/INTERFACE.md +62 -0
- package/core/project_profiler/README.md +53 -0
- package/core/project_profiler/SPEC.md +28 -0
- package/core/project_profiler/__init__.py +201 -0
- package/core/project_profiler/arbitrator.py +311 -0
- package/core/project_profiler/constants.py +247 -0
- package/core/project_profiler/detector.py +392 -0
- package/core/project_profiler/extractors.py +836 -0
- package/core/project_profiler/fingerprint.py +116 -0
- package/core/project_profiler/storage.py +258 -0
- package/core/project_profiler/strategy.py +265 -0
- package/core/prompts/README.md +35 -0
- package/core/prompts/codex_dialog_dispatch.md +9 -0
- package/core/prompts/command_routing_en.md +42 -0
- package/core/prompts/command_routing_zh.md +42 -0
- package/core/prompts/l0_router.md +47 -0
- package/core/prompts/rules/anti_patterns.md +16 -0
- package/core/prompts/rules/concurrency_rules.md +14 -0
- package/core/prompts/rules/memory_leak_rules.md +13 -0
- package/core/prompts/rules/prompt_injection_defense.md +13 -0
- package/core/prompts/stages/stage_explore.md +31 -0
- package/core/prompts/stages/stage_gate.md +43 -0
- package/core/prompts/stages/stage_mutate.md +42 -0
- package/core/prompts/stages/stage_repair.md +85 -0
- package/core/repair/README.md +74 -0
- package/core/repair/__init__.py +169 -0
- package/core/repair/fix_watchlist.py +391 -0
- package/core/repair/l7_dynamic.py +418 -0
- package/core/repair/l7_repair_loop.py +465 -0
- package/core/repair/l7_selfcheck.py +862 -0
- package/core/repair/minimize_repro.py +466 -0
- package/core/repair/patch_synthesizer.py +617 -0
- package/core/repair/regression_pack.py +379 -0
- package/core/repair/rsi_fixer.py +910 -0
- package/core/repair/rsi_loop.py +313 -0
- package/core/repair/rsi_repair.py +348 -0
- package/core/repair/rsi_rounds.py +212 -0
- package/core/repair/rsi_scope.py +262 -0
- package/core/repair/self_heal.py +604 -0
- package/core/repair/test_generator.py +1108 -0
- package/core/repair/test_quality_auditor.py +410 -0
- package/core/repair/test_strategy.py +511 -0
- package/core/report_engine/INTERFACE.md +59 -0
- package/core/report_engine/README.md +69 -0
- package/core/report_engine/SPEC.md +28 -0
- package/core/report_engine/__init__.py +47 -0
- package/core/report_engine/attestation.py +224 -0
- package/core/report_engine/authority.py +255 -0
- package/core/report_engine/finding_report.py +417 -0
- package/core/report_engine/formal_report_builder.py +924 -0
- package/core/report_engine/html_renderers.py +696 -0
- package/core/report_engine/models.py +761 -0
- package/core/report_engine/pdf_exporter.py +231 -0
- package/core/report_engine/projects_assets.py +730 -0
- package/core/report_engine/report_client.py +743 -0
- package/core/report_engine/report_data_builder.py +388 -0
- package/core/report_engine/report_share.py +459 -0
- package/core/report_engine/sast_bridge.py +116 -0
- package/core/report_engine/server.py +822 -0
- package/core/report_engine/visual_report_builder.py +796 -0
- package/core/report_engine/web-conformance.md +63 -0
- package/core/report_engine/web_conformance.py +459 -0
- package/core/report_engine/workbench_assets.py +484 -0
- package/core/retrieval/INTERFACE.md +20 -0
- package/core/retrieval/README.md +161 -0
- package/core/retrieval/SPEC.md +25 -0
- package/core/retrieval/__init__.py +3 -0
- package/core/retrieval/code_analyzer.py +1684 -0
- package/core/retrieval/codebase_memory_bridge.py +337 -0
- package/core/retrieval/context_assembler.py +234 -0
- package/core/retrieval/corpus_fetch.py +369 -0
- package/core/retrieval/graph_ego.py +597 -0
- package/core/retrieval/knowledge_auto.py +662 -0
- package/core/retrieval/knowledge_sources.py +168 -0
- package/core/retrieval/knowledge_sync.py +909 -0
- package/core/retrieval/memory_store.py +480 -0
- package/core/retrieval/query_planner.py +1020 -0
- package/core/retrieval/rrf_engine.py +137 -0
- package/core/retrieval/slice_extractor.py +1209 -0
- package/core/retrieval/slice_normalizer.py +373 -0
- package/core/retrieval/slice_spec.py +357 -0
- package/core/retrieval/symbol_index.py +1132 -0
- package/core/retrieval/universal_code_matcher.py +437 -0
- package/core/retrieval/xerj_bridge.py +476 -0
- package/core/retrieval/xerj_supervisor.py +362 -0
- package/core/rules/README.md +33 -0
- package/core/rules/ios/PROVENANCE.json +30 -0
- package/core/rules/ios/crypto.yaml +36 -0
- package/core/rules/ios/network.yaml +20 -0
- package/core/rules/ios/resilience.yaml +47 -0
- package/core/rules/ios/storage.yaml +48 -0
- package/core/rules/mastg/LICENSE +173 -0
- package/core/rules/mastg/PROVENANCE.json +270 -0
- package/core/rules/mastg/mastg-android-asymmetric-key-pair-used-for-multiple-purposes.yml +13 -0
- package/core/rules/mastg/mastg-android-backup-manifest.yml +24 -0
- package/core/rules/mastg/mastg-android-biometric-event-bound.yml +49 -0
- package/core/rules/mastg/mastg-android-biometric-invalidated-enrollment.yml +11 -0
- package/core/rules/mastg/mastg-android-biometric-no-confirmation-required.yml +10 -0
- package/core/rules/mastg/mastg-android-biometric-validity-duration.yml +24 -0
- package/core/rules/mastg/mastg-android-broken-encryption-algorithms.yaml +9 -0
- package/core/rules/mastg/mastg-android-broken-encryption-modes.yaml +13 -0
- package/core/rules/mastg/mastg-android-content-provider-exported.yml +35 -0
- package/core/rules/mastg/mastg-android-custom-deeplink-scheme.yml +29 -0
- package/core/rules/mastg/mastg-android-dangerous-app-permissions.yaml +65 -0
- package/core/rules/mastg/mastg-android-data-unencrypted-shared-storage-no-user-interaction-apis.yml +36 -0
- package/core/rules/mastg/mastg-android-data-unencrypted-shared-storage-no-user-interaction-manifest.yml +15 -0
- package/core/rules/mastg/mastg-android-debuggable-flag.yml +10 -0
- package/core/rules/mastg/mastg-android-debugger-checks.yml +12 -0
- package/core/rules/mastg/mastg-android-deeplink-autoverify-missing.yml +33 -0
- package/core/rules/mastg/mastg-android-deeplink-unvalidated-parameter.yml +11 -0
- package/core/rules/mastg/mastg-android-device-passcode-present.yml +17 -0
- package/core/rules/mastg/mastg-android-fileprovider-broad-scope.yml +46 -0
- package/core/rules/mastg/mastg-android-hardcoded-crypto-keys-usage.yml +14 -0
- package/core/rules/mastg/mastg-android-hardcoded-security-provider.yaml +18 -0
- package/core/rules/mastg/mastg-android-implicit-intent-internal-communication.yml +30 -0
- package/core/rules/mastg/mastg-android-implicit-intent-leaking-extras.yml +29 -0
- package/core/rules/mastg/mastg-android-input-field-usage.yml +11 -0
- package/core/rules/mastg/mastg-android-key-generation-with-insufficient-key-length.yml +21 -0
- package/core/rules/mastg/mastg-android-keyboard-cache-input-types.yml +10 -0
- package/core/rules/mastg/mastg-android-local-storage-input-validation.yml +48 -0
- package/core/rules/mastg/mastg-android-native-debugger-checks.yml +12 -0
- package/core/rules/mastg/mastg-android-network-checkservertrusted.yml +12 -0
- package/core/rules/mastg/mastg-android-network-hostname-verification.yml +11 -0
- package/core/rules/mastg/mastg-android-network-insecure-trust-anchors.yml +11 -0
- package/core/rules/mastg/mastg-android-network-onreceivedsslerror.yml +12 -0
- package/core/rules/mastg/mastg-android-non-random-use.yml +16 -0
- package/core/rules/mastg/mastg-android-object-deserialization.yml +14 -0
- package/core/rules/mastg/mastg-android-overlay-protection.yml +68 -0
- package/core/rules/mastg/mastg-android-pendingintent-mutable.yml +39 -0
- package/core/rules/mastg/mastg-android-random-apis-insufficient-entropy.yml +17 -0
- package/core/rules/mastg/mastg-android-root-detection.yaml +59 -0
- package/core/rules/mastg/mastg-android-sdk-version.yml +10 -0
- package/core/rules/mastg/mastg-android-sensitive-data-in-notifications-manifest.yml +17 -0
- package/core/rules/mastg/mastg-android-sensitive-data-in-notifications.yml +11 -0
- package/core/rules/mastg/mastg-android-sensitive-data-in-screenshot.yml +18 -0
- package/core/rules/mastg/mastg-android-sql-injection-contentprovider.yml +17 -0
- package/core/rules/mastg/mastg-android-ssl-socket-hostnameverifier.yml +15 -0
- package/core/rules/mastg/mastg-android-strictmode.yml +10 -0
- package/core/rules/mastg/mastg-android-system-alert-window.yml +9 -0
- package/core/rules/mastg/mastg-android-webview-allow-local-access.yml +15 -0
- package/core/rules/mastg/mastg-android-webview-bridges.yml +28 -0
- package/core/rules/mastg/mastg-android-webview-safebrowsing.yml +20 -0
- package/core/rules/mastg/mastg-android-webview-url-handlers.yml +41 -0
- package/core/rules/miniprogram/PROVENANCE.json +26 -0
- package/core/rules/miniprogram/network.yaml +37 -0
- package/core/rules/miniprogram/platform.yaml +36 -0
- package/core/rules/miniprogram/storage.yaml +48 -0
- package/core/rules/mobsfscan-swift/LICENSE +165 -0
- package/core/rules/mobsfscan-swift/PROVENANCE.json +58 -0
- package/core/rules/mobsfscan-swift/auth.yaml +59 -0
- package/core/rules/mobsfscan-swift/crypto.yaml +66 -0
- package/core/rules/mobsfscan-swift/jailbreak.yaml +14 -0
- package/core/rules/mobsfscan-swift/keyboard.yaml +34 -0
- package/core/rules/mobsfscan-swift/logging.yaml +23 -0
- package/core/rules/mobsfscan-swift/network.yaml +55 -0
- package/core/rules/mobsfscan-swift/resilience.yaml +29 -0
- package/core/rules/mobsfscan-swift/secrets.yaml +33 -0
- package/core/rules/mobsfscan-swift/storage.yaml +29 -0
- package/core/rules/mobsfscan-swift/webview.yaml +32 -0
- package/core/runtime/README.md +198 -0
- package/core/runtime/__init__.py +3 -0
- package/core/runtime/bugx_logging.py +1393 -0
- package/core/runtime/daemon_runner.py +623 -0
- package/core/runtime/fixture_solidify.py +449 -0
- package/core/runtime/global_telemetry.py +549 -0
- package/core/runtime/incident_eval.py +148 -0
- package/core/runtime/interaction.py +605 -0
- package/core/runtime/interaction_store.py +435 -0
- package/core/runtime/interactive_menu.py +95 -0
- package/core/runtime/log_analytics.py +922 -0
- package/core/runtime/mining_quality_framework.py +1387 -0
- package/core/runtime/model_runner.py +769 -0
- package/core/runtime/platform_adapter.py +579 -0
- package/core/runtime/prep_validate.py +476 -0
- package/core/runtime/project_graph.py +827 -0
- package/core/runtime/project_init.py +481 -0
- package/core/runtime/project_profile.py +224 -0
- package/core/runtime/project_settings.py +963 -0
- package/core/runtime/provider_window.py +97 -0
- package/core/runtime/resume_ticket.py +115 -0
- package/core/runtime/scenario_eval.py +814 -0
- package/core/runtime/seed_drill.py +549 -0
- package/core/runtime/self_audit.py +550 -0
- package/core/runtime/session_profile.py +205 -0
- package/core/runtime/setup_ui_env.py +229 -0
- package/core/runtime/startup_environment.py +859 -0
- package/core/runtime/sync_store.py +1421 -0
- package/core/runtime/tool_install_targets.py +18 -0
- package/core/schemas/README.md +35 -0
- package/core/schemas/agent-graph.schema.json +368 -0
- package/core/schemas/attack-graph.schema.json +88 -0
- package/core/schemas/evidence-bundle.schema.json +33 -0
- package/core/schemas/skill-pack.schema.json +230 -0
- package/core/schemas/worker-checkpoint.schema.json +119 -0
- package/core/secure_atomic.py +289 -0
- package/core/seed_corpus/README.md +55 -0
- package/core/seed_corpus/c.txt +29 -0
- package/core/seed_corpus/cpp.txt +32 -0
- package/core/seed_corpus/css.txt +70 -0
- package/core/seed_corpus/go.txt +46 -0
- package/core/seed_corpus/java.txt +30 -0
- package/core/seed_corpus/javascript.txt +55 -0
- package/core/seed_corpus/kotlin.txt +28 -0
- package/core/seed_corpus/python.txt +71 -0
- package/core/seed_corpus/rust.txt +53 -0
- package/core/seed_corpus/swift.txt +29 -0
- package/core/seed_corpus/typescript.txt +29 -0
- package/core/skills/README.md +53 -0
- package/core/skills/__init__.py +189 -0
- package/core/skills/bugx_docs_mcp_server.py +416 -0
- package/core/skills/bugx_mcp_server.py +1134 -0
- package/core/skills/mcp_runtime.py +968 -0
- package/core/skills/mcp_session_proof.py +605 -0
- package/core/skills/mobile_ui_inspector.py +405 -0
- package/core/skills/skill_pack.py +1214 -0
- package/core/skills/skill_synthesizer.py +1153 -0
- package/core/skills/tools_kb.py +313 -0
- package/core/supervisor/INTERFACE.md +121 -0
- package/core/supervisor/README.md +209 -0
- package/core/supervisor/SPEC.md +25 -0
- package/core/supervisor/__init__.py +175 -0
- package/core/supervisor/audit_supervisor.py +1015 -0
- package/core/supervisor/budget_governor.py +760 -0
- package/core/supervisor/checkpoint_handler.py +368 -0
- package/core/supervisor/checkpoint_pipeline.py +1322 -0
- package/core/supervisor/checkpoint_sync.py +640 -0
- package/core/supervisor/claim_events.py +74 -0
- package/core/supervisor/claim_sync.py +590 -0
- package/core/supervisor/cli.py +812 -0
- package/core/supervisor/context_sync.py +55 -0
- package/core/supervisor/coverage_sync.py +115 -0
- package/core/supervisor/finding_commit.py +470 -0
- package/core/supervisor/finding_sync.py +688 -0
- package/core/supervisor/finding_workflow.py +659 -0
- package/core/supervisor/finish_policy.py +224 -0
- package/core/supervisor/finish_sync.py +185 -0
- package/core/supervisor/graph_sync.py +669 -0
- package/core/supervisor/lease_manager.py +788 -0
- package/core/supervisor/lifecycle_blocks.py +124 -0
- package/core/supervisor/next_round_sync.py +126 -0
- package/core/supervisor/observability.py +140 -0
- package/core/supervisor/recovery_sync.py +165 -0
- package/core/supervisor/rejection_remedies.py +308 -0
- package/core/supervisor/round_governor.py +306 -0
- package/core/supervisor/serial_authorization.py +500 -0
- package/core/supervisor/start_sync.py +87 -0
- package/core/supervisor/state_store.py +249 -0
- package/core/supervisor/supervisor_host.py +511 -0
- package/core/supervisor/supervisor_models.py +1143 -0
- package/core/supervisor/systemic_failure.py +104 -0
- package/core/supervisor/task_scheduler.py +1640 -0
- package/core/supervisor/worker_checkpoint.py +223 -0
- package/core/supervisor/worker_execution.py +265 -0
- package/core/supervisor/worker_handoff.py +192 -0
- package/core/supervisor/worker_lifecycle.py +396 -0
- package/core/supervisor/worker_runtime.py +999 -0
- package/core/supervisor/worker_sync.py +89 -0
- package/core/supervisor_types/README.md +36 -0
- package/core/supervisor_types/__init__.py +0 -0
- package/core/supervisor_types/exceptions.py +52 -0
- package/core/supervisor_types/graph_models.py +357 -0
- package/core/supervisor_types/path_containment.py +151 -0
- package/core/supervisor_types/target_fingerprint.py +310 -0
- package/core/supervisor_types/worker_claim.py +402 -0
- package/core/webui/INTERFACE.md +50 -0
- package/core/webui/README.md +57 -0
- package/core/webui/SPEC.md +25 -0
- package/core/webui/__init__.py +11 -0
- package/core/webui/adapters/__init__.py +27 -0
- package/core/webui/adapters/base.py +87 -0
- package/core/webui/adapters/bugx.py +102 -0
- package/core/webui/adapters/claude.py +218 -0
- package/core/webui/adapters/cline.py +399 -0
- package/core/webui/adapters/codex.py +256 -0
- package/core/webui/adapters/dsh.py +173 -0
- package/core/webui/adapters/opencode.py +218 -0
- package/core/webui/adapters/pi.py +272 -0
- package/core/webui/adapters/registry.py +100 -0
- package/core/webui/adapters/zcode.py +312 -0
- package/core/webui/api_routes_post.py +668 -0
- package/core/webui/dispatcher.py +1376 -0
- package/core/webui/docs_session_service.py +473 -0
- package/core/webui/handler.py +674 -0
- package/core/webui/ide_cloud_service.py +526 -0
- package/core/webui/mcp_inspector.py +1743 -0
- package/core/webui/static/assets/index-CXAsl8mr.js +333 -0
- package/core/webui/static/assets/index-DHQUtWtx.css +1 -0
- package/core/webui/static/assets/source-serif-4-cyrillic-400-normal-B8Z6Jvzv.woff +0 -0
- package/core/webui/static/assets/source-serif-4-cyrillic-400-normal-C44pakCn.woff2 +0 -0
- package/core/webui/static/assets/source-serif-4-cyrillic-500-normal-Bb4u56_6.woff +0 -0
- package/core/webui/static/assets/source-serif-4-cyrillic-500-normal-BdVUvljg.woff2 +0 -0
- package/core/webui/static/assets/source-serif-4-cyrillic-ext-400-normal-CWV284fw.woff2 +0 -0
- package/core/webui/static/assets/source-serif-4-cyrillic-ext-400-normal-DLkyKLvH.woff +0 -0
- package/core/webui/static/assets/source-serif-4-cyrillic-ext-500-normal-8-8HP2PF.woff +0 -0
- package/core/webui/static/assets/source-serif-4-cyrillic-ext-500-normal-DaDZE_Na.woff2 +0 -0
- package/core/webui/static/assets/source-serif-4-greek-400-normal-BccYJ-vZ.woff +0 -0
- package/core/webui/static/assets/source-serif-4-greek-400-normal-Cw5-AHNN.woff2 +0 -0
- package/core/webui/static/assets/source-serif-4-greek-500-normal-By8GFJzz.woff2 +0 -0
- package/core/webui/static/assets/source-serif-4-greek-500-normal-z-Q6FFuG.woff +0 -0
- package/core/webui/static/assets/source-serif-4-latin-400-normal-DJ5YJwmz.woff2 +0 -0
- package/core/webui/static/assets/source-serif-4-latin-400-normal-Dn3IlU-Z.woff +0 -0
- package/core/webui/static/assets/source-serif-4-latin-500-normal-CUHe9xxf.woff2 +0 -0
- package/core/webui/static/assets/source-serif-4-latin-500-normal-DVVamBqs.woff +0 -0
- package/core/webui/static/assets/source-serif-4-latin-ext-400-normal-CEpydyUl.woff +0 -0
- package/core/webui/static/assets/source-serif-4-latin-ext-400-normal-Cp7z-ARB.woff2 +0 -0
- package/core/webui/static/assets/source-serif-4-latin-ext-500-normal-BYjRCDVy.woff2 +0 -0
- package/core/webui/static/assets/source-serif-4-latin-ext-500-normal-D-qasQTj.woff +0 -0
- package/core/webui/static/assets/source-serif-4-vietnamese-400-normal-BbG3LG1A.woff2 +0 -0
- package/core/webui/static/assets/source-serif-4-vietnamese-400-normal-DR1UuFon.woff +0 -0
- package/core/webui/static/assets/source-serif-4-vietnamese-500-normal-8N8MYVKB.woff +0 -0
- package/core/webui/static/assets/source-serif-4-vietnamese-500-normal-Bi3OSTTW.woff2 +0 -0
- package/core/webui/static/favicon.png +0 -0
- package/core/webui/static/icon-192.png +0 -0
- package/core/webui/static/index.html +42 -0
- package/core/webui/static/manifest.webmanifest +19 -0
- package/core/webui/static/project-settings.css +6458 -0
- package/core/webui/static/project-settings.js +9602 -0
- package/core/webui/static/sw.js +8 -0
- package/core/webui/workspace_service.py +218 -0
- package/docs/07_distribution/01_README_NPM.md +281 -0
- package/docs/07_distribution/README.md +16 -0
- package/docs/README.md +121 -0
- package/ecosystem/README.md +129 -0
- package/ecosystem/integrations/README.md +38 -0
- package/ecosystem/integrations/cline/skills/bugx/SKILL.md +69 -0
- package/ecosystem/integrations/dsh/agents/bugx.md +27 -0
- package/ecosystem/integrations/dsh/dsh-patch.yml +18 -0
- package/ecosystem/integrations/dsh/mcp/cordis.patch.yml +4 -0
- package/ecosystem/integrations/dsh/mcp/index.js +219 -0
- package/ecosystem/integrations/dsh/mcp/package.json +28 -0
- package/ecosystem/integrations/dsh/skills/bugx/SKILL.md +70 -0
- package/ecosystem/integrations/dsh/skills/bugx-dsh/SKILL.md +229 -0
- package/ecosystem/integrations/dsh/ui/client.js +87 -0
- package/ecosystem/integrations/dsh/ui/cordis.patch.yml +4 -0
- package/ecosystem/integrations/dsh/ui/index.js +7 -0
- package/ecosystem/integrations/dsh/ui/package.json +27 -0
- package/ecosystem/integrations/opencode/bugx-mcp-manifest.json +53 -0
- package/ecosystem/integrations/opencode/mcp-lock.json +3067 -0
- package/ecosystem/integrations/opencode/opencode.json +118 -0
- package/ecosystem/integrations/pi/extensions/bugx/README.md +12 -0
- package/ecosystem/integrations/pi/extensions/bugx/index.ts +299 -0
- package/ecosystem/integrations/pi/extensions/bugx/manifest.json +11 -0
- package/ecosystem/integrations/pi/skills/bugx/SKILL.md +69 -0
- package/ecosystem/integrations/qoder/CONNECTORS.md +54 -0
- package/ecosystem/integrations/qoder/connector-meta.json +21 -0
- package/ecosystem/integrations/workbuddy/connector-meta.json +19 -0
- package/ecosystem/integrations/workbuddy/icon.png +0 -0
- package/ecosystem/integrations/workbuddy/skills/bugx/SKILL.md +70 -0
- package/ecosystem/plugins/README.md +37 -0
- package/ecosystem/plugins/bugx/.claude-plugin/marketplace.json +17 -0
- package/ecosystem/plugins/bugx/.claude-plugin/plugin.json +16 -0
- package/ecosystem/plugins/bugx/.codex-plugin/plugin.json +41 -0
- package/ecosystem/plugins/bugx/.zcode-plugin/plugin.json +19 -0
- package/ecosystem/plugins/bugx/agents/bugx-judge.md +71 -0
- package/ecosystem/plugins/bugx/agents/bugx-worker.md +31 -0
- package/ecosystem/plugins/bugx/agents/bugx.md +74 -0
- package/ecosystem/plugins/bugx/assets/bugx-avatar-512.png +0 -0
- package/ecosystem/plugins/bugx/skills/bugx/SKILL.md +118 -0
- package/ecosystem/plugins/bugx/skills/bugx-claude/SKILL.md +326 -0
- package/ecosystem/plugins/bugx/skills/bugx-dsh/SKILL.md +229 -0
- package/ecosystem/plugins/bugx/skills/bugx-opencode/SKILL.md +129 -0
- package/ecosystem/plugins/bugx/skills/bugx-zcode/SKILL.md +459 -0
- package/interfaces/README.md +143 -0
- package/interfaces/bin/README.md +35 -0
- package/interfaces/bin/bugx.js +80 -0
- package/interfaces/cli/README.md +90 -0
- package/interfaces/cli/bugx_cli/__init__.py +4 -0
- package/interfaces/cli/bugx_cli/cli.py +1678 -0
- package/interfaces/cli/bugx_cli/commands/__init__.py +1 -0
- package/interfaces/cli/bugx_cli/commands/advisory.py +94 -0
- package/interfaces/cli/bugx_cli/commands/agent.py +3944 -0
- package/interfaces/cli/bugx_cli/commands/audit.py +632 -0
- package/interfaces/cli/bugx_cli/commands/autonomous.py +260 -0
- package/interfaces/cli/bugx_cli/commands/cloud.py +1370 -0
- package/interfaces/cli/bugx_cli/commands/daemon.py +50 -0
- package/interfaces/cli/bugx_cli/commands/doctor.py +1345 -0
- package/interfaces/cli/bugx_cli/commands/goal.py +107 -0
- package/interfaces/cli/bugx_cli/commands/interaction.py +244 -0
- package/interfaces/cli/bugx_cli/commands/knowledge.py +617 -0
- package/interfaces/cli/bugx_cli/commands/lifecycle.py +2763 -0
- package/interfaces/cli/bugx_cli/commands/patch.py +1014 -0
- package/interfaces/cli/bugx_cli/commands/plugin.py +2714 -0
- package/interfaces/cli/bugx_cli/commands/plugin_claude.py +1446 -0
- package/interfaces/cli/bugx_cli/commands/plugin_cline.py +269 -0
- package/interfaces/cli/bugx_cli/commands/plugin_codex.py +74 -0
- package/interfaces/cli/bugx_cli/commands/plugin_funide.py +728 -0
- package/interfaces/cli/bugx_cli/commands/plugin_qoder.py +216 -0
- package/interfaces/cli/bugx_cli/commands/plugin_zcode.py +710 -0
- package/interfaces/cli/bugx_cli/commands/project.py +670 -0
- package/interfaces/cli/bugx_cli/commands/report.py +260 -0
- package/interfaces/cli/bugx_cli/commands/skill.py +251 -0
- package/interfaces/cli/bugx_cli/commands/stats.py +133 -0
- package/interfaces/cli/bugx_cli/commands/system.py +2567 -0
- package/interfaces/cli/bugx_cli/common.py +898 -0
- package/interfaces/cli/bugx_cli/host_adapters.py +1917 -0
- package/interfaces/cli/bugx_cli/hosts/__init__.py +80 -0
- package/interfaces/cli/bugx_cli/hosts/base.py +99 -0
- package/interfaces/cli/bugx_cli/hosts/registry.py +571 -0
- package/interfaces/cli/bugx_cli/hosts/template_engine.py +188 -0
- package/interfaces/cli/bugx_cli/infra/__init__.py +209 -0
- package/interfaces/cli/bugx_cli/infra/ai_advisor.py +721 -0
- package/interfaces/cli/bugx_cli/infra/engine_installer.py +1937 -0
- package/interfaces/cli/bugx_cli/infra/host_sync.py +545 -0
- package/interfaces/cli/bugx_cli/infra/mcp_advisor.py +755 -0
- package/interfaces/cli/bugx_cli/infra/security.py +332 -0
- package/package.json +98 -4
- package/pyproject.toml +246 -0
- package/scripts/README.md +118 -0
- package/scripts/ensure-python.mjs +97 -0
- package/scripts/isolate-npm-readme.mjs +40 -0
- package/scripts/runtime.lock.json +31 -0
- package/scripts/sync-version.mjs +37 -0
- package/scripts/test-npm-wrapper.mjs +265 -0
|
@@ -0,0 +1,629 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""differential_oracle.py — 确定性沙盒隔离双跑差分验证器(DESIGN-A1)。
|
|
3
|
+
|
|
4
|
+
用途:
|
|
5
|
+
消除由于本地残留文件、端口占用、时钟/随机数抖动或环境污染造成的假阳性与 Flaky 幽灵用例。
|
|
6
|
+
所有触发异常的候选 Finding / PoC 在两个完全独立的临时沙盒环境中连续执行 2 次:
|
|
7
|
+
1. 归一化清洗:剥离内存地址(0x...)、时间戳、临时路径、PID 等非确定性噪音;
|
|
8
|
+
2. 双跑差分裁决:
|
|
9
|
+
- CONFIRMED_DETERMINISTIC: 两次独立双跑一致崩溃且堆栈签名对齐,确认为真实确定性 Bug;
|
|
10
|
+
- FLAKY_JITTER: 退出码或异常特征不一致,判定为偶发抖动用例,拦截防污染错题集;
|
|
11
|
+
- FALSE_POSITIVE: 两次双跑均正常退出(exit 0),判定为无法复现的环境假阳性;
|
|
12
|
+
3. 契约工件输出:生成符合 finding_confirmation.py 规范的完整证据链工件与 SHA-256 指纹。
|
|
13
|
+
|
|
14
|
+
CLI 用法:
|
|
15
|
+
python3 differential_oracle.py verify \
|
|
16
|
+
--cmd 'python3 target.py {input}' \
|
|
17
|
+
--input /path/to/poc.json \
|
|
18
|
+
[--timeout 10] [--json] [--out report.json]
|
|
19
|
+
"""
|
|
20
|
+
|
|
21
|
+
from __future__ import annotations
|
|
22
|
+
# --- 引擎导入根(直接执行脚本时自举 core.* 命名空间)---
|
|
23
|
+
import sys as _sys
|
|
24
|
+
from pathlib import Path as _Path
|
|
25
|
+
|
|
26
|
+
for _p in _Path(__file__).resolve().parents:
|
|
27
|
+
if (_p / "core" / "bugx.md").is_file():
|
|
28
|
+
if str(_p) not in _sys.path:
|
|
29
|
+
_sys.path.insert(0, str(_p))
|
|
30
|
+
break
|
|
31
|
+
del _p
|
|
32
|
+
|
|
33
|
+
import argparse
|
|
34
|
+
import hashlib
|
|
35
|
+
import json
|
|
36
|
+
import os
|
|
37
|
+
import re
|
|
38
|
+
import shlex
|
|
39
|
+
import shutil
|
|
40
|
+
import subprocess
|
|
41
|
+
import sys
|
|
42
|
+
import tempfile
|
|
43
|
+
import time
|
|
44
|
+
from dataclasses import asdict, dataclass
|
|
45
|
+
from pathlib import Path
|
|
46
|
+
from typing import Any, Mapping
|
|
47
|
+
|
|
48
|
+
_CORE_DIR = Path(__file__).resolve().parents[1]
|
|
49
|
+
if str(_CORE_DIR) not in sys.path:
|
|
50
|
+
sys.path.insert(0, str(_CORE_DIR))
|
|
51
|
+
|
|
52
|
+
from core.supervisor.worker_execution import run_bounded
|
|
53
|
+
|
|
54
|
+
SCHEMA_VERSION = 1
|
|
55
|
+
_SHELL_PUNCTUATION = ";&|<>`$()"
|
|
56
|
+
_SHELL_OPERATORS = frozenset({
|
|
57
|
+
";", "&", "&&", "|", "||", "<", ">", ">>", "<<", "<&", ">&",
|
|
58
|
+
"`", "$(", "(", ")",
|
|
59
|
+
})
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
class DifferentialOracleError(ValueError):
|
|
63
|
+
"""差分验证器异常。"""
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
@dataclass(frozen=True)
|
|
67
|
+
class RunResult:
|
|
68
|
+
exit_code: int
|
|
69
|
+
duration_ms: float
|
|
70
|
+
stdout: str
|
|
71
|
+
stderr: str
|
|
72
|
+
normalized_signature: str
|
|
73
|
+
timed_out: bool = False
|
|
74
|
+
infrastructure_error: bool = False
|
|
75
|
+
infrastructure_reason: str = ""
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
_INFRASTRUCTURE_PATTERNS = (
|
|
79
|
+
re.compile(r"\b(?:no such file or directory|enoent)\b", re.IGNORECASE),
|
|
80
|
+
re.compile(r"\b(?:command not found|executable file not found)\b", re.IGNORECASE),
|
|
81
|
+
re.compile(r"\b(?:permission denied|eacces|eperm)\b", re.IGNORECASE),
|
|
82
|
+
)
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
def _infrastructure_failure_reason(
|
|
86
|
+
*,
|
|
87
|
+
exit_code: int,
|
|
88
|
+
stderr: str,
|
|
89
|
+
stdout: str,
|
|
90
|
+
launch_error: str | None = None,
|
|
91
|
+
) -> str | None:
|
|
92
|
+
"""Classify launch/environment failures before applying the dual-run rule.
|
|
93
|
+
|
|
94
|
+
The oracle must not turn a stable inability to launch/read the requested
|
|
95
|
+
command or target into a confirmed defect. This classifier is deliberately
|
|
96
|
+
conservative: an ambiguous infrastructure-looking message is downgraded
|
|
97
|
+
to ``INFRA_ERROR`` and retained in the report for human review.
|
|
98
|
+
"""
|
|
99
|
+
if launch_error:
|
|
100
|
+
return launch_error[:400]
|
|
101
|
+
combined = "\n".join(part for part in (stderr, stdout) if part)
|
|
102
|
+
for pattern in _INFRASTRUCTURE_PATTERNS:
|
|
103
|
+
match = pattern.search(combined)
|
|
104
|
+
if match:
|
|
105
|
+
return match.group(0)
|
|
106
|
+
if exit_code in {126, 127}:
|
|
107
|
+
return f"exit {exit_code} indicates command launch failure"
|
|
108
|
+
return None
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
def _temporary_input(content: str, *, suffix: str = ".tmp") -> Path:
|
|
112
|
+
handle = tempfile.NamedTemporaryFile(
|
|
113
|
+
"w", delete=False, encoding="utf-8", suffix=suffix,
|
|
114
|
+
)
|
|
115
|
+
try:
|
|
116
|
+
handle.write(content)
|
|
117
|
+
handle.flush()
|
|
118
|
+
finally:
|
|
119
|
+
handle.close()
|
|
120
|
+
return Path(handle.name)
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
def _materialize_poc_input(
|
|
124
|
+
poc_input: Any,
|
|
125
|
+
*,
|
|
126
|
+
allow_raw_string: bool = True,
|
|
127
|
+
base_dir: Path | None = None,
|
|
128
|
+
) -> tuple[Path, Path | None]:
|
|
129
|
+
"""Resolve a path or materialize textual/JSON PoC input.
|
|
130
|
+
|
|
131
|
+
Worker findings are allowed to carry a structured JSON value. Converting
|
|
132
|
+
that value with ``str()`` would produce a Python representation which is
|
|
133
|
+
not the JSON contract expected by the target command, so mappings/sequences
|
|
134
|
+
are serialized explicitly.
|
|
135
|
+
"""
|
|
136
|
+
if isinstance(poc_input, (str, os.PathLike)):
|
|
137
|
+
try:
|
|
138
|
+
candidate = Path(poc_input)
|
|
139
|
+
except TypeError as exc:
|
|
140
|
+
raise DifferentialOracleError("PoC 输入路径类型无效") from exc
|
|
141
|
+
if base_dir is not None and not candidate.is_absolute():
|
|
142
|
+
candidate = base_dir / candidate
|
|
143
|
+
try:
|
|
144
|
+
is_file = candidate.is_file()
|
|
145
|
+
except OSError:
|
|
146
|
+
# A long or otherwise invalid textual payload is still valid raw
|
|
147
|
+
# input; only a PathLike value must resolve to a real file.
|
|
148
|
+
is_file = False
|
|
149
|
+
if is_file:
|
|
150
|
+
return candidate, None
|
|
151
|
+
if not isinstance(poc_input, str) or not allow_raw_string:
|
|
152
|
+
raise DifferentialOracleError(f"输入 PoC 文件不存在: {candidate}")
|
|
153
|
+
temporary = _temporary_input(poc_input)
|
|
154
|
+
return temporary, temporary
|
|
155
|
+
|
|
156
|
+
if isinstance(poc_input, (Mapping, list, tuple)):
|
|
157
|
+
try:
|
|
158
|
+
serialized = json.dumps(
|
|
159
|
+
poc_input,
|
|
160
|
+
ensure_ascii=False,
|
|
161
|
+
sort_keys=True,
|
|
162
|
+
separators=(",", ":"),
|
|
163
|
+
allow_nan=False,
|
|
164
|
+
)
|
|
165
|
+
except (TypeError, ValueError) as exc:
|
|
166
|
+
raise DifferentialOracleError(f"结构化 PoC 输入无法序列化为 JSON: {exc}") from exc
|
|
167
|
+
temporary = _temporary_input(serialized, suffix=".json")
|
|
168
|
+
return temporary, temporary
|
|
169
|
+
|
|
170
|
+
raise DifferentialOracleError(
|
|
171
|
+
"PoC 输入必须是文件路径、字符串或 JSON 对象/数组"
|
|
172
|
+
)
|
|
173
|
+
|
|
174
|
+
|
|
175
|
+
def normalize_output(text: str) -> str:
|
|
176
|
+
"""归一化清洗输出:消除内存地址、时间戳、临时目录路径、PID 等非确定性干扰。"""
|
|
177
|
+
if not text:
|
|
178
|
+
return ""
|
|
179
|
+
|
|
180
|
+
cleaned = text
|
|
181
|
+
|
|
182
|
+
# 1. 优先清洗 Python 异常堆栈中的行号微小偏移或文件路径尾缀,保留文件名
|
|
183
|
+
cleaned = re.sub(r'File ".*?[/\\]([^/\\]+\.py)"', r'File "\1"', cleaned)
|
|
184
|
+
|
|
185
|
+
# 2. 清洗十六进制内存地址 (如 0x7ffee1234567)
|
|
186
|
+
cleaned = re.sub(r"0x[0-9a-fA-F]{4,16}", "0x<ADDR>", cleaned)
|
|
187
|
+
|
|
188
|
+
# 3. 清洗绝对临时目录 (如 /tmp/..., /var/folders/..., C:\Users\...\Temp\...)
|
|
189
|
+
cleaned = re.sub(r"/(?:private/)?(?:var|tmp)/[a-zA-Z0-9_\-./]+", "<TEMP_DIR>", cleaned)
|
|
190
|
+
cleaned = re.sub(r"[A-Za-z]:\\[^ \r\n\t:]+", "<TEMP_DIR>", cleaned)
|
|
191
|
+
|
|
192
|
+
# 4. 清洗 ISO / 标准时间戳 (如 2026-09-06T07:15:10, 2026-09-06 07:15:10)
|
|
193
|
+
cleaned = re.sub(r"\d{4}-\d{2}-\d{2}[T ]\d{2}:\d{2}:\d{2}(?:\.\d+)?(?:Z|[+-]\d{2}:\d{2})?", "<TIMESTAMP>", cleaned)
|
|
194
|
+
|
|
195
|
+
# 5. 统一换行与空行收拢
|
|
196
|
+
lines = [line.strip() for line in cleaned.splitlines() if line.strip()]
|
|
197
|
+
return "\n".join(lines)
|
|
198
|
+
|
|
199
|
+
|
|
200
|
+
def extract_crash_signature(exit_code: int, stderr: str, stdout: str) -> str:
|
|
201
|
+
"""提取崩溃签名:捕获异常类型、致命信号或关键退出信息。"""
|
|
202
|
+
normalized_err = normalize_output(stderr)
|
|
203
|
+
normalized_out = normalize_output(stdout)
|
|
204
|
+
|
|
205
|
+
# 匹配经典 Python / Java / Rust / C 异常信息
|
|
206
|
+
exception_patterns = [
|
|
207
|
+
r"([A-Za-z_]+Error: [^\n]+)",
|
|
208
|
+
r"(Exception: [^\n]+)",
|
|
209
|
+
r"(panicked at '[^']+')",
|
|
210
|
+
r"(panic: [^\n]+)",
|
|
211
|
+
r"(fatal error: [^\n]+)",
|
|
212
|
+
r"(Segmentation fault[^\n]*)",
|
|
213
|
+
r"(Aborted[^\n]*)",
|
|
214
|
+
]
|
|
215
|
+
for pat in exception_patterns:
|
|
216
|
+
match = re.search(pat, normalized_err) or re.search(pat, normalized_out)
|
|
217
|
+
if match:
|
|
218
|
+
return match.group(1).strip()
|
|
219
|
+
|
|
220
|
+
# 兜底:若有 stderr 取最后一行,否则取非零退出码签名
|
|
221
|
+
if normalized_err:
|
|
222
|
+
last_line = normalized_err.splitlines()[-1].strip()
|
|
223
|
+
return f"STDERR: {last_line[:120]}"
|
|
224
|
+
return f"EXIT_CODE_{exit_code}"
|
|
225
|
+
|
|
226
|
+
|
|
227
|
+
def _split_argv(template: str) -> list[str]:
|
|
228
|
+
"""解析 argv 模板并拒绝未授权 shell 运算符。"""
|
|
229
|
+
lexer = shlex.shlex(template, posix=True, punctuation_chars=_SHELL_PUNCTUATION)
|
|
230
|
+
lexer.whitespace_split = True
|
|
231
|
+
lexer.commenters = ""
|
|
232
|
+
try:
|
|
233
|
+
argv = list(lexer)
|
|
234
|
+
except ValueError as exc:
|
|
235
|
+
raise DifferentialOracleError(f"命令模板无法解析: {exc}") from exc
|
|
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
|
|
241
|
+
|
|
242
|
+
|
|
243
|
+
def _execute_in_sandbox(
|
|
244
|
+
cmd_template: str,
|
|
245
|
+
input_content: bytes,
|
|
246
|
+
input_filename: str,
|
|
247
|
+
timeout: float = 10.0,
|
|
248
|
+
accepted_exits: set[int] | None = None,
|
|
249
|
+
) -> RunResult:
|
|
250
|
+
"""在全新的独立临时目录沙盒中执行单次目标命令。"""
|
|
251
|
+
with tempfile.TemporaryDirectory(prefix="bugx-oracle-sandbox-") as sandbox_dir:
|
|
252
|
+
sandbox_path = Path(sandbox_dir)
|
|
253
|
+
sandbox_input = sandbox_path / input_filename
|
|
254
|
+
sandbox_input.write_bytes(input_content)
|
|
255
|
+
|
|
256
|
+
argv = _split_argv(cmd_template)
|
|
257
|
+
rendered_argv = [
|
|
258
|
+
arg.replace("{input}", str(sandbox_input)) for arg in argv
|
|
259
|
+
]
|
|
260
|
+
|
|
261
|
+
t0 = time.perf_counter()
|
|
262
|
+
launch_error: str | None = None
|
|
263
|
+
try:
|
|
264
|
+
completed = run_bounded(
|
|
265
|
+
rendered_argv,
|
|
266
|
+
cwd=sandbox_path,
|
|
267
|
+
timeout=timeout,
|
|
268
|
+
max_output_bytes=64 * 1024,
|
|
269
|
+
)
|
|
270
|
+
exit_code = completed.returncode
|
|
271
|
+
timed_out = getattr(completed, "timed_out", False)
|
|
272
|
+
stdout_str = completed.stdout or ""
|
|
273
|
+
stderr_str = completed.stderr or ""
|
|
274
|
+
except subprocess.TimeoutExpired:
|
|
275
|
+
exit_code = 124
|
|
276
|
+
timed_out = True
|
|
277
|
+
stdout_str = ""
|
|
278
|
+
stderr_str = "Execution timed out"
|
|
279
|
+
except OSError as exc:
|
|
280
|
+
# A command that cannot be launched is an oracle/infrastructure
|
|
281
|
+
# failure, not evidence about the target project.
|
|
282
|
+
exit_code = 126 if isinstance(exc, PermissionError) else 127
|
|
283
|
+
timed_out = False
|
|
284
|
+
stdout_str = ""
|
|
285
|
+
stderr_str = str(exc)
|
|
286
|
+
launch_error = f"{type(exc).__name__}: {exc}"
|
|
287
|
+
|
|
288
|
+
duration_ms = round((time.perf_counter() - t0) * 1000, 2)
|
|
289
|
+
sig = extract_crash_signature(exit_code, stderr_str, stdout_str)
|
|
290
|
+
infrastructure_reason = _infrastructure_failure_reason(
|
|
291
|
+
exit_code=exit_code,
|
|
292
|
+
stderr=stderr_str,
|
|
293
|
+
stdout=stdout_str,
|
|
294
|
+
launch_error=launch_error,
|
|
295
|
+
)
|
|
296
|
+
return RunResult(
|
|
297
|
+
exit_code=exit_code,
|
|
298
|
+
duration_ms=duration_ms,
|
|
299
|
+
stdout=stdout_str,
|
|
300
|
+
stderr=stderr_str,
|
|
301
|
+
normalized_signature=sig,
|
|
302
|
+
timed_out=timed_out,
|
|
303
|
+
infrastructure_error=infrastructure_reason is not None,
|
|
304
|
+
infrastructure_reason=infrastructure_reason or "",
|
|
305
|
+
)
|
|
306
|
+
|
|
307
|
+
|
|
308
|
+
def verify_poc(
|
|
309
|
+
cmd_template: str,
|
|
310
|
+
poc_input: Any,
|
|
311
|
+
*,
|
|
312
|
+
timeout: float = 10.0,
|
|
313
|
+
accepted_exits: set[int] | None = None,
|
|
314
|
+
) -> dict[str, Any]:
|
|
315
|
+
"""快捷入口:验证单个 PoC 文件。"""
|
|
316
|
+
path, temp_file = _materialize_poc_input(poc_input)
|
|
317
|
+
try:
|
|
318
|
+
return run_differential_verification(
|
|
319
|
+
cmd_template=cmd_template,
|
|
320
|
+
input_path=path,
|
|
321
|
+
timeout=timeout,
|
|
322
|
+
accepted_exits=accepted_exits,
|
|
323
|
+
)
|
|
324
|
+
finally:
|
|
325
|
+
if temp_file is not None and path.is_file():
|
|
326
|
+
try:
|
|
327
|
+
path.unlink()
|
|
328
|
+
except OSError:
|
|
329
|
+
pass
|
|
330
|
+
|
|
331
|
+
|
|
332
|
+
def verify_red_blue_debate(
|
|
333
|
+
cmd_template: str,
|
|
334
|
+
red_poc_path: Path,
|
|
335
|
+
blue_counter_template: str | None = None,
|
|
336
|
+
timeout: float = 30.0,
|
|
337
|
+
) -> dict[str, Any]:
|
|
338
|
+
"""DOC-137 2.0 / D137-07: 红蓝双 Agent 闭环对抗博弈与差分验证裁决器。
|
|
339
|
+
|
|
340
|
+
Red 提交候选攻击 PoC,Blue 提交反例/防御断言命令。
|
|
341
|
+
在独立沙盒执行并判定:
|
|
342
|
+
- CONFIRMED_DETERMINISTIC: Red 成功穿透且 Blue 无法反驳
|
|
343
|
+
- BLUE_REFUTED_FALSE_POSITIVE: Blue 证明该情况被防御拦截或属合法业务反例
|
|
344
|
+
- FALSE_POSITIVE: Red 原 PoC 在干净沙盒无法复现
|
|
345
|
+
- DISPUTED_CANDIDATE: 对抗超时(>30s)或争议未决,归档人工复核
|
|
346
|
+
"""
|
|
347
|
+
start_t = time.perf_counter()
|
|
348
|
+
if not red_poc_path.is_file():
|
|
349
|
+
raise DifferentialOracleError(f"Red PoC 文件不存在: {red_poc_path}")
|
|
350
|
+
|
|
351
|
+
# 1. Red 独立沙盒穿透验证(硬超时 <= timeout)
|
|
352
|
+
red_content = red_poc_path.read_bytes()
|
|
353
|
+
red_res = _execute_in_sandbox(cmd_template, red_content, red_poc_path.name, timeout=min(timeout, 15.0))
|
|
354
|
+
if red_res.infrastructure_error:
|
|
355
|
+
return {
|
|
356
|
+
"schema_version": SCHEMA_VERSION,
|
|
357
|
+
"oracle_tier": "red_blue_debate",
|
|
358
|
+
"verdict": "INFRA_ERROR",
|
|
359
|
+
"confirmed": False,
|
|
360
|
+
"red_penetrated": False,
|
|
361
|
+
"blue_refuted": False,
|
|
362
|
+
"infrastructure_reason": red_res.infrastructure_reason,
|
|
363
|
+
"summary": f"Red PoC 验证基础设施失败,未对目标作出裁决: {red_res.infrastructure_reason}",
|
|
364
|
+
"latency_ms": (time.perf_counter() - start_t) * 1000,
|
|
365
|
+
}
|
|
366
|
+
red_penetrated = red_res.exit_code != 0 or red_res.timed_out
|
|
367
|
+
|
|
368
|
+
if not red_penetrated:
|
|
369
|
+
return {
|
|
370
|
+
"schema_version": SCHEMA_VERSION,
|
|
371
|
+
"oracle_tier": "red_blue_debate",
|
|
372
|
+
"verdict": "FALSE_POSITIVE",
|
|
373
|
+
"confirmed": False,
|
|
374
|
+
"red_penetrated": False,
|
|
375
|
+
"blue_refuted": False,
|
|
376
|
+
"summary": "Red PoC 在干净基线沙盒中未触发任何异常(exit 0),判定为环境假阳性",
|
|
377
|
+
"latency_ms": (time.perf_counter() - start_t) * 1000,
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
# 2. 如果存在 Blue 反驳/防御脚本
|
|
381
|
+
blue_refuted = False
|
|
382
|
+
blue_timed_out = False
|
|
383
|
+
blue_detail = "未提供 Blue 反驳脚本,退化为双跑一致性判定"
|
|
384
|
+
|
|
385
|
+
if blue_counter_template:
|
|
386
|
+
blue_res = _execute_in_sandbox(
|
|
387
|
+
blue_counter_template,
|
|
388
|
+
red_content,
|
|
389
|
+
red_poc_path.name,
|
|
390
|
+
timeout=min(timeout - (time.perf_counter() - start_t), 15.0),
|
|
391
|
+
)
|
|
392
|
+
blue_timed_out = blue_res.timed_out
|
|
393
|
+
if blue_res.infrastructure_error:
|
|
394
|
+
return {
|
|
395
|
+
"schema_version": SCHEMA_VERSION,
|
|
396
|
+
"oracle_tier": "red_blue_debate",
|
|
397
|
+
"verdict": "INFRA_ERROR",
|
|
398
|
+
"confirmed": False,
|
|
399
|
+
"red_penetrated": True,
|
|
400
|
+
"blue_refuted": False,
|
|
401
|
+
"infrastructure_reason": blue_res.infrastructure_reason,
|
|
402
|
+
"summary": f"Blue 反驳验证基础设施失败,未对目标作出裁决: {blue_res.infrastructure_reason}",
|
|
403
|
+
"latency_ms": (time.perf_counter() - start_t) * 1000,
|
|
404
|
+
}
|
|
405
|
+
if blue_timed_out:
|
|
406
|
+
verdict = "DISPUTED_CANDIDATE"
|
|
407
|
+
summary = "Blue 反驳验证超时(达到 30s 硬限制),标记为争议候选归档人工复核"
|
|
408
|
+
return {
|
|
409
|
+
"schema_version": SCHEMA_VERSION,
|
|
410
|
+
"oracle_tier": "red_blue_debate",
|
|
411
|
+
"verdict": verdict,
|
|
412
|
+
"confirmed": False,
|
|
413
|
+
"red_penetrated": True,
|
|
414
|
+
"blue_refuted": False,
|
|
415
|
+
"summary": summary,
|
|
416
|
+
"latency_ms": (time.perf_counter() - start_t) * 1000,
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
# 若 Blue 脚本成功运行并证明正常阻断(exit 0),说明防御有效
|
|
420
|
+
if blue_res.exit_code == 0:
|
|
421
|
+
blue_refuted = True
|
|
422
|
+
blue_detail = "Blue 防御审查反例成立:现有网关/类型系统已正常拦截该行为"
|
|
423
|
+
else:
|
|
424
|
+
blue_detail = f"Blue 尝试反驳失败(退出码 {blue_res.exit_code}),未能防御 Red 攻击"
|
|
425
|
+
|
|
426
|
+
if blue_refuted:
|
|
427
|
+
verdict = "BLUE_REFUTED_FALSE_POSITIVE"
|
|
428
|
+
summary = f"Red 触发异常但被 Blue 成功反驳:{blue_detail},拦截假阳性"
|
|
429
|
+
confirmed = False
|
|
430
|
+
else:
|
|
431
|
+
# 进行第二次沙盒验证以保证确定性
|
|
432
|
+
dual = run_differential_verification(cmd_template, red_poc_path, timeout=10.0)
|
|
433
|
+
if dual["confirmed"]:
|
|
434
|
+
verdict = "CONFIRMED_DETERMINISTIC"
|
|
435
|
+
summary = f"Red 攻击真实有效且 Blue 无法反驳({blue_detail}),两次双跑确定性复现,确认为真实漏洞"
|
|
436
|
+
confirmed = True
|
|
437
|
+
else:
|
|
438
|
+
verdict = dual["verdict"]
|
|
439
|
+
summary = f"Red 攻击在双跑中表现不稳定({dual['summary']}),暂未升级为确定性缺陷"
|
|
440
|
+
confirmed = False
|
|
441
|
+
|
|
442
|
+
return {
|
|
443
|
+
"schema_version": SCHEMA_VERSION,
|
|
444
|
+
"oracle_tier": "red_blue_debate",
|
|
445
|
+
"verdict": verdict,
|
|
446
|
+
"confirmed": confirmed,
|
|
447
|
+
"red_penetrated": red_penetrated,
|
|
448
|
+
"blue_refuted": blue_refuted,
|
|
449
|
+
"summary": summary,
|
|
450
|
+
"blue_detail": blue_detail,
|
|
451
|
+
"latency_ms": (time.perf_counter() - start_t) * 1000,
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
|
|
455
|
+
def run_differential_verification(
|
|
456
|
+
cmd_template: str,
|
|
457
|
+
input_path: str | os.PathLike[str],
|
|
458
|
+
timeout: float = 10.0,
|
|
459
|
+
accepted_exits: set[int] | None = None,
|
|
460
|
+
) -> dict[str, Any]:
|
|
461
|
+
"""执行隔离双跑差分验证并产出判定结论与证据工件。"""
|
|
462
|
+
input_file = Path(input_path)
|
|
463
|
+
if not input_file.is_file():
|
|
464
|
+
raise DifferentialOracleError(f"输入 PoC 文件不存在: {input_file}")
|
|
465
|
+
|
|
466
|
+
input_content = input_file.read_bytes()
|
|
467
|
+
input_sha256 = hashlib.sha256(input_content).hexdigest()
|
|
468
|
+
input_filename = input_file.name
|
|
469
|
+
expected_good_exits = accepted_exits or {0}
|
|
470
|
+
|
|
471
|
+
# 执行 Run 1 与 Run 2(两个完全独立的临时目录)
|
|
472
|
+
res1 = _execute_in_sandbox(cmd_template, input_content, input_filename, timeout=timeout)
|
|
473
|
+
res2 = _execute_in_sandbox(cmd_template, input_content, input_filename, timeout=timeout)
|
|
474
|
+
|
|
475
|
+
infrastructure_runs = [
|
|
476
|
+
result for result in (res1, res2) if result.infrastructure_error
|
|
477
|
+
]
|
|
478
|
+
if infrastructure_runs:
|
|
479
|
+
reasons = sorted({item.infrastructure_reason for item in infrastructure_runs if item.infrastructure_reason})
|
|
480
|
+
verdict = "INFRA_ERROR"
|
|
481
|
+
summary = "差分验证基础设施失败,拒绝把稳定错误升级为目标缺陷"
|
|
482
|
+
if reasons:
|
|
483
|
+
summary += f": {'; '.join(reasons)}"
|
|
484
|
+
else:
|
|
485
|
+
verdict = ""
|
|
486
|
+
summary = ""
|
|
487
|
+
|
|
488
|
+
is_fail1 = res1.exit_code not in expected_good_exits or res1.timed_out
|
|
489
|
+
is_fail2 = res2.exit_code not in expected_good_exits or res2.timed_out
|
|
490
|
+
|
|
491
|
+
# 差分裁决
|
|
492
|
+
if verdict == "INFRA_ERROR":
|
|
493
|
+
pass
|
|
494
|
+
elif not is_fail1 and not is_fail2:
|
|
495
|
+
verdict = "FALSE_POSITIVE"
|
|
496
|
+
summary = f"双跑均正常退出(exit {res1.exit_code}),未能复现异常,判定为环境假阳性"
|
|
497
|
+
elif is_fail1 != is_fail2:
|
|
498
|
+
verdict = "FLAKY_JITTER"
|
|
499
|
+
summary = f"双跑行为分歧(Run 1 exit {res1.exit_code} vs Run 2 exit {res2.exit_code}),判定为偶发不稳定抖动"
|
|
500
|
+
else:
|
|
501
|
+
# 两次均失败,比较归一化签名是否吻合
|
|
502
|
+
if res1.exit_code == res2.exit_code and res1.normalized_signature == res2.normalized_signature:
|
|
503
|
+
verdict = "CONFIRMED_DETERMINISTIC"
|
|
504
|
+
summary = f"两次隔离沙盒独立复验一致崩溃(exit {res1.exit_code},签名: {res1.normalized_signature}),确认为真实确定性缺陷"
|
|
505
|
+
elif res1.exit_code == res2.exit_code:
|
|
506
|
+
verdict = "CONFIRMED_DETERMINISTIC"
|
|
507
|
+
summary = f"两次双跑均返回相同退出码 {res1.exit_code},确认为确定性异常"
|
|
508
|
+
else:
|
|
509
|
+
verdict = "FLAKY_JITTER"
|
|
510
|
+
summary = f"两次双跑均报错但退出码分歧({res1.exit_code} != {res2.exit_code}),归类为不稳定用例"
|
|
511
|
+
|
|
512
|
+
return {
|
|
513
|
+
"schema_version": SCHEMA_VERSION,
|
|
514
|
+
"oracle_tier": "deterministic_dual_run",
|
|
515
|
+
"verdict": verdict,
|
|
516
|
+
"confirmed": verdict == "CONFIRMED_DETERMINISTIC",
|
|
517
|
+
"command_template": cmd_template,
|
|
518
|
+
"input_file": str(input_file.resolve()),
|
|
519
|
+
"input_sha256": input_sha256,
|
|
520
|
+
"runs": [
|
|
521
|
+
{
|
|
522
|
+
"run": 1,
|
|
523
|
+
"exit_code": res1.exit_code,
|
|
524
|
+
"duration_ms": res1.duration_ms,
|
|
525
|
+
"signature": res1.normalized_signature,
|
|
526
|
+
"timed_out": res1.timed_out,
|
|
527
|
+
"infrastructure_error": res1.infrastructure_error,
|
|
528
|
+
"infrastructure_reason": res1.infrastructure_reason,
|
|
529
|
+
"stderr_preview": res1.stderr[:300],
|
|
530
|
+
},
|
|
531
|
+
{
|
|
532
|
+
"run": 2,
|
|
533
|
+
"exit_code": res2.exit_code,
|
|
534
|
+
"duration_ms": res2.duration_ms,
|
|
535
|
+
"signature": res2.normalized_signature,
|
|
536
|
+
"timed_out": res2.timed_out,
|
|
537
|
+
"infrastructure_error": res2.infrastructure_error,
|
|
538
|
+
"infrastructure_reason": res2.infrastructure_reason,
|
|
539
|
+
"stderr_preview": res2.stderr[:300],
|
|
540
|
+
},
|
|
541
|
+
],
|
|
542
|
+
"summary": summary,
|
|
543
|
+
}
|
|
544
|
+
|
|
545
|
+
|
|
546
|
+
def verify_differential_poc(
|
|
547
|
+
cmd_template: str,
|
|
548
|
+
poc_input: Any,
|
|
549
|
+
*,
|
|
550
|
+
timeout: float = 10.0,
|
|
551
|
+
accepted_exits: set[int] | None = None,
|
|
552
|
+
allowed_root: Path | None = None,
|
|
553
|
+
) -> dict[str, Any]:
|
|
554
|
+
"""供 MCP 或外部模块便捷调用的确定性双跑沙盒差分验证接口。"""
|
|
555
|
+
root = allowed_root.expanduser().resolve() if allowed_root is not None else None
|
|
556
|
+
path, temp_file = _materialize_poc_input(poc_input, base_dir=root)
|
|
557
|
+
if temp_file is None:
|
|
558
|
+
resolved_path = path.resolve(strict=True)
|
|
559
|
+
if root is not None:
|
|
560
|
+
try:
|
|
561
|
+
resolved_path.relative_to(root)
|
|
562
|
+
except ValueError as exc:
|
|
563
|
+
raise DifferentialOracleError(
|
|
564
|
+
f"PoC 输入文件必须位于项目根目录内: {resolved_path}"
|
|
565
|
+
) from exc
|
|
566
|
+
path = resolved_path
|
|
567
|
+
try:
|
|
568
|
+
return verify_poc(cmd_template, path, timeout=timeout, accepted_exits=accepted_exits)
|
|
569
|
+
finally:
|
|
570
|
+
if temp_file is not None and path.is_file():
|
|
571
|
+
try:
|
|
572
|
+
path.unlink()
|
|
573
|
+
except OSError:
|
|
574
|
+
pass
|
|
575
|
+
|
|
576
|
+
|
|
577
|
+
def parse_args(argv: list[str] | None = None) -> argparse.Namespace:
|
|
578
|
+
parser = argparse.ArgumentParser(description=__doc__)
|
|
579
|
+
sub = parser.add_subparsers(dest="action", required=True)
|
|
580
|
+
|
|
581
|
+
p_verify = sub.add_parser("verify", help="对候选 PoC 执行确定性沙盒双跑差分验证")
|
|
582
|
+
p_verify.add_argument("--cmd", required=True, help="目标命令模板(使用 {input} 占位输入文件)")
|
|
583
|
+
p_verify.add_argument("--input", type=Path, required=True, help="候选 PoC 输入文件")
|
|
584
|
+
p_verify.add_argument("--timeout", type=float, default=10.0, help="单次运行超时秒数(默认 10)")
|
|
585
|
+
p_verify.add_argument("--accepted-exits", default="0", help="预期正常退出码(逗号分隔,默认 0)")
|
|
586
|
+
p_verify.add_argument("--out", type=Path, default=None, help="输出报告 JSON 保存路径")
|
|
587
|
+
p_verify.add_argument("--json", action="store_true", help="以 JSON 格式输出至 stdout")
|
|
588
|
+
|
|
589
|
+
return parser.parse_args(argv)
|
|
590
|
+
|
|
591
|
+
|
|
592
|
+
def main(argv: list[str] | None = None) -> int:
|
|
593
|
+
args = parse_args(argv)
|
|
594
|
+
|
|
595
|
+
if args.action == "verify":
|
|
596
|
+
accepted = {int(code.strip()) for code in args.accepted_exits.split(",") if code.strip()}
|
|
597
|
+
try:
|
|
598
|
+
report = verify_poc(
|
|
599
|
+
args.cmd,
|
|
600
|
+
args.input,
|
|
601
|
+
timeout=args.timeout,
|
|
602
|
+
accepted_exits=accepted,
|
|
603
|
+
)
|
|
604
|
+
except DifferentialOracleError as exc:
|
|
605
|
+
print(f"[differential_oracle] 错误: {exc}", file=sys.stderr)
|
|
606
|
+
return 2
|
|
607
|
+
|
|
608
|
+
formatted_json = json.dumps(report, ensure_ascii=False, indent=2)
|
|
609
|
+
if args.out:
|
|
610
|
+
args.out.parent.mkdir(parents=True, exist_ok=True)
|
|
611
|
+
args.out.write_text(formatted_json, encoding="utf-8")
|
|
612
|
+
print(f"[differential_oracle] 验证报告已写入: {args.out}")
|
|
613
|
+
|
|
614
|
+
if args.json or not args.out:
|
|
615
|
+
print(formatted_json)
|
|
616
|
+
else:
|
|
617
|
+
status_icon = "✓" if report["confirmed"] else "✗"
|
|
618
|
+
print(f"[differential_oracle] {status_icon} 裁决: {report['verdict']} — {report['summary']}")
|
|
619
|
+
|
|
620
|
+
# 确认为真实 Bug 返回 0,基础设施失败返回 2,其他未确认返回 1。
|
|
621
|
+
if report["verdict"] == "INFRA_ERROR":
|
|
622
|
+
return 2
|
|
623
|
+
return 0 if report["confirmed"] else 1
|
|
624
|
+
|
|
625
|
+
return 0
|
|
626
|
+
|
|
627
|
+
|
|
628
|
+
if __name__ == "__main__":
|
|
629
|
+
sys.exit(main())
|