pwn 0.5.784 → 0.5.787
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.ruby-version +1 -1
- data/Gemfile +6 -6
- data/README.md +37 -0
- data/bin/pwn +2 -1
- data/bin/pwn_web_cache_deception +35 -7
- data/build_gem.sh +1 -1
- data/documentation/AI-Integration.md +7 -5
- data/documentation/Agent-Tool-Registry.md +2 -2
- data/documentation/Backup-Retention.md +69 -15
- data/documentation/Configuration.md +10 -6
- data/documentation/Contributing.md +1 -1
- data/documentation/Cron.md +2 -2
- data/documentation/Diagrams.md +2 -2
- data/documentation/General-PWN-Usage.md +4 -3
- data/documentation/Harness-Evaluation.md +1 -1
- data/documentation/Home.md +6 -5
- data/documentation/How-PWN-Works.md +6 -5
- data/documentation/Installation.md +12 -9
- data/documentation/Mission-Cancellation.md +134 -0
- data/documentation/Operability.md +18 -0
- data/documentation/Persistence.md +7 -5
- data/documentation/Plugin-Degradation.md +14 -0
- data/documentation/Plugins.md +3 -2
- data/documentation/Policy-Benchmark.md +32 -33
- data/documentation/Runtime-Source-Protection.md +162 -0
- data/documentation/Transparent-Browser.md +11 -0
- data/documentation/Troubleshooting.md +3 -2
- data/documentation/What-is-PWN.md +2 -2
- data/documentation/YubiKey-Vaults.md +185 -0
- data/documentation/YubiKey.md +218 -0
- data/documentation/diagrams/cron-scheduling.svg +130 -130
- data/documentation/diagrams/dot/cron-scheduling.dot +3 -3
- data/documentation/diagrams/dot/persistence-filesystem.dot +5 -3
- data/documentation/diagrams/dot/plugin-ecosystem.dot +2 -2
- data/documentation/diagrams/dot/pwn-ai-feedback-learning-loop.dot +1 -1
- data/documentation/diagrams/dot/reinforcement-learning.dot +2 -2
- data/documentation/diagrams/persistence-filesystem.svg +172 -142
- data/documentation/diagrams/plugin-ecosystem.svg +64 -64
- data/documentation/diagrams/pwn-ai-feedback-learning-loop.svg +1 -1
- data/documentation/diagrams/reinforcement-learning.svg +89 -89
- data/documentation/pwn-ai-Agent.md +10 -4
- data/etc/default_cron/session_cleanup.rb +43 -27
- data/etc/default_skills/pwn/ai/agent/mission_namespace/SKILL.md +21 -0
- data/etc/default_skills/pwn/ai/agent/tools/browser_act/SKILL.md +45 -0
- data/etc/default_skills/pwn/ai/agent/tools/loot_query/SKILL.md +27 -26
- data/etc/default_skills/pwn/ai/agent/tools/recon_run/SKILL.md +25 -15
- data/etc/default_skills/pwn/ai/agent/tools/workspace_tool/SKILL.md +24 -0
- data/etc/default_skills/pwn/ai/server_tools/SKILL.md +25 -0
- data/etc/default_skills/pwn/backups/SKILL.md +54 -0
- data/etc/default_skills/pwn/plugins/recon/SKILL.md +12 -1
- data/etc/default_skills/pwn/plugins/yubikey/SKILL.md +157 -0
- data/etc/default_skills/pwn/plugins/yubikey/fido/SKILL.md +189 -0
- data/etc/default_skills/pwn/plugins/yubikey/hsmauth/SKILL.md +83 -0
- data/etc/default_skills/pwn/plugins/yubikey/management/SKILL.md +80 -0
- data/etc/default_skills/pwn/plugins/yubikey/oath/SKILL.md +115 -0
- data/etc/default_skills/pwn/plugins/yubikey/openpgp/SKILL.md +144 -0
- data/etc/default_skills/pwn/plugins/yubikey/otp/SKILL.md +97 -0
- data/etc/default_skills/pwn/plugins/yubikey/piv/SKILL.md +110 -0
- data/etc/default_skills/pwn/plugins/yubikey/protocol/SKILL.md +21 -0
- data/etc/default_skills/pwn/plugins/yubikey/security_domain/SKILL.md +75 -0
- data/etc/default_skills/pwn/plugins/yubikey/security_domain/scp/SKILL.md +46 -0
- data/etc/default_skills/pwn/plugins/yubikey/transport/SKILL.md +98 -0
- data/etc/default_skills/pwn/redaction/SKILL.md +13 -1
- data/lib/pwn/ai/agent/dispatch.rb +26 -15
- data/lib/pwn/ai/agent/learning.rb +14 -18
- data/lib/pwn/ai/agent/loop.rb +17 -1
- data/lib/pwn/ai/agent/mission_namespace.rb +331 -0
- data/lib/pwn/ai/agent/policy_evaluation.rb +334 -36
- data/lib/pwn/ai/agent/prompt_builder.rb +13 -2
- data/lib/pwn/ai/agent/request_runtime.rb +122 -18
- data/lib/pwn/ai/agent/reward.rb +5 -3
- data/lib/pwn/ai/agent/skill_consolidation.rb +3 -2
- data/lib/pwn/ai/agent/skill_review.rb +9 -5
- data/lib/pwn/ai/agent/swarm.rb +4 -0
- data/lib/pwn/ai/agent/tools/browser_act.rb +32 -0
- data/lib/pwn/ai/agent/tools/loot_query.rb +11 -1
- data/lib/pwn/ai/agent/tools/recon_run.rb +11 -1
- data/lib/pwn/ai/agent/tools/workspace_tool.rb +29 -0
- data/lib/pwn/ai/agent/turn_finalizer.rb +6 -2
- data/lib/pwn/ai/agent.rb +1 -0
- data/lib/pwn/ai/anthropic.rb +8 -33
- data/lib/pwn/ai/cli.rb +34 -5
- data/lib/pwn/ai/gemini.rb +1 -0
- data/lib/pwn/ai/grok.rb +39 -28
- data/lib/pwn/ai/ollama.rb +4 -2
- data/lib/pwn/ai/open_ai.rb +11 -32
- data/lib/pwn/ai/open_web_ui.rb +62 -4
- data/lib/pwn/ai/router.rb +8 -1
- data/lib/pwn/ai/server_tools.rb +231 -0
- data/lib/pwn/ai.rb +1 -0
- data/lib/pwn/backups.rb +349 -0
- data/lib/pwn/config.rb +70 -39
- data/lib/pwn/migrate.rb +85 -280
- data/lib/pwn/module_skills.rb +7 -0
- data/lib/pwn/plugins/ai_sandbox.rb +538 -1
- data/lib/pwn/plugins/authentication_helper.rb +74 -4
- data/lib/pwn/plugins/basic_auth.rb +2 -1
- data/lib/pwn/plugins/google_workspace.rb +4 -21
- data/lib/pwn/plugins/jobs.rb +1 -1
- data/lib/pwn/plugins/log.rb +3 -1
- data/lib/pwn/plugins/preflight_checker.rb +34 -9
- data/lib/pwn/plugins/recon.rb +4 -1
- data/lib/pwn/plugins/repl/ai.rb +293 -26
- data/lib/pwn/plugins/repl/ai_console.rb +268 -88
- data/lib/pwn/plugins/repl/ai_swarm.rb +177 -58
- data/lib/pwn/plugins/repl/mesh.rb +14 -19
- data/lib/pwn/plugins/repl/vault.rb +4 -15
- data/lib/pwn/plugins/repl.rb +9 -216
- data/lib/pwn/plugins/sandbox/driver.rb +4 -0
- data/lib/pwn/plugins/transparent_browser.rb +215 -0
- data/lib/pwn/plugins/vault.rb +412 -135
- data/lib/pwn/plugins/yubikey/fido.rb +1288 -0
- data/lib/pwn/plugins/yubikey/hsmauth.rb +439 -0
- data/lib/pwn/plugins/yubikey/management.rb +686 -0
- data/lib/pwn/plugins/yubikey/oath.rb +766 -0
- data/lib/pwn/plugins/yubikey/openpgp.rb +1063 -0
- data/lib/pwn/plugins/yubikey/otp.rb +897 -0
- data/lib/pwn/plugins/yubikey/piv.rb +1315 -0
- data/lib/pwn/plugins/yubikey/protocol.rb +341 -0
- data/lib/pwn/plugins/yubikey/security_domain/scp.rb +482 -0
- data/lib/pwn/plugins/yubikey/security_domain.rb +464 -0
- data/lib/pwn/plugins/yubikey/transport.rb +1017 -0
- data/lib/pwn/plugins/yubikey.rb +844 -0
- data/lib/pwn/plugins.rb +1 -0
- data/lib/pwn/redaction.rb +69 -12
- data/lib/pwn/session_trace.rb +4 -0
- data/lib/pwn/setup.rb +114 -24
- data/lib/pwn/version.rb +1 -1
- data/lib/pwn/www/app_cobalt_io.rb +16 -5
- data/lib/pwn/www/bug_crowd.rb +16 -5
- data/lib/pwn/www/coinbase_pro.rb +16 -5
- data/lib/pwn/www/github.rb +30 -14
- data/lib/pwn/www/paypal.rb +15 -4
- data/lib/pwn/www/synack.rb +16 -5
- data/lib/pwn/www/twitter.rb +17 -6
- data/lib/pwn.rb +1 -0
- data/spec/documentation/installation_md_spec.rb +1 -1
- data/spec/fixtures/yubikey/apdu_frames.json +162 -0
- data/spec/integration/authentication_helper_oath_spec.rb +117 -0
- data/spec/integration/controller_spill_spec.rb +48 -0
- data/spec/integration/harness_process_spec.rb +97 -0
- data/spec/integration/mission_cancel_spec.rb +79 -0
- data/spec/integration/mission_curses_pty_spec.rb +44 -0
- data/spec/integration/readme_security_spec.rb +47 -0
- data/spec/integration/web_cache_deception_yubikey_spec.rb +159 -0
- data/spec/lib/pwn/ai/agent/dispatch_spec.rb +6 -3
- data/spec/lib/pwn/ai/agent/dispatch_vault_safety_spec.rb +86 -0
- data/spec/lib/pwn/ai/agent/injection_guard_spec.rb +2 -0
- data/spec/lib/pwn/ai/agent/learning_spec.rb +4 -4
- data/spec/lib/pwn/ai/agent/loop_artifacts_spec.rb +5 -0
- data/spec/lib/pwn/ai/agent/loop_spec.rb +104 -29
- data/spec/lib/pwn/ai/agent/mission_namespace_spec.rb +138 -0
- data/spec/lib/pwn/ai/agent/policy_evaluation_spec.rb +10 -23
- data/spec/lib/pwn/ai/agent/request_runtime_spec.rb +48 -0
- data/spec/lib/pwn/ai/agent/shell_search_effect_spec.rb +44 -0
- data/spec/lib/pwn/ai/agent/solve_spec.rb +6 -4
- data/spec/lib/pwn/ai/agent/tools/browser_act_spec.rb +44 -0
- data/spec/lib/pwn/ai/agent/tools/loot_query_yubikey_spec.rb +55 -0
- data/spec/lib/pwn/ai/agent/tools/recon_run_yubikey_spec.rb +43 -0
- data/spec/lib/pwn/ai/agent/tools/workspace_tool_spec.rb +20 -0
- data/spec/lib/pwn/ai/agent/turn_finalizer_spec.rb +7 -0
- data/spec/lib/pwn/ai/anthropic_vault_enrollment_spec.rb +37 -0
- data/spec/lib/pwn/ai/cli_spec.rb +8 -16
- data/spec/lib/pwn/ai/oauth_vault_persistence_spec.rb +195 -0
- data/spec/lib/pwn/ai/open_ai_spec.rb +2 -2
- data/spec/lib/pwn/ai/open_web_ui_workspace_spec.rb +36 -0
- data/spec/lib/pwn/ai/router_spec.rb +1 -1
- data/spec/lib/pwn/ai/server_tools_spec.rb +39 -0
- data/spec/lib/pwn/backups_spec.rb +129 -0
- data/spec/lib/pwn/config_redaction_yubikey_spec.rb +28 -0
- data/spec/lib/pwn/config_yubikey_spec.rb +92 -0
- data/spec/lib/pwn/migrate_spec.rb +29 -81
- data/spec/lib/pwn/migrate_yubikey_spec.rb +128 -0
- data/spec/lib/pwn/module_skills_spec.rb +8 -0
- data/spec/lib/pwn/plugins/ai_sandbox_spec.rb +230 -0
- data/spec/lib/pwn/plugins/authentication_helper_native_yubikey_spec.rb +40 -0
- data/spec/lib/pwn/plugins/authentication_helper_yubikey_spec.rb +90 -0
- data/spec/lib/pwn/plugins/capability_broker/daemon_spec.rb +1 -1
- data/spec/lib/pwn/plugins/google_workspace_spec.rb +17 -35
- data/spec/lib/pwn/plugins/log_yubikey_spec.rb +47 -0
- data/spec/lib/pwn/plugins/preflight_checker_native_yubikey_spec.rb +19 -0
- data/spec/lib/pwn/plugins/preflight_checker_yubikey_spec.rb +55 -0
- data/spec/lib/pwn/plugins/recon_yubikey_spec.rb +43 -0
- data/spec/lib/pwn/plugins/repl/ai_console_spec.rb +110 -75
- data/spec/lib/pwn/plugins/repl/ai_legacy_containment_spec.rb +200 -0
- data/spec/lib/pwn/plugins/repl/ai_swarm_spec.rb +19 -16
- data/spec/lib/pwn/plugins/repl/ai_vault_edit_yubikey_spec.rb +103 -0
- data/spec/lib/pwn/plugins/repl/ai_yubikey_spec.rb +48 -0
- data/spec/lib/pwn/plugins/repl/mesh_vault_persistence_spec.rb +149 -0
- data/spec/lib/pwn/plugins/repl/vault_yaml_serialization_spec.rb +11 -0
- data/spec/lib/pwn/plugins/repl/vault_yubikey_spec.rb +39 -0
- data/spec/lib/pwn/plugins/repl_mesh_layout_spec.rb +2 -0
- data/spec/lib/pwn/plugins/repl_spec.rb +56 -5
- data/spec/lib/pwn/plugins/transparent_browser_jev_spec.rb +46 -0
- data/spec/lib/pwn/plugins/vault_native_yubikey_spec.rb +29 -0
- data/spec/lib/pwn/plugins/vault_publication_safety_spec.rb +258 -0
- data/spec/lib/pwn/plugins/vault_store_safety_spec.rb +241 -0
- data/spec/lib/pwn/plugins/vault_yubikey_safety_spec.rb +168 -0
- data/spec/lib/pwn/plugins/vault_yubikey_spec.rb +128 -0
- data/spec/lib/pwn/plugins/vault_yubikey_vector_spec.rb +45 -0
- data/spec/lib/pwn/plugins/yubikey/fido_spec.rb +854 -0
- data/spec/lib/pwn/plugins/yubikey/hsmauth_spec.rb +235 -0
- data/spec/lib/pwn/plugins/yubikey/management_spec.rb +277 -0
- data/spec/lib/pwn/plugins/yubikey/oath_spec.rb +349 -0
- data/spec/lib/pwn/plugins/yubikey/openpgp_spec.rb +810 -0
- data/spec/lib/pwn/plugins/yubikey/otp_spec.rb +337 -0
- data/spec/lib/pwn/plugins/yubikey/piv_spec.rb +646 -0
- data/spec/lib/pwn/plugins/yubikey/protocol_secure_spec.rb +28 -0
- data/spec/lib/pwn/plugins/yubikey/protocol_spec.rb +149 -0
- data/spec/lib/pwn/plugins/yubikey/protocol_vectors_spec.rb +18 -0
- data/spec/lib/pwn/plugins/yubikey/security_domain/scp_spec.rb +256 -0
- data/spec/lib/pwn/plugins/yubikey/security_domain/support.rb +153 -0
- data/spec/lib/pwn/plugins/yubikey/security_domain_spec.rb +296 -0
- data/spec/lib/pwn/plugins/yubikey/transport_spec.rb +760 -0
- data/spec/lib/pwn/plugins/yubikey_security_spec.rb +260 -0
- data/spec/lib/pwn/plugins/yubikey_spec.rb +209 -0
- data/spec/lib/pwn/plugins/yubikey_terminal_spec.rb +147 -0
- data/spec/lib/pwn/redaction_yubikey_spec.rb +61 -0
- data/spec/lib/pwn/session_cleanup_default_spec.rb +7 -5
- data/spec/lib/pwn/session_cleanup_payload_spec.rb +11 -11
- data/spec/lib/pwn/session_cleanup_recovery_spec.rb +34 -20
- data/spec/lib/pwn/setup_native_yubikey_spec.rb +66 -0
- data/spec/lib/pwn/setup_vault_yubikey_spec.rb +61 -0
- data/spec/lib/pwn/setup_yubikey_spec.rb +40 -0
- data/spec/lib/pwn/www/login_yubikey_spec.rb +273 -0
- data/spec/spec_helper.rb +15 -0
- data/spec/support/harness/cli_faults.rb +13 -9
- data/spec/support/harness/controller_spill.rb +26 -0
- data/spec/support/harness/controller_state.rb +54 -0
- data/spec/support/harness/evaluate.rb +12 -1
- data/spec/support/harness/experiments.rb +1 -1
- data/spec/support/harness/fake_provider.rb +22 -6
- data/spec/support/harness/fault_preload.rb +3 -1
- data/spec/support/harness/mission_console.rb +54 -0
- data/spec/support/harness/mission_curses_pty.rb +41 -0
- data/spec/support/harness/mission_dispatch.rb +30 -0
- data/spec/support/harness/mission_fixture_preload.rb +24 -0
- data/spec/support/harness/mission_job_lifetime.rb +25 -0
- data/spec/support/harness/mission_legacy.rb +25 -0
- data/spec/support/harness/mission_normal_exit.rb +34 -0
- data/spec/support/harness/mission_swarm.rb +23 -0
- data/spec/support/harness/mission_unsupported.rb +29 -0
- data/spec/support/harness/package_acceptance.rb +33 -5
- data/spec/support/harness/session_acceptance.rb +4 -4
- data/spec/support/harness/swarm_acceptance.rb +1 -1
- data/spec/support/harness/swarm_control.rb +44 -0
- data/spec/support/mission_namespace.rb +14 -0
- data/spec/support/mission_pipe_queue.rb +33 -0
- data/third_party/pwn_rdoc.jsonl +605 -19
- metadata +129 -16
- data/scripts/benchmark_policy.rb +0 -376
- data/scripts/build_gate.rb +0 -58
- data/spec/integration/build_gate_spec.rb +0 -73
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'spec_helper'
|
|
4
|
+
require 'tmpdir'
|
|
5
|
+
|
|
6
|
+
RSpec.describe PWN::Plugins::Vault, 'YubiKey credential envelopes' do
|
|
7
|
+
before do
|
|
8
|
+
@device = double('YubiKey HMAC fixture')
|
|
9
|
+
stub_const('PWN::Plugins::YubiKey', @device)
|
|
10
|
+
allow(@device).to receive(:challenge_response) do |opts|
|
|
11
|
+
expect(opts[:slot]).to eq(2)
|
|
12
|
+
expect(opts[:challenge].bytesize).to eq(32)
|
|
13
|
+
OpenSSL::HMAC.digest('SHA1', 'synthetic-slot-secret', opts[:challenge])
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
it 'round trips credentials with a hardware-derived key and no software key material in the envelope' do
|
|
18
|
+
envelope = described_class.seal_credentials(credentials: { 'token' => 'fixture-token' }, yubikey: { slot: 2 })
|
|
19
|
+
expect(envelope['kdf']).to eq('yubikey-hmac-sha1-hkdf-sha256')
|
|
20
|
+
expect(envelope.fetch('yubikey')).to include('slot' => 2)
|
|
21
|
+
expect(JSON.generate(envelope)).not_to include('fixture-token', 'synthetic-slot-secret')
|
|
22
|
+
expect(described_class.open_credentials(envelope: envelope)).to eq('token' => 'fixture-token')
|
|
23
|
+
expect(@device).to have_received(:challenge_response).twice
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
it 'encrypts a binary file and dumps or decrypts it without a software decryptor' do
|
|
27
|
+
Dir.mktmpdir('vault-yubikey-') do |root|
|
|
28
|
+
path = File.join(root, 'fixture')
|
|
29
|
+
bytes = "binary\x00\xff\n".b
|
|
30
|
+
File.binwrite(path, bytes)
|
|
31
|
+
expect(PWN::Plugins::AuthenticationHelper).not_to receive(:mask_password)
|
|
32
|
+
described_class.encrypt(file: path, yubikey: { slot: 2 })
|
|
33
|
+
ciphertext = File.binread(path)
|
|
34
|
+
expect(ciphertext).to start_with(described_class::YUBIKEY_HEADER)
|
|
35
|
+
expect(described_class.file_encrypted?(file: path)).to be(true)
|
|
36
|
+
expect(described_class.dump(file: path, yaml: false)).to eq(bytes)
|
|
37
|
+
expect(File.binread(path)).to eq(ciphertext)
|
|
38
|
+
described_class.decrypt(file: path)
|
|
39
|
+
expect(File.binread(path)).to eq(bytes)
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
it 'updates a hardware configuration without requiring a sidecar or ever writing plaintext' do
|
|
44
|
+
Dir.mktmpdir('vault-update-') do |root|
|
|
45
|
+
path = File.join(root, 'pwn.yaml')
|
|
46
|
+
File.write(path, YAML.dump(ai: { active: 'ollama', ollama: { model: 'before' } }, retained: 'fixture'))
|
|
47
|
+
described_class.encrypt(file: path, yubikey: { slot: 2 })
|
|
48
|
+
before = File.binread(path)
|
|
49
|
+
expect(described_class.access_options(file: path)).to eq(yubikey: { slot: 2 })
|
|
50
|
+
expect(described_class.update(file: path) { |cfg| cfg[:ai][:ollama][:model] = 'after' }).to eq(:saved)
|
|
51
|
+
expect(File.binread(path)).not_to eq(before)
|
|
52
|
+
expect(described_class.dump(file: path)).to include(ai: { active: 'ollama', ollama: { model: 'after' } }, retained: 'fixture')
|
|
53
|
+
before = File.binread(path)
|
|
54
|
+
allow(@device).to receive(:challenge_response).and_raise(IOError, 'Device unavailable')
|
|
55
|
+
expect { described_class.update(file: path, &:clear) }.to raise_error(IOError, 'Device unavailable')
|
|
56
|
+
expect(File.binread(path)).to eq(before)
|
|
57
|
+
expect(Dir.children(root)).to eq(['pwn.yaml'])
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
it 'creates and rotates a hardware vault without printing or persisting a software decryptor' do
|
|
62
|
+
Dir.mktmpdir('vault-create-') do |root|
|
|
63
|
+
path = File.join(root, 'secret.yaml')
|
|
64
|
+
File.write(path, "token: fixture-only\n")
|
|
65
|
+
expect { described_class.create(file: path, yubikey: { slot: 2 }) }.not_to output.to_stdout
|
|
66
|
+
before = File.binread(path)
|
|
67
|
+
described_class.refresh_encryption_secrets(file: path)
|
|
68
|
+
expect(File.binread(path)).not_to eq(before)
|
|
69
|
+
expect(described_class.dump(file: path)).to eq(token: 'fixture-only')
|
|
70
|
+
expect(Dir.children(root)).to eq(['secret.yaml'])
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
it 'edits only a private temporary copy and retains ciphertext if the key disappears before save' do
|
|
75
|
+
Dir.mktmpdir('vault-edit-') do |root|
|
|
76
|
+
allow(Dir).to receive(:home).and_return(root)
|
|
77
|
+
path = File.join(root, 'vault')
|
|
78
|
+
File.write(path, "token: original\n")
|
|
79
|
+
described_class.create(file: path, yubikey: { slot: 2 })
|
|
80
|
+
before = File.binread(path)
|
|
81
|
+
edited = nil
|
|
82
|
+
expect(PWN::Plugins::AuthenticationHelper).not_to receive(:mask_password)
|
|
83
|
+
allow(described_class).to receive(:system) do |editor, temporary|
|
|
84
|
+
expect(editor).to eq('/usr/bin/true')
|
|
85
|
+
expect(temporary).not_to eq(path)
|
|
86
|
+
expect(File.stat(temporary).mode & 0o777).to eq(0o600)
|
|
87
|
+
expect(File.binread(path)).to eq(before)
|
|
88
|
+
edited = temporary
|
|
89
|
+
File.write(temporary, "token: changed\n")
|
|
90
|
+
allow(@device).to receive(:challenge_response).and_raise(IOError, 'Device removed')
|
|
91
|
+
true
|
|
92
|
+
end
|
|
93
|
+
expect { described_class.edit(file: path, editor: '/usr/bin/true') }.to raise_error(IOError, 'Device removed')
|
|
94
|
+
expect(File.binread(path)).to eq(before)
|
|
95
|
+
expect(File).not_to exist(edited)
|
|
96
|
+
end
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
it 'protects engagement loot and its offer, expansion and redaction consumers without a disk master key' do
|
|
100
|
+
Dir.mktmpdir('vault-loot-hardware-') do |root|
|
|
101
|
+
allow(Dir).to receive(:home).and_return(root)
|
|
102
|
+
selector = { slot: 2 }
|
|
103
|
+
described_class.store(label: 'hardware', secret: 'fixture-password', host: 'login.example.test', username: 'fixture-user', yubikey: selector)
|
|
104
|
+
expect(File).not_to exist(File.join(root, '.pwn-vault.key'))
|
|
105
|
+
expect(described_class.fetch(label: 'hardware')).to eq('fixture-password')
|
|
106
|
+
expect(described_class.offer(host: 'login.example.test').first[:secret]).to eq('fixture-password')
|
|
107
|
+
expect(described_class.expand(text: '{{vault:hardware}}', yubikey: selector)).to eq('fixture-password')
|
|
108
|
+
expect(described_class.redact(text: 'fixture-password', yubikey: selector)).to eq('{{vault:hardware}}')
|
|
109
|
+
expect(PWN::Plugins::BasicAuth.encode(host: 'login.example.test', yubikey: selector)).to eq(Base64.strict_encode64('fixture-user:fixture-password'))
|
|
110
|
+
before = File.binread(File.join(root, '.pwn', 'engagements', 'default', 'loot.json'))
|
|
111
|
+
allow(@device).to receive(:challenge_response).and_raise(IOError, 'Device unavailable')
|
|
112
|
+
expect { described_class.fetch(label: 'hardware') }.to raise_error(IOError, 'Device unavailable')
|
|
113
|
+
expect { described_class.store(label: 'hardware', secret: 'replacement', yubikey: selector) }.to raise_error(IOError)
|
|
114
|
+
expect(File.binread(File.join(root, '.pwn', 'engagements', 'default', 'loot.json'))).to eq(before)
|
|
115
|
+
end
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
it 'allows redaction capture to explicitly use the hardware loot backend' do
|
|
119
|
+
Dir.mktmpdir('redaction-yubikey-') do |root|
|
|
120
|
+
allow(Dir).to receive(:home).and_return(root)
|
|
121
|
+
capture = PWN::Redaction.capture(value: 'password=fixture-password', yubikey: { slot: 2 })
|
|
122
|
+
label = capture[:refs].first.fetch(:token)
|
|
123
|
+
expect(capture[:redacted]).not_to include('fixture-password')
|
|
124
|
+
expect(File).not_to exist(File.join(root, '.pwn-vault.key'))
|
|
125
|
+
expect(described_class.fetch(label: label)).to eq('password=fixture-password')
|
|
126
|
+
end
|
|
127
|
+
end
|
|
128
|
+
end
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'spec_helper'
|
|
4
|
+
|
|
5
|
+
RSpec.describe PWN::Plugins::Vault, 'independent hardware envelope vector' do
|
|
6
|
+
# Offline fixture: key bytes 00..13, challenge 00..1f, salt 00..0f,
|
|
7
|
+
# nonce 20..2b. Independently computed with Python hmac, manual RFC 5869
|
|
8
|
+
# extract/expand, and cryptography AESGCM, not the production Vault encoder.
|
|
9
|
+
let(:envelope) do
|
|
10
|
+
{
|
|
11
|
+
'version' => 1, 'cipher' => 'aes-256-gcm', 'kdf' => 'yubikey-hmac-sha1-hkdf-sha256',
|
|
12
|
+
'key_id' => 'pwn-ai-credentials', 'iterations' => 600_000,
|
|
13
|
+
'salt' => 'AAECAwQFBgcICQoLDA0ODw==',
|
|
14
|
+
'yubikey' => { 'slot' => 2, 'serial' => '12345678', 'challenge' => 'AAECAwQFBgcICQoLDA0ODxAREhMUFRYXGBkaGxwdHh8=' },
|
|
15
|
+
'iv' => 'ICEiIyQlJicoKSor', 'ct' => '3SNJ2cNhpHZ2I/o6/9fiAE9MeMop+YfsWrGP',
|
|
16
|
+
'tag' => 'w4t/Vmz98ro9opHAmz472Q=='
|
|
17
|
+
}
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
before do
|
|
21
|
+
arguments = { slot: 2, serial: '12345678', challenge: (0...32).to_a.pack('C*') }
|
|
22
|
+
allow(PWN::Plugins::YubiKey).to receive(:challenge_response).with(arguments).and_return(['533bd067d1bbf825ed021f8f278adbb571c51627'].pack('H*'))
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
it 'opens independently produced authenticated ciphertext without re-encoding it' do
|
|
26
|
+
ciphertext = "#{described_class::YUBIKEY_HEADER}#{JSON.generate(envelope)}\n"
|
|
27
|
+
expect(described_class.decrypt_data(data: ciphertext)).to eq("offline:\x00\xff\n".b)
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
it 'matches the independent envelope with fixed public randomness' do
|
|
31
|
+
allow(OpenSSL::Random).to receive(:random_bytes).with(16).and_return((0...16).to_a.pack('C*'))
|
|
32
|
+
allow(OpenSSL::Random).to receive(:random_bytes).with(32).and_return((0...32).to_a.pack('C*'))
|
|
33
|
+
allow(OpenSSL::Cipher).to receive(:new).and_wrap_original do |build, *args|
|
|
34
|
+
cipher = build.call(*args)
|
|
35
|
+
allow(cipher).to receive(:random_iv) do
|
|
36
|
+
nonce = (32...44).to_a.pack('C*')
|
|
37
|
+
cipher.iv = nonce
|
|
38
|
+
nonce
|
|
39
|
+
end
|
|
40
|
+
cipher
|
|
41
|
+
end
|
|
42
|
+
ciphertext = described_class.encrypt_data(data: "offline:\x00\xff\n".b, yubikey: { slot: 2, serial: '12345678' })
|
|
43
|
+
expect(JSON.parse(ciphertext.delete_prefix(described_class::YUBIKEY_HEADER))).to eq(envelope)
|
|
44
|
+
end
|
|
45
|
+
end
|