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.
Files changed (384) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +8 -8
  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/Mission-Cancellation.md +6 -4
  10. data/documentation/Operability.md +1 -1
  11. data/documentation/What-is-PWN.md +1 -1
  12. data/documentation/diagrams/aws-cloud-security.svg +1 -1
  13. data/documentation/diagrams/dot/aws-cloud-security.dot +1 -1
  14. data/documentation/diagrams/dot/network-infra-testing.dot +1 -1
  15. data/documentation/diagrams/network-infra-testing.svg +1 -1
  16. data/etc/default_cron/session_cleanup.rb +84 -51
  17. data/etc/default_skills/pwn/ai/agent/mission_namespace/SKILL.md +6 -4
  18. data/lib/pwn/ai/agent/assembly.rb +0 -2
  19. data/lib/pwn/ai/agent/btc.rb +0 -2
  20. data/lib/pwn/ai/agent/burp_suite.rb +0 -2
  21. data/lib/pwn/ai/agent/curriculum.rb +2 -2
  22. data/lib/pwn/ai/agent/dispatch.rb +3 -0
  23. data/lib/pwn/ai/agent/engagement.rb +96 -41
  24. data/lib/pwn/ai/agent/extrospection/osint/bridges.rb +2 -0
  25. data/lib/pwn/ai/agent/extrospection.rb +50 -13
  26. data/lib/pwn/ai/agent/gqrx.rb +0 -2
  27. data/lib/pwn/ai/agent/hacker_one.rb +0 -2
  28. data/lib/pwn/ai/agent/learning.rb +45 -13
  29. data/lib/pwn/ai/agent/loop.rb +16 -11
  30. data/lib/pwn/ai/agent/metrics.rb +1 -1
  31. data/lib/pwn/ai/agent/mission.rb +6 -3
  32. data/lib/pwn/ai/agent/mission_namespace.rb +70 -14
  33. data/lib/pwn/ai/agent/policy.rb +1 -1
  34. data/lib/pwn/ai/agent/policy_evaluation.rb +2 -2
  35. data/lib/pwn/ai/agent/reflect.rb +1 -0
  36. data/lib/pwn/ai/agent/request_runtime.rb +1 -1
  37. data/lib/pwn/ai/agent/reward.rb +155 -53
  38. data/lib/pwn/ai/agent/sast.rb +0 -2
  39. data/lib/pwn/ai/agent/task_dag.rb +5 -3
  40. data/lib/pwn/ai/agent/task_summarizer.rb +21 -11
  41. data/lib/pwn/ai/agent/tool_guard.rb +19 -0
  42. data/lib/pwn/ai/agent/tools/ruby_eval.rb +1 -1
  43. data/lib/pwn/ai/agent/tools/verify.rb +7 -3
  44. data/lib/pwn/ai/agent/transparent_browser.rb +0 -2
  45. data/lib/pwn/ai/agent/turn_finalizer.rb +3 -0
  46. data/lib/pwn/ai/anthropic.rb +3 -3
  47. data/lib/pwn/ai/context.rb +2 -1
  48. data/lib/pwn/ai/gemini.rb +7 -5
  49. data/lib/pwn/ai/grok.rb +37 -18
  50. data/lib/pwn/ai/mcp.rb +17 -5
  51. data/lib/pwn/ai/ollama.rb +76 -35
  52. data/lib/pwn/ai/open_ai.rb +7 -19
  53. data/lib/pwn/ai/open_web_ui.rb +76 -40
  54. data/lib/pwn/aws/cloud_search_domain.rb +6 -0
  55. data/lib/pwn/aws/iam.rb +2 -2
  56. data/lib/pwn/aws/workspaces.rb +2 -2
  57. data/lib/pwn/aws.rb +0 -5
  58. data/lib/pwn/bounty/lifecycle_authz_replay.rb +1 -1
  59. data/lib/pwn/config.rb +17 -10
  60. data/lib/pwn/corpus.rb +33 -5
  61. data/lib/pwn/cron.rb +60 -17
  62. data/lib/pwn/driver.rb +2 -3
  63. data/lib/pwn/engagement.rb +28 -10
  64. data/lib/pwn/ffi/capstone.rb +3 -2
  65. data/lib/pwn/ffi/fftw.rb +8 -6
  66. data/lib/pwn/ffi/keystone.rb +3 -2
  67. data/lib/pwn/ffi/soapy_sdr.rb +10 -6
  68. data/lib/pwn/json_text.rb +25 -13
  69. data/lib/pwn/memory_index.rb +6 -4
  70. data/lib/pwn/module_skills.rb +3 -1
  71. data/lib/pwn/plugins/aflplusplus.rb +1 -0
  72. data/lib/pwn/plugins/ai_sandbox.rb +42 -10
  73. data/lib/pwn/plugins/android.rb +429 -466
  74. data/lib/pwn/plugins/artifact_registry.rb +12 -2
  75. data/lib/pwn/plugins/assembly.rb +9 -42
  76. data/lib/pwn/plugins/authentication_helper.rb +4 -3
  77. data/lib/pwn/plugins/baresip.rb +70 -28
  78. data/lib/pwn/plugins/binary_analysis.rb +14 -5
  79. data/lib/pwn/plugins/binary_parser.rb +42 -7
  80. data/lib/pwn/plugins/black_duck_binary_analysis.rb +3 -3
  81. data/lib/pwn/plugins/burp_suite.rb +15 -12
  82. data/lib/pwn/plugins/bus_pirate.rb +3 -7
  83. data/lib/pwn/plugins/char.rb +9 -3
  84. data/lib/pwn/plugins/credit_card.rb +7 -0
  85. data/lib/pwn/plugins/dao_ldap.rb +2 -2
  86. data/lib/pwn/plugins/dao_mongo.rb +1 -1
  87. data/lib/pwn/plugins/debugger.rb +1 -1
  88. data/lib/pwn/plugins/defect_dojo.rb +7 -3
  89. data/lib/pwn/plugins/detect_os.rb +1 -1
  90. data/lib/pwn/plugins/detonate.rb +9 -19
  91. data/lib/pwn/plugins/exploit_db.rb +1 -1
  92. data/lib/pwn/plugins/file_fu.rb +4 -1
  93. data/lib/pwn/plugins/findings.rb +76 -2
  94. data/lib/pwn/plugins/fuzz.rb +12 -3
  95. data/lib/pwn/plugins/gdb.rb +7 -2
  96. data/lib/pwn/plugins/gdbmi.rb +10 -6
  97. data/lib/pwn/plugins/git.rb +18 -13
  98. data/lib/pwn/plugins/github.rb +11 -6
  99. data/lib/pwn/plugins/google_workspace.rb +11 -3
  100. data/lib/pwn/plugins/hacker_one.rb +5 -1
  101. data/lib/pwn/plugins/httpx.rb +24 -8
  102. data/lib/pwn/plugins/ip_info.rb +11 -8
  103. data/lib/pwn/plugins/irc.rb +73 -45
  104. data/lib/pwn/plugins/jenkins.rb +2 -2
  105. data/lib/pwn/plugins/jira_data_center.rb +13 -6
  106. data/lib/pwn/plugins/jobs.rb +62 -4
  107. data/lib/pwn/plugins/log.rb +1 -1
  108. data/lib/pwn/plugins/monkey_patch.rb +1 -1
  109. data/lib/pwn/plugins/msr206.rb +157 -182
  110. data/lib/pwn/plugins/nessus_cloud.rb +2 -2
  111. data/lib/pwn/plugins/nexpose_vuln_scan.rb +44 -33
  112. data/lib/pwn/plugins/nuclei.rb +24 -8
  113. data/lib/pwn/plugins/ocr.rb +3 -1
  114. data/lib/pwn/plugins/open_api.rb +0 -4
  115. data/lib/pwn/plugins/openvas.rb +31 -43
  116. data/lib/pwn/plugins/packet.rb +40 -25
  117. data/lib/pwn/plugins/pony.rb +2 -2
  118. data/lib/pwn/plugins/preflight_checker.rb +1 -1
  119. data/lib/pwn/plugins/process_tube.rb +17 -2
  120. data/lib/pwn/plugins/ps.rb +6 -1
  121. data/lib/pwn/plugins/pwn_logger.rb +37 -1
  122. data/lib/pwn/plugins/repl/ai.rb +1 -0
  123. data/lib/pwn/plugins/repl/ai_console.rb +18 -6
  124. data/lib/pwn/plugins/repl/mesh.rb +51 -28
  125. data/lib/pwn/plugins/sbom.rb +59 -27
  126. data/lib/pwn/plugins/scannable_codes.rb +3 -1
  127. data/lib/pwn/plugins/serial.rb +102 -44
  128. data/lib/pwn/plugins/shodan.rb +4 -10
  129. data/lib/pwn/plugins/sock.rb +16 -11
  130. data/lib/pwn/plugins/ssn.rb +3 -1
  131. data/lib/pwn/plugins/transparent_browser.rb +43 -3
  132. data/lib/pwn/plugins/vault.rb +92 -30
  133. data/lib/pwn/plugins/vin.rb +2 -1
  134. data/lib/pwn/plugins/vsphere.rb +2 -1
  135. data/lib/pwn/plugins/xxd.rb +3 -5
  136. data/lib/pwn/plugins/yubikey/security_domain/scp.rb +4 -0
  137. data/lib/pwn/plugins/yubikey/transport.rb +42 -11
  138. data/lib/pwn/plugins/yubikey.rb +21 -6
  139. data/lib/pwn/plugins/zaproxy.rb +3 -4
  140. data/lib/pwn/reports/ai_red_team.rb +4 -4
  141. data/lib/pwn/reports/pdf.rb +9 -5
  142. data/lib/pwn/reports/sast.rb +4 -4
  143. data/lib/pwn/sast/keystore.rb +2 -2
  144. data/lib/pwn/sast/logger.rb +1 -1
  145. data/lib/pwn/sast/php_type_juggling.rb +3 -6
  146. data/lib/pwn/sast/pom_version.rb +12 -6
  147. data/lib/pwn/sast/port.rb +1 -1
  148. data/lib/pwn/sast/sql.rb +3 -7
  149. data/lib/pwn/sast/test_case_engine.rb +62 -16
  150. data/lib/pwn/sast/type_script_type_juggling.rb +3 -6
  151. data/lib/pwn/sdr/decoder/base.rb +8 -0
  152. data/lib/pwn/sdr/decoder/lora.rb +1 -1
  153. data/lib/pwn/sdr/flipper_zero.rb +4 -7
  154. data/lib/pwn/sdr/gqrx.rb +35 -16
  155. data/lib/pwn/sdr/son_micro_rfid.rb +44 -26
  156. data/lib/pwn/sdr.rb +1 -1
  157. data/lib/pwn/session_trace.rb +7 -2
  158. data/lib/pwn/sessions.rb +310 -41
  159. data/lib/pwn/setup.rb +4 -3
  160. data/lib/pwn/version.rb +1 -1
  161. data/lib/pwn/www/app_cobalt_io.rb +14 -2
  162. data/lib/pwn/www/bing.rb +13 -1
  163. data/lib/pwn/www/bug_crowd.rb +14 -2
  164. data/lib/pwn/www/checkip.rb +13 -1
  165. data/lib/pwn/www/coinbase_pro.rb +14 -2
  166. data/lib/pwn/www/duckduckgo.rb +13 -1
  167. data/lib/pwn/www/facebook.rb +14 -2
  168. data/lib/pwn/www/github.rb +14 -2
  169. data/lib/pwn/www/google.rb +13 -1
  170. data/lib/pwn/www/hacker_one.rb +117 -33
  171. data/lib/pwn/www/linkedin.rb +14 -2
  172. data/lib/pwn/www/pandora.rb +14 -2
  173. data/lib/pwn/www/pastebin.rb +13 -1
  174. data/lib/pwn/www/paypal.rb +16 -4
  175. data/lib/pwn/www/synack.rb +14 -2
  176. data/lib/pwn/www/torch.rb +17 -3
  177. data/lib/pwn/www/trading_view.rb +14 -2
  178. data/lib/pwn/www/twitter.rb +14 -2
  179. data/lib/pwn/www/uber.rb +14 -2
  180. data/lib/pwn/www/upwork.rb +14 -2
  181. data/lib/pwn/www/wayback_machine.rb +16 -2
  182. data/lib/pwn/www/youtube.rb +13 -1
  183. data/lib/pwn.rb +11 -0
  184. data/pwn.gemspec +4 -0
  185. data/spec/conventions_spec.rb +43 -0
  186. data/spec/integration/authentication_helper_oath_spec.rb +1 -1
  187. data/spec/integration/autoinc_lifecycle_supplement_spec.rb +47 -0
  188. data/spec/integration/gemspec_deleted_files_spec.rb +43 -0
  189. data/spec/integration/harness_evaluation_spec.rb +22 -31
  190. data/spec/integration/harness_live_spec.rb +8 -18
  191. data/spec/integration/spec_curriculum_isolation_spec.rb +41 -0
  192. data/spec/integration/verify_acceptance_eui_regression_spec.rb +162 -0
  193. data/spec/integration/web_cache_lifecycle_closure_spec.rb +89 -0
  194. data/spec/integration/web_cache_lifecycle_supplement_spec.rb +70 -0
  195. data/spec/lib/pwn/ai/agent/analysis_errors_regression_spec.rb +33 -0
  196. data/spec/lib/pwn/ai/agent/curriculum_cooldown_regression_spec.rb +19 -0
  197. data/spec/lib/pwn/ai/agent/curriculum_spec.rb +2 -0
  198. data/spec/lib/pwn/ai/agent/engagement_boundary_regression_spec.rb +42 -0
  199. data/spec/lib/pwn/ai/agent/engagement_dispatch_review_spec.rb +82 -0
  200. data/spec/lib/pwn/ai/agent/engagement_roe_regression_spec.rb +25 -0
  201. data/spec/lib/pwn/ai/agent/engagement_scope_regression_spec.rb +37 -0
  202. data/spec/lib/pwn/ai/agent/extrospection/osint/bridges_spec.rb +4 -0
  203. data/spec/lib/pwn/ai/agent/extrospection_input_regression_spec.rb +31 -0
  204. data/spec/lib/pwn/ai/agent/extrospection_review_spec.rb +61 -0
  205. data/spec/lib/pwn/ai/agent/extrospection_serial_review_spec.rb +42 -0
  206. data/spec/lib/pwn/ai/agent/extrospection_spec.rb +9 -0
  207. data/spec/lib/pwn/ai/agent/extrospection_verification_regression_spec.rb +39 -0
  208. data/spec/lib/pwn/ai/agent/learning_last_answer_regression_spec.rb +32 -0
  209. data/spec/lib/pwn/ai/agent/learning_lifecycle_closure_spec.rb +84 -0
  210. data/spec/lib/pwn/ai/agent/learning_prune_regression_spec.rb +17 -0
  211. data/spec/lib/pwn/ai/agent/learning_spec.rb +2 -1
  212. data/spec/lib/pwn/ai/agent/loop_execution_audit_spec.rb +30 -0
  213. data/spec/lib/pwn/ai/agent/metrics_usage_regression_spec.rb +20 -0
  214. data/spec/lib/pwn/ai/agent/mission_execution_audit_spec.rb +27 -0
  215. data/spec/lib/pwn/ai/agent/mission_namespace_spec.rb +218 -18
  216. data/spec/lib/pwn/ai/agent/policy_confidence_regression_spec.rb +16 -0
  217. data/spec/lib/pwn/ai/agent/policy_evaluation_spec.rb +1 -1
  218. data/spec/lib/pwn/ai/agent/policy_evaluation_tmp_regression_spec.rb +36 -0
  219. data/spec/lib/pwn/ai/agent/reflect_model_regression_spec.rb +15 -0
  220. data/spec/lib/pwn/ai/agent/request_runtime_execution_audit_spec.rb +43 -0
  221. data/spec/lib/pwn/ai/agent/reward_binding_review_spec.rb +129 -0
  222. data/spec/lib/pwn/ai/agent/reward_dispatch_review_spec.rb +154 -0
  223. data/spec/lib/pwn/ai/agent/reward_envelope_regression_spec.rb +45 -0
  224. data/spec/lib/pwn/ai/agent/reward_turn_regression_spec.rb +40 -0
  225. data/spec/lib/pwn/ai/agent/swarm_spec.rb +2 -2
  226. data/spec/lib/pwn/ai/agent/task_dag_execution_audit_spec.rb +45 -0
  227. data/spec/lib/pwn/ai/agent/task_summarizer_failure_regression_spec.rb +26 -0
  228. data/spec/lib/pwn/ai/agent/tools/verify_execution_audit_spec.rb +33 -0
  229. data/spec/lib/pwn/ai/context_range_audit_spec.rb +24 -0
  230. data/spec/lib/pwn/ai/gemini_roundtrip_audit_spec.rb +33 -0
  231. data/spec/lib/pwn/ai/grok_reasoning_effort_spec.rb +43 -0
  232. data/spec/lib/pwn/ai/mcp_session_audit_spec.rb +36 -0
  233. data/spec/lib/pwn/ai/ollama_spec.rb +6 -11
  234. data/spec/lib/pwn/ai/open_web_ui_spec.rb +6 -11
  235. data/spec/lib/pwn/ai/provider_history_audit_spec.rb +44 -0
  236. data/spec/lib/pwn/ai/provider_operations_audit_spec.rb +53 -0
  237. data/spec/lib/pwn/ai/provider_review_history_stream_regression_spec.rb +143 -0
  238. data/spec/lib/pwn/ai/provider_review_tls_regression_spec.rb +62 -0
  239. data/spec/lib/pwn/ai/provider_stream_audit_spec.rb +49 -0
  240. data/spec/lib/pwn/aws/iam_decoding_regression_spec.rb +23 -0
  241. data/spec/lib/pwn/aws/services_runtime_regression_spec.rb +51 -0
  242. data/spec/lib/pwn/aws_spec.rb +6 -0
  243. data/spec/lib/pwn/banner_operational_audit_spec.rb +105 -0
  244. data/spec/lib/pwn/bounty/lifecycle_authz_replay_spec.rb +17 -0
  245. data/spec/lib/pwn/config_redaction_regression_spec.rb +24 -0
  246. data/spec/lib/pwn/config_skills_regression_spec.rb +38 -0
  247. data/spec/lib/pwn/corpus_core_review_regression_spec.rb +96 -0
  248. data/spec/lib/pwn/corpus_spec.rb +13 -0
  249. data/spec/lib/pwn/cron_core_review_regression_spec.rb +95 -0
  250. data/spec/lib/pwn/cron_execution_spec.rb +75 -0
  251. data/spec/lib/pwn/driver_core_review_regression_spec.rb +38 -0
  252. data/spec/lib/pwn/driver_spec.rb +13 -0
  253. data/spec/lib/pwn/engagement_core_review_regression_spec.rb +88 -0
  254. data/spec/lib/pwn/engagement_storage_regression_spec.rb +44 -0
  255. data/spec/lib/pwn/ffi/capstone_spec.rb +19 -0
  256. data/spec/lib/pwn/ffi/fftw_spec.rb +19 -0
  257. data/spec/lib/pwn/ffi/keystone_spec.rb +13 -0
  258. data/spec/lib/pwn/ffi/soapy_sdr_spec.rb +13 -0
  259. data/spec/lib/pwn/json_schemer_regexp_parser_spec.rb +12 -0
  260. data/spec/lib/pwn/json_text_spec.rb +25 -0
  261. data/spec/lib/pwn/memory_index_spec.rb +23 -0
  262. data/spec/lib/pwn/module_skills_parsing_regression_spec.rb +34 -0
  263. data/spec/lib/pwn/module_skills_spec.rb +11 -1
  264. data/spec/lib/pwn/plugins/ai_sandbox_boundary_review_spec.rb +57 -0
  265. data/spec/lib/pwn/plugins/ai_sandbox_spec.rb +10 -18
  266. data/spec/lib/pwn/plugins/android_review_fixes_spec.rb +121 -0
  267. data/spec/lib/pwn/plugins/android_transport_audit_spec.rb +64 -0
  268. data/spec/lib/pwn/plugins/api_import_namespace_audit_spec.rb +49 -0
  269. data/spec/lib/pwn/plugins/artifact_registry_namespace_audit_spec.rb +20 -0
  270. data/spec/lib/pwn/plugins/artifact_registry_review_fixes_spec.rb +63 -0
  271. data/spec/lib/pwn/plugins/assembly_namespace_audit_spec.rb +16 -0
  272. data/spec/lib/pwn/plugins/assembly_review_fixes_spec.rb +33 -0
  273. data/spec/lib/pwn/plugins/authentication_helper_spec.rb +14 -0
  274. data/spec/lib/pwn/plugins/baresip_review_fixes_spec.rb +127 -0
  275. data/spec/lib/pwn/plugins/baresip_transport_audit_spec.rb +59 -0
  276. data/spec/lib/pwn/plugins/binary_analysis_process_review_spec.rb +57 -0
  277. data/spec/lib/pwn/plugins/black_duck_namespace_audit_spec.rb +25 -0
  278. data/spec/lib/pwn/plugins/burp_suite_har_review_fixes_spec.rb +60 -0
  279. data/spec/lib/pwn/plugins/burp_suite_import_review_fixes_spec.rb +62 -0
  280. data/spec/lib/pwn/plugins/burp_suite_namespace_audit_spec.rb +37 -0
  281. data/spec/lib/pwn/plugins/bus_pirate_transport_audit_spec.rb +19 -0
  282. data/spec/lib/pwn/plugins/file_fu_namespace_audit_spec.rb +17 -0
  283. data/spec/lib/pwn/plugins/findings_structured_spec.rb +1 -1
  284. data/spec/lib/pwn/plugins/gdbmi_namespace_audit_spec.rb +28 -0
  285. data/spec/lib/pwn/plugins/gdbmi_review_fixes_spec.rb +73 -0
  286. data/spec/lib/pwn/plugins/github_argv_review_spec.rb +49 -0
  287. data/spec/lib/pwn/plugins/google_workspace_provider_review_oauth_spec.rb +80 -0
  288. data/spec/lib/pwn/plugins/irc_review_fixes_spec.rb +92 -0
  289. data/spec/lib/pwn/plugins/irc_transport_audit_spec.rb +37 -0
  290. data/spec/lib/pwn/plugins/jenkins_namespace_audit_spec.rb +12 -0
  291. data/spec/lib/pwn/plugins/jira_data_center_namespace_audit_spec.rb +44 -0
  292. data/spec/lib/pwn/plugins/jira_data_center_review_fixes_spec.rb +81 -0
  293. data/spec/lib/pwn/plugins/jsonl_elf_review_fixes_spec.rb +59 -0
  294. data/spec/lib/pwn/plugins/log_spec.rb +36 -20
  295. data/spec/lib/pwn/plugins/monkey_patch_spec.rb +16 -0
  296. data/spec/lib/pwn/plugins/msr206_readback_review_fixes_spec.rb +119 -0
  297. data/spec/lib/pwn/plugins/msr206_review_fixes_spec.rb +50 -0
  298. data/spec/lib/pwn/plugins/msr206_transport_audit_spec.rb +64 -0
  299. data/spec/lib/pwn/plugins/nessus_cloud_namespace_audit_spec.rb +14 -0
  300. data/spec/lib/pwn/plugins/nexpose_review_fixes_spec.rb +55 -0
  301. data/spec/lib/pwn/plugins/open_api_namespace_audit_spec.rb +22 -0
  302. data/spec/lib/pwn/plugins/packet_transport_audit_spec.rb +47 -0
  303. data/spec/lib/pwn/plugins/plugins_b_operational_regression_spec.rb +600 -0
  304. data/spec/lib/pwn/plugins/pony_namespace_audit_spec.rb +17 -0
  305. data/spec/lib/pwn/plugins/pony_review_fixes_spec.rb +33 -0
  306. data/spec/lib/pwn/plugins/process_tube_namespace_audit_spec.rb +19 -0
  307. data/spec/lib/pwn/plugins/ps_namespace_audit_spec.rb +12 -0
  308. data/spec/lib/pwn/plugins/pwn_logger_spec.rb +30 -0
  309. data/spec/lib/pwn/plugins/repl/ai_console_spec.rb +127 -0
  310. data/spec/lib/pwn/plugins/repl/ai_spec.rb +38 -0
  311. data/spec/lib/pwn/plugins/repl/mesh_spec.rb +52 -0
  312. data/spec/lib/pwn/plugins/repl_mesh_rx_errors_spec.rb +18 -0
  313. data/spec/lib/pwn/plugins/sandbox_spec.rb +9 -7
  314. data/spec/lib/pwn/plugins/sbom_review_fixes_spec.rb +43 -0
  315. data/spec/lib/pwn/plugins/scannable_codes_namespace_audit_spec.rb +15 -0
  316. data/spec/lib/pwn/plugins/serial_review_fixes_spec.rb +76 -0
  317. data/spec/lib/pwn/plugins/serial_transport_audit_spec.rb +102 -0
  318. data/spec/lib/pwn/plugins/shodan_namespace_audit_spec.rb +10 -0
  319. data/spec/lib/pwn/plugins/sock_transport_audit_spec.rb +55 -0
  320. data/spec/lib/pwn/plugins/transparent_browser_navigation_review_spec.rb +21 -0
  321. data/spec/lib/pwn/plugins/vault_master_key_eui_regression_spec.rb +242 -0
  322. data/spec/lib/pwn/plugins/vault_spec.rb +58 -0
  323. data/spec/lib/pwn/plugins/vault_store_safety_spec.rb +1 -1
  324. data/spec/lib/pwn/plugins/xxd_namespace_audit_spec.rb +34 -0
  325. data/spec/lib/pwn/plugins/yubikey_hid_cleanup_review_fixes_spec.rb +52 -0
  326. data/spec/lib/pwn/plugins/yubikey_lifecycle_audit_spec.rb +65 -0
  327. data/spec/lib/pwn/plugins/yubikey_options_audit_spec.rb +30 -0
  328. data/spec/lib/pwn/plugins/yubikey_selector_audit_spec.rb +26 -0
  329. data/spec/lib/pwn/plugins/yubikey_spec.rb +1 -1
  330. data/spec/lib/pwn/plugins/zaproxy_namespace_audit_spec.rb +30 -0
  331. data/spec/lib/pwn/reports/empty_report_audit_spec.rb +18 -0
  332. data/spec/lib/pwn/reports/pdf_spec.rb +25 -0
  333. data/spec/lib/pwn/reports/provider_review_encoding_regression_spec.rb +35 -0
  334. data/spec/lib/pwn/sast/engine_runtime_regression_spec.rb +91 -0
  335. data/spec/lib/pwn/sast/filter_edge_regression_spec.rb +39 -0
  336. data/spec/lib/pwn/sast/formatter_review_fixes_spec.rb +178 -0
  337. data/spec/lib/pwn/sast/path_review_fixes_spec.rb +60 -0
  338. data/spec/lib/pwn/sast/pom_runtime_regression_spec.rb +37 -0
  339. data/spec/lib/pwn/sast/rules_runtime_regression_spec.rb +78 -0
  340. data/spec/lib/pwn/sast/sql_review_fixes_spec.rb +38 -0
  341. data/spec/lib/pwn/sdr/decoder/base_iq_spec.rb +21 -18
  342. data/spec/lib/pwn/sdr/decoder/base_review_fixes_spec.rb +49 -0
  343. data/spec/lib/pwn/sdr/decoder/base_validation_spec.rb +78 -0
  344. data/spec/lib/pwn/sdr/decoder/lora_spec.rb +9 -0
  345. data/spec/lib/pwn/sdr/flipper_zero_review_fixes_spec.rb +34 -0
  346. data/spec/lib/pwn/sdr/gqrx_operational_spec.rb +83 -0
  347. data/spec/lib/pwn/sdr/gqrx_review_fixes_spec.rb +22 -0
  348. data/spec/lib/pwn/sdr/son_micro_rfid_review_fixes_spec.rb +113 -0
  349. data/spec/lib/pwn/sdr/son_micro_rfid_serial_review_fixes_spec.rb +76 -0
  350. data/spec/lib/pwn/sdr/son_micro_rfid_spec.rb +39 -0
  351. data/spec/lib/pwn/sdr_spec.rb +5 -0
  352. data/spec/lib/pwn/session_cleanup_concurrency_spec.rb +21 -0
  353. data/spec/lib/pwn/session_cleanup_default_spec.rb +1 -1
  354. data/spec/lib/pwn/session_cleanup_lifecycle_supplement_spec.rb +39 -0
  355. data/spec/lib/pwn/session_cleanup_payload_spec.rb +3 -2
  356. data/spec/lib/pwn/session_trace_lifecycle_supplement_spec.rb +39 -0
  357. data/spec/lib/pwn/sessions_archive_closure_spec.rb +126 -0
  358. data/spec/lib/pwn/sessions_lifecycle_closure_spec.rb +373 -0
  359. data/spec/lib/pwn/sessions_lifecycle_supplement_spec.rb +204 -0
  360. data/spec/lib/pwn/setup_operational_regression_spec.rb +36 -0
  361. data/spec/lib/pwn/www/browser_review_fixes_spec.rb +70 -0
  362. data/spec/lib/pwn/www/browser_runtime_regression_spec.rb +100 -0
  363. data/spec/lib/pwn/www/hacker_one_runtime_regression_spec.rb +146 -0
  364. data/spec/lib/pwn/www/pagination_review_fixes_spec.rb +84 -0
  365. data/spec/spec_helper.rb +34 -5
  366. data/spec/support/namespace_controller_observability_fixture.rb +141 -0
  367. data/spec/support/sandbox.rb +8 -5
  368. data/third_party/pwn_rdoc.jsonl +83 -32
  369. metadata +7690 -7386
  370. data/etc/default_skills/pwn/aws/elastic_transcoder/SKILL.md +0 -48
  371. data/etc/default_skills/pwn/aws/lambda_preview/SKILL.md +0 -48
  372. data/etc/default_skills/pwn/aws/ops_works/SKILL.md +0 -48
  373. data/etc/default_skills/pwn/aws/ops_works_cm/SKILL.md +0 -48
  374. data/etc/default_skills/pwn/aws/sms/SKILL.md +0 -48
  375. data/lib/pwn/aws/elastic_transcoder.rb +0 -95
  376. data/lib/pwn/aws/lambda_preview.rb +0 -95
  377. data/lib/pwn/aws/ops_works.rb +0 -95
  378. data/lib/pwn/aws/ops_works_cm.rb +0 -95
  379. data/lib/pwn/aws/sms.rb +0 -95
  380. data/spec/lib/pwn/aws/elastic_transcoder_spec.rb +0 -15
  381. data/spec/lib/pwn/aws/lambda_preview_spec.rb +0 -15
  382. data/spec/lib/pwn/aws/ops_works_cm_spec.rb +0 -15
  383. data/spec/lib/pwn/aws/ops_works_spec.rb +0 -15
  384. data/spec/lib/pwn/aws/sms_spec.rb +0 -15
@@ -471,7 +471,7 @@ module PWN
471
471
  method: http_method,
472
472
  url: "#{base_uri}/#{rest_call}",
473
473
  headers: headers,
474
- verify_ssl: oauth_selected,
474
+ verify_ssl: true,
475
475
  max_redirects: oauth_selected ? 0 : 10,
476
476
  timeout: timeout
477
477
  )
@@ -485,7 +485,7 @@ module PWN
485
485
  url: "#{base_uri}/#{rest_call}",
486
486
  headers: headers,
487
487
  payload: http_body,
488
- verify_ssl: oauth_selected,
488
+ verify_ssl: true,
489
489
  max_redirects: oauth_selected ? 0 : 10,
490
490
  timeout: timeout
491
491
  )
@@ -495,7 +495,7 @@ module PWN
495
495
  url: "#{base_uri}/#{rest_call}",
496
496
  headers: headers,
497
497
  payload: http_body.to_json,
498
- verify_ssl: oauth_selected,
498
+ verify_ssl: true,
499
499
  max_redirects: oauth_selected ? 0 : 10,
500
500
  timeout: timeout
501
501
  )
@@ -545,20 +545,8 @@ module PWN
545
545
  rescue RestClient::ExceptionWithResponse => e
546
546
  raise e if oauth_selected || e.is_a?(RestClient::TooManyRequests) || Thread.current[:pwn_provider_attempt_owner]
547
547
 
548
- puts "ERROR: #{e.message}: #{e.response}" unless opts[:quiet]
549
- "#{e.message}: #{e.response}" if opts[:quiet]
550
- rescue StandardError => e
551
- raise e if oauth_selected
552
- raise e if Thread.current[:pwn_provider_attempt_owner]
553
-
554
- case e.message
555
- when '400 Bad Request', '404 Resource Not Found'
556
- nil
557
- else
558
- raise e unless opts[:quiet]
559
-
560
- end
561
- "#{e.message}: #{e.response}"
548
+ e.message = "OpenAI HTTP #{e.http_code} (#{http_method.to_s.upcase} #{rest_call}): #{e.response&.body}"
549
+ raise
562
550
  ensure
563
551
  PWN::Plugins::TTYSpinner.stop(spin: spin)
564
552
  end
@@ -1440,7 +1428,7 @@ module PWN
1440
1428
  file = opts[:file]
1441
1429
  timeout = opts[:timeout]
1442
1430
 
1443
- response = list_files(token: token)
1431
+ response = list_files(timeout: timeout)
1444
1432
  file_id = response[:data].select { |f| f if f[:filename] == File.basename(file) }.first[:id]
1445
1433
 
1446
1434
  rest_call = "files/#{file_id}"
@@ -1468,7 +1456,7 @@ module PWN
1468
1456
 
1469
1457
  timeout = opts[:timeout]
1470
1458
 
1471
- response = list_files(token: token)
1459
+ response = list_files(timeout: timeout)
1472
1460
  file_id = response[:data].select { |f| f if f[:filename] == File.basename(file) }.first[:id]
1473
1461
 
1474
1462
  rest_call = "files/#{file_id}"
@@ -98,7 +98,7 @@ module PWN
98
98
  method: http_method,
99
99
  url: "#{base_uri}/#{rest_call}",
100
100
  headers: headers,
101
- verify_ssl: false,
101
+ verify_ssl: true,
102
102
  timeout: timeout
103
103
  )
104
104
 
@@ -111,7 +111,7 @@ module PWN
111
111
  url: "#{base_uri}/#{rest_call}",
112
112
  headers: headers,
113
113
  payload: http_body,
114
- verify_ssl: false,
114
+ verify_ssl: true,
115
115
  timeout: timeout
116
116
  )
117
117
  elsif stream
@@ -138,7 +138,7 @@ module PWN
138
138
  url: "#{base_uri}/#{rest_call}",
139
139
  headers: headers,
140
140
  payload: http_body.to_json,
141
- verify_ssl: false,
141
+ verify_ssl: true,
142
142
  open_timeout: [timeout.to_f, 30.0].min,
143
143
  read_timeout: idle_timeout,
144
144
  block_response: lambda do |http_resp|
@@ -180,7 +180,7 @@ module PWN
180
180
  url: "#{base_uri}/#{rest_call}",
181
181
  headers: headers,
182
182
  payload: http_body.to_json,
183
- verify_ssl: false,
183
+ verify_ssl: true,
184
184
  timeout: timeout
185
185
  )
186
186
  end
@@ -280,46 +280,84 @@ module PWN
280
280
  body = opts[:body].to_s
281
281
  rest_call = opts[:rest_call].to_s
282
282
 
283
- lines = body.each_line.map(&:strip).reject(&:empty?)
284
- # Strip SSE "data: " prefix when present; drop the terminal [DONE].
285
- payloads = lines.filter_map do |line|
286
- line = line.sub(/\Adata:\s*/, '')
287
- next if line.empty? || line == '[DONE]'
283
+ records = stream_records(body: body, rest_call: rest_call)
284
+ done = false
285
+ payloads = records.filter_map do |record|
286
+ raise "ERROR: Open WebUI incomplete SSE stream for #{rest_call}: unterminated event" if record[:incomplete]
288
287
 
289
- begin
290
- JSON.parse(line, symbolize_names: true)
291
- rescue JSON::ParserError
292
- nil
288
+ data = record[:data]
289
+ if data == '[DONE]'
290
+ done = true
291
+ next
293
292
  end
294
- end
295
- if payloads.empty?
296
- return {
297
- message: {
298
- role: 'assistant',
299
- content: '',
300
- error: 'empty_stream_payloads'
301
- },
302
- done: true,
303
- done_reason: 'error'
304
- }.to_json
305
- end
293
+ raise "ERROR: Open WebUI malformed stream after [DONE] for #{rest_call}" if done
306
294
 
307
- openai_compat = rest_call.include?('/v1/') ||
308
- rest_call.start_with?('v1/') ||
309
- rest_call.include?('chat/completions') ||
310
- payloads.any? { |p| p.key?(:choices) }
295
+ payload = parse_stream_payload(data: data, rest_call: rest_call)
296
+ error = payload[:error] || (payload if record[:event] == 'error')
297
+ if error
298
+ detail = error.is_a?(Hash) ? (error[:message] || error) : error
299
+ raise "ERROR: Open WebUI stream error for #{rest_call}: #{detail}"
300
+ end
301
+ payload
302
+ end
303
+ raise "ERROR: Open WebUI incomplete stream for #{rest_call}: no payloads" if payloads.empty?
311
304
 
305
+ openai_compat = rest_call.include?('chat/completions') || payloads.any? { |p| p.key?(:choices) }
312
306
  if openai_compat
307
+ finished = payloads.any? { |p| Array(p[:choices]).any? { |ch| ch[:finish_reason] } }
308
+ raise "ERROR: Open WebUI incomplete stream for #{rest_call}: missing terminal event" unless done || finished
309
+
313
310
  assemble_openai_compat_stream(payloads: payloads)
314
311
  else
312
+ raise "ERROR: Open WebUI malformed native stream for #{rest_call}: expected message object" unless payloads.any? { |p| p[:message].is_a?(Hash) } && payloads.all? { |p| !p.key?(:message) || p[:message].is_a?(Hash) }
313
+ raise "ERROR: Open WebUI incomplete native stream for #{rest_call}: missing terminal done frame" unless payloads.last[:done] == true && payloads[0...-1].all? { |p| p[:done] == false }
314
+
315
315
  assemble_native_chat_stream(payloads: payloads)
316
316
  end
317
317
  end
318
318
 
319
+ # SSE dispatches at blank lines, joining every data field with a newline.
320
+ # Native NDJSON accepts a complete last record without a trailing newline.
321
+ private_class_method def self.stream_records(opts = {})
322
+ lines = opts[:body].sub(/\A\uFEFF/, '').split(/\r\n|\r|\n/, -1)
323
+ lines.pop if lines.last == ''
324
+ sse = lines.any? { |line| line.match?(/\A(?:data|event|id|retry)(?::|\z)|\A:/) }
325
+ return lines.reject { |line| line.strip.empty? }.map { |line| { data: line } } unless sse
326
+
327
+ records = []
328
+ data = []
329
+ event = nil
330
+ lines.each do |line|
331
+ if line.empty?
332
+ records << { data: data.join("\n"), event: event } unless data.empty?
333
+ data = []
334
+ event = nil
335
+ else
336
+ field, value = line.split(':', 2)
337
+ value = value.to_s.delete_prefix(' ')
338
+ data << value if field == 'data'
339
+ event = value if field == 'event'
340
+ end
341
+ end
342
+ # Keep framing failures ordered after any earlier provider error event.
343
+ records.reject! { |record| record[:data].empty? }
344
+ records << { incomplete: true } unless data.empty?
345
+ records
346
+ end
347
+
348
+ private_class_method def self.parse_stream_payload(opts = {})
349
+ payload = JSON.parse(opts[:data], symbolize_names: true)
350
+ raise "ERROR: Open WebUI malformed stream for #{opts[:rest_call]}: expected object" unless payload.is_a?(Hash)
351
+
352
+ payload
353
+ rescue JSON::ParserError
354
+ raise "ERROR: Open WebUI malformed stream JSON for #{opts[:rest_call]}"
355
+ end
356
+
319
357
  # Proxied Ollama /ollama/api/chat NDJSON → single-object JSON string.
320
358
  private_class_method def self.assemble_native_chat_stream(opts = {})
321
359
  payloads = opts[:payloads]
322
- final = payloads.reverse.find { |p| p[:done] } || payloads.last
360
+ final = payloads.last
323
361
  content = +''
324
362
  thinking = +''
325
363
  tool_calls = []
@@ -346,7 +384,7 @@ module PWN
346
384
  model: final[:model],
347
385
  created_at: final[:created_at],
348
386
  message: message,
349
- done: true,
387
+ done: final[:done],
350
388
  done_reason: final[:done_reason],
351
389
  total_duration: final[:total_duration],
352
390
  load_duration: final[:load_duration],
@@ -565,7 +603,7 @@ module PWN
565
603
  text = (row.key?(:content) ? row[:content] : row['content']).to_s
566
604
  parts << text unless text.strip.empty?
567
605
  else
568
- rest << row
606
+ rest << row.dup
569
607
  end
570
608
  end
571
609
  return rest if parts.empty?
@@ -576,7 +614,8 @@ module PWN
576
614
  user = rest.find { |row| (row[:role] || row['role']).to_s == 'user' }
577
615
  if user
578
616
  body = (user.key?(:content) ? user[:content] : user['content']).to_s
579
- user[:content] = "#{text}\n\n#{body}"
617
+ # Returned history may already contain this strict-template prefix.
618
+ user[:content] = body == text || body.start_with?("#{text}\n\n") ? body : "#{text}\n\n#{body}"
580
619
  user.delete('content')
581
620
  rest
582
621
  else
@@ -804,8 +843,6 @@ module PWN
804
843
 
805
844
  response_history = opts[:response_history]
806
845
 
807
- max_tokens = response_history[:usage][:total_tokens] unless response_history.nil?
808
-
809
846
  system_role_content = opts[:system_role_content] ||= engine[:system_role_content]
810
847
 
811
848
  system_role = {
@@ -819,7 +856,6 @@ module PWN
819
856
  }
820
857
 
821
858
  response_history ||= { choices: [system_role] }
822
- choices_len = response_history[:choices].length
823
859
 
824
860
  http_body = {
825
861
  model: model,
@@ -828,10 +864,10 @@ module PWN
828
864
  stream: true
829
865
  }
830
866
 
831
- if response_history[:choices].length > 1
832
- response_history[:choices][1..].each do |message|
833
- http_body[:messages].push(message)
834
- end
867
+ Array(response_history[:choices] || response_history['choices']).each_with_index do |message, index|
868
+ next if index.zero? && %w[system developer].include?((message[:role] || message['role']).to_s)
869
+
870
+ http_body[:messages].push(message)
835
871
  end
836
872
 
837
873
  http_body[:messages].push(user_role)
@@ -10,6 +10,7 @@ module PWN
10
10
 
11
11
  # Supported Method Parameters::
12
12
  # PWN::AWS::CloudSearchDomain.connect(
13
+ # endpoint: 'required - CloudSearch domain search or document endpoint URL unless configured in the AWS SDK',
13
14
  # region: 'required - region name to connect (eu-west-1, ap-southeast-1, ap-southeast-2, eu-central-1, ap-northeast-2, ap-northeast-1, us-east-1, sa-east-1, us-west-1, us-west-2)',
14
15
  # access_key_id: 'required - Use AWS STS for best privacy (i.e. temporary access key id)',
15
16
  # secret_access_key: 'required - Use AWS STS for best privacy (i.e. temporary secret access key',
@@ -18,6 +19,8 @@ module PWN
18
19
 
19
20
  public_class_method def self.connect(opts = {})
20
21
  region = opts[:region].to_s.scrub.chomp.strip
22
+ endpoint = opts[:endpoint]
23
+ endpoint_options = endpoint.nil? ? {} : { endpoint: endpoint }
21
24
  access_key_id = opts[:access_key_id].to_s.scrub.chomp.strip
22
25
  secret_access_key = opts[:secret_access_key].to_s.scrub.chomp.strip
23
26
  sts_session_token = opts[:sts_session_token].to_s.scrub.chomp.strip
@@ -25,12 +28,14 @@ module PWN
25
28
  @@logger.info('Connecting to AWS CloudSearchDomain...')
26
29
  if sts_session_token == ''
27
30
  cloud_search_domain_obj = Aws::CloudSearchDomain::Client.new(
31
+ **endpoint_options,
28
32
  region: region,
29
33
  access_key_id: access_key_id,
30
34
  secret_access_key: secret_access_key
31
35
  )
32
36
  else
33
37
  cloud_search_domain_obj = Aws::CloudSearchDomain::Client.new(
38
+ **endpoint_options,
34
39
  region: region,
35
40
  access_key_id: access_key_id,
36
41
  secret_access_key: secret_access_key,
@@ -74,6 +79,7 @@ module PWN
74
79
  puts "USAGE:
75
80
  # Run connect and return its result
76
81
  #{self}.connect(
82
+ endpoint: 'required - CloudSearch domain search or document endpoint URL unless configured in the AWS SDK',
77
83
  region: 'required - region name to connect (eu-west-1, ap-southeast-1, ap-southeast-2, eu-central-1, ap-northeast-2, ap-northeast-1, us-east-1, sa-east-1, us-west-1, us-west-2)',
78
84
  access_key_id: 'required - Use AWS STS for best privacy (i.e. temporary access key id)',
79
85
  secret_access_key: 'required - Use AWS STS for best privacy (i.e. temporary secret access key',
data/lib/pwn/aws/iam.rb CHANGED
@@ -52,7 +52,7 @@ module PWN
52
52
  # key_type: 'optional - key type :access_key_id|:secret_access_key|:sts_session_token (Default: access_key_id)',
53
53
  # )
54
54
  public_class_method def self.decode_key(opts = {})
55
- key = opts[:key].to_s.scrub.chomp.strip.upcase
55
+ key = opts[:key].to_s.scrub.chomp.strip
56
56
  raise 'ERROR: Key is required' if key == ''
57
57
 
58
58
  key_type = opts[:key_type] || :access_key_id
@@ -107,7 +107,7 @@ module PWN
107
107
 
108
108
  case key_type
109
109
  when :access_key_id
110
- suffix = key[4..-1]
110
+ suffix = key[4..-1].upcase
111
111
  decoded_suffix = Base32.decode(suffix)
112
112
  trimmed_decoded_suffix = decoded_suffix[0..5]
113
113
  z = trimmed_decoded_suffix.bytes.inject { |total, byte| (total << 8) + byte }
@@ -24,13 +24,13 @@ module PWN
24
24
 
25
25
  @@logger.info('Connecting to AWS Workspaces...')
26
26
  if sts_session_token == ''
27
- workspaces_obj = Aws::Workspaces::Client.new(
27
+ workspaces_obj = Aws::WorkSpaces::Client.new(
28
28
  region: region,
29
29
  access_key_id: access_key_id,
30
30
  secret_access_key: secret_access_key
31
31
  )
32
32
  else
33
- workspaces_obj = Aws::Workspaces::Client.new(
33
+ workspaces_obj = Aws::WorkSpaces::Client.new(
34
34
  region: region,
35
35
  access_key_id: access_key_id,
36
36
  secret_access_key: secret_access_key,
data/lib/pwn/aws.rb CHANGED
@@ -46,7 +46,6 @@ module PWN
46
46
  autoload :ElasticBeanstalk, 'pwn/aws/elastic_beanstalk'
47
47
  autoload :ElasticLoadBalancing, 'pwn/aws/elastic_load_balancing'
48
48
  autoload :ElasticLoadBalancingV2, 'pwn/aws/elastic_load_balancing_v2'
49
- autoload :ElasticTranscoder, 'pwn/aws/elastic_transcoder'
50
49
  autoload :ElasticsearchService, 'pwn/aws/elasticsearch_service'
51
50
  autoload :Firehose, 'pwn/aws/firehose'
52
51
  autoload :GameLift, 'pwn/aws/game_lift'
@@ -61,14 +60,11 @@ module PWN
61
60
  autoload :Kinesis, 'pwn/aws/kinesis'
62
61
  autoload :KinesisAnalytics, 'pwn/aws/kinesis_analytics'
63
62
  autoload :Lambda, 'pwn/aws/lambda'
64
- autoload :LambdaPreview, 'pwn/aws/lambda_preview'
65
63
  autoload :Lex, 'pwn/aws/lex'
66
64
  autoload :Lightsail, 'pwn/aws/lightsail'
67
65
  autoload :MachineLearning, 'pwn/aws/machine_learning'
68
66
  autoload :MarketplaceCommerceAnalytics, 'pwn/aws/marketplace_commerce_analytics'
69
67
  autoload :MarketplaceMetering, 'pwn/aws/marketplace_metering'
70
- autoload :OpsWorks, 'pwn/aws/ops_works'
71
- autoload :OpsWorksCM, 'pwn/aws/ops_works_cm'
72
68
  autoload :Pinpoint, 'pwn/aws/pinpoint'
73
69
  autoload :Polly, 'pwn/aws/polly'
74
70
  autoload :RDS, 'pwn/aws/rds'
@@ -78,7 +74,6 @@ module PWN
78
74
  autoload :Route53Domains, 'pwn/aws/route53_domains'
79
75
  autoload :S3, 'pwn/aws/s3'
80
76
  autoload :SES, 'pwn/aws/ses'
81
- autoload :SMS, 'pwn/aws/sms'
82
77
  autoload :SNS, 'pwn/aws/sns'
83
78
  autoload :SQS, 'pwn/aws/sqs'
84
79
  autoload :SSM, 'pwn/aws/ssm'
@@ -516,7 +516,7 @@ module PWN
516
516
  path = opts[:path]
517
517
  obj = opts[:obj]
518
518
  FileUtils.mkdir_p(File.dirname(path))
519
- yaml_obj = YAML.dump(obj).gsub(/^\s*:(\w+):/, '\\1:')
519
+ yaml_obj = YAML.dump(obj, stringify_names: true)
520
520
  File.write(path, yaml_obj)
521
521
  rescue StandardError => e
522
522
  raise e
data/lib/pwn/config.rb CHANGED
@@ -438,8 +438,14 @@ module PWN
438
438
  # config: 'optional - Hash to redact sensitive artifacts from. Defaults to PWN::Env'
439
439
  # )
440
440
  public_class_method def self.redact_sensitive_artifacts(opts = {})
441
- config = opts[:config] ||= PWN::Env
442
- return config.map { |value| value.is_a?(Hash) || value.is_a?(Array) ? redact_sensitive_artifacts(config: value) : value } if config.is_a?(Array)
441
+ redact_config(config: opts[:config] || PWN::Env, depth: 0)
442
+ end
443
+
444
+ private_class_method def self.redact_config(opts = {})
445
+ config = opts[:config]
446
+ depth = opts[:depth]
447
+ raise JSON::NestingError, 'redaction exceeds configuration nesting limit (100)' if depth >= 100
448
+ return config.map { |value| value.is_a?(Hash) || value.is_a?(Array) ? redact_config(config: value, depth: depth + 1) : value } if config.is_a?(Array)
443
449
 
444
450
  sensitive_keys = %i[
445
451
  admin_key
@@ -486,7 +492,7 @@ module PWN
486
492
  if sensitive_keys.include?(config.keys[k].to_s.downcase.tr('-', '_').to_sym)
487
493
  '>>> REDACTED >>> USE `pwn-vault` FOR ADMINISTRATION <<< REDACTED <<<'
488
494
  else
489
- v.is_a?(Hash) || v.is_a?(Array) ? redact_sensitive_artifacts(config: v) : v
495
+ v.is_a?(Hash) || v.is_a?(Array) ? redact_config(config: v, depth: depth + 1) : v
490
496
  end
491
497
  end
492
498
  rescue StandardError => e
@@ -791,16 +797,17 @@ module PWN
791
797
  # Missing / malformed frontmatter returns { frontmatter: {}, body: content }.
792
798
  public_class_method def self.parse_skill_frontmatter(opts = {})
793
799
  content = opts[:content].to_s
794
- return { frontmatter: {}, body: content } unless content.start_with?("---\n")
800
+ opening = content.match(/\A---[ \t]*\r?\n/)
801
+ return { frontmatter: {}, body: content } unless opening
795
802
 
796
- fm_end = content.index(/^---\s*$/, 4)
797
- return { frontmatter: {}, body: content } unless fm_end
803
+ closing = content.match(/^---[ \t]*(?:\r?\n|\z)/, opening.end(0))
804
+ return { frontmatter: {}, body: content } unless closing
798
805
 
799
806
  require 'yaml'
800
- raw = content[4...fm_end]
807
+ raw = content[opening.end(0)...closing.begin(0)]
801
808
  fm = YAML.safe_load(raw, permitted_classes: [Symbol, Date, Time], aliases: true) || {}
802
809
  fm = {} unless fm.is_a?(Hash)
803
- body = content[fm_end..].to_s.sub(/\A---\s*\n?/, '')
810
+ body = content[closing.end(0)..].to_s
804
811
  { frontmatter: fm, body: body }
805
812
  rescue StandardError
806
813
  { frontmatter: {}, body: content }
@@ -1055,7 +1062,7 @@ module PWN
1055
1062
  }
1056
1063
  scripts.each do |rb|
1057
1064
  require rb
1058
- rescue StandardError => e
1065
+ rescue LoadError, SyntaxError, StandardError => e
1059
1066
  meta[:loaded] = false
1060
1067
  meta[:error] = e.message
1061
1068
  end
@@ -1114,7 +1121,7 @@ module PWN
1114
1121
  begin
1115
1122
  require skill_file
1116
1123
  skills[key] = base.merge(type: :ruby, loaded: true)
1117
- rescue StandardError => e
1124
+ rescue LoadError, SyntaxError, StandardError => e
1118
1125
  skills[key] = base.merge(type: :ruby, loaded: false, error: e.message)
1119
1126
  end
1120
1127
  else
data/lib/pwn/corpus.rb CHANGED
@@ -5,6 +5,7 @@ require 'digest'
5
5
  require 'json'
6
6
  require 'net/http'
7
7
  require 'uri'
8
+ require 'tmpdir'
8
9
 
9
10
  module PWN
10
11
  # Named wordlist and payload corpora under ~/.pwn/corpora.
@@ -43,6 +44,10 @@ module PWN
43
44
  path
44
45
  end
45
46
 
47
+ # Roll back caught publication errors while restore I/O remains possible.
48
+ # This is not a two-file atomic commit: concurrent readers/writers and
49
+ # process termination or power loss can observe an intermediate pair.
50
+ # If rollback itself raises, retain the private recovery directory.
46
51
  public_class_method def self.update(opts = {})
47
52
  opts = { name: opts } unless opts.is_a?(Hash)
48
53
  name = (opts[:name] || opts[:corpus]).to_s.to_sym
@@ -51,9 +56,31 @@ module PWN
51
56
  raise ArgumentError, 'builtin corpora have no remote update' if spec[:builtin]
52
57
 
53
58
  path = File.join(ROOT, "#{name}.txt")
54
- tmp = "#{path}.tmp"
55
- fetch(url: spec[:url], path: tmp, sha256: spec[:sha256])
56
- FileUtils.mv(tmp, path)
59
+ FileUtils.mkdir_p(ROOT)
60
+ directory = Dir.mktmpdir('.corpus-update-', ROOT)
61
+ cleanup = true
62
+ begin
63
+ tmp = File.join(directory, 'download.tmp')
64
+ fetch(url: spec[:url], path: tmp, sha256: spec[:sha256])
65
+ backups = [path, "#{path}.sha256"].to_h do |destination|
66
+ backup = File.join(directory, File.basename(destination))
67
+ FileUtils.cp(destination, backup) if File.file?(destination)
68
+ [destination, File.file?(backup) ? backup : nil]
69
+ end
70
+ begin
71
+ FileUtils.mv(tmp, path)
72
+ FileUtils.mv("#{tmp}.sha256", "#{path}.sha256")
73
+ rescue StandardError
74
+ cleanup = false
75
+ backups.each do |destination, backup|
76
+ backup ? File.rename(backup, destination) : FileUtils.rm_f(destination)
77
+ end
78
+ cleanup = true
79
+ raise
80
+ end
81
+ ensure
82
+ FileUtils.remove_entry(directory) if cleanup
83
+ end
57
84
  path
58
85
  end
59
86
 
@@ -71,7 +98,9 @@ module PWN
71
98
  offline: 'optional - true uses the cache only and raises on miss'
72
99
  )
73
100
 
74
- # Replace a remotely pinned corpus from its source URL.
101
+ # Replace a remote corpus; caught publication errors restore the prior pair if rollback I/O succeeds.
102
+ # Not power-loss/process-crash atomic or synchronized with concurrent readers/writers.
103
+ # Failed rollback retains recovery files under ROOT/.corpus-update-* for manual recovery.
75
104
  #{self}.update(
76
105
  name: 'required - corpus symbol with a remote URL',
77
106
  corpus: 'optional - alias for name'
@@ -99,7 +128,6 @@ module PWN
99
128
 
100
129
  FileUtils.mkdir_p(File.dirname(opts[:path]))
101
130
  File.write(opts[:path], body)
102
- File.write("#{opts[:path].sub(/\\.tmp\\z/, '')}.sha256", digest)
103
131
  File.write("#{opts[:path]}.sha256", digest)
104
132
  opts[:path]
105
133
  end
data/lib/pwn/cron.rb CHANGED
@@ -3,9 +3,11 @@
3
3
  require 'yaml'
4
4
  require 'fileutils'
5
5
  require 'time'
6
+ require 'date'
6
7
  require 'securerandom'
7
8
  require 'rbconfig'
8
9
  require 'shellwords'
10
+ require 'open3'
9
11
  require 'etc'
10
12
 
11
13
  module PWN
@@ -109,6 +111,10 @@ module PWN
109
111
  result = PWN::AI::Anthropic.chat(request: job[:prompt], spinner: false)
110
112
  when :gemini
111
113
  result = PWN::AI::Gemini.chat(request: job[:prompt], spinner: false)
114
+ when :openwebui
115
+ result = PWN::AI::OpenWebUI.chat(request: job[:prompt], spinner: false)
116
+ else
117
+ raise ArgumentError, "Unsupported cron AI engine: #{engine}"
112
118
  end
113
119
  result = begin
114
120
  result[:choices].last[:content]
@@ -117,8 +123,9 @@ module PWN
117
123
  end
118
124
  elsif job[:ruby]
119
125
  result = eval(job[:ruby], TOPLEVEL_BINDING) # rubocop:disable Security/Eval
120
- elsif job[:script] && File.exist?(job[:script])
121
- result = `#{job[:script]} 2>&1`
126
+ elsif job[:script] && !job[:script].to_s.empty? && File.exist?(script = File.absolute_path(job[:script].to_s))
127
+ result, process_status = Open3.capture2e([script, script])
128
+ status = 'error' unless process_status.success?
122
129
  else
123
130
  result = 'No prompt/ruby/script defined'
124
131
  end
@@ -432,19 +439,25 @@ module PWN
432
439
 
433
440
  fields = schedule.split
434
441
  return false unless fields.length == 5
442
+ return false unless [[0, 59], [0, 23], [1, 31], [1, 12], [0, 7]].each_with_index.all? do |(min, max), index|
443
+ cron_field_valid?(expr: fields[index], min: min, max: max)
444
+ end
435
445
 
436
446
  prev = last || (now - (24 * 60 * 60))
437
447
  # Walk minute-aligned slots from the minute AFTER last_run
438
448
  # (or the last 24h if never run) up to `now`.
439
449
  t = Time.at(((prev.to_i / 60) + 1) * 60)
440
- t = Time.local(t.year, t.month, t.day, t.hour, t.min, 0)
441
- limit = Time.local(now.year, now.month, now.day, now.hour, now.min, 0)
442
- safety = 0
443
- while t <= limit && safety < 10_080
444
- return true if cron_match?(fields: fields, time: t)
445
-
446
- t += 60
447
- safety += 1
450
+ limit = Time.at((now.to_i / 60) * 60)
451
+
452
+ while t <= limit
453
+ if cron_date_match?(fields: fields, time: t)
454
+ return true if cron_match?(fields: fields, time: t)
455
+
456
+ t += 60
457
+ else
458
+ day = t.to_date.next_day
459
+ t = Time.local(day.year, day.month, day.day)
460
+ end
448
461
  end
449
462
  false
450
463
  rescue StandardError
@@ -546,7 +559,7 @@ module PWN
546
559
  waited += 1
547
560
  end
548
561
  {
549
- started: !(live && process_alive?(pid: live)).nil?,
562
+ started: !live.nil? && process_alive?(pid: live),
550
563
  pid: live,
551
564
  spawn_pid: pid,
552
565
  interval: interval,
@@ -673,12 +686,39 @@ module PWN
673
686
  private_class_method def self.cron_match?(opts = {})
674
687
  fields = opts[:fields]
675
688
  time = opts[:time]
676
- min, hour, mday, mon, wday = fields
689
+ min, hour = fields
677
690
  cron_field?(expr: min, value: time.min, min: 0, max: 59) &&
678
691
  cron_field?(expr: hour, value: time.hour, min: 0, max: 23) &&
679
- cron_field?(expr: mday, value: time.day, min: 1, max: 31) &&
680
- cron_field?(expr: mon, value: time.month, min: 1, max: 12) &&
681
- cron_field?(expr: wday, value: time.wday, min: 0, max: 7)
692
+ cron_date_match?(fields: fields, time: time)
693
+ end
694
+
695
+ private_class_method def self.cron_date_match?(opts = {})
696
+ _min, _hour, mday, mon, wday = opts[:fields]
697
+ time = opts[:time]
698
+ return false unless cron_field?(expr: mon, value: time.month, min: 1, max: 12)
699
+
700
+ month_day = cron_field?(expr: mday, value: time.day, min: 1, max: 31)
701
+ week_day = cron_field?(expr: wday, value: time.wday, min: 0, max: 7)
702
+ mday.start_with?('*') || wday.start_with?('*') ? month_day && week_day : month_day || week_day
703
+ end
704
+
705
+ # Validate all list members before OR matching can mask an invalid member.
706
+ private_class_method def self.cron_field_valid?(opts = {})
707
+ parts = opts[:expr].to_s.split(',', -1)
708
+ return false if parts.empty?
709
+
710
+ parts.all? do |part|
711
+ match = %r{\A(?:(\*)|(\d+)(?:-(\d+))?)(?:/(\d+))?\z}.match(part)
712
+ next false unless match
713
+
714
+ wildcard, first, last, step = match.captures
715
+ next false if step && (step.to_i.zero? || (!wildcard && !last))
716
+ next true if wildcard
717
+
718
+ first = first.to_i
719
+ last = last ? last.to_i : first
720
+ first.between?(opts[:min], opts[:max]) && last.between?(first, opts[:max])
721
+ end
682
722
  end
683
723
 
684
724
  private_class_method def self.cron_field?(opts = {})
@@ -686,7 +726,10 @@ module PWN
686
726
  value = opts[:value]
687
727
  min = opts[:min]
688
728
  max = opts[:max]
689
- expr.to_s.split(',').any? { |part| cron_atom?(atom: part, value: value, min: min, max: max) }
729
+ expr.to_s.split(',').any? do |part|
730
+ cron_atom?(atom: part, value: value, min: min, max: max) ||
731
+ (min.zero? && max == 7 && value.zero? && cron_atom?(atom: part, value: 7, min: min, max: max))
732
+ end
690
733
  end
691
734
 
692
735
  private_class_method def self.cron_atom?(opts = {})
@@ -714,7 +757,7 @@ module PWN
714
757
  end
715
758
  return value.between?(Regexp.last_match(1).to_i, Regexp.last_match(2).to_i) if atom =~ /\A(\d+)-(\d+)\z/
716
759
 
717
- n = Integer(atom)
760
+ n = Integer(atom, 10)
718
761
  # cron Sunday is 0 or 7
719
762
  return true if n == value
720
763
  return true if min.zero? && max == 7 && ((n == 7 && value.zero?) || (n.zero? && value == 7))