pwn 0.5.795 → 0.5.796

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.
Files changed (369) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +1 -1
  3. data/bin/pwn_autoinc_version +4 -5
  4. data/bin/pwn_web_cache_deception +40 -29
  5. data/documentation/AWS.md +15 -5
  6. data/documentation/Diagrams.md +1 -1
  7. data/documentation/Home.md +2 -2
  8. data/documentation/How-PWN-Works.md +1 -1
  9. data/documentation/What-is-PWN.md +1 -1
  10. data/documentation/diagrams/aws-cloud-security.svg +1 -1
  11. data/documentation/diagrams/dot/aws-cloud-security.dot +1 -1
  12. data/documentation/diagrams/dot/network-infra-testing.dot +1 -1
  13. data/documentation/diagrams/network-infra-testing.svg +1 -1
  14. data/etc/default_cron/session_cleanup.rb +84 -51
  15. data/lib/pwn/ai/agent/assembly.rb +0 -2
  16. data/lib/pwn/ai/agent/btc.rb +0 -2
  17. data/lib/pwn/ai/agent/burp_suite.rb +0 -2
  18. data/lib/pwn/ai/agent/curriculum.rb +2 -2
  19. data/lib/pwn/ai/agent/dispatch.rb +3 -0
  20. data/lib/pwn/ai/agent/engagement.rb +96 -41
  21. data/lib/pwn/ai/agent/extrospection/osint/bridges.rb +2 -0
  22. data/lib/pwn/ai/agent/extrospection.rb +50 -13
  23. data/lib/pwn/ai/agent/gqrx.rb +0 -2
  24. data/lib/pwn/ai/agent/hacker_one.rb +0 -2
  25. data/lib/pwn/ai/agent/learning.rb +45 -13
  26. data/lib/pwn/ai/agent/loop.rb +12 -11
  27. data/lib/pwn/ai/agent/metrics.rb +1 -1
  28. data/lib/pwn/ai/agent/mission.rb +6 -3
  29. data/lib/pwn/ai/agent/policy.rb +1 -1
  30. data/lib/pwn/ai/agent/policy_evaluation.rb +2 -2
  31. data/lib/pwn/ai/agent/reflect.rb +1 -0
  32. data/lib/pwn/ai/agent/request_runtime.rb +1 -1
  33. data/lib/pwn/ai/agent/reward.rb +155 -53
  34. data/lib/pwn/ai/agent/sast.rb +0 -2
  35. data/lib/pwn/ai/agent/task_dag.rb +5 -3
  36. data/lib/pwn/ai/agent/task_summarizer.rb +21 -11
  37. data/lib/pwn/ai/agent/tool_guard.rb +19 -0
  38. data/lib/pwn/ai/agent/tools/ruby_eval.rb +1 -1
  39. data/lib/pwn/ai/agent/tools/verify.rb +7 -3
  40. data/lib/pwn/ai/agent/transparent_browser.rb +0 -2
  41. data/lib/pwn/ai/agent/turn_finalizer.rb +3 -0
  42. data/lib/pwn/ai/anthropic.rb +3 -3
  43. data/lib/pwn/ai/context.rb +2 -1
  44. data/lib/pwn/ai/gemini.rb +7 -5
  45. data/lib/pwn/ai/grok.rb +37 -18
  46. data/lib/pwn/ai/mcp.rb +17 -5
  47. data/lib/pwn/ai/ollama.rb +76 -35
  48. data/lib/pwn/ai/open_ai.rb +7 -19
  49. data/lib/pwn/ai/open_web_ui.rb +76 -40
  50. data/lib/pwn/aws/cloud_search_domain.rb +6 -0
  51. data/lib/pwn/aws/iam.rb +2 -2
  52. data/lib/pwn/aws/workspaces.rb +2 -2
  53. data/lib/pwn/aws.rb +0 -5
  54. data/lib/pwn/bounty/lifecycle_authz_replay.rb +1 -1
  55. data/lib/pwn/config.rb +17 -10
  56. data/lib/pwn/corpus.rb +33 -5
  57. data/lib/pwn/cron.rb +60 -17
  58. data/lib/pwn/driver.rb +2 -3
  59. data/lib/pwn/engagement.rb +28 -10
  60. data/lib/pwn/ffi/capstone.rb +3 -2
  61. data/lib/pwn/ffi/fftw.rb +8 -6
  62. data/lib/pwn/ffi/keystone.rb +3 -2
  63. data/lib/pwn/ffi/soapy_sdr.rb +10 -6
  64. data/lib/pwn/json_text.rb +25 -13
  65. data/lib/pwn/memory_index.rb +6 -4
  66. data/lib/pwn/module_skills.rb +3 -1
  67. data/lib/pwn/plugins/aflplusplus.rb +1 -0
  68. data/lib/pwn/plugins/ai_sandbox.rb +42 -10
  69. data/lib/pwn/plugins/android.rb +429 -466
  70. data/lib/pwn/plugins/artifact_registry.rb +12 -2
  71. data/lib/pwn/plugins/assembly.rb +9 -42
  72. data/lib/pwn/plugins/authentication_helper.rb +4 -3
  73. data/lib/pwn/plugins/baresip.rb +70 -28
  74. data/lib/pwn/plugins/binary_analysis.rb +14 -5
  75. data/lib/pwn/plugins/binary_parser.rb +42 -7
  76. data/lib/pwn/plugins/black_duck_binary_analysis.rb +3 -3
  77. data/lib/pwn/plugins/burp_suite.rb +15 -12
  78. data/lib/pwn/plugins/bus_pirate.rb +3 -7
  79. data/lib/pwn/plugins/char.rb +9 -3
  80. data/lib/pwn/plugins/credit_card.rb +7 -0
  81. data/lib/pwn/plugins/dao_ldap.rb +2 -2
  82. data/lib/pwn/plugins/dao_mongo.rb +1 -1
  83. data/lib/pwn/plugins/debugger.rb +1 -1
  84. data/lib/pwn/plugins/defect_dojo.rb +7 -3
  85. data/lib/pwn/plugins/detect_os.rb +1 -1
  86. data/lib/pwn/plugins/detonate.rb +9 -19
  87. data/lib/pwn/plugins/exploit_db.rb +1 -1
  88. data/lib/pwn/plugins/file_fu.rb +4 -1
  89. data/lib/pwn/plugins/findings.rb +76 -2
  90. data/lib/pwn/plugins/fuzz.rb +12 -3
  91. data/lib/pwn/plugins/gdb.rb +7 -2
  92. data/lib/pwn/plugins/gdbmi.rb +10 -6
  93. data/lib/pwn/plugins/git.rb +18 -13
  94. data/lib/pwn/plugins/github.rb +11 -6
  95. data/lib/pwn/plugins/google_workspace.rb +11 -3
  96. data/lib/pwn/plugins/hacker_one.rb +5 -1
  97. data/lib/pwn/plugins/httpx.rb +24 -8
  98. data/lib/pwn/plugins/ip_info.rb +11 -8
  99. data/lib/pwn/plugins/irc.rb +73 -45
  100. data/lib/pwn/plugins/jenkins.rb +2 -2
  101. data/lib/pwn/plugins/jira_data_center.rb +13 -6
  102. data/lib/pwn/plugins/jobs.rb +62 -4
  103. data/lib/pwn/plugins/log.rb +1 -1
  104. data/lib/pwn/plugins/monkey_patch.rb +1 -1
  105. data/lib/pwn/plugins/msr206.rb +157 -182
  106. data/lib/pwn/plugins/nessus_cloud.rb +2 -2
  107. data/lib/pwn/plugins/nexpose_vuln_scan.rb +44 -33
  108. data/lib/pwn/plugins/nuclei.rb +24 -8
  109. data/lib/pwn/plugins/ocr.rb +3 -1
  110. data/lib/pwn/plugins/open_api.rb +0 -4
  111. data/lib/pwn/plugins/openvas.rb +31 -43
  112. data/lib/pwn/plugins/packet.rb +40 -25
  113. data/lib/pwn/plugins/pony.rb +2 -2
  114. data/lib/pwn/plugins/preflight_checker.rb +1 -1
  115. data/lib/pwn/plugins/process_tube.rb +17 -2
  116. data/lib/pwn/plugins/ps.rb +6 -1
  117. data/lib/pwn/plugins/repl/ai.rb +1 -0
  118. data/lib/pwn/plugins/repl/ai_console.rb +12 -5
  119. data/lib/pwn/plugins/repl/mesh.rb +10 -2
  120. data/lib/pwn/plugins/sbom.rb +59 -27
  121. data/lib/pwn/plugins/scannable_codes.rb +3 -1
  122. data/lib/pwn/plugins/serial.rb +102 -44
  123. data/lib/pwn/plugins/shodan.rb +4 -10
  124. data/lib/pwn/plugins/sock.rb +16 -11
  125. data/lib/pwn/plugins/ssn.rb +3 -1
  126. data/lib/pwn/plugins/transparent_browser.rb +43 -3
  127. data/lib/pwn/plugins/vault.rb +92 -30
  128. data/lib/pwn/plugins/vin.rb +2 -1
  129. data/lib/pwn/plugins/vsphere.rb +2 -1
  130. data/lib/pwn/plugins/xxd.rb +3 -5
  131. data/lib/pwn/plugins/yubikey/security_domain/scp.rb +4 -0
  132. data/lib/pwn/plugins/yubikey/transport.rb +42 -11
  133. data/lib/pwn/plugins/yubikey.rb +21 -6
  134. data/lib/pwn/plugins/zaproxy.rb +3 -4
  135. data/lib/pwn/reports/ai_red_team.rb +4 -4
  136. data/lib/pwn/reports/pdf.rb +9 -5
  137. data/lib/pwn/reports/sast.rb +4 -4
  138. data/lib/pwn/sast/keystore.rb +2 -2
  139. data/lib/pwn/sast/logger.rb +1 -1
  140. data/lib/pwn/sast/php_type_juggling.rb +3 -6
  141. data/lib/pwn/sast/pom_version.rb +12 -6
  142. data/lib/pwn/sast/port.rb +1 -1
  143. data/lib/pwn/sast/sql.rb +3 -7
  144. data/lib/pwn/sast/test_case_engine.rb +62 -16
  145. data/lib/pwn/sast/type_script_type_juggling.rb +3 -6
  146. data/lib/pwn/sdr/decoder/base.rb +8 -0
  147. data/lib/pwn/sdr/decoder/lora.rb +1 -1
  148. data/lib/pwn/sdr/flipper_zero.rb +4 -7
  149. data/lib/pwn/sdr/gqrx.rb +35 -16
  150. data/lib/pwn/sdr/son_micro_rfid.rb +44 -26
  151. data/lib/pwn/sdr.rb +1 -1
  152. data/lib/pwn/session_trace.rb +7 -2
  153. data/lib/pwn/sessions.rb +307 -39
  154. data/lib/pwn/setup.rb +4 -3
  155. data/lib/pwn/version.rb +1 -1
  156. data/lib/pwn/www/app_cobalt_io.rb +14 -2
  157. data/lib/pwn/www/bing.rb +13 -1
  158. data/lib/pwn/www/bug_crowd.rb +14 -2
  159. data/lib/pwn/www/checkip.rb +13 -1
  160. data/lib/pwn/www/coinbase_pro.rb +14 -2
  161. data/lib/pwn/www/duckduckgo.rb +13 -1
  162. data/lib/pwn/www/facebook.rb +14 -2
  163. data/lib/pwn/www/github.rb +14 -2
  164. data/lib/pwn/www/google.rb +13 -1
  165. data/lib/pwn/www/hacker_one.rb +117 -33
  166. data/lib/pwn/www/linkedin.rb +14 -2
  167. data/lib/pwn/www/pandora.rb +14 -2
  168. data/lib/pwn/www/pastebin.rb +13 -1
  169. data/lib/pwn/www/paypal.rb +16 -4
  170. data/lib/pwn/www/synack.rb +14 -2
  171. data/lib/pwn/www/torch.rb +17 -3
  172. data/lib/pwn/www/trading_view.rb +14 -2
  173. data/lib/pwn/www/twitter.rb +14 -2
  174. data/lib/pwn/www/uber.rb +14 -2
  175. data/lib/pwn/www/upwork.rb +14 -2
  176. data/lib/pwn/www/wayback_machine.rb +16 -2
  177. data/lib/pwn/www/youtube.rb +13 -1
  178. data/pwn.gemspec +4 -0
  179. data/spec/integration/authentication_helper_oath_spec.rb +1 -1
  180. data/spec/integration/autoinc_lifecycle_supplement_spec.rb +47 -0
  181. data/spec/integration/gemspec_deleted_files_spec.rb +43 -0
  182. data/spec/integration/spec_curriculum_isolation_spec.rb +41 -0
  183. data/spec/integration/verify_acceptance_eui_regression_spec.rb +162 -0
  184. data/spec/integration/web_cache_lifecycle_closure_spec.rb +89 -0
  185. data/spec/integration/web_cache_lifecycle_supplement_spec.rb +70 -0
  186. data/spec/lib/pwn/ai/agent/analysis_errors_regression_spec.rb +33 -0
  187. data/spec/lib/pwn/ai/agent/curriculum_cooldown_regression_spec.rb +19 -0
  188. data/spec/lib/pwn/ai/agent/curriculum_spec.rb +2 -0
  189. data/spec/lib/pwn/ai/agent/engagement_boundary_regression_spec.rb +42 -0
  190. data/spec/lib/pwn/ai/agent/engagement_dispatch_review_spec.rb +82 -0
  191. data/spec/lib/pwn/ai/agent/engagement_roe_regression_spec.rb +25 -0
  192. data/spec/lib/pwn/ai/agent/engagement_scope_regression_spec.rb +37 -0
  193. data/spec/lib/pwn/ai/agent/extrospection/osint/bridges_spec.rb +4 -0
  194. data/spec/lib/pwn/ai/agent/extrospection_input_regression_spec.rb +31 -0
  195. data/spec/lib/pwn/ai/agent/extrospection_review_spec.rb +61 -0
  196. data/spec/lib/pwn/ai/agent/extrospection_serial_review_spec.rb +42 -0
  197. data/spec/lib/pwn/ai/agent/extrospection_spec.rb +9 -0
  198. data/spec/lib/pwn/ai/agent/extrospection_verification_regression_spec.rb +39 -0
  199. data/spec/lib/pwn/ai/agent/learning_last_answer_regression_spec.rb +32 -0
  200. data/spec/lib/pwn/ai/agent/learning_lifecycle_closure_spec.rb +84 -0
  201. data/spec/lib/pwn/ai/agent/learning_prune_regression_spec.rb +17 -0
  202. data/spec/lib/pwn/ai/agent/learning_spec.rb +2 -1
  203. data/spec/lib/pwn/ai/agent/loop_execution_audit_spec.rb +30 -0
  204. data/spec/lib/pwn/ai/agent/metrics_usage_regression_spec.rb +20 -0
  205. data/spec/lib/pwn/ai/agent/mission_execution_audit_spec.rb +27 -0
  206. data/spec/lib/pwn/ai/agent/mission_namespace_spec.rb +210 -18
  207. data/spec/lib/pwn/ai/agent/policy_confidence_regression_spec.rb +16 -0
  208. data/spec/lib/pwn/ai/agent/policy_evaluation_spec.rb +1 -1
  209. data/spec/lib/pwn/ai/agent/policy_evaluation_tmp_regression_spec.rb +36 -0
  210. data/spec/lib/pwn/ai/agent/reflect_model_regression_spec.rb +15 -0
  211. data/spec/lib/pwn/ai/agent/request_runtime_execution_audit_spec.rb +43 -0
  212. data/spec/lib/pwn/ai/agent/reward_binding_review_spec.rb +129 -0
  213. data/spec/lib/pwn/ai/agent/reward_dispatch_review_spec.rb +154 -0
  214. data/spec/lib/pwn/ai/agent/reward_envelope_regression_spec.rb +45 -0
  215. data/spec/lib/pwn/ai/agent/reward_turn_regression_spec.rb +40 -0
  216. data/spec/lib/pwn/ai/agent/swarm_spec.rb +2 -2
  217. data/spec/lib/pwn/ai/agent/task_dag_execution_audit_spec.rb +45 -0
  218. data/spec/lib/pwn/ai/agent/task_summarizer_failure_regression_spec.rb +26 -0
  219. data/spec/lib/pwn/ai/agent/tools/verify_execution_audit_spec.rb +33 -0
  220. data/spec/lib/pwn/ai/context_range_audit_spec.rb +24 -0
  221. data/spec/lib/pwn/ai/gemini_roundtrip_audit_spec.rb +33 -0
  222. data/spec/lib/pwn/ai/grok_reasoning_effort_spec.rb +43 -0
  223. data/spec/lib/pwn/ai/mcp_session_audit_spec.rb +36 -0
  224. data/spec/lib/pwn/ai/ollama_spec.rb +6 -11
  225. data/spec/lib/pwn/ai/open_web_ui_spec.rb +6 -11
  226. data/spec/lib/pwn/ai/provider_history_audit_spec.rb +44 -0
  227. data/spec/lib/pwn/ai/provider_operations_audit_spec.rb +53 -0
  228. data/spec/lib/pwn/ai/provider_review_history_stream_regression_spec.rb +143 -0
  229. data/spec/lib/pwn/ai/provider_review_tls_regression_spec.rb +62 -0
  230. data/spec/lib/pwn/ai/provider_stream_audit_spec.rb +49 -0
  231. data/spec/lib/pwn/aws/iam_decoding_regression_spec.rb +23 -0
  232. data/spec/lib/pwn/aws/services_runtime_regression_spec.rb +51 -0
  233. data/spec/lib/pwn/aws_spec.rb +6 -0
  234. data/spec/lib/pwn/banner_operational_audit_spec.rb +105 -0
  235. data/spec/lib/pwn/bounty/lifecycle_authz_replay_spec.rb +17 -0
  236. data/spec/lib/pwn/config_redaction_regression_spec.rb +24 -0
  237. data/spec/lib/pwn/config_skills_regression_spec.rb +38 -0
  238. data/spec/lib/pwn/corpus_core_review_regression_spec.rb +96 -0
  239. data/spec/lib/pwn/corpus_spec.rb +13 -0
  240. data/spec/lib/pwn/cron_core_review_regression_spec.rb +95 -0
  241. data/spec/lib/pwn/cron_execution_spec.rb +75 -0
  242. data/spec/lib/pwn/driver_core_review_regression_spec.rb +38 -0
  243. data/spec/lib/pwn/driver_spec.rb +13 -0
  244. data/spec/lib/pwn/engagement_core_review_regression_spec.rb +88 -0
  245. data/spec/lib/pwn/engagement_storage_regression_spec.rb +44 -0
  246. data/spec/lib/pwn/ffi/capstone_spec.rb +19 -0
  247. data/spec/lib/pwn/ffi/fftw_spec.rb +19 -0
  248. data/spec/lib/pwn/ffi/keystone_spec.rb +13 -0
  249. data/spec/lib/pwn/ffi/soapy_sdr_spec.rb +13 -0
  250. data/spec/lib/pwn/json_text_spec.rb +25 -0
  251. data/spec/lib/pwn/memory_index_spec.rb +23 -0
  252. data/spec/lib/pwn/module_skills_parsing_regression_spec.rb +34 -0
  253. data/spec/lib/pwn/plugins/ai_sandbox_boundary_review_spec.rb +57 -0
  254. data/spec/lib/pwn/plugins/ai_sandbox_spec.rb +10 -18
  255. data/spec/lib/pwn/plugins/android_review_fixes_spec.rb +121 -0
  256. data/spec/lib/pwn/plugins/android_transport_audit_spec.rb +64 -0
  257. data/spec/lib/pwn/plugins/api_import_namespace_audit_spec.rb +49 -0
  258. data/spec/lib/pwn/plugins/artifact_registry_namespace_audit_spec.rb +20 -0
  259. data/spec/lib/pwn/plugins/artifact_registry_review_fixes_spec.rb +63 -0
  260. data/spec/lib/pwn/plugins/assembly_namespace_audit_spec.rb +16 -0
  261. data/spec/lib/pwn/plugins/assembly_review_fixes_spec.rb +33 -0
  262. data/spec/lib/pwn/plugins/authentication_helper_spec.rb +14 -0
  263. data/spec/lib/pwn/plugins/baresip_review_fixes_spec.rb +127 -0
  264. data/spec/lib/pwn/plugins/baresip_transport_audit_spec.rb +59 -0
  265. data/spec/lib/pwn/plugins/binary_analysis_process_review_spec.rb +57 -0
  266. data/spec/lib/pwn/plugins/black_duck_namespace_audit_spec.rb +25 -0
  267. data/spec/lib/pwn/plugins/burp_suite_har_review_fixes_spec.rb +60 -0
  268. data/spec/lib/pwn/plugins/burp_suite_import_review_fixes_spec.rb +62 -0
  269. data/spec/lib/pwn/plugins/burp_suite_namespace_audit_spec.rb +37 -0
  270. data/spec/lib/pwn/plugins/bus_pirate_transport_audit_spec.rb +19 -0
  271. data/spec/lib/pwn/plugins/file_fu_namespace_audit_spec.rb +17 -0
  272. data/spec/lib/pwn/plugins/findings_structured_spec.rb +1 -1
  273. data/spec/lib/pwn/plugins/gdbmi_namespace_audit_spec.rb +28 -0
  274. data/spec/lib/pwn/plugins/gdbmi_review_fixes_spec.rb +73 -0
  275. data/spec/lib/pwn/plugins/github_argv_review_spec.rb +49 -0
  276. data/spec/lib/pwn/plugins/google_workspace_provider_review_oauth_spec.rb +80 -0
  277. data/spec/lib/pwn/plugins/irc_review_fixes_spec.rb +92 -0
  278. data/spec/lib/pwn/plugins/irc_transport_audit_spec.rb +37 -0
  279. data/spec/lib/pwn/plugins/jenkins_namespace_audit_spec.rb +12 -0
  280. data/spec/lib/pwn/plugins/jira_data_center_namespace_audit_spec.rb +44 -0
  281. data/spec/lib/pwn/plugins/jira_data_center_review_fixes_spec.rb +81 -0
  282. data/spec/lib/pwn/plugins/jsonl_elf_review_fixes_spec.rb +59 -0
  283. data/spec/lib/pwn/plugins/log_spec.rb +36 -20
  284. data/spec/lib/pwn/plugins/monkey_patch_spec.rb +16 -0
  285. data/spec/lib/pwn/plugins/msr206_readback_review_fixes_spec.rb +119 -0
  286. data/spec/lib/pwn/plugins/msr206_review_fixes_spec.rb +50 -0
  287. data/spec/lib/pwn/plugins/msr206_transport_audit_spec.rb +64 -0
  288. data/spec/lib/pwn/plugins/nessus_cloud_namespace_audit_spec.rb +14 -0
  289. data/spec/lib/pwn/plugins/nexpose_review_fixes_spec.rb +55 -0
  290. data/spec/lib/pwn/plugins/open_api_namespace_audit_spec.rb +22 -0
  291. data/spec/lib/pwn/plugins/packet_transport_audit_spec.rb +47 -0
  292. data/spec/lib/pwn/plugins/plugins_b_operational_regression_spec.rb +600 -0
  293. data/spec/lib/pwn/plugins/pony_namespace_audit_spec.rb +17 -0
  294. data/spec/lib/pwn/plugins/pony_review_fixes_spec.rb +33 -0
  295. data/spec/lib/pwn/plugins/process_tube_namespace_audit_spec.rb +19 -0
  296. data/spec/lib/pwn/plugins/ps_namespace_audit_spec.rb +12 -0
  297. data/spec/lib/pwn/plugins/repl/ai_console_spec.rb +111 -0
  298. data/spec/lib/pwn/plugins/repl/ai_spec.rb +38 -0
  299. data/spec/lib/pwn/plugins/repl/mesh_spec.rb +52 -0
  300. data/spec/lib/pwn/plugins/sandbox_spec.rb +9 -7
  301. data/spec/lib/pwn/plugins/sbom_review_fixes_spec.rb +43 -0
  302. data/spec/lib/pwn/plugins/scannable_codes_namespace_audit_spec.rb +15 -0
  303. data/spec/lib/pwn/plugins/serial_review_fixes_spec.rb +76 -0
  304. data/spec/lib/pwn/plugins/serial_transport_audit_spec.rb +102 -0
  305. data/spec/lib/pwn/plugins/shodan_namespace_audit_spec.rb +10 -0
  306. data/spec/lib/pwn/plugins/sock_transport_audit_spec.rb +55 -0
  307. data/spec/lib/pwn/plugins/transparent_browser_navigation_review_spec.rb +21 -0
  308. data/spec/lib/pwn/plugins/vault_master_key_eui_regression_spec.rb +242 -0
  309. data/spec/lib/pwn/plugins/vault_spec.rb +58 -0
  310. data/spec/lib/pwn/plugins/vault_store_safety_spec.rb +1 -1
  311. data/spec/lib/pwn/plugins/xxd_namespace_audit_spec.rb +34 -0
  312. data/spec/lib/pwn/plugins/yubikey_hid_cleanup_review_fixes_spec.rb +52 -0
  313. data/spec/lib/pwn/plugins/yubikey_lifecycle_audit_spec.rb +65 -0
  314. data/spec/lib/pwn/plugins/yubikey_options_audit_spec.rb +30 -0
  315. data/spec/lib/pwn/plugins/yubikey_selector_audit_spec.rb +26 -0
  316. data/spec/lib/pwn/plugins/yubikey_spec.rb +1 -1
  317. data/spec/lib/pwn/plugins/zaproxy_namespace_audit_spec.rb +30 -0
  318. data/spec/lib/pwn/reports/empty_report_audit_spec.rb +18 -0
  319. data/spec/lib/pwn/reports/pdf_spec.rb +25 -0
  320. data/spec/lib/pwn/reports/provider_review_encoding_regression_spec.rb +45 -0
  321. data/spec/lib/pwn/sast/engine_runtime_regression_spec.rb +91 -0
  322. data/spec/lib/pwn/sast/filter_edge_regression_spec.rb +39 -0
  323. data/spec/lib/pwn/sast/formatter_review_fixes_spec.rb +178 -0
  324. data/spec/lib/pwn/sast/path_review_fixes_spec.rb +60 -0
  325. data/spec/lib/pwn/sast/pom_runtime_regression_spec.rb +37 -0
  326. data/spec/lib/pwn/sast/rules_runtime_regression_spec.rb +78 -0
  327. data/spec/lib/pwn/sast/sql_review_fixes_spec.rb +38 -0
  328. data/spec/lib/pwn/sdr/decoder/base_iq_spec.rb +21 -18
  329. data/spec/lib/pwn/sdr/decoder/base_review_fixes_spec.rb +49 -0
  330. data/spec/lib/pwn/sdr/decoder/base_validation_spec.rb +78 -0
  331. data/spec/lib/pwn/sdr/decoder/lora_spec.rb +9 -0
  332. data/spec/lib/pwn/sdr/flipper_zero_review_fixes_spec.rb +34 -0
  333. data/spec/lib/pwn/sdr/gqrx_operational_spec.rb +83 -0
  334. data/spec/lib/pwn/sdr/gqrx_review_fixes_spec.rb +22 -0
  335. data/spec/lib/pwn/sdr/son_micro_rfid_review_fixes_spec.rb +113 -0
  336. data/spec/lib/pwn/sdr/son_micro_rfid_serial_review_fixes_spec.rb +76 -0
  337. data/spec/lib/pwn/sdr/son_micro_rfid_spec.rb +39 -0
  338. data/spec/lib/pwn/sdr_spec.rb +5 -0
  339. data/spec/lib/pwn/session_cleanup_default_spec.rb +1 -1
  340. data/spec/lib/pwn/session_cleanup_lifecycle_supplement_spec.rb +39 -0
  341. data/spec/lib/pwn/session_cleanup_payload_spec.rb +3 -2
  342. data/spec/lib/pwn/session_trace_lifecycle_supplement_spec.rb +39 -0
  343. data/spec/lib/pwn/sessions_archive_closure_spec.rb +126 -0
  344. data/spec/lib/pwn/sessions_lifecycle_closure_spec.rb +373 -0
  345. data/spec/lib/pwn/sessions_lifecycle_supplement_spec.rb +204 -0
  346. data/spec/lib/pwn/setup_operational_regression_spec.rb +36 -0
  347. data/spec/lib/pwn/www/browser_review_fixes_spec.rb +70 -0
  348. data/spec/lib/pwn/www/browser_runtime_regression_spec.rb +100 -0
  349. data/spec/lib/pwn/www/hacker_one_runtime_regression_spec.rb +146 -0
  350. data/spec/lib/pwn/www/pagination_review_fixes_spec.rb +84 -0
  351. data/spec/support/namespace_controller_observability_fixture.rb +141 -0
  352. data/spec/support/sandbox.rb +8 -5
  353. data/third_party/pwn_rdoc.jsonl +73 -31
  354. metadata +137 -18
  355. data/etc/default_skills/pwn/aws/elastic_transcoder/SKILL.md +0 -48
  356. data/etc/default_skills/pwn/aws/lambda_preview/SKILL.md +0 -48
  357. data/etc/default_skills/pwn/aws/ops_works/SKILL.md +0 -48
  358. data/etc/default_skills/pwn/aws/ops_works_cm/SKILL.md +0 -48
  359. data/etc/default_skills/pwn/aws/sms/SKILL.md +0 -48
  360. data/lib/pwn/aws/elastic_transcoder.rb +0 -95
  361. data/lib/pwn/aws/lambda_preview.rb +0 -95
  362. data/lib/pwn/aws/ops_works.rb +0 -95
  363. data/lib/pwn/aws/ops_works_cm.rb +0 -95
  364. data/lib/pwn/aws/sms.rb +0 -95
  365. data/spec/lib/pwn/aws/elastic_transcoder_spec.rb +0 -15
  366. data/spec/lib/pwn/aws/lambda_preview_spec.rb +0 -15
  367. data/spec/lib/pwn/aws/ops_works_cm_spec.rb +0 -15
  368. data/spec/lib/pwn/aws/ops_works_spec.rb +0 -15
  369. data/spec/lib/pwn/aws/sms_spec.rb +0 -15
@@ -14,8 +14,7 @@ module PWN
14
14
  ACTIVE_FILE = File.join(ROOT, 'active')
15
15
 
16
16
  public_class_method def self.open(opts = {})
17
- name = (opts[:name] || opts[:engagement] || 'default').to_s
18
- raise 'ERROR: name is required' if name.empty?
17
+ name = validate_name(name: opts[:name] || opts[:engagement] || 'default')
19
18
 
20
19
  FileUtils.mkdir_p(ROOT)
21
20
  path = File.join(ROOT, "#{name}.json")
@@ -38,9 +37,10 @@ module PWN
38
37
  end
39
38
 
40
39
  public_class_method def self.status(opts = {})
41
- name = (opts[:name] || current_name).to_s
42
- return { active: nil } if name.empty?
40
+ name = opts[:name] || opts[:engagement] || current_name
41
+ return { active: nil } if name.nil?
43
42
 
43
+ name = validate_name(name: name)
44
44
  path = File.join(ROOT, "#{name}.json")
45
45
  return { active: name, missing: true } unless File.file?(path)
46
46
 
@@ -51,7 +51,15 @@ module PWN
51
51
  return nil unless opts.is_a?(Hash)
52
52
  return nil unless File.file?(ACTIVE_FILE)
53
53
 
54
- File.read(ACTIVE_FILE).strip
54
+ validate_name(name: File.read(ACTIVE_FILE))
55
+ end
56
+
57
+ public_class_method def self.validate_name(opts = {})
58
+ name = opts[:name].to_s
59
+ raise ArgumentError, 'Invalid engagement name: expected a single nonempty filename component' if name.empty? || %w[. ..].include?(name) || name.match?(%r{[/\\\x00-\x1f\x7f]})
60
+ raise ArgumentError, 'Invalid engagement name: active pointer and .json metadata names are reserved' if name == File.basename(ACTIVE_FILE) || name.downcase.end_with?('.json')
61
+
62
+ name
55
63
  end
56
64
 
57
65
  public_class_method def self.in_scope?(opts = {})
@@ -59,45 +67,23 @@ module PWN
59
67
  return true if token.empty?
60
68
 
61
69
  roe = load_roe
62
- host = token
63
- begin
64
- host = URI.parse(token).host || token if token.include?('://')
65
- rescue StandardError
66
- host = token
67
- end
68
- host = host.sub(%r{\Ahttps?://}i, '').split('/').first.to_s.split(':').first
70
+ host = scope_host(target: token)
69
71
  if roe[:present]
70
72
  deny = Array(roe[:targets_deny])
71
- return false if deny.any? { |ex| host == ex.to_s || host.end_with?(".#{ex}") || host.include?(ex.to_s) }
73
+ return false if deny.any? { |ex| scope_match?(host: host, target: ex, deny: true) }
72
74
 
73
75
  allow = Array(roe[:targets_allow])
74
- unless allow.empty?
75
- ok = allow.any? do |a|
76
- a = a.to_s
77
- host == a || host.end_with?(".#{a}") || begin
78
- IPAddr.new(a).include?(IPAddr.new(host))
79
- rescue StandardError
80
- false
81
- end
82
- end
83
- return false unless ok
84
- end
76
+ return false unless allow.empty? || allow.any? { |target| scope_match?(host: host, target: target) }
85
77
  end
86
78
 
87
- row = status
88
- return true if row[:active].nil? || row[:missing]
79
+ row = status(name: opts[:name] || opts[:engagement])
80
+ return true if row[:active].nil?
81
+ return false if row[:missing]
89
82
 
90
83
  enforce = engagement_enforce
91
84
  return true if enforce == 'off'
92
85
 
93
- host = token
94
- begin
95
- host = URI.parse(token).host || token if token.include?('://')
96
- rescue StandardError
97
- host = token
98
- end
99
- host = host.sub(%r{\Ahttps?://}i, '').split('/').first.to_s.split(':').first
100
- return false if Array(row[:excluded]).any? { |ex| host.include?(ex.to_s) }
86
+ return false if Array(row[:excluded]).any? { |ex| scope_match?(host: host, target: ex, deny: true) }
101
87
 
102
88
  cidrs = Array(row[:scope_cidrs]).map(&:to_s).reject(&:empty?)
103
89
  domains = Array(row[:scope_domains]).map(&:to_s).reject(&:empty?)
@@ -126,7 +112,7 @@ module PWN
126
112
  violating: [tech_hit]
127
113
  }
128
114
  end
129
- tokens = blob.scan(/(?:\d{1,3}\.){3}\d{1,3}|[A-Za-z0-9.-]+\.[A-Za-z]{2,}/).uniq
115
+ tokens = scope_targets(value: args)
130
116
  bad = tokens.reject { |tok| in_scope?(host: tok) }
131
117
  return nil if bad.empty?
132
118
 
@@ -143,8 +129,10 @@ module PWN
143
129
  return { present: false, targets_allow: [], targets_deny: [], techniques_deny: [] } unless File.file?(path)
144
130
 
145
131
  require 'yaml'
146
- raw = YAML.safe_load_file(path, permitted_classes: [], symbolize_names: true) || {}
147
- raw = {} unless raw.is_a?(Hash)
132
+ raw = YAML.safe_load_file(path, permitted_classes: [], symbolize_names: true)
133
+ raw = {} if raw.nil?
134
+ raise ArgumentError, 'Invalid RoE policy: expected a YAML mapping' unless raw.is_a?(Hash)
135
+
148
136
  {
149
137
  present: true,
150
138
  targets_allow: Array(raw[:targets_allow] || raw['targets_allow']),
@@ -152,8 +140,8 @@ module PWN
152
140
  techniques_deny: Array(raw[:techniques_deny] || raw['techniques_deny']),
153
141
  time_windows: raw[:time_windows] || raw['time_windows']
154
142
  }
155
- rescue StandardError
156
- { present: false, targets_allow: [], targets_deny: [], techniques_deny: [] }
143
+ rescue Psych::Exception, SystemCallError, IOError
144
+ raise ArgumentError, 'Invalid RoE policy: cannot read or parse the policy file'
157
145
  end
158
146
 
159
147
  public_class_method def self.authors
@@ -180,7 +168,8 @@ module PWN
180
168
 
181
169
  # Return the active engagement document.
182
170
  #{self}.status(
183
- name: 'optional - engagement name (defaults to active)'
171
+ name: 'optional - engagement name (defaults to active)',
172
+ engagement: 'optional - alias for name'
184
173
  )
185
174
 
186
175
  # Return the active engagement name or nil.
@@ -188,12 +177,19 @@ module PWN
188
177
  unused: 'optional - reserved'
189
178
  )
190
179
 
180
+ # Validate an engagement filename component without normalizing it.
181
+ #{self}.validate_name(
182
+ name: 'required - nonempty engagement name without separators or control characters; active and .json suffixes are reserved'
183
+ )
184
+
191
185
  # True when host/ip/url is inside the active engagement scope.
192
186
  #{self}.in_scope?(
193
187
  host: 'optional - DNS hostname to test against scope_domains',
194
188
  ip: 'optional - IPv4 or IPv6 address to test against scope_cidrs',
195
189
  target: 'optional - host or IP alias when the caller has one field',
196
- url: 'optional - URL whose host is extracted and tested'
190
+ url: 'optional - URL whose host is extracted and tested',
191
+ name: 'optional - explicit engagement name; otherwise use the active engagement',
192
+ engagement: 'optional - alias for name'
197
193
  )
198
194
 
199
195
  # Structured denial when args mention an out-of-scope host.
@@ -214,6 +210,65 @@ module PWN
214
210
  constants.sort
215
211
  end
216
212
 
213
+ private_class_method def self.scope_match?(opts = {})
214
+ target = opts[:target].to_s
215
+ host = opts[:host].to_s
216
+ begin
217
+ network = IPAddr.new(target)
218
+ rescue IPAddr::InvalidAddressError
219
+ raise ArgumentError, 'Invalid scope network' if target.include?('/')
220
+
221
+ return host == target || host.end_with?(".#{target}") || (opts[:deny] == true && host.include?(target))
222
+ end
223
+ begin
224
+ network.include?(IPAddr.new(host))
225
+ rescue IPAddr::InvalidAddressError
226
+ false
227
+ end
228
+ end
229
+
230
+ # Read typed target fields first; scan code/commands without treating URL
231
+ # paths as extra destinations. IPAddr validates candidates, never resolves DNS.
232
+ private_class_method def self.scope_targets(opts = {})
233
+ value = opts[:value]
234
+ case value
235
+ when Hash
236
+ value.flat_map { |key, item| scope_targets(value: item, typed: key.to_s.match?(/\A(?:hosts?|ips?|targets?|urls?|hostname|address)\z/)) }.uniq
237
+ when Array
238
+ value.flat_map { |item| scope_targets(value: item, typed: opts[:typed]) }.uniq
239
+ when String
240
+ return [scope_host(target: value)] if opts[:typed] && !value.match?(/\s/)
241
+
242
+ tokens = []
243
+ rest = value.gsub(%r{[a-z][a-z0-9+.-]*://[^\s"'<>]+}i) do |url|
244
+ tokens << scope_host(target: url)
245
+ ' '
246
+ end
247
+ rest = rest.gsub(/(?<![\w:])[\da-f]*:[\da-f:.]+(?:%[\w.-]+)?/i) do |candidate|
248
+ address = IPAddr.new(candidate)
249
+ tokens << candidate if address.ipv6?
250
+ ' '
251
+ rescue IPAddr::InvalidAddressError
252
+ candidate
253
+ end
254
+ (tokens + rest.scan(/(?:\d{1,3}\.){3}\d{1,3}|[A-Za-z0-9.-]+\.[A-Za-z]{2,}/)).reject(&:empty?).uniq
255
+ else
256
+ []
257
+ end
258
+ end
259
+
260
+ private_class_method def self.scope_host(opts = {})
261
+ token = opts[:target].to_s
262
+ return URI.parse(token).hostname.to_s if token.include?('://')
263
+
264
+ host = token.split('/').first.to_s
265
+ return host[/\A\[([^\]]+)\]/, 1] if host.start_with?('[')
266
+
267
+ host.count(':') <= 1 ? host.split(':').first.to_s : host
268
+ rescue URI::InvalidURIError
269
+ token
270
+ end
271
+
217
272
  private_class_method def self.engagement_enforce
218
273
  v = (PWN::Env.dig(:ai, :engagement, :enforce) if defined?(PWN::Env))
219
274
  (v || 'block').to_s
@@ -49,6 +49,8 @@ module PWN
49
49
  private_class_method def self.bridge_domain(opts = {})
50
50
  q = opts[:query].to_s.strip.sub(%r{\Ahttps?://}i, '').sub(%r{/.*\z}, '')
51
51
  q = q.split('@').last if q.include?('@')
52
+ return '' unless q.length <= 253 && q.match?(/\A[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?(?:\.[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?)+\.?\z/i)
53
+
52
54
  q
53
55
  end
54
56
 
@@ -319,7 +319,7 @@ module PWN
319
319
  # On :refuted -> Mistakes.record(tool:'assumption', error:claim) so the
320
320
  # KNOWN MISTAKES block warns every future run.
321
321
  # On :confirmed-> observe(category::intel, ttl:30d) reinforces w/ freshness.
322
- # On :unknown -> Learning.note_outcome(success:false, tags:['needs_human']).
322
+ # On :unknown -> Learning.note_outcome with a nil training decision.
323
323
  #
324
324
  # This is the extrospective mirror of Mistakes: a PROACTIVE trigger that
325
325
  # catches the model being wrong about the world before a human does.
@@ -344,8 +344,11 @@ module PWN
344
344
  fp = fingerprint_page(browser_obj: bo, url: u)
345
345
  evidence << fp if fp
346
346
  end
347
- body = evidence.map { |e| e[:text].to_s }.join(' ')
348
- if evidence.empty? || evidence.all? { |e| e[:status].to_i >= 400 } || body =~ /could not be found|does not exist|reserved but/i
347
+ pages = evidence.select { |page| canonical_cve_page?(page: page, cve: cve) }
348
+ next if pages.empty?
349
+
350
+ body = pages.map { |page| page[:text].to_s }.join(' ')
351
+ if body =~ /could not be found|does not exist|reserved but/i
349
352
  verdict = :refuted
350
353
  conf = 0.8
351
354
  else
@@ -363,7 +366,10 @@ module PWN
363
366
  u = opts[:url] || claim[URI::DEFAULT_PARSER.make_regexp(%w[http https])]
364
367
  fp = fingerprint_page(browser_obj: bo, url: u)
365
368
  evidence << fp if fp
366
- if fp.nil? || fp[:status].to_i >= 400 || fp[:reachable] == false
369
+ next unless fp && (fp[:status].to_i.between?(200, 299) || [404, 410].include?(fp[:status].to_i))
370
+ next if fp[:reachable] == false && fp[:status].to_i < 400
371
+
372
+ if fp[:status].to_i >= 400
367
373
  verdict = :refuted
368
374
  conf = 0.7
369
375
  else
@@ -406,7 +412,10 @@ module PWN
406
412
  action = commit ? commit_verdict(claim: claim, kind: kind, verdict: verdict, confidence: conf, evidence: evidence) : nil
407
413
  { claim: claim, kind: kind, verdict: verdict, confidence: conf.round(2), evidence: evidence, action_taken: action }
408
414
  rescue StandardError => e
409
- { claim: claim, kind: kind, verdict: :unknown, confidence: 0.0, evidence: evidence, error: "#{e.class}: #{e.message}", action_taken: nil }
415
+ evidence = Array(evidence).map { |page| page.except(:text) }
416
+ evidence << { reachable: false, error: e.class.name }
417
+ action = commit ? commit_verdict(claim: claim, kind: kind, verdict: :unknown, confidence: 0.0, evidence: evidence) : nil
418
+ { claim: claim, kind: kind, verdict: :unknown, confidence: 0.0, evidence: evidence, error: "#{e.class}: #{e.message}", action_taken: action }
410
419
  end
411
420
 
412
421
  # Supported Method Parameters::
@@ -733,10 +742,10 @@ module PWN
733
742
  stop_bits: (opts[:stop_bits] || 1).to_i,
734
743
  parity: (opts[:parity] || :none).to_sym
735
744
  )
736
- PWN::Plugins::Serial.flush_session_data
745
+ PWN::Plugins::Serial.flush_session_data(serial_obj: serial_obj)
737
746
  PWN::Plugins::Serial.request(serial_obj: serial_obj, payload: payload) if payload
738
747
  sleep settle
739
- raw = Array(PWN::Plugins::Serial.dump_session_data)
748
+ raw = Array(PWN::Plugins::Serial.dump_session_data(serial_obj: serial_obj))
740
749
  text = raw.join.force_encoding('UTF-8').scrub
741
750
  hex = raw.map do |b|
742
751
  case b
@@ -1626,6 +1635,26 @@ module PWN
1626
1635
  end
1627
1636
  end
1628
1637
 
1638
+ private_class_method def self.canonical_cve_page?(opts = {})
1639
+ page = opts[:page]
1640
+ return false unless page[:reachable] != false && page[:status].to_i.between?(200, 299)
1641
+
1642
+ url = URI.parse((page[:final_url] || page[:url]).to_s)
1643
+ return false unless url.scheme == 'https' && %w[nvd.nist.gov www.cve.org cve.org].include?(url.host)
1644
+ return false if page[:title].to_s.match?(/\bmaintenance|\blogin\b|sign in|access denied|service unavailable|\berror\b|\bchallenge\b/i)
1645
+
1646
+ text = page[:text].to_s
1647
+ return false unless text.match?(/\b#{Regexp.escape(opts[:cve].to_s)}\b/i)
1648
+ return false if text.match?(/temporarily unavailable|checking your browser|sign in to continue|under maintenance|verify you are human/i)
1649
+
1650
+ # Record identity alone is also present on empty JS shells and login
1651
+ # pages. Require rendered canonical description content, not HTTP 200.
1652
+ description = text[/\bDescription\b\s*:?\s*(.+)/im, 1].to_s.strip
1653
+ description.length >= 20 && description.match?(/[a-z]{3}/i)
1654
+ rescue URI::InvalidURIError
1655
+ false
1656
+ end
1657
+
1629
1658
  private_class_method def self.fingerprint_page(opts = {})
1630
1659
  bo = opts[:browser_obj]
1631
1660
  url = opts[:url].to_s
@@ -1637,8 +1666,9 @@ module PWN
1637
1666
  resp = b.get(url) { |r, _rq, _res| r }
1638
1667
  body = resp.body.to_s
1639
1668
  require 'nokogiri'
1640
- doc = Nokogiri::HTML.parse(body)
1641
- text = doc.text.to_s
1669
+ doc = Nokogiri::HTML.parse(body)
1670
+ doc.css('script, style').remove
1671
+ text = doc.xpath('//text()').map(&:text).join(' ')
1642
1672
  cfp, cna = tls_fingerprint(url: url)
1643
1673
  return { url: url, final_url: url, status: resp.code.to_i, title: doc.title.to_s,
1644
1674
  server: resp.headers[:server].to_s, generator: doc.at('meta[name="generator"]')&.[]('content').to_s,
@@ -1756,7 +1786,14 @@ module PWN
1756
1786
  if junk_unknown
1757
1787
  :skipped_junk
1758
1788
  else
1759
- Learning.note_outcome(task: "extro_verify: #{claim[0, 120]}", success: false, details: 'verdict :unknown - needs human review', tags: %w[needs_human extro_verify]) if defined?(Learning) && Learning.respond_to?(:note_outcome)
1789
+ if defined?(Learning) && Learning.respond_to?(:note_outcome)
1790
+ Learning.note_outcome(
1791
+ task: "extro_verify: #{claim[0, 120]}", success: nil,
1792
+ details: 'verdict :unknown - needs human review', tags: %w[needs_human extro_verify],
1793
+ outcome: { score: nil, confidence: opts[:confidence], source: :extro_verify,
1794
+ grounded: { verdict: :unknown, kind: opts[:kind], evidence: opts[:evidence] } }
1795
+ )
1796
+ end
1760
1797
  :learning_note
1761
1798
  end
1762
1799
  end
@@ -2570,10 +2607,10 @@ module PWN
2570
2607
  else 'unknown'
2571
2608
  end
2572
2609
  nanp = nil
2573
- if digits.match?(/\A1?(\d{3})(\d{3})(\d{4})\z/)
2574
- area = Regexp.last_match(1)
2610
+ if (match = digits.match(/\A1?(\d{3})(\d{3})(\d{4})\z/))
2611
+ area = match[1]
2575
2612
  # Area-code → region via public NPA style (best-effort subset)
2576
- nanp = { area_code: area, nxx: Regexp.last_match(2), station: Regexp.last_match(3) }
2613
+ nanp = { area_code: area, nxx: match[2], station: match[3] }
2577
2614
  end
2578
2615
  # OpenCNAM-style public CNAM is largely paywalled; expose format + link targets for deeper manual/keyed lookup.
2579
2616
  {
@@ -25,8 +25,6 @@ module PWN
25
25
  request: request,
26
26
  suppress_pii_warning: true
27
27
  )
28
- rescue StandardError => e
29
- raise e.backtrace
30
28
  end
31
29
 
32
30
  # Author(s):: 0day Inc. <support@0dayinc.com>
@@ -35,8 +35,6 @@ module PWN
35
35
  spinner: true,
36
36
  suppress_pii_warning: true
37
37
  )
38
- rescue StandardError => e
39
- raise e.backtrace
40
38
  end
41
39
 
42
40
  # Author(s):: 0day Inc. <support@0dayinc.com>
@@ -30,6 +30,7 @@ module PWN
30
30
  DISPUTED_FILE = File.join(Dir.home, '.pwn', 'learning', 'disputed.jsonl')
31
31
  LESSONS_FILE = File.join(Dir.home, '.pwn', 'lessons.json')
32
32
  FINETUNE_DIR = File.join(Dir.home, '.pwn', 'finetune')
33
+ EVIDENCE_ANNOTATION_VERSION = 2
33
34
  # Evidence is immutable; provenance is not permission to remove a session.
34
35
  # All readers validate the content hash and full-snapshot contract first.
35
36
  public_class_method def self.evidence_transcript(opts = {})
@@ -230,15 +231,14 @@ module PWN
230
231
  return { annotated: false } unless row
231
232
 
232
233
  transcript = session_evidence(session_id: sid)
234
+ binding = opts[:binding]
235
+ return { annotated: false, reason: :stale_binding } unless Reward.prm_binding_valid?(binding: binding, transcript: transcript, session_id: sid) && rewards.length == binding[:actions].length
236
+
233
237
  prior = row[:evidence_ref][:sha256]
234
238
  artifact = File.join(File.dirname(LEARNING_FILE), 'learning', 'evidence', "#{prior}.json")
235
239
  data = JSON.parse(evidence_read(path: artifact), symbolize_names: true)
236
- index = -1
237
- transcript.each do |entry|
238
- next unless entry[:role].to_s == 'tool'
239
-
240
- index += 1
241
- entry[:step_reward] = rewards[index] unless rewards[index].nil?
240
+ binding[:actions].each_with_index do |action, index|
241
+ transcript[action[:row_index]][:step_reward] = rewards[index] unless rewards[index].nil?
242
242
  end
243
243
  return { annotated: false, unchanged: true } if transcript == data[:transcript]
244
244
 
@@ -247,7 +247,7 @@ module PWN
247
247
  updated = rows.map { |entry| entry[:session_id] == sid ? entry.except(:evidence_ref) : entry }
248
248
  snapshot = { body: body, source: nil, path: File.join(PWN::Sessions::SESSIONS_DIR, "#{sid}.jsonl"),
249
249
  ref: { version: 1, id: hash, sha256: hash } }
250
- evidence_commit(rows: updated, original: original, snapshots: { sid => snapshot }, report: { migrated_rows: 0 }).merge(annotated: true)
250
+ evidence_commit(rows: updated, original: original, snapshots: { sid => snapshot }, report: { migrated_rows: 0 }).merge(annotated: true, binding_sha256: Digest::SHA256.hexdigest(JSON.generate(binding)))
251
251
  ensure
252
252
  learning_unlock(lock: lock) if lock
253
253
  end
@@ -455,6 +455,7 @@ module PWN
455
455
 
456
456
  public_class_method def self.note_outcome(opts = {})
457
457
  lock = learning_lock
458
+ lease, evidence_ref = source_ownership(session_id: opts[:session_id])
458
459
  task = opts[:task].to_s
459
460
  # 4.1 — allow success: 'soft' (HER) distinct from true/false
460
461
  raw_ok = opts[:success]
@@ -493,6 +494,7 @@ module PWN
493
494
  timestamp: Time.now.utc.iso8601
494
495
  }
495
496
  entry[:score] = score if decision || opts.key?(:score)
497
+ entry[:evidence_ref] = evidence_ref if evidence_ref
496
498
  if decision
497
499
  %i[verdict confidence training_score decision_version verification verifier_verdict grounded critic_pass judge_score quality_score rationale claimed_completion verified_completion false_completion].each do |key|
498
500
  entry[key] = decision[key] if decision.key?(key)
@@ -534,6 +536,7 @@ module PWN
534
536
  end
535
537
  entry
536
538
  ensure
539
+ PWN::Sessions.deactivate(lease: lease)
537
540
  learning_unlock(lock: lock) if lock
538
541
  end
539
542
 
@@ -546,10 +549,33 @@ module PWN
546
549
  end
547
550
 
548
551
  public_class_method def self.disputed_save(opts = {})
552
+ lock = learning_lock
549
553
  entry = opts[:entry] || {}
554
+ lease, evidence_ref = source_ownership(session_id: entry[:session_id])
555
+ entry = entry.merge(evidence_ref: evidence_ref) if evidence_ref
550
556
  FileUtils.mkdir_p(File.dirname(DISPUTED_FILE))
551
557
  File.open(DISPUTED_FILE, 'a') { |f| f.puts(JSON.generate(entry)) }
552
558
  entry
559
+ ensure
560
+ PWN::Sessions.deactivate(lease: lease)
561
+ learning_unlock(lock: lock) if lock
562
+ end
563
+
564
+ # Manual noncanonical IDs are legacy provenance, not canonical evidence
565
+ # claims. Existing legacy transcripts still get lifetime ownership.
566
+ # Called only under learning_lock, so deletion cannot race this decision.
567
+ private_class_method def self.source_ownership(opts = {})
568
+ sid = opts[:session_id].to_s
569
+ safe = !sid.empty? && File.basename(sid) == sid && !sid.include?("\0") && !%w[. ..].include?(sid)
570
+ path = File.join(PWN::Sessions::SESSIONS_DIR, "#{sid}.jsonl") if safe
571
+ return [PWN::Sessions.activate(session_id: sid), nil] if path && (File.exist?(path) || File.symlink?(path))
572
+ return [nil, nil] unless sid.match?(PWN::Sessions::SESSION_ID)
573
+
574
+ raise IOError, 'Missing learning source or verified archived evidence' unless session_evidence(session_id: sid)
575
+
576
+ rows = evidence_read(path: LEARNING_FILE).lines.map { |line| JSON.parse(line, symbolize_names: true) }
577
+ row = rows.find { |item| item[:session_id] == sid && item[:evidence_ref] }
578
+ [nil, row.fetch(:evidence_ref)]
553
579
  end
554
580
 
555
581
  # Supported Method Parameters::
@@ -2025,11 +2051,16 @@ module PWN
2025
2051
  return { kept: 0, removed: 0, skipped: true } unless File.exist?(LEARNING_FILE)
2026
2052
 
2027
2053
  before_bytes = File.size(LEARNING_FILE)
2028
- rows = File.readlines(LEARNING_FILE).map do |l|
2029
- JSON.parse(l, symbolize_names: true)
2030
- rescue StandardError
2054
+ rows = File.readlines(LEARNING_FILE).map do |line|
2055
+ JSON.parse(line, symbolize_names: true)
2056
+ rescue JSON::ParserError
2031
2057
  nil
2032
- end.compact
2058
+ end
2059
+ malformed = rows.count { |row| !row.is_a?(Hash) }
2060
+ if malformed.positive?
2061
+ return { state: 'blocked', aborted: true, reason: 'malformed_learning_rows', malformed_rows: malformed,
2062
+ kept: rows.length, removed: 0, bytes_before: before_bytes, bytes_after: before_bytes, dry_run: dry }
2063
+ end
2033
2064
 
2034
2065
  now = Time.now.utc
2035
2066
  age_days = lambda do |r|
@@ -2126,7 +2157,7 @@ module PWN
2126
2157
 
2127
2158
  {
2128
2159
  kept: kept.size,
2129
- removed: (rows.size - kept.size) + removed_dupes,
2160
+ removed: rows.size - kept.size,
2130
2161
  deduped: removed_dupes,
2131
2162
  truncated_details: truncated,
2132
2163
  protected: protected.size,
@@ -2433,7 +2464,8 @@ module PWN
2433
2464
  # Persist derived PRM rewards without rewriting immutable supporting content.
2434
2465
  #{self}.annotate_evidence(
2435
2466
  session_id: 'required - canonical source session ID with retained evidence and no live transcript',
2436
- rewards: 'required - Array of integer -1, 0, 1 or nil per tool row'
2467
+ rewards: 'required - Array of integer -1, 0, 1 or nil per bound tool row',
2468
+ binding: 'required - versioned Reward.prm_snapshot binding for the exact request turn and original action bytes'
2437
2469
  )
2438
2470
 
2439
2471
  # Read and verify the immutable evidence supporting one outcome.
@@ -1354,12 +1354,12 @@ module PWN
1354
1354
  # additionally knows grep exit 1 / diff exit 1 / xargs 123 are
1355
1355
  # informational. Metrics records :ok; Mistakes only records
1356
1356
  # !semantic_ok. Kills the phantom 31f1871b8a15 class permanently.
1357
- sem = defined?(Reward) ? Reward.semantic_ok(name: name, raw: raw, args: opts[:args]) : { ok: raw.include?('"success":true'), semantic_ok: raw.include?('"success":true'), err: raw[/"error":"([^"]{1,300})"/, 1] }
1357
+ sem = defined?(Reward) ? Reward.semantic_ok(name: name, raw: raw, args: opts[:args]) : { ok: nil, semantic_ok: nil, err: nil, shape: :unknown }
1358
1358
  dur = started ? (Time.now - started) : 0.0
1359
1359
  # 1.2 — align Metrics proxy with R4 semantic_ok (handler-ok alone
1360
1360
  # was the reward-signal lie: grep exit 1 looked like 100% success
1361
1361
  # while Mistakes stayed quiet, OR the inverse phantom class).
1362
- Metrics.record(name: name, success: sem[:semantic_ok], duration: dur, error: sem[:err], engine: opts[:engine]) if defined?(Metrics)
1362
+ Metrics.record(name: name, success: sem[:semantic_ok], duration: dur, error: sem[:err], engine: opts[:engine]) if defined?(Metrics) && !sem[:semantic_ok].nil?
1363
1363
  # R5 — live MDP step. Hygiene reward only; terminal credit is judge.
1364
1364
  if defined?(PWN::AI::Agent::Policy) && Policy.respond_to?(:observe_step)
1365
1365
  policy_args = begin
@@ -1382,7 +1382,7 @@ module PWN
1382
1382
  )
1383
1383
  end
1384
1384
  m = nil
1385
- if !sem[:semantic_ok] && defined?(Mistakes) && sem[:shape].to_s != 'invalid_payload' && !raw.include?('extinguished_repeat')
1385
+ if sem[:semantic_ok] == false && defined?(Mistakes) && sem[:shape].to_s != 'invalid_payload' && !raw.include?('extinguished_repeat')
1386
1386
  cause = attribute_cause(name: name)
1387
1387
  err = sem[:err] || raw[0, 300]
1388
1388
  shape = sem[:shape]
@@ -2873,6 +2873,7 @@ module PWN
2873
2873
  private_class_method def self.answer_recall(opts = {})
2874
2874
  request = opts[:request].to_s
2875
2875
  session_id = opts[:session_id]
2876
+ source_session_id = session_id
2876
2877
  system_role_content = opts[:system_role_content].to_s
2877
2878
  target = recall_target(request: request)
2878
2879
  last_session = request.match?(LAST_SESSION_RX)
@@ -2885,7 +2886,7 @@ module PWN
2885
2886
  return txt
2886
2887
  end
2887
2888
 
2888
- session_id = prev
2889
+ source_session_id = prev
2889
2890
  end
2890
2891
 
2891
2892
  prior_user = nil
@@ -2901,20 +2902,20 @@ module PWN
2901
2902
  pair =
2902
2903
  if match == :non_meta || match.nil?
2903
2904
  PWN::Memory.find_turn_pair(
2904
- session_id: session_id,
2905
+ session_id: source_session_id,
2905
2906
  skip_meta: true,
2906
2907
  pairs: 12,
2907
2908
  max_chars: 4_000
2908
2909
  )
2909
2910
  else
2910
2911
  PWN::Memory.find_turn_pair(
2911
- session_id: session_id,
2912
+ session_id: source_session_id,
2912
2913
  match: match,
2913
2914
  skip_meta: true,
2914
2915
  pairs: 12,
2915
2916
  max_chars: 4_000
2916
2917
  ) || PWN::Memory.find_turn_pair(
2917
- session_id: session_id,
2918
+ session_id: source_session_id,
2918
2919
  skip_meta: true,
2919
2920
  pairs: 12,
2920
2921
  max_chars: 4_000
@@ -2931,19 +2932,19 @@ module PWN
2931
2932
  # original utterance when appropriate; default stays newest.
2932
2933
  skip_meta = target == :assistant || last_session
2933
2934
  prior_user = PWN::Memory.prior_user_message(
2934
- session_id: session_id,
2935
+ session_id: source_session_id,
2935
2936
  max_chars: 4_000,
2936
2937
  skip_meta: skip_meta,
2937
2938
  pairs: 8
2938
2939
  )
2939
2940
  prior_asst = PWN::Memory.prior_assistant_message(
2940
- session_id: session_id,
2941
+ session_id: source_session_id,
2941
2942
  max_chars: 4_000,
2942
2943
  skip_meta: skip_meta,
2943
2944
  pairs: 8
2944
2945
  )
2945
2946
  end
2946
- dialog = PWN::Memory.recent_dialog(session_id: session_id, pairs: 4, max_chars: 1_500)
2947
+ dialog = PWN::Memory.recent_dialog(session_id: source_session_id, pairs: 4, max_chars: 1_500)
2947
2948
  end
2948
2949
 
2949
2950
  user_body = prior_user && prior_user[:content].to_s.strip
@@ -3061,7 +3062,7 @@ module PWN
3061
3062
  request: request,
3062
3063
  system_role_content: recall_sys,
3063
3064
  response_history: chat_response_history(
3064
- session_id: session_id,
3065
+ session_id: source_session_id,
3065
3066
  request: request,
3066
3067
  system_role_content: recall_sys
3067
3068
  ),
@@ -172,7 +172,7 @@ module PWN
172
172
  public_class_method def self.record_tokens(opts = {})
173
173
  n = opts[:tokens].to_i
174
174
  cost = opts[:cost].to_f
175
- model = opts[:model].to_s
175
+ model = opts[:model].to_s.to_sym
176
176
  m = load
177
177
  m[:usage] ||= { tokens: 0, cost: 0.0, calls: 0, by_model: {} }
178
178
  m[:usage][:tokens] += n
@@ -98,7 +98,7 @@ module PWN
98
98
  approved: row[:approved] == true,
99
99
  unattended: row[:unattended]
100
100
  )
101
- ids = Array(report[:results]).map { |step| step[:id] || step['id'] }.compact
101
+ ids = Array(report[:results]).filter_map { |step| step[:id] || step['id'] if step[:ok] == true || step['ok'] == true }
102
102
  mutate!(id: row[:id]) do |locked|
103
103
  locked[:last_completed_step] = ids.last if ids.any?
104
104
  locked[:status] = 'open'
@@ -228,8 +228,11 @@ module PWN
228
228
 
229
229
  public_class_method def self.report_text(opts = {})
230
230
  report = opts[:report] || {}
231
- ids = Array(report[:results]).map { |step| step[:id] || step['id'] }
232
- "Resumed mission for #{opts[:request]}. Completed steps: #{ids.join(', ')}. Named-duration work stays open until wall time elapses."
231
+ completed, failed = Array(report[:results]).partition { |step| step[:ok] == true || step['ok'] == true }
232
+ ids = completed.map { |step| step[:id] || step['id'] }
233
+ failures = failed.map { |step| step[:id] || step['id'] }
234
+ failure_text = failures.empty? ? '' : " Failed steps: #{failures.join(', ')}."
235
+ "Resumed mission for #{opts[:request]}. Completed steps: #{ids.join(', ')}.#{failure_text} Named-duration work stays open until wall time elapses."
233
236
  end
234
237
 
235
238
  public_class_method def self.authors
@@ -1151,7 +1151,7 @@ module PWN
1151
1151
 
1152
1152
  private_class_method def self.terminal_reward(opts = {})
1153
1153
  conf = opts[:confidence]
1154
- conf = 1.0 if conf.nil? || conf.to_f <= 0.0
1154
+ conf = 1.0 if conf.nil?
1155
1155
  conf = conf.to_f.clamp(0.0, 1.0)
1156
1156
  unless opts[:score].nil?
1157
1157
  base = ((2.0 * opts[:score].to_f) - 1.0).clamp(-1.0, 1.0)