pwn 0.5.795 → 0.5.798
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.
- checksums.yaml +4 -4
- data/Gemfile +8 -8
- data/bin/pwn_autoinc_version +4 -5
- data/bin/pwn_web_cache_deception +40 -29
- data/documentation/AWS.md +15 -5
- data/documentation/Diagrams.md +1 -1
- data/documentation/Home.md +2 -2
- data/documentation/How-PWN-Works.md +1 -1
- data/documentation/Mission-Cancellation.md +6 -4
- data/documentation/Operability.md +1 -1
- data/documentation/What-is-PWN.md +1 -1
- data/documentation/diagrams/aws-cloud-security.svg +1 -1
- data/documentation/diagrams/dot/aws-cloud-security.dot +1 -1
- data/documentation/diagrams/dot/network-infra-testing.dot +1 -1
- data/documentation/diagrams/network-infra-testing.svg +1 -1
- data/etc/default_cron/session_cleanup.rb +84 -51
- data/etc/default_skills/pwn/ai/agent/mission_namespace/SKILL.md +6 -4
- data/lib/pwn/ai/agent/assembly.rb +0 -2
- data/lib/pwn/ai/agent/btc.rb +0 -2
- data/lib/pwn/ai/agent/burp_suite.rb +0 -2
- data/lib/pwn/ai/agent/curriculum.rb +2 -2
- data/lib/pwn/ai/agent/dispatch.rb +3 -0
- data/lib/pwn/ai/agent/engagement.rb +96 -41
- data/lib/pwn/ai/agent/extrospection/osint/bridges.rb +2 -0
- data/lib/pwn/ai/agent/extrospection.rb +50 -13
- data/lib/pwn/ai/agent/gqrx.rb +0 -2
- data/lib/pwn/ai/agent/hacker_one.rb +0 -2
- data/lib/pwn/ai/agent/learning.rb +45 -13
- data/lib/pwn/ai/agent/loop.rb +16 -11
- data/lib/pwn/ai/agent/metrics.rb +1 -1
- data/lib/pwn/ai/agent/mission.rb +6 -3
- data/lib/pwn/ai/agent/mission_namespace.rb +70 -14
- data/lib/pwn/ai/agent/policy.rb +1 -1
- data/lib/pwn/ai/agent/policy_evaluation.rb +2 -2
- data/lib/pwn/ai/agent/reflect.rb +1 -0
- data/lib/pwn/ai/agent/request_runtime.rb +1 -1
- data/lib/pwn/ai/agent/reward.rb +155 -53
- data/lib/pwn/ai/agent/sast.rb +0 -2
- data/lib/pwn/ai/agent/task_dag.rb +5 -3
- data/lib/pwn/ai/agent/task_summarizer.rb +21 -11
- data/lib/pwn/ai/agent/tool_guard.rb +19 -0
- data/lib/pwn/ai/agent/tools/ruby_eval.rb +1 -1
- data/lib/pwn/ai/agent/tools/verify.rb +7 -3
- data/lib/pwn/ai/agent/transparent_browser.rb +0 -2
- data/lib/pwn/ai/agent/turn_finalizer.rb +3 -0
- data/lib/pwn/ai/anthropic.rb +3 -3
- data/lib/pwn/ai/context.rb +2 -1
- data/lib/pwn/ai/gemini.rb +7 -5
- data/lib/pwn/ai/grok.rb +37 -18
- data/lib/pwn/ai/mcp.rb +17 -5
- data/lib/pwn/ai/ollama.rb +76 -35
- data/lib/pwn/ai/open_ai.rb +7 -19
- data/lib/pwn/ai/open_web_ui.rb +76 -40
- data/lib/pwn/aws/cloud_search_domain.rb +6 -0
- data/lib/pwn/aws/iam.rb +2 -2
- data/lib/pwn/aws/workspaces.rb +2 -2
- data/lib/pwn/aws.rb +0 -5
- data/lib/pwn/bounty/lifecycle_authz_replay.rb +1 -1
- data/lib/pwn/config.rb +17 -10
- data/lib/pwn/corpus.rb +33 -5
- data/lib/pwn/cron.rb +60 -17
- data/lib/pwn/driver.rb +2 -3
- data/lib/pwn/engagement.rb +28 -10
- data/lib/pwn/ffi/capstone.rb +3 -2
- data/lib/pwn/ffi/fftw.rb +8 -6
- data/lib/pwn/ffi/keystone.rb +3 -2
- data/lib/pwn/ffi/soapy_sdr.rb +10 -6
- data/lib/pwn/json_text.rb +25 -13
- data/lib/pwn/memory_index.rb +6 -4
- data/lib/pwn/module_skills.rb +3 -1
- data/lib/pwn/plugins/aflplusplus.rb +1 -0
- data/lib/pwn/plugins/ai_sandbox.rb +42 -10
- data/lib/pwn/plugins/android.rb +429 -466
- data/lib/pwn/plugins/artifact_registry.rb +12 -2
- data/lib/pwn/plugins/assembly.rb +9 -42
- data/lib/pwn/plugins/authentication_helper.rb +4 -3
- data/lib/pwn/plugins/baresip.rb +70 -28
- data/lib/pwn/plugins/binary_analysis.rb +14 -5
- data/lib/pwn/plugins/binary_parser.rb +42 -7
- data/lib/pwn/plugins/black_duck_binary_analysis.rb +3 -3
- data/lib/pwn/plugins/burp_suite.rb +15 -12
- data/lib/pwn/plugins/bus_pirate.rb +3 -7
- data/lib/pwn/plugins/char.rb +9 -3
- data/lib/pwn/plugins/credit_card.rb +7 -0
- data/lib/pwn/plugins/dao_ldap.rb +2 -2
- data/lib/pwn/plugins/dao_mongo.rb +1 -1
- data/lib/pwn/plugins/debugger.rb +1 -1
- data/lib/pwn/plugins/defect_dojo.rb +7 -3
- data/lib/pwn/plugins/detect_os.rb +1 -1
- data/lib/pwn/plugins/detonate.rb +9 -19
- data/lib/pwn/plugins/exploit_db.rb +1 -1
- data/lib/pwn/plugins/file_fu.rb +4 -1
- data/lib/pwn/plugins/findings.rb +76 -2
- data/lib/pwn/plugins/fuzz.rb +12 -3
- data/lib/pwn/plugins/gdb.rb +7 -2
- data/lib/pwn/plugins/gdbmi.rb +10 -6
- data/lib/pwn/plugins/git.rb +18 -13
- data/lib/pwn/plugins/github.rb +11 -6
- data/lib/pwn/plugins/google_workspace.rb +11 -3
- data/lib/pwn/plugins/hacker_one.rb +5 -1
- data/lib/pwn/plugins/httpx.rb +24 -8
- data/lib/pwn/plugins/ip_info.rb +11 -8
- data/lib/pwn/plugins/irc.rb +73 -45
- data/lib/pwn/plugins/jenkins.rb +2 -2
- data/lib/pwn/plugins/jira_data_center.rb +13 -6
- data/lib/pwn/plugins/jobs.rb +62 -4
- data/lib/pwn/plugins/log.rb +1 -1
- data/lib/pwn/plugins/monkey_patch.rb +1 -1
- data/lib/pwn/plugins/msr206.rb +157 -182
- data/lib/pwn/plugins/nessus_cloud.rb +2 -2
- data/lib/pwn/plugins/nexpose_vuln_scan.rb +44 -33
- data/lib/pwn/plugins/nuclei.rb +24 -8
- data/lib/pwn/plugins/ocr.rb +3 -1
- data/lib/pwn/plugins/open_api.rb +0 -4
- data/lib/pwn/plugins/openvas.rb +31 -43
- data/lib/pwn/plugins/packet.rb +40 -25
- data/lib/pwn/plugins/pony.rb +2 -2
- data/lib/pwn/plugins/preflight_checker.rb +1 -1
- data/lib/pwn/plugins/process_tube.rb +17 -2
- data/lib/pwn/plugins/ps.rb +6 -1
- data/lib/pwn/plugins/pwn_logger.rb +37 -1
- data/lib/pwn/plugins/repl/ai.rb +1 -0
- data/lib/pwn/plugins/repl/ai_console.rb +18 -6
- data/lib/pwn/plugins/repl/mesh.rb +51 -28
- data/lib/pwn/plugins/sbom.rb +59 -27
- data/lib/pwn/plugins/scannable_codes.rb +3 -1
- data/lib/pwn/plugins/serial.rb +102 -44
- data/lib/pwn/plugins/shodan.rb +4 -10
- data/lib/pwn/plugins/sock.rb +16 -11
- data/lib/pwn/plugins/ssn.rb +3 -1
- data/lib/pwn/plugins/transparent_browser.rb +43 -3
- data/lib/pwn/plugins/vault.rb +92 -30
- data/lib/pwn/plugins/vin.rb +2 -1
- data/lib/pwn/plugins/vsphere.rb +2 -1
- data/lib/pwn/plugins/xxd.rb +3 -5
- data/lib/pwn/plugins/yubikey/security_domain/scp.rb +4 -0
- data/lib/pwn/plugins/yubikey/transport.rb +42 -11
- data/lib/pwn/plugins/yubikey.rb +21 -6
- data/lib/pwn/plugins/zaproxy.rb +3 -4
- data/lib/pwn/reports/ai_red_team.rb +4 -4
- data/lib/pwn/reports/pdf.rb +9 -5
- data/lib/pwn/reports/sast.rb +4 -4
- data/lib/pwn/sast/keystore.rb +2 -2
- data/lib/pwn/sast/logger.rb +1 -1
- data/lib/pwn/sast/php_type_juggling.rb +3 -6
- data/lib/pwn/sast/pom_version.rb +12 -6
- data/lib/pwn/sast/port.rb +1 -1
- data/lib/pwn/sast/sql.rb +3 -7
- data/lib/pwn/sast/test_case_engine.rb +62 -16
- data/lib/pwn/sast/type_script_type_juggling.rb +3 -6
- data/lib/pwn/sdr/decoder/base.rb +8 -0
- data/lib/pwn/sdr/decoder/lora.rb +1 -1
- data/lib/pwn/sdr/flipper_zero.rb +4 -7
- data/lib/pwn/sdr/gqrx.rb +35 -16
- data/lib/pwn/sdr/son_micro_rfid.rb +44 -26
- data/lib/pwn/sdr.rb +1 -1
- data/lib/pwn/session_trace.rb +7 -2
- data/lib/pwn/sessions.rb +310 -41
- data/lib/pwn/setup.rb +4 -3
- data/lib/pwn/version.rb +1 -1
- data/lib/pwn/www/app_cobalt_io.rb +14 -2
- data/lib/pwn/www/bing.rb +13 -1
- data/lib/pwn/www/bug_crowd.rb +14 -2
- data/lib/pwn/www/checkip.rb +13 -1
- data/lib/pwn/www/coinbase_pro.rb +14 -2
- data/lib/pwn/www/duckduckgo.rb +13 -1
- data/lib/pwn/www/facebook.rb +14 -2
- data/lib/pwn/www/github.rb +14 -2
- data/lib/pwn/www/google.rb +13 -1
- data/lib/pwn/www/hacker_one.rb +117 -33
- data/lib/pwn/www/linkedin.rb +14 -2
- data/lib/pwn/www/pandora.rb +14 -2
- data/lib/pwn/www/pastebin.rb +13 -1
- data/lib/pwn/www/paypal.rb +16 -4
- data/lib/pwn/www/synack.rb +14 -2
- data/lib/pwn/www/torch.rb +17 -3
- data/lib/pwn/www/trading_view.rb +14 -2
- data/lib/pwn/www/twitter.rb +14 -2
- data/lib/pwn/www/uber.rb +14 -2
- data/lib/pwn/www/upwork.rb +14 -2
- data/lib/pwn/www/wayback_machine.rb +16 -2
- data/lib/pwn/www/youtube.rb +13 -1
- data/lib/pwn.rb +11 -0
- data/pwn.gemspec +4 -0
- data/spec/conventions_spec.rb +43 -0
- data/spec/integration/authentication_helper_oath_spec.rb +1 -1
- data/spec/integration/autoinc_lifecycle_supplement_spec.rb +47 -0
- data/spec/integration/gemspec_deleted_files_spec.rb +43 -0
- data/spec/integration/harness_evaluation_spec.rb +22 -31
- data/spec/integration/harness_live_spec.rb +8 -18
- data/spec/integration/spec_curriculum_isolation_spec.rb +41 -0
- data/spec/integration/verify_acceptance_eui_regression_spec.rb +162 -0
- data/spec/integration/web_cache_lifecycle_closure_spec.rb +89 -0
- data/spec/integration/web_cache_lifecycle_supplement_spec.rb +70 -0
- data/spec/lib/pwn/ai/agent/analysis_errors_regression_spec.rb +33 -0
- data/spec/lib/pwn/ai/agent/curriculum_cooldown_regression_spec.rb +19 -0
- data/spec/lib/pwn/ai/agent/curriculum_spec.rb +2 -0
- data/spec/lib/pwn/ai/agent/engagement_boundary_regression_spec.rb +42 -0
- data/spec/lib/pwn/ai/agent/engagement_dispatch_review_spec.rb +82 -0
- data/spec/lib/pwn/ai/agent/engagement_roe_regression_spec.rb +25 -0
- data/spec/lib/pwn/ai/agent/engagement_scope_regression_spec.rb +37 -0
- data/spec/lib/pwn/ai/agent/extrospection/osint/bridges_spec.rb +4 -0
- data/spec/lib/pwn/ai/agent/extrospection_input_regression_spec.rb +31 -0
- data/spec/lib/pwn/ai/agent/extrospection_review_spec.rb +61 -0
- data/spec/lib/pwn/ai/agent/extrospection_serial_review_spec.rb +42 -0
- data/spec/lib/pwn/ai/agent/extrospection_spec.rb +9 -0
- data/spec/lib/pwn/ai/agent/extrospection_verification_regression_spec.rb +39 -0
- data/spec/lib/pwn/ai/agent/learning_last_answer_regression_spec.rb +32 -0
- data/spec/lib/pwn/ai/agent/learning_lifecycle_closure_spec.rb +84 -0
- data/spec/lib/pwn/ai/agent/learning_prune_regression_spec.rb +17 -0
- data/spec/lib/pwn/ai/agent/learning_spec.rb +2 -1
- data/spec/lib/pwn/ai/agent/loop_execution_audit_spec.rb +30 -0
- data/spec/lib/pwn/ai/agent/metrics_usage_regression_spec.rb +20 -0
- data/spec/lib/pwn/ai/agent/mission_execution_audit_spec.rb +27 -0
- data/spec/lib/pwn/ai/agent/mission_namespace_spec.rb +218 -18
- data/spec/lib/pwn/ai/agent/policy_confidence_regression_spec.rb +16 -0
- data/spec/lib/pwn/ai/agent/policy_evaluation_spec.rb +1 -1
- data/spec/lib/pwn/ai/agent/policy_evaluation_tmp_regression_spec.rb +36 -0
- data/spec/lib/pwn/ai/agent/reflect_model_regression_spec.rb +15 -0
- data/spec/lib/pwn/ai/agent/request_runtime_execution_audit_spec.rb +43 -0
- data/spec/lib/pwn/ai/agent/reward_binding_review_spec.rb +129 -0
- data/spec/lib/pwn/ai/agent/reward_dispatch_review_spec.rb +154 -0
- data/spec/lib/pwn/ai/agent/reward_envelope_regression_spec.rb +45 -0
- data/spec/lib/pwn/ai/agent/reward_turn_regression_spec.rb +40 -0
- data/spec/lib/pwn/ai/agent/swarm_spec.rb +2 -2
- data/spec/lib/pwn/ai/agent/task_dag_execution_audit_spec.rb +45 -0
- data/spec/lib/pwn/ai/agent/task_summarizer_failure_regression_spec.rb +26 -0
- data/spec/lib/pwn/ai/agent/tools/verify_execution_audit_spec.rb +33 -0
- data/spec/lib/pwn/ai/context_range_audit_spec.rb +24 -0
- data/spec/lib/pwn/ai/gemini_roundtrip_audit_spec.rb +33 -0
- data/spec/lib/pwn/ai/grok_reasoning_effort_spec.rb +43 -0
- data/spec/lib/pwn/ai/mcp_session_audit_spec.rb +36 -0
- data/spec/lib/pwn/ai/ollama_spec.rb +6 -11
- data/spec/lib/pwn/ai/open_web_ui_spec.rb +6 -11
- data/spec/lib/pwn/ai/provider_history_audit_spec.rb +44 -0
- data/spec/lib/pwn/ai/provider_operations_audit_spec.rb +53 -0
- data/spec/lib/pwn/ai/provider_review_history_stream_regression_spec.rb +143 -0
- data/spec/lib/pwn/ai/provider_review_tls_regression_spec.rb +62 -0
- data/spec/lib/pwn/ai/provider_stream_audit_spec.rb +49 -0
- data/spec/lib/pwn/aws/iam_decoding_regression_spec.rb +23 -0
- data/spec/lib/pwn/aws/services_runtime_regression_spec.rb +51 -0
- data/spec/lib/pwn/aws_spec.rb +6 -0
- data/spec/lib/pwn/banner_operational_audit_spec.rb +105 -0
- data/spec/lib/pwn/bounty/lifecycle_authz_replay_spec.rb +17 -0
- data/spec/lib/pwn/config_redaction_regression_spec.rb +24 -0
- data/spec/lib/pwn/config_skills_regression_spec.rb +38 -0
- data/spec/lib/pwn/corpus_core_review_regression_spec.rb +96 -0
- data/spec/lib/pwn/corpus_spec.rb +13 -0
- data/spec/lib/pwn/cron_core_review_regression_spec.rb +95 -0
- data/spec/lib/pwn/cron_execution_spec.rb +75 -0
- data/spec/lib/pwn/driver_core_review_regression_spec.rb +38 -0
- data/spec/lib/pwn/driver_spec.rb +13 -0
- data/spec/lib/pwn/engagement_core_review_regression_spec.rb +88 -0
- data/spec/lib/pwn/engagement_storage_regression_spec.rb +44 -0
- data/spec/lib/pwn/ffi/capstone_spec.rb +19 -0
- data/spec/lib/pwn/ffi/fftw_spec.rb +19 -0
- data/spec/lib/pwn/ffi/keystone_spec.rb +13 -0
- data/spec/lib/pwn/ffi/soapy_sdr_spec.rb +13 -0
- data/spec/lib/pwn/json_schemer_regexp_parser_spec.rb +12 -0
- data/spec/lib/pwn/json_text_spec.rb +25 -0
- data/spec/lib/pwn/memory_index_spec.rb +23 -0
- data/spec/lib/pwn/module_skills_parsing_regression_spec.rb +34 -0
- data/spec/lib/pwn/module_skills_spec.rb +11 -1
- data/spec/lib/pwn/plugins/ai_sandbox_boundary_review_spec.rb +57 -0
- data/spec/lib/pwn/plugins/ai_sandbox_spec.rb +10 -18
- data/spec/lib/pwn/plugins/android_review_fixes_spec.rb +121 -0
- data/spec/lib/pwn/plugins/android_transport_audit_spec.rb +64 -0
- data/spec/lib/pwn/plugins/api_import_namespace_audit_spec.rb +49 -0
- data/spec/lib/pwn/plugins/artifact_registry_namespace_audit_spec.rb +20 -0
- data/spec/lib/pwn/plugins/artifact_registry_review_fixes_spec.rb +63 -0
- data/spec/lib/pwn/plugins/assembly_namespace_audit_spec.rb +16 -0
- data/spec/lib/pwn/plugins/assembly_review_fixes_spec.rb +33 -0
- data/spec/lib/pwn/plugins/authentication_helper_spec.rb +14 -0
- data/spec/lib/pwn/plugins/baresip_review_fixes_spec.rb +127 -0
- data/spec/lib/pwn/plugins/baresip_transport_audit_spec.rb +59 -0
- data/spec/lib/pwn/plugins/binary_analysis_process_review_spec.rb +57 -0
- data/spec/lib/pwn/plugins/black_duck_namespace_audit_spec.rb +25 -0
- data/spec/lib/pwn/plugins/burp_suite_har_review_fixes_spec.rb +60 -0
- data/spec/lib/pwn/plugins/burp_suite_import_review_fixes_spec.rb +62 -0
- data/spec/lib/pwn/plugins/burp_suite_namespace_audit_spec.rb +37 -0
- data/spec/lib/pwn/plugins/bus_pirate_transport_audit_spec.rb +19 -0
- data/spec/lib/pwn/plugins/file_fu_namespace_audit_spec.rb +17 -0
- data/spec/lib/pwn/plugins/findings_structured_spec.rb +1 -1
- data/spec/lib/pwn/plugins/gdbmi_namespace_audit_spec.rb +28 -0
- data/spec/lib/pwn/plugins/gdbmi_review_fixes_spec.rb +73 -0
- data/spec/lib/pwn/plugins/github_argv_review_spec.rb +49 -0
- data/spec/lib/pwn/plugins/google_workspace_provider_review_oauth_spec.rb +80 -0
- data/spec/lib/pwn/plugins/irc_review_fixes_spec.rb +92 -0
- data/spec/lib/pwn/plugins/irc_transport_audit_spec.rb +37 -0
- data/spec/lib/pwn/plugins/jenkins_namespace_audit_spec.rb +12 -0
- data/spec/lib/pwn/plugins/jira_data_center_namespace_audit_spec.rb +44 -0
- data/spec/lib/pwn/plugins/jira_data_center_review_fixes_spec.rb +81 -0
- data/spec/lib/pwn/plugins/jsonl_elf_review_fixes_spec.rb +59 -0
- data/spec/lib/pwn/plugins/log_spec.rb +36 -20
- data/spec/lib/pwn/plugins/monkey_patch_spec.rb +16 -0
- data/spec/lib/pwn/plugins/msr206_readback_review_fixes_spec.rb +119 -0
- data/spec/lib/pwn/plugins/msr206_review_fixes_spec.rb +50 -0
- data/spec/lib/pwn/plugins/msr206_transport_audit_spec.rb +64 -0
- data/spec/lib/pwn/plugins/nessus_cloud_namespace_audit_spec.rb +14 -0
- data/spec/lib/pwn/plugins/nexpose_review_fixes_spec.rb +55 -0
- data/spec/lib/pwn/plugins/open_api_namespace_audit_spec.rb +22 -0
- data/spec/lib/pwn/plugins/packet_transport_audit_spec.rb +47 -0
- data/spec/lib/pwn/plugins/plugins_b_operational_regression_spec.rb +600 -0
- data/spec/lib/pwn/plugins/pony_namespace_audit_spec.rb +17 -0
- data/spec/lib/pwn/plugins/pony_review_fixes_spec.rb +33 -0
- data/spec/lib/pwn/plugins/process_tube_namespace_audit_spec.rb +19 -0
- data/spec/lib/pwn/plugins/ps_namespace_audit_spec.rb +12 -0
- data/spec/lib/pwn/plugins/pwn_logger_spec.rb +30 -0
- data/spec/lib/pwn/plugins/repl/ai_console_spec.rb +127 -0
- data/spec/lib/pwn/plugins/repl/ai_spec.rb +38 -0
- data/spec/lib/pwn/plugins/repl/mesh_spec.rb +52 -0
- data/spec/lib/pwn/plugins/repl_mesh_rx_errors_spec.rb +18 -0
- data/spec/lib/pwn/plugins/sandbox_spec.rb +9 -7
- data/spec/lib/pwn/plugins/sbom_review_fixes_spec.rb +43 -0
- data/spec/lib/pwn/plugins/scannable_codes_namespace_audit_spec.rb +15 -0
- data/spec/lib/pwn/plugins/serial_review_fixes_spec.rb +76 -0
- data/spec/lib/pwn/plugins/serial_transport_audit_spec.rb +102 -0
- data/spec/lib/pwn/plugins/shodan_namespace_audit_spec.rb +10 -0
- data/spec/lib/pwn/plugins/sock_transport_audit_spec.rb +55 -0
- data/spec/lib/pwn/plugins/transparent_browser_navigation_review_spec.rb +21 -0
- data/spec/lib/pwn/plugins/vault_master_key_eui_regression_spec.rb +242 -0
- data/spec/lib/pwn/plugins/vault_spec.rb +58 -0
- data/spec/lib/pwn/plugins/vault_store_safety_spec.rb +1 -1
- data/spec/lib/pwn/plugins/xxd_namespace_audit_spec.rb +34 -0
- data/spec/lib/pwn/plugins/yubikey_hid_cleanup_review_fixes_spec.rb +52 -0
- data/spec/lib/pwn/plugins/yubikey_lifecycle_audit_spec.rb +65 -0
- data/spec/lib/pwn/plugins/yubikey_options_audit_spec.rb +30 -0
- data/spec/lib/pwn/plugins/yubikey_selector_audit_spec.rb +26 -0
- data/spec/lib/pwn/plugins/yubikey_spec.rb +1 -1
- data/spec/lib/pwn/plugins/zaproxy_namespace_audit_spec.rb +30 -0
- data/spec/lib/pwn/reports/empty_report_audit_spec.rb +18 -0
- data/spec/lib/pwn/reports/pdf_spec.rb +25 -0
- data/spec/lib/pwn/reports/provider_review_encoding_regression_spec.rb +35 -0
- data/spec/lib/pwn/sast/engine_runtime_regression_spec.rb +91 -0
- data/spec/lib/pwn/sast/filter_edge_regression_spec.rb +39 -0
- data/spec/lib/pwn/sast/formatter_review_fixes_spec.rb +178 -0
- data/spec/lib/pwn/sast/path_review_fixes_spec.rb +60 -0
- data/spec/lib/pwn/sast/pom_runtime_regression_spec.rb +37 -0
- data/spec/lib/pwn/sast/rules_runtime_regression_spec.rb +78 -0
- data/spec/lib/pwn/sast/sql_review_fixes_spec.rb +38 -0
- data/spec/lib/pwn/sdr/decoder/base_iq_spec.rb +21 -18
- data/spec/lib/pwn/sdr/decoder/base_review_fixes_spec.rb +49 -0
- data/spec/lib/pwn/sdr/decoder/base_validation_spec.rb +78 -0
- data/spec/lib/pwn/sdr/decoder/lora_spec.rb +9 -0
- data/spec/lib/pwn/sdr/flipper_zero_review_fixes_spec.rb +34 -0
- data/spec/lib/pwn/sdr/gqrx_operational_spec.rb +83 -0
- data/spec/lib/pwn/sdr/gqrx_review_fixes_spec.rb +22 -0
- data/spec/lib/pwn/sdr/son_micro_rfid_review_fixes_spec.rb +113 -0
- data/spec/lib/pwn/sdr/son_micro_rfid_serial_review_fixes_spec.rb +76 -0
- data/spec/lib/pwn/sdr/son_micro_rfid_spec.rb +39 -0
- data/spec/lib/pwn/sdr_spec.rb +5 -0
- data/spec/lib/pwn/session_cleanup_concurrency_spec.rb +21 -0
- data/spec/lib/pwn/session_cleanup_default_spec.rb +1 -1
- data/spec/lib/pwn/session_cleanup_lifecycle_supplement_spec.rb +39 -0
- data/spec/lib/pwn/session_cleanup_payload_spec.rb +3 -2
- data/spec/lib/pwn/session_trace_lifecycle_supplement_spec.rb +39 -0
- data/spec/lib/pwn/sessions_archive_closure_spec.rb +126 -0
- data/spec/lib/pwn/sessions_lifecycle_closure_spec.rb +373 -0
- data/spec/lib/pwn/sessions_lifecycle_supplement_spec.rb +204 -0
- data/spec/lib/pwn/setup_operational_regression_spec.rb +36 -0
- data/spec/lib/pwn/www/browser_review_fixes_spec.rb +70 -0
- data/spec/lib/pwn/www/browser_runtime_regression_spec.rb +100 -0
- data/spec/lib/pwn/www/hacker_one_runtime_regression_spec.rb +146 -0
- data/spec/lib/pwn/www/pagination_review_fixes_spec.rb +84 -0
- data/spec/spec_helper.rb +34 -5
- data/spec/support/namespace_controller_observability_fixture.rb +141 -0
- data/spec/support/sandbox.rb +8 -5
- data/third_party/pwn_rdoc.jsonl +83 -32
- metadata +7690 -7386
- data/etc/default_skills/pwn/aws/elastic_transcoder/SKILL.md +0 -48
- data/etc/default_skills/pwn/aws/lambda_preview/SKILL.md +0 -48
- data/etc/default_skills/pwn/aws/ops_works/SKILL.md +0 -48
- data/etc/default_skills/pwn/aws/ops_works_cm/SKILL.md +0 -48
- data/etc/default_skills/pwn/aws/sms/SKILL.md +0 -48
- data/lib/pwn/aws/elastic_transcoder.rb +0 -95
- data/lib/pwn/aws/lambda_preview.rb +0 -95
- data/lib/pwn/aws/ops_works.rb +0 -95
- data/lib/pwn/aws/ops_works_cm.rb +0 -95
- data/lib/pwn/aws/sms.rb +0 -95
- data/spec/lib/pwn/aws/elastic_transcoder_spec.rb +0 -15
- data/spec/lib/pwn/aws/lambda_preview_spec.rb +0 -15
- data/spec/lib/pwn/aws/ops_works_cm_spec.rb +0 -15
- data/spec/lib/pwn/aws/ops_works_spec.rb +0 -15
- data/spec/lib/pwn/aws/sms_spec.rb +0 -15
data/lib/pwn/sessions.rb
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
require 'json'
|
|
4
4
|
require 'fileutils'
|
|
5
|
+
require 'tmpdir'
|
|
5
6
|
require 'time'
|
|
6
7
|
require 'securerandom'
|
|
7
8
|
require 'digest'
|
|
@@ -29,6 +30,16 @@ module PWN
|
|
|
29
30
|
TITLE_WORD_MAX = 7
|
|
30
31
|
METADATA_MUTEX = Mutex.new
|
|
31
32
|
|
|
33
|
+
# A checked unlink can fail after earlier files have already disappeared.
|
|
34
|
+
class PartialDeletion < IOError
|
|
35
|
+
attr_reader :result
|
|
36
|
+
|
|
37
|
+
def initialize(result)
|
|
38
|
+
@result = result
|
|
39
|
+
super('Session deletion interrupted; inspect the recovery ledger before retrying')
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
|
|
32
43
|
SESSION_ID = /\A\d{8}_\d{6}_[0-9a-f]{8}\z/
|
|
33
44
|
# Selectors follow writer-owned schemas only; never recurse through payloads.
|
|
34
45
|
# :values is a documented map, :items an array, :path a session file path.
|
|
@@ -68,8 +79,8 @@ module PWN
|
|
|
68
79
|
|
|
69
80
|
# Supported Method Parameters::
|
|
70
81
|
# dir = PWN::Sessions.sessions_dir
|
|
71
|
-
public_class_method def self.sessions_dir
|
|
72
|
-
FileUtils.mkdir_p(SESSIONS_DIR)
|
|
82
|
+
public_class_method def self.sessions_dir(opts = {})
|
|
83
|
+
FileUtils.mkdir_p(SESSIONS_DIR) unless opts[:read_only]
|
|
73
84
|
SESSIONS_DIR
|
|
74
85
|
end
|
|
75
86
|
|
|
@@ -88,7 +99,7 @@ module PWN
|
|
|
88
99
|
when :trace then ['traces', File.join(id, 'trace.jsonl')]
|
|
89
100
|
else raise ArgumentError, 'Invalid session support kind'
|
|
90
101
|
end
|
|
91
|
-
directory = opts[:read_only]
|
|
102
|
+
directory = sessions_dir(read_only: opts[:read_only] == true)
|
|
92
103
|
legacy = File.join(directory, name)
|
|
93
104
|
return legacy if File.exist?(legacy) || File.symlink?(legacy)
|
|
94
105
|
|
|
@@ -105,7 +116,7 @@ module PWN
|
|
|
105
116
|
# Supported Method Parameters::
|
|
106
117
|
# sessions = PWN::Sessions.list
|
|
107
118
|
public_class_method def self.list(opts = {})
|
|
108
|
-
dir = sessions_dir
|
|
119
|
+
dir = sessions_dir(read_only: true)
|
|
109
120
|
references = opts[:references] || dependency_index
|
|
110
121
|
Dir.glob(File.join(dir, '*.jsonl')).reverse.filter_map do |f|
|
|
111
122
|
naming = retention_status(session_id: File.basename(f, '.jsonl'), references: references)
|
|
@@ -566,8 +577,9 @@ module PWN
|
|
|
566
577
|
path = support_path(kind: :owner, session_id: "#{Process.pid}-#{start}")
|
|
567
578
|
@activity_owner_mutex ||= Mutex.new
|
|
568
579
|
@activity_owner_mutex.synchronize do
|
|
569
|
-
|
|
570
|
-
|
|
580
|
+
# A fork can inherit a Hash still being iterated by a vanished thread.
|
|
581
|
+
# Insert into a fresh registry, never into that inherited iterator.
|
|
582
|
+
@activity_owners = (@activity_owners || {}).reject do |owner_path, handle|
|
|
571
583
|
expired = !File.exist?(owner_path) || !owner_path.include?(".activity-owner-#{Process.pid}-")
|
|
572
584
|
handle.close if expired && !handle.closed?
|
|
573
585
|
expired
|
|
@@ -641,13 +653,13 @@ module PWN
|
|
|
641
653
|
# this effective title. Explicit titles follow the same seven-word limit.
|
|
642
654
|
public_class_method def self.metadata(opts = {})
|
|
643
655
|
sid = opts[:session_id].to_s
|
|
644
|
-
path = support_path(kind: :metadata, session_id: sid)
|
|
656
|
+
path = support_path(kind: :metadata, session_id: sid, read_only: true)
|
|
645
657
|
if File.file?(path)
|
|
646
658
|
stored = JSON.parse(File.read(path), symbolize_names: true)
|
|
647
659
|
return stored.merge(id: sid, title: bounded_title(title: stored[:title])) if stored.is_a?(Hash) && !bounded_title(title: stored[:title]).empty?
|
|
648
660
|
end
|
|
649
661
|
|
|
650
|
-
first = File.open(File.join(
|
|
662
|
+
first = File.open(File.join(SESSIONS_DIR, "#{sid}.jsonl"), &:gets)
|
|
651
663
|
row = JSON.parse(first.to_s, symbolize_names: true)
|
|
652
664
|
title = row[:content].to_s.delete_prefix('Session started: ') if row[:role] == 'system' && row[:content].to_s.start_with?('Session started: ')
|
|
653
665
|
{ id: sid, title: bounded_title(title: title.to_s.empty? ? "pwn-ai session #{sid}" : title) }
|
|
@@ -663,10 +675,10 @@ module PWN
|
|
|
663
675
|
status = { title_source: nil, is_summarized: false, classification: :unknown, title_reason: 'invalid_session' }
|
|
664
676
|
return status unless sid.match?(SESSION_ID)
|
|
665
677
|
|
|
666
|
-
path = File.join(
|
|
678
|
+
path = File.join(SESSIONS_DIR, "#{sid}.jsonl")
|
|
667
679
|
return status.merge(title_reason: 'invalid_transcript') unless cleanup_transcript_valid?(path: path)
|
|
668
680
|
|
|
669
|
-
meta_path = support_path(kind: :metadata, session_id: sid)
|
|
681
|
+
meta_path = support_path(kind: :metadata, session_id: sid, read_only: true)
|
|
670
682
|
return status.merge(classification: :unnamed, title_reason: 'missing_summary_provenance') unless File.exist?(meta_path) || File.symlink?(meta_path)
|
|
671
683
|
return status.merge(title_reason: 'unsafe_metadata') unless File.file?(meta_path) && !File.symlink?(meta_path)
|
|
672
684
|
|
|
@@ -887,11 +899,14 @@ module PWN
|
|
|
887
899
|
# Supported Method Parameters::
|
|
888
900
|
# transcript = PWN::Sessions.load(session_id: 'required')
|
|
889
901
|
public_class_method def self.load(opts = {})
|
|
890
|
-
sid = opts[:session_id]
|
|
902
|
+
sid = opts[:session_id].to_s
|
|
903
|
+
raise ArgumentError, 'Invalid session ID' if sid.empty? || File.basename(sid) != sid || sid.include?("\0") || %w[. ..].include?(sid)
|
|
904
|
+
|
|
891
905
|
path = File.join(sessions_dir, "#{sid}.jsonl")
|
|
906
|
+
raise IOError, 'Unsafe session transcript' if File.symlink?(path) || (File.exist?(path) && File.realpath(path) != File.expand_path(path))
|
|
892
907
|
return PWN::AI::Agent::Learning.session_evidence(session_id: sid) || [] unless File.exist?(path)
|
|
893
908
|
|
|
894
|
-
File.
|
|
909
|
+
File.open(path, File::RDONLY | File::NOFOLLOW) { |file| file.each_line.map { |line| JSON.parse(line, symbolize_names: true) } }
|
|
895
910
|
end
|
|
896
911
|
|
|
897
912
|
# Newest session that is not exclude_session_id (the prior pwn-ai run).
|
|
@@ -1064,6 +1079,53 @@ module PWN
|
|
|
1064
1079
|
[]
|
|
1065
1080
|
end
|
|
1066
1081
|
|
|
1082
|
+
# Store locks precede transcript leases and transcript writer locks. All
|
|
1083
|
+
# maintenance acquisitions are nonblocking, including initially absent stores.
|
|
1084
|
+
# Learning precedes Backups (the coordinator already owns both). Producers
|
|
1085
|
+
# take their store lock then a nonblocking shared source lease before reading
|
|
1086
|
+
# or publishing references; a publisher losing deletion must reject the source.
|
|
1087
|
+
public_class_method def self.with_dependency_locks(opts = {})
|
|
1088
|
+
return yield if opts[:dry_run] || dependency_locks_owned?
|
|
1089
|
+
|
|
1090
|
+
locks = []
|
|
1091
|
+
previous = Thread.current[:pwn_session_dependency_locks]
|
|
1092
|
+
learning = PWN::AI::Agent::Learning.send(:learning_lock, nonblocking: true)
|
|
1093
|
+
raise IOError, 'Dependency writer active: Learning' if learning == :busy
|
|
1094
|
+
|
|
1095
|
+
return PWN::Backups.transaction { with_dependency_locks(opts.merge(backup: false)) { yield } } if opts[:backup] && !PWN::Backups.active? # rubocop:disable Style/ExplicitBlockArgument -- public module contract accepts only the options hash
|
|
1096
|
+
|
|
1097
|
+
root = File.join(Dir.home, '.pwn')
|
|
1098
|
+
paths = [File.join(File.dirname(PWN::Plugins::Findings::FILE), '.findings-write.lock'),
|
|
1099
|
+
File.join(root, '.swarm-continuations.lock'), "#{PWN::Memory::MEMORY_FILE}.write.lock",
|
|
1100
|
+
"#{PWN::AI::Agent::Mistakes::MISTAKES_FILE}.write.lock"]
|
|
1101
|
+
# The index scans HOME; explicit writer paths may be overridden by callers.
|
|
1102
|
+
paths.concat(%w[.findings-write.lock memory.json.write.lock mistakes.json.write.lock].map { |name| File.join(root, name) })
|
|
1103
|
+
paths << File.join(root, '.learning-write.lock') unless File.dirname(PWN::AI::Agent::Learning::LEARNING_FILE) == root
|
|
1104
|
+
paths = paths.uniq.sort
|
|
1105
|
+
paths.each do |path|
|
|
1106
|
+
FileUtils.mkdir_p(File.dirname(path), mode: 0o700)
|
|
1107
|
+
raise IOError, 'Unsafe dependency lock directory' unless File.realpath(File.dirname(path)) == File.expand_path(File.dirname(path))
|
|
1108
|
+
|
|
1109
|
+
lock = File.open(path, File::RDWR | File::CREAT | File::NOFOLLOW, 0o600) # rubocop:disable Style/FileOpen -- transaction owns all handles
|
|
1110
|
+
locks << lock
|
|
1111
|
+
raise IOError, 'Dependency writer active' unless lock.flock(File::LOCK_EX | File::LOCK_NB)
|
|
1112
|
+
end
|
|
1113
|
+
Thread.current[:pwn_session_dependency_locks] = { pid: Process.pid, thread: Thread.current, root: root, locks: locks }
|
|
1114
|
+
yield
|
|
1115
|
+
ensure
|
|
1116
|
+
if locks
|
|
1117
|
+
Thread.current[:pwn_session_dependency_locks] = previous
|
|
1118
|
+
locks.reverse_each(&:close)
|
|
1119
|
+
PWN::AI::Agent::Learning.send(:learning_unlock, lock: learning) if learning && learning != :busy
|
|
1120
|
+
end
|
|
1121
|
+
end
|
|
1122
|
+
|
|
1123
|
+
private_class_method def self.dependency_locks_owned?
|
|
1124
|
+
owner = Thread.current[:pwn_session_dependency_locks]
|
|
1125
|
+
owner && owner[:pid] == Process.pid && owner[:thread] == Thread.current &&
|
|
1126
|
+
owner[:root] == File.join(Dir.home, '.pwn') && owner[:locks].none?(&:closed?)
|
|
1127
|
+
end
|
|
1128
|
+
|
|
1067
1129
|
# Supported Method Parameters::
|
|
1068
1130
|
# PWN::Sessions.delete(
|
|
1069
1131
|
# session_id: 'required',
|
|
@@ -1071,6 +1133,8 @@ module PWN
|
|
|
1071
1133
|
# )
|
|
1072
1134
|
# Refuses deletion of pinned sessions (hot/gold/mistake/current) unless force:true.
|
|
1073
1135
|
public_class_method def self.delete(opts = {})
|
|
1136
|
+
return with_dependency_locks(backup: true) { delete(opts) } unless dependency_locks_owned?
|
|
1137
|
+
|
|
1074
1138
|
sid = opts[:session_id].to_s
|
|
1075
1139
|
raise 'ERROR: session_id required' if sid.to_s.empty?
|
|
1076
1140
|
raise ArgumentError, 'Invalid session ID' if File.basename(sid) != sid || sid.include?("\0") || sid == '.' || sid == '..'
|
|
@@ -1082,17 +1146,86 @@ module PWN
|
|
|
1082
1146
|
raise IOError, "Session #{sid} is active" unless File.identical?(lock, lock_path) && lock.flock(File::LOCK_EX | File::LOCK_NB)
|
|
1083
1147
|
|
|
1084
1148
|
unless force
|
|
1085
|
-
pins = protected_session_ids(current_session_id: opts[:current_session_id])
|
|
1149
|
+
pins = protected_session_ids(current_session_id: opts[:current_session_id], hot_days: opts[:hot_days], include_activity: false)
|
|
1086
1150
|
raise "ERROR: refusing to delete protected session #{sid.inspect} (pinned by HOT_DAYS/gold/mistakes/current; pass force:true)" if pins.include?(sid.to_s)
|
|
1087
1151
|
end
|
|
1088
1152
|
|
|
1089
|
-
|
|
1090
|
-
|
|
1153
|
+
paths = [path, support_path(kind: :metadata, session_id: sid, read_only: true)].select { |file| File.exist?(file) || File.symlink?(file) }
|
|
1154
|
+
return true if paths.empty?
|
|
1155
|
+
|
|
1156
|
+
progress = { session_id: sid, state: 'prepared', deleted_paths: [], remaining_paths: paths.dup }
|
|
1157
|
+
journal = opts[:deletion_progress] || deletion_journal(session_id: sid, paths: paths)
|
|
1158
|
+
journal.call(progress)
|
|
1159
|
+
paths.each do |file|
|
|
1160
|
+
File.unlink(file)
|
|
1161
|
+
progress[:deleted_paths] << file
|
|
1162
|
+
progress[:remaining_paths].delete(file)
|
|
1163
|
+
journal.call(progress)
|
|
1164
|
+
end
|
|
1165
|
+
progress[:state] = 'committed'
|
|
1166
|
+
journal.call(progress)
|
|
1091
1167
|
true
|
|
1168
|
+
rescue StandardError, Interrupt, SystemExit => e
|
|
1169
|
+
if progress && journal
|
|
1170
|
+
progress[:state] = 'interrupted'
|
|
1171
|
+
progress[:error] = e.class.name
|
|
1172
|
+
begin
|
|
1173
|
+
journal.call(progress)
|
|
1174
|
+
rescue StandardError => journal_error
|
|
1175
|
+
progress[:journal_error] = journal_error.class.name
|
|
1176
|
+
end
|
|
1177
|
+
raise PartialDeletion, progress if e.is_a?(StandardError) && progress[:deleted_paths].any?
|
|
1178
|
+
end
|
|
1179
|
+
raise
|
|
1092
1180
|
ensure
|
|
1093
1181
|
lock&.close unless opts[:cleanup_lock]
|
|
1094
1182
|
end
|
|
1095
1183
|
|
|
1184
|
+
# The callback form lets the coordinator use its already verified backup
|
|
1185
|
+
# without duplicating payload I/O or overwriting its multi-session ledger.
|
|
1186
|
+
private_class_method def self.deletion_journal(opts = {})
|
|
1187
|
+
id = opts[:session_id]
|
|
1188
|
+
directory = PWN::Backups.directory(label: 'session-delete')
|
|
1189
|
+
record = { id: id, files: {} }
|
|
1190
|
+
opts[:paths].each do |path|
|
|
1191
|
+
raise IOError, 'Unsafe deletion source' unless File.file?(path) && File.realpath(path) == File.expand_path(path)
|
|
1192
|
+
|
|
1193
|
+
bytes = File.binread(path)
|
|
1194
|
+
digest = Digest::SHA256.hexdigest(bytes)
|
|
1195
|
+
target = File.join(directory, File.basename(path))
|
|
1196
|
+
atomic_publish(path: target, bytes: bytes)
|
|
1197
|
+
raise IOError, 'Deletion backup mismatch' unless Digest::SHA256.file(target).hexdigest == digest && File.binread(path) == bytes
|
|
1198
|
+
|
|
1199
|
+
record[:files][File.basename(path)] = { sha256: digest, size: bytes.bytesize }
|
|
1200
|
+
end
|
|
1201
|
+
ledger = File.join(directory, 'ledger.json')
|
|
1202
|
+
lambda do |progress|
|
|
1203
|
+
progress[:ledger] = ledger
|
|
1204
|
+
record[:deletion] = progress
|
|
1205
|
+
record[:deleted] = progress[:state] == 'committed'
|
|
1206
|
+
deleted = progress[:deleted_paths].any? { |path| path.end_with?("/#{id}.jsonl") }
|
|
1207
|
+
atomic_publish(path: ledger, bytes: JSON.generate(state: progress[:state], dry_run: false, records: [record], deleted_ids: deleted ? [id] : []))
|
|
1208
|
+
end
|
|
1209
|
+
end
|
|
1210
|
+
|
|
1211
|
+
private_class_method def self.atomic_publish(opts = {})
|
|
1212
|
+
path = opts[:path]
|
|
1213
|
+
temporary = "#{path}.#{SecureRandom.hex(12)}.tmp"
|
|
1214
|
+
identity = nil
|
|
1215
|
+
File.open(temporary, File::WRONLY | File::CREAT | File::EXCL | File::NOFOLLOW, 0o600) do |file|
|
|
1216
|
+
identity = [file.stat.dev, file.stat.ino]
|
|
1217
|
+
file.write(opts[:bytes])
|
|
1218
|
+
file.flush
|
|
1219
|
+
file.fsync
|
|
1220
|
+
raise IOError, 'Atomic temporary changed' unless File.identical?(file, temporary)
|
|
1221
|
+
|
|
1222
|
+
File.rename(temporary, path)
|
|
1223
|
+
File.open(File.dirname(path), File::RDONLY, &:fsync)
|
|
1224
|
+
end
|
|
1225
|
+
ensure
|
|
1226
|
+
remove_owned_temporary(path: temporary, identity: identity) if identity
|
|
1227
|
+
end
|
|
1228
|
+
|
|
1096
1229
|
# Supported Method Parameters::
|
|
1097
1230
|
# stats = PWN::Sessions.stats
|
|
1098
1231
|
public_class_method def self.stats
|
|
@@ -1127,7 +1260,7 @@ module PWN
|
|
|
1127
1260
|
current = opts[:current_session_id].to_s
|
|
1128
1261
|
current = PWN::Env.dig(:ai, :session_id).to_s if current.empty? && defined?(PWN::Env)
|
|
1129
1262
|
|
|
1130
|
-
dir =
|
|
1263
|
+
dir = SESSIONS_DIR
|
|
1131
1264
|
files = Dir.glob(File.join(dir, '*.jsonl'))
|
|
1132
1265
|
before_bytes = files.sum { |f| File.size(f) }
|
|
1133
1266
|
now = Time.now.utc
|
|
@@ -1142,6 +1275,17 @@ module PWN
|
|
|
1142
1275
|
deleted = []
|
|
1143
1276
|
compacted = []
|
|
1144
1277
|
protected_n = 0
|
|
1278
|
+
skipped = {}
|
|
1279
|
+
partial_deletions = []
|
|
1280
|
+
remove = lambda do |entry|
|
|
1281
|
+
delete(session_id: entry[:id], current_session_id: current, hot_days: hot_days) unless dry
|
|
1282
|
+
deleted << entry[:id]
|
|
1283
|
+
rescue PartialDeletion => e
|
|
1284
|
+
partial_deletions << e.result
|
|
1285
|
+
deleted << entry[:id] if e.result[:deleted_paths].include?(entry[:path])
|
|
1286
|
+
rescue IOError, RuntimeError, SystemCallError => e
|
|
1287
|
+
skipped[entry[:id]] = e.class.name
|
|
1288
|
+
end
|
|
1145
1289
|
|
|
1146
1290
|
# Classify
|
|
1147
1291
|
entries = files.map do |path|
|
|
@@ -1162,8 +1306,7 @@ module PWN
|
|
|
1162
1306
|
aged = e[:age] > retain_days
|
|
1163
1307
|
next unless stub || aged
|
|
1164
1308
|
|
|
1165
|
-
|
|
1166
|
-
FileUtils.rm_f([e[:path], support_path(kind: :metadata, session_id: e[:id])]) unless dry
|
|
1309
|
+
remove.call(e)
|
|
1167
1310
|
end
|
|
1168
1311
|
|
|
1169
1312
|
# Refresh remaining after deletes
|
|
@@ -1174,9 +1317,8 @@ module PWN
|
|
|
1174
1317
|
unpinned = remaining.reject { |e| e[:pinned] }.sort_by { |e| e[:mtime] }
|
|
1175
1318
|
over = remaining.size - max_files
|
|
1176
1319
|
unpinned.first(over).each do |e|
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
remaining.delete(e)
|
|
1320
|
+
remove.call(e)
|
|
1321
|
+
remaining.delete(e) if deleted.include?(e[:id])
|
|
1180
1322
|
end
|
|
1181
1323
|
end
|
|
1182
1324
|
|
|
@@ -1199,10 +1341,17 @@ module PWN
|
|
|
1199
1341
|
after_bytes = after_files.sum { |f| File.size(f) }
|
|
1200
1342
|
|
|
1201
1343
|
{
|
|
1344
|
+
state: if partial_deletions.empty?
|
|
1345
|
+
dry ? 'planned' : 'committed'
|
|
1346
|
+
else
|
|
1347
|
+
'interrupted'
|
|
1348
|
+
end,
|
|
1349
|
+
partial_deletions: partial_deletions,
|
|
1202
1350
|
deleted: deleted.length,
|
|
1203
1351
|
deleted_ids: deleted.first(30),
|
|
1204
1352
|
compacted: compacted.length,
|
|
1205
1353
|
compacted_ids: compacted.first(30),
|
|
1354
|
+
skipped: skipped,
|
|
1206
1355
|
protected: protected_n,
|
|
1207
1356
|
remaining: after_files.size,
|
|
1208
1357
|
bytes_before: before_bytes,
|
|
@@ -1222,10 +1371,12 @@ module PWN
|
|
|
1222
1371
|
Dir.glob(File.join(SESSIONS_DIR, '*.jsonl')).each { |path| pins[File.basename(path, '.jsonl')] = true } if references[:errors].any?
|
|
1223
1372
|
pins[opts[:current_session_id].to_s] = true unless opts[:current_session_id].to_s.empty?
|
|
1224
1373
|
|
|
1225
|
-
#
|
|
1226
|
-
|
|
1374
|
+
# Activity is a pin, but callers already holding the exclusive cleanup
|
|
1375
|
+
# lease omit their own lock from this probe and still recheck dependencies.
|
|
1376
|
+
Dir.glob(File.join(SESSIONS_DIR, '*.jsonl')).each do |path|
|
|
1377
|
+
id = File.basename(path, '.jsonl')
|
|
1227
1378
|
age = (now - File.mtime(path).utc) / 86_400.0
|
|
1228
|
-
pins[
|
|
1379
|
+
pins[id] = true if age <= hot_days || (opts[:include_activity] != false && active?(session_id: id))
|
|
1229
1380
|
end
|
|
1230
1381
|
|
|
1231
1382
|
# Learning gold
|
|
@@ -1271,15 +1422,26 @@ module PWN
|
|
|
1271
1422
|
end
|
|
1272
1423
|
|
|
1273
1424
|
private_class_method def self.compact_transcript!(opts = {})
|
|
1425
|
+
return with_dependency_locks { compact_transcript!(opts) } unless opts[:dry_run] || dependency_locks_owned?
|
|
1426
|
+
|
|
1274
1427
|
path = opts[:path]
|
|
1275
1428
|
tool_max = opts[:tool_max] || TOOL_CONTENT_MAX
|
|
1276
1429
|
asst_max = opts[:assistant_content_max] || opts[:asst_max] || ASSISTANT_CONTENT_MAX
|
|
1277
1430
|
dry = opts[:dry_run] ? true : false
|
|
1278
1431
|
return false unless File.exist?(path)
|
|
1279
1432
|
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1433
|
+
id = File.basename(path, '.jsonl')
|
|
1434
|
+
return false if dry && active?(session_id: id)
|
|
1435
|
+
|
|
1436
|
+
unless dry
|
|
1437
|
+
lease = File.open(support_path(kind: :lease, session_id: id), File::RDWR | File::CREAT | File::NOFOLLOW, 0o600) # rubocop:disable Style/FileOpen -- exclusive maintenance lease closed in ensure
|
|
1438
|
+
return false unless lease.flock(File::LOCK_EX | File::LOCK_NB)
|
|
1439
|
+
|
|
1440
|
+
writer = File.open("#{path}.write.lock", File::RDWR | File::CREAT | File::NOFOLLOW, 0o600) # rubocop:disable Style/FileOpen -- held through atomic replace; ensure closes it
|
|
1441
|
+
writer.flock(File::LOCK_EX)
|
|
1442
|
+
end
|
|
1443
|
+
return false if protected_session_ids(hot_days: 0, include_activity: dry).include?(id)
|
|
1444
|
+
|
|
1283
1445
|
lines = File.readlines(path)
|
|
1284
1446
|
rows = lines.map { |line| JSON.parse(line, symbolize_names: true) }
|
|
1285
1447
|
return false if rows.empty?
|
|
@@ -1307,7 +1469,9 @@ module PWN
|
|
|
1307
1469
|
return changed if dry || !changed
|
|
1308
1470
|
|
|
1309
1471
|
tmp = "#{path}.#{SecureRandom.hex(12)}.tmp"
|
|
1472
|
+
identity = nil
|
|
1310
1473
|
File.open(tmp, File::WRONLY | File::CREAT | File::EXCL | File::NOFOLLOW, 0o600) do |f|
|
|
1474
|
+
identity = [f.stat.dev, f.stat.ino]
|
|
1311
1475
|
f.flock(File::LOCK_EX)
|
|
1312
1476
|
rows.each { |e| f.puts(JSON.generate(e)) }
|
|
1313
1477
|
f.flush
|
|
@@ -1317,7 +1481,7 @@ module PWN
|
|
|
1317
1481
|
File.open(File.dirname(path), File::RDONLY, &:fsync)
|
|
1318
1482
|
true
|
|
1319
1483
|
ensure
|
|
1320
|
-
|
|
1484
|
+
remove_owned_temporary(path: tmp, identity: identity) if identity
|
|
1321
1485
|
writer&.close
|
|
1322
1486
|
deactivate(lease: lease)
|
|
1323
1487
|
end
|
|
@@ -1334,7 +1498,13 @@ module PWN
|
|
|
1334
1498
|
|
|
1335
1499
|
dir = File.join(Dir.home, '.pwn', 'exports')
|
|
1336
1500
|
FileUtils.mkdir_p(dir)
|
|
1501
|
+
raise IOError, 'Unsafe session export directory' unless File.realpath(dir) == File.expand_path(dir)
|
|
1502
|
+
|
|
1337
1503
|
dest = File.join(dir, "#{sid}.tar.gz")
|
|
1504
|
+
archive = File.join(dir, ".#{sid}.#{SecureRandom.hex(12)}.tmp")
|
|
1505
|
+
archive_file = File.open(archive, File::RDWR | File::CREAT | File::EXCL | File::NOFOLLOW, 0o600) # rubocop:disable Style/FileOpen -- reserved through tar and atomic publication
|
|
1506
|
+
archive_identity = [archive_file.stat.dev, archive_file.stat.ino]
|
|
1507
|
+
archive_file.flock(File::LOCK_EX)
|
|
1338
1508
|
manifest = {}
|
|
1339
1509
|
Dir.mktmpdir do |tmp|
|
|
1340
1510
|
lines = transcript.map { |row| JSON.generate(PWN::Redaction.redact(value: row)) }
|
|
@@ -1351,35 +1521,128 @@ module PWN
|
|
|
1351
1521
|
end
|
|
1352
1522
|
end
|
|
1353
1523
|
File.write(File.join(tmp, 'manifest.json'), JSON.generate(manifest))
|
|
1354
|
-
system('tar', '-czf',
|
|
1524
|
+
raise IOError, 'Session export tar failed' unless system('tar', '-czf', '-', '-C', tmp, '.', out: archive_file)
|
|
1525
|
+
raise IOError, 'Session export temporary changed' unless File.identical?(archive_file, archive)
|
|
1526
|
+
|
|
1527
|
+
archive_file.flush
|
|
1528
|
+
archive_file.fsync
|
|
1529
|
+
File.rename(archive, dest)
|
|
1355
1530
|
end
|
|
1356
1531
|
{ path: dest, session_id: sid, manifest: manifest }
|
|
1532
|
+
ensure
|
|
1533
|
+
archive_file&.close
|
|
1534
|
+
remove_owned_temporary(path: archive, identity: archive_identity) if archive_identity
|
|
1357
1535
|
end
|
|
1358
1536
|
|
|
1359
1537
|
public_class_method def self.retain(opts = {})
|
|
1538
|
+
return with_dependency_locks { retain(opts) } unless dependency_locks_owned?
|
|
1539
|
+
|
|
1360
1540
|
days = (opts[:days] || 90).to_i
|
|
1361
1541
|
cutoff = Time.now - (days * 86_400)
|
|
1362
|
-
|
|
1542
|
+
records = []
|
|
1363
1543
|
pins = protected_session_ids(hot_days: 0)
|
|
1364
1544
|
Dir[File.join(sessions_dir, '*.jsonl')].each do |path|
|
|
1365
|
-
next if pins.include?(File.basename(path, '.jsonl'))
|
|
1366
|
-
next if File.mtime(path) > cutoff
|
|
1367
|
-
|
|
1368
1545
|
id = File.basename(path, '.jsonl')
|
|
1546
|
+
next if pins.include?(id) || File.mtime(path) > cutoff
|
|
1547
|
+
|
|
1369
1548
|
File.open(support_path(kind: :lease, session_id: id), File::RDWR | File::CREAT | File::NOFOLLOW, 0o600) do |lock|
|
|
1370
1549
|
next unless lock.flock(File::LOCK_EX | File::LOCK_NB)
|
|
1371
1550
|
next unless File.file?(path) && File.mtime(path) <= cutoff
|
|
1551
|
+
next if protected_session_ids(hot_days: 0, include_activity: false).include?(id)
|
|
1552
|
+
|
|
1553
|
+
records << retain_transcript(path: path, session_id: id)
|
|
1554
|
+
end
|
|
1555
|
+
end
|
|
1556
|
+
{ deleted: 0, gzipped: records.count { |row| row[:state] == 'committed' }, days: days, records: records }
|
|
1557
|
+
end
|
|
1372
1558
|
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1559
|
+
private_class_method def self.retain_transcript(opts = {})
|
|
1560
|
+
path = opts[:path]
|
|
1561
|
+
id = opts[:session_id]
|
|
1562
|
+
archive = "#{path}.gz"
|
|
1563
|
+
directory = File.join(Dir.home, '.pwn', 'maintenance', 'retention')
|
|
1564
|
+
ancestor = directory
|
|
1565
|
+
ancestor = File.dirname(ancestor) until File.exist?(ancestor) || File.symlink?(ancestor)
|
|
1566
|
+
raise IOError, 'Unsafe retention journal directory' unless File.realpath(ancestor) == File.expand_path(ancestor)
|
|
1567
|
+
|
|
1568
|
+
FileUtils.mkdir_p(directory, mode: 0o700)
|
|
1569
|
+
ledger = File.join(directory, "#{Digest::SHA256.hexdigest(path)}.json")
|
|
1570
|
+
source_hash = Digest::SHA256.file(path).hexdigest
|
|
1571
|
+
report = { id: id, state: 'prepared', ledger: ledger }
|
|
1572
|
+
if File.exist?(archive) || File.symlink?(archive)
|
|
1573
|
+
raise IOError, 'Unowned retention archive' unless File.file?(ledger) && !File.symlink?(ledger)
|
|
1574
|
+
|
|
1575
|
+
record = JSON.parse(File.binread(ledger), symbolize_names: true)
|
|
1576
|
+
raise IOError, 'Unverified retention archive' unless record[:version] == 1 && record[:path] == path && record[:source_sha256] == source_hash &&
|
|
1577
|
+
record[:archive] == archive && !File.symlink?(archive) && File.file?(archive) &&
|
|
1578
|
+
[File.stat(archive).dev, File.stat(archive).ino] == record[:identity] && Digest::SHA256.file(archive).hexdigest == record[:sha256]
|
|
1579
|
+
|
|
1580
|
+
owned_record = true
|
|
1581
|
+
else
|
|
1582
|
+
lines = File.readlines(path)
|
|
1583
|
+
keep = lines.length <= 40 ? lines : lines.first(20) + lines.last(20)
|
|
1584
|
+
temporary = "#{path}.#{SecureRandom.hex(12)}.tmp"
|
|
1585
|
+
identity = nil
|
|
1586
|
+
File.open(temporary, File::WRONLY | File::CREAT | File::EXCL | File::NOFOLLOW, 0o600) do |file|
|
|
1587
|
+
identity = [file.stat.dev, file.stat.ino]
|
|
1588
|
+
file.flock(File::LOCK_EX)
|
|
1589
|
+
gz = Zlib::GzipWriter.new(file)
|
|
1590
|
+
begin
|
|
1376
1591
|
keep.each { |line| gz.write("#{JSON.generate(PWN::Redaction.redact(value: JSON.parse(line)))}\n") }
|
|
1592
|
+
gz.finish
|
|
1593
|
+
file.flush
|
|
1594
|
+
file.fsync
|
|
1595
|
+
ensure
|
|
1596
|
+
gz.close unless gz.closed?
|
|
1377
1597
|
end
|
|
1378
|
-
|
|
1379
|
-
|
|
1598
|
+
end
|
|
1599
|
+
record = { version: 1, state: 'prepared', path: path, source_sha256: source_hash, archive: archive,
|
|
1600
|
+
temporary: temporary, identity: identity, sha256: Digest::SHA256.file(temporary).hexdigest }
|
|
1601
|
+
atomic_publish(path: ledger, bytes: JSON.generate(record))
|
|
1602
|
+
owned_record = true
|
|
1603
|
+
File.link(temporary, archive) # No-clobber publication, even for unrelated valid gzip files.
|
|
1604
|
+
File.open(File.dirname(archive), File::RDONLY, &:fsync)
|
|
1605
|
+
end
|
|
1606
|
+
record[:state] = 'published'
|
|
1607
|
+
atomic_publish(path: ledger, bytes: JSON.generate(record))
|
|
1608
|
+
raise IOError, 'Retention source changed' unless Digest::SHA256.file(path).hexdigest == source_hash
|
|
1609
|
+
|
|
1610
|
+
File.delete(path)
|
|
1611
|
+
File.open(File.dirname(path), File::RDONLY, &:fsync)
|
|
1612
|
+
record[:state] = 'committed'
|
|
1613
|
+
atomic_publish(path: ledger, bytes: JSON.generate(record))
|
|
1614
|
+
report.merge(state: 'committed')
|
|
1615
|
+
rescue StandardError => e
|
|
1616
|
+
# A published verified archive is recoverable; unknown/preexisting archives
|
|
1617
|
+
# are explicit conflicts. Neither outcome may starve later candidates.
|
|
1618
|
+
state = owned_record ? 'interrupted' : 'conflict'
|
|
1619
|
+
if owned_record
|
|
1620
|
+
record[:state] = 'interrupted'
|
|
1621
|
+
record[:error] = e.class.name
|
|
1622
|
+
begin
|
|
1623
|
+
atomic_publish(path: ledger, bytes: JSON.generate(record))
|
|
1624
|
+
rescue StandardError => journal_error
|
|
1625
|
+
report[:journal_error] = journal_error.class.name
|
|
1380
1626
|
end
|
|
1381
1627
|
end
|
|
1382
|
-
{
|
|
1628
|
+
(report || { id: id, ledger: ledger }).merge(state: state, error: e.class.name)
|
|
1629
|
+
ensure
|
|
1630
|
+
remove_owned_temporary(path: temporary, identity: identity) if identity
|
|
1631
|
+
remove_owned_temporary(path: record[:temporary], identity: record[:identity]) if owned_record && record[:state] == 'committed' && record[:temporary].to_s.match?(/\A#{Regexp.escape(path)}\.[0-9a-f]{24}\.tmp\z/)
|
|
1632
|
+
end
|
|
1633
|
+
|
|
1634
|
+
private_class_method def self.remove_owned_temporary(opts = {})
|
|
1635
|
+
path = opts[:path]
|
|
1636
|
+
identity = opts[:identity]
|
|
1637
|
+
return unless path && identity && File.exist?(path) && !File.symlink?(path)
|
|
1638
|
+
|
|
1639
|
+
File.open(path, File::RDONLY | File::NOFOLLOW) do |file|
|
|
1640
|
+
next unless file.flock(File::LOCK_EX | File::LOCK_NB) && File.identical?(file, path) && [file.stat.dev, file.stat.ino] == identity
|
|
1641
|
+
|
|
1642
|
+
File.unlink(path)
|
|
1643
|
+
end
|
|
1644
|
+
rescue IOError, SystemCallError
|
|
1645
|
+
nil
|
|
1383
1646
|
end
|
|
1384
1647
|
|
|
1385
1648
|
public_class_method def self.redact(opts = {})
|
|
@@ -1394,7 +1657,7 @@ module PWN
|
|
|
1394
1657
|
public_class_method def self.help
|
|
1395
1658
|
puts "USAGE:
|
|
1396
1659
|
# Run sessions dir and return its result
|
|
1397
|
-
#{self}.sessions_dir
|
|
1660
|
+
#{self}.sessions_dir(read_only: 'optional - resolve the session directory without creating it')
|
|
1398
1661
|
|
|
1399
1662
|
# Run list and return its result
|
|
1400
1663
|
#{self}.list(include_hidden: 'optional - include unretained sessions for diagnostics and explicit resume', current_session_id: 'optional - include this active session regardless of naming classification', references: 'optional - precomputed structural dependency index')
|
|
@@ -1411,6 +1674,9 @@ module PWN
|
|
|
1411
1674
|
# Index exact dependency file paths and uncertain stores for cleanup and listing.
|
|
1412
1675
|
#{self}.dependency_index
|
|
1413
1676
|
|
|
1677
|
+
# Serialize reference checks and mutation with cooperating publishers.
|
|
1678
|
+
#{self}.with_dependency_locks(dry_run: 'optional - yield without creating or acquiring locks for read-only plans', backup: 'optional - acquire the backup transaction before other dependency locks') { ... }
|
|
1679
|
+
|
|
1414
1680
|
# Hold a shared per-session OS lease until deactivate or process exit.
|
|
1415
1681
|
#{self}.activate(
|
|
1416
1682
|
session_id: 'required - stable transcript identifier for activity ownership',
|
|
@@ -1494,7 +1760,9 @@ module PWN
|
|
|
1494
1760
|
session_id: 'required - session id value consumed by #delete',
|
|
1495
1761
|
force: 'optional - Boolean bypass pin policy (default false)',
|
|
1496
1762
|
current_session_id: 'optional - current session id value consumed by #delete',
|
|
1497
|
-
|
|
1763
|
+
hot_days: 'optional - hot-file protection window, defaults HOT_DAYS',
|
|
1764
|
+
cleanup_lock: 'optional - already-held per-session exclusive cleanup lock',
|
|
1765
|
+
deletion_progress: 'optional - coordinator callback persisting prepared and per-file deletion states with its verified recovery backup'
|
|
1498
1766
|
)
|
|
1499
1767
|
|
|
1500
1768
|
# Run stats and return its result
|
|
@@ -1516,6 +1784,7 @@ module PWN
|
|
|
1516
1784
|
now: 'optional - now value consumed by #protected_session_ids (defaults to Time.now.utc)',
|
|
1517
1785
|
hot_days: 'optional - hot days value consumed by #protected_session_ids',
|
|
1518
1786
|
retain_days: 'optional - retain days value consumed by #protected_session_ids',
|
|
1787
|
+
include_activity: 'optional - include held activity leases; default true, false only while the caller holds an exclusive cleanup lease',
|
|
1519
1788
|
current_session_id: 'optional - current session id value consumed by #protected_session_ids'
|
|
1520
1789
|
)
|
|
1521
1790
|
|
data/lib/pwn/setup.rb
CHANGED
|
@@ -804,7 +804,7 @@ module PWN
|
|
|
804
804
|
io.puts
|
|
805
805
|
io.puts 'Re-checking…'
|
|
806
806
|
io.puts
|
|
807
|
-
result = check(io: io)
|
|
807
|
+
result = check(io: io, profile: profile)
|
|
808
808
|
{ profile: profile, ran: ran, check: result }
|
|
809
809
|
rescue StandardError => e
|
|
810
810
|
raise e
|
|
@@ -898,7 +898,7 @@ module PWN
|
|
|
898
898
|
io.puts ' backup ~/.pwn/backup (shared seven-generation store)'
|
|
899
899
|
io.puts
|
|
900
900
|
|
|
901
|
-
unless yes
|
|
901
|
+
unless yes || dry_run
|
|
902
902
|
io.print 'Proceed? [y/N] '
|
|
903
903
|
io.flush
|
|
904
904
|
ans = $stdin.gets.to_s.strip.downcase
|
|
@@ -1015,7 +1015,8 @@ module PWN
|
|
|
1015
1015
|
engine = opts[:engine]
|
|
1016
1016
|
return false unless engine
|
|
1017
1017
|
|
|
1018
|
-
PWN::Env.dig(:ai, engine.to_sym, :key).to_s
|
|
1018
|
+
key = PWN::Env.dig(:ai, engine.to_sym, :key).to_s.strip
|
|
1019
|
+
!key.empty? && !key.match?(/\A(?:required|optional)\b|REDACTED/i)
|
|
1019
1020
|
rescue StandardError
|
|
1020
1021
|
false
|
|
1021
1022
|
end
|
data/lib/pwn/version.rb
CHANGED
|
@@ -15,13 +15,25 @@ module PWN
|
|
|
15
15
|
# )
|
|
16
16
|
|
|
17
17
|
public_class_method def self.open(opts = {})
|
|
18
|
-
browser_obj = PWN::Plugins::TransparentBrowser.open(opts)
|
|
18
|
+
browser_obj = PWN::Plugins::TransparentBrowser.open(opts.dup)
|
|
19
19
|
|
|
20
20
|
browser = browser_obj[:browser]
|
|
21
21
|
browser.goto('https://app.cobalt.io')
|
|
22
22
|
|
|
23
23
|
browser_obj
|
|
24
24
|
rescue StandardError => e
|
|
25
|
+
begin
|
|
26
|
+
if browser_obj
|
|
27
|
+
# Teardown independently: a driver failure must not strand Tor.
|
|
28
|
+
begin
|
|
29
|
+
PWN::Plugins::TransparentBrowser.close(browser_obj: browser_obj.reject { |key| key == :tor_obj })
|
|
30
|
+
ensure
|
|
31
|
+
PWN::Plugins::TransparentBrowser.close(browser_obj: { tor_obj: browser_obj[:tor_obj] }) if browser_obj[:tor_obj]
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
rescue StandardError => cleanup_error
|
|
35
|
+
warn "Browser cleanup failed (#{cleanup_error.class}); preserving the navigation error"
|
|
36
|
+
end
|
|
25
37
|
raise e
|
|
26
38
|
end
|
|
27
39
|
|
|
@@ -46,7 +58,7 @@ module PWN
|
|
|
46
58
|
if password.nil?
|
|
47
59
|
password = PWN::Plugins::AuthenticationHelper.mask_password
|
|
48
60
|
else
|
|
49
|
-
password = opts[:password].to_s
|
|
61
|
+
password = opts[:password].to_s
|
|
50
62
|
end
|
|
51
63
|
mfa = opts[:mfa]
|
|
52
64
|
|