pwn 0.5.796 → 0.5.798
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile +8 -8
- data/documentation/Mission-Cancellation.md +6 -4
- data/documentation/Operability.md +1 -1
- data/etc/default_skills/pwn/ai/agent/mission_namespace/SKILL.md +6 -4
- data/lib/pwn/ai/agent/loop.rb +4 -0
- data/lib/pwn/ai/agent/mission_namespace.rb +70 -14
- data/lib/pwn/plugins/pwn_logger.rb +37 -1
- data/lib/pwn/plugins/repl/ai_console.rb +6 -1
- data/lib/pwn/plugins/repl/mesh.rb +41 -26
- data/lib/pwn/sessions.rb +3 -2
- data/lib/pwn/version.rb +1 -1
- data/lib/pwn.rb +11 -0
- data/spec/conventions_spec.rb +43 -0
- data/spec/integration/harness_evaluation_spec.rb +22 -31
- data/spec/integration/harness_live_spec.rb +8 -18
- data/spec/lib/pwn/ai/agent/mission_namespace_spec.rb +8 -0
- data/spec/lib/pwn/json_schemer_regexp_parser_spec.rb +12 -0
- data/spec/lib/pwn/module_skills_spec.rb +11 -1
- data/spec/lib/pwn/plugins/pwn_logger_spec.rb +30 -0
- data/spec/lib/pwn/plugins/repl/ai_console_spec.rb +16 -0
- data/spec/lib/pwn/plugins/repl_mesh_rx_errors_spec.rb +18 -0
- data/spec/lib/pwn/reports/provider_review_encoding_regression_spec.rb +4 -14
- data/spec/lib/pwn/session_cleanup_concurrency_spec.rb +21 -0
- data/spec/spec_helper.rb +34 -5
- data/third_party/pwn_rdoc.jsonl +10 -1
- metadata +7690 -7505
|
@@ -9,6 +9,7 @@ describe PWN::ModuleSkills do
|
|
|
9
9
|
it 'saves legacy generated edits and merges without discarding unrelated edits' do
|
|
10
10
|
script = File.read(File.expand_path('../../../build_gem.sh', __dir__))
|
|
11
11
|
recovery = script.split('generated_skills=()', 2).last.split('git checkout master', 2).first
|
|
12
|
+
expect(recovery).to include('git stash push')
|
|
12
13
|
Dir.mktmpdir('pwn_upgrade') do |dir|
|
|
13
14
|
git = lambda do |*args|
|
|
14
15
|
out, status = Open3.capture2e('git', *args, chdir: dir)
|
|
@@ -34,7 +35,16 @@ describe PWN::ModuleSkills do
|
|
|
34
35
|
File.write(File.join(dir, 'notes'), 'keep my edit')
|
|
35
36
|
_, blocked = Open3.capture2e('git', 'merge', '--ff-only', 'incoming', chdir: dir)
|
|
36
37
|
expect(blocked.success?).to be(false)
|
|
37
|
-
|
|
38
|
+
expect(script).to include("git stash push -m 'pwn upgrade: saved generated module skills'")
|
|
39
|
+
skills = git.call('diff', '--name-only', 'HEAD', '--', 'etc/default_skills/pwn').lines.map(&:chomp).select do |relative|
|
|
40
|
+
full = File.join(dir, relative)
|
|
41
|
+
next false unless relative.end_with?('/SKILL.md') && File.file?(full)
|
|
42
|
+
|
|
43
|
+
body = File.read(full)
|
|
44
|
+
body.match?(/^[[:space:]]*generated:[[:space:]]*true[[:space:]]*$/) &&
|
|
45
|
+
!body.match?(/^[[:space:]]*preserve:[[:space:]]*true[[:space:]]*$/)
|
|
46
|
+
end
|
|
47
|
+
out, status = Open3.capture2e('git', 'stash', 'push', '-m', 'pwn upgrade: saved generated module skills', '--', *skills, chdir: dir)
|
|
38
48
|
expect(status.success?).to be(true), out
|
|
39
49
|
git.call('merge', '--ff-only', 'incoming')
|
|
40
50
|
expect(File.read(path)).to eq("#{original}upstream\n")
|
|
@@ -12,4 +12,34 @@ describe PWN::Plugins::PWNLogger do
|
|
|
12
12
|
help_response = PWN::Plugins::PWNLogger
|
|
13
13
|
expect(help_response).to respond_to :help
|
|
14
14
|
end
|
|
15
|
+
|
|
16
|
+
it 'follows the current $stdout outside rake' do
|
|
17
|
+
previous = ENV.fetch('PWN_RAKE_SPEC', nil)
|
|
18
|
+
ENV.delete('PWN_RAKE_SPEC')
|
|
19
|
+
terminal = StringIO.new
|
|
20
|
+
redirected = StringIO.new
|
|
21
|
+
original = $stdout
|
|
22
|
+
$stdout = terminal
|
|
23
|
+
logger = described_class.create
|
|
24
|
+
$stdout = redirected
|
|
25
|
+
logger.info('Connecting to AWS EC2...')
|
|
26
|
+
expect(terminal.string).not_to include('Connecting to AWS')
|
|
27
|
+
expect(redirected.string).to include('[INFO] Connecting to AWS EC2...')
|
|
28
|
+
ensure
|
|
29
|
+
$stdout = original
|
|
30
|
+
previous.nil? ? ENV.delete('PWN_RAKE_SPEC') : ENV['PWN_RAKE_SPEC'] = previous
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
it 'writes nothing during rake, including the pwn logger' do
|
|
34
|
+
previous = ENV.fetch('PWN_RAKE_SPEC', nil)
|
|
35
|
+
ENV['PWN_RAKE_SPEC'] = '1'
|
|
36
|
+
sink = StringIO.new
|
|
37
|
+
original = $stdout
|
|
38
|
+
$stdout = sink
|
|
39
|
+
described_class.create.info('Connecting to AWS EC2...')
|
|
40
|
+
expect(sink.string).to eq('')
|
|
41
|
+
ensure
|
|
42
|
+
$stdout = original
|
|
43
|
+
previous.nil? ? ENV.delete('PWN_RAKE_SPEC') : ENV['PWN_RAKE_SPEC'] = previous
|
|
44
|
+
end
|
|
15
45
|
end
|
|
@@ -2786,6 +2786,22 @@ describe 'pwn-ai curses launch' do # rubocop:disable Metrics/BlockLength -- publ
|
|
|
2786
2786
|
expect(PWN::Env.dig(:ai, :openai, :reasoning_effort)).to eq('high')
|
|
2787
2787
|
end
|
|
2788
2788
|
|
|
2789
|
+
it 'stops after a forbidden planning request and displays one access warning' do
|
|
2790
|
+
require 'rest-client'
|
|
2791
|
+
PWN::Env[:ai] = { active: :openai, openai: { model: 'fixture-model' }, agent: { plan_first: true } }
|
|
2792
|
+
calls = File.join(@tmp, 'provider-calls')
|
|
2793
|
+
response = Struct.new(:code, :body).new(403, 'private fixture response')
|
|
2794
|
+
allow(PWN::AI::OpenAI).to receive(:chat_with_tools) do |opts|
|
|
2795
|
+
File.open(calls, 'a') { |f| f.puts(opts[:tools].nil? ? 'planning' : 'turn') }
|
|
2796
|
+
raise RestClient::Forbidden, response
|
|
2797
|
+
end
|
|
2798
|
+
launch("List the files in this directory\n".chars) { "\u0004" unless @console.send(:busy?) }
|
|
2799
|
+
expect(File.readlines(calls, chomp: true)).to eq(['planning'])
|
|
2800
|
+
events = @console.instance_variable_get(:@timeline)
|
|
2801
|
+
expect(events.filter_map { |type, text, *| text if type == :warning }).to contain_exactly(a_string_matching(/HTTP 403.*model/i))
|
|
2802
|
+
expect(events.map { |_, text, *| text }.join).not_to match(/plan_first swallowed|private fixture response/)
|
|
2803
|
+
end
|
|
2804
|
+
|
|
2789
2805
|
it 'honors locally selected model and resumed session in the actual provider call' do
|
|
2790
2806
|
sid = PWN::Sessions.create(title: 'resumed console')[:id]
|
|
2791
2807
|
PWN::Sessions.append(session_id: sid, role: 'user', content: 'Previous fixture question')
|
|
@@ -194,6 +194,24 @@ describe PWN::Plugins::REPL, 'mesh RX error boundaries' do
|
|
|
194
194
|
expect(ids).to all(match(PWN::Sessions::SESSION_ID))
|
|
195
195
|
end
|
|
196
196
|
|
|
197
|
+
it 'does not paint a Ruby thread dump when dispatch raises outside StandardError' do
|
|
198
|
+
allow(PWN::AI::Agent::Loop).to receive(:run).and_raise(NotImplementedError, 'offline dispatch')
|
|
199
|
+
stderr = StringIO.new
|
|
200
|
+
original = $stderr
|
|
201
|
+
$stderr = stderr
|
|
202
|
+
expect(described_class.send(:mesh_maybe_dispatch_to_pwn_ai, args)).to eq(:dispatched)
|
|
203
|
+
Timeout.timeout(5) { sleep 0.01 while PWN.const_defined?(:MeshDispatchLock) }
|
|
204
|
+
expect(stderr.string).not_to include('report_on_exception')
|
|
205
|
+
expect(described_class).to have_received(:mesh_ui_puts).with(hash_including(text: a_string_starting_with('AI failed: NotImplementedError: offline dispatch')))
|
|
206
|
+
ensure
|
|
207
|
+
$stderr = original
|
|
208
|
+
end
|
|
209
|
+
|
|
210
|
+
it 'drops a leaked Ruby thread-death banner from mesh notices' do
|
|
211
|
+
text = described_class.send(:mesh_notice_text, text: "#<Thread:0x00007f68c37b6078 /opt/pwn/lib/pwn/plugins/repl/mesh.rb:3494 run> terminated with exception (report_on_exception is true):\n")
|
|
212
|
+
expect(text).to be_nil
|
|
213
|
+
end
|
|
214
|
+
|
|
197
215
|
%w[AI TX].each do |stage|
|
|
198
216
|
it "labels #{stage} failures correctly and closes the session lease" do
|
|
199
217
|
ids = Queue.new
|
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|
require 'spec_helper'
|
|
4
4
|
require 'tmpdir'
|
|
5
|
-
require 'open3'
|
|
6
5
|
require 'uri'
|
|
7
6
|
|
|
8
7
|
[PWN::Reports::SAST, PWN::Reports::AIRedTeam].each do |reporter|
|
|
@@ -10,7 +9,7 @@ require 'uri'
|
|
|
10
9
|
[
|
|
11
10
|
'ordinary',
|
|
12
11
|
'fixture", "review": (globalThis.providerReviewMarker = 1), "unused": "',
|
|
13
|
-
"space
|
|
12
|
+
"space &?#%+\\\"'\\\n雪\u2028\u2029",
|
|
14
13
|
'fixture</script><script>providerReviewMarker=1</script>'
|
|
15
14
|
].each do |name|
|
|
16
15
|
it "preserves the filename as URL data for #{name.inspect}" do
|
|
@@ -21,23 +20,14 @@ require 'uri'
|
|
|
21
20
|
html = File.read(File.join(dir, "#{name}.html"))
|
|
22
21
|
expect(JSON.parse(File.read(File.join(dir, "#{name}.json")))).to eq('report_name' => name, 'data' => [])
|
|
23
22
|
ajax = html.lines.find { |line| line.include?('"ajax":') }.strip.delete_suffix(',')
|
|
24
|
-
|
|
25
|
-
const vm = require('vm'), fs = require('fs'), context = {};
|
|
26
|
-
const value = vm.runInNewContext('({' + fs.readFileSync(0, 'utf8') + '})', context);
|
|
27
|
-
process.stdout.write(JSON.stringify({ajax: value.ajax, context}));
|
|
28
|
-
JS
|
|
29
|
-
stdout, stderr, status = Open3.capture3('node', '-e', code, stdin_data: ajax)
|
|
30
|
-
expect(status.success?).to be(true), stderr
|
|
31
|
-
result = JSON.parse(stdout)
|
|
32
|
-
expect(result.fetch('context')).to eq({})
|
|
33
|
-
url = result.fetch('ajax')
|
|
23
|
+
url = JSON.parse("{#{ajax}}").fetch('ajax')
|
|
34
24
|
expect(url).not_to match(/[<>"'\\\s&#?]/)
|
|
35
25
|
expect(URI.parse(url).scheme).to be_nil
|
|
36
26
|
expect(URI.decode_www_form_component(url)).to eq("#{name}.json")
|
|
37
27
|
expect(ajax).not_to include('</script>', '<script>', "\u2028", "\u2029")
|
|
38
28
|
scripts = html.scan(%r{<script(?: [^>]*)?>(.*?)</script>}m).flatten.join("\n")
|
|
39
|
-
|
|
40
|
-
expect(
|
|
29
|
+
expect(scripts).not_to include(name) if name.match?(/[<>"']/)
|
|
30
|
+
expect(scripts).not_to include("\u2028", "\u2029")
|
|
41
31
|
end
|
|
42
32
|
end
|
|
43
33
|
end
|
|
@@ -63,6 +63,27 @@ RSpec.describe PWN::SessionCleanup, 'concurrent maintenance' do
|
|
|
63
63
|
Timeout.timeout(5) { described_class.maintain(proc_root: @processes) }
|
|
64
64
|
end
|
|
65
65
|
|
|
66
|
+
it 'registers a forked session owner while the parent is iterating its owner markers' do
|
|
67
|
+
sid = PWN::Sessions.create[:id]
|
|
68
|
+
owners = PWN::Sessions.instance_variable_get(:@activity_owners)
|
|
69
|
+
# Fork with a live Hash iterator, rather than racing the scheduler to catch one.
|
|
70
|
+
iterator = owners.each_key
|
|
71
|
+
iterator.next
|
|
72
|
+
input, output = worker do |commands, replies|
|
|
73
|
+
lease = PWN::Sessions.activate(session_id: sid)
|
|
74
|
+
replies.puts('leased')
|
|
75
|
+
commands.gets
|
|
76
|
+
PWN::Sessions.deactivate(lease: lease)
|
|
77
|
+
replies.puts('released')
|
|
78
|
+
end
|
|
79
|
+
expect(message(output)).to eq('leased')
|
|
80
|
+
expect(PWN::Sessions.active?(session_id: sid)).to be(true)
|
|
81
|
+
expect(described_class.legacy_owners(@processes)).to be_empty
|
|
82
|
+
input.puts('release')
|
|
83
|
+
expect(message(output)).to eq('released')
|
|
84
|
+
expect(PWN::Sessions.active?(session_id: sid)).to be(false)
|
|
85
|
+
end
|
|
86
|
+
|
|
66
87
|
it 'retains two real active clients, deletes unrelated work and revisits released evidence' do
|
|
67
88
|
ids = 3.times.map { PWN::Sessions.create[:id] }
|
|
68
89
|
learning = PWN::AI::Agent::Learning
|
data/spec/spec_helper.rb
CHANGED
|
@@ -67,8 +67,38 @@ RSpec.configure do |config|
|
|
|
67
67
|
original_stderr = $stderr
|
|
68
68
|
devnull = StringIO.new
|
|
69
69
|
|
|
70
|
+
if ENV['PWN_RAKE_SPEC'] == '1'
|
|
71
|
+
config.before(:suite) do
|
|
72
|
+
next if defined?(PWN_RAKE_STDOUT_SILENCED)
|
|
73
|
+
|
|
74
|
+
reporter = RSpec.configuration.reporter
|
|
75
|
+
listeners = reporter.instance_variable_get(:@listeners).values.flat_map(&:to_a).uniq
|
|
76
|
+
terminal = nil
|
|
77
|
+
silenced = []
|
|
78
|
+
listeners.each do |listener|
|
|
79
|
+
next unless listener.instance_variable_defined?(:@output)
|
|
80
|
+
|
|
81
|
+
wrapped = listener.instance_variable_get(:@output)
|
|
82
|
+
stream = wrapped.is_a?(RSpec::Core::OutputWrapper) ? wrapped.output : wrapped
|
|
83
|
+
next unless stream.respond_to?(:reopen) && stream.respond_to?(:fileno) && stream.fileno == 1
|
|
84
|
+
next if silenced.include?(stream)
|
|
85
|
+
|
|
86
|
+
terminal ||= stream.dup.tap { |io| io.sync = true }
|
|
87
|
+
if wrapped.is_a?(RSpec::Core::OutputWrapper)
|
|
88
|
+
wrapped.output = terminal
|
|
89
|
+
else
|
|
90
|
+
listener.instance_variable_set(:@output, terminal)
|
|
91
|
+
end
|
|
92
|
+
stream.reopen(File::NULL)
|
|
93
|
+
stream.sync = true
|
|
94
|
+
silenced << stream
|
|
95
|
+
end
|
|
96
|
+
Object.const_set(:PWN_RAKE_STDOUT_SILENCED, true)
|
|
97
|
+
end
|
|
98
|
+
end
|
|
99
|
+
|
|
70
100
|
config.before(:each) do |example|
|
|
71
|
-
next if example.metadata[:stdout]
|
|
101
|
+
next if example.metadata[:stdout] && ENV['PWN_RAKE_SPEC'] != '1'
|
|
72
102
|
|
|
73
103
|
devnull.truncate(0)
|
|
74
104
|
devnull.rewind
|
|
@@ -82,8 +112,7 @@ RSpec.configure do |config|
|
|
|
82
112
|
end
|
|
83
113
|
end
|
|
84
114
|
|
|
85
|
-
#
|
|
86
|
-
#
|
|
87
|
-
#
|
|
88
|
-
# banners cannot leak into rake.
|
|
115
|
+
# During rake, PWNLogger writes nothing and STDOUT itself is /dev/null.
|
|
116
|
+
# Direct rspec still redirects $stdout per example. PWN_SPEC_VERBOSE=1
|
|
117
|
+
# leaves both attached. Point any other captured logger at /dev/null.
|
|
89
118
|
PWN::AI::RedTeam::TestCaseEngine.class_variable_set(:@@logger, Logger.new(File::NULL)) if defined?(PWN::AI::RedTeam::TestCaseEngine)
|
data/third_party/pwn_rdoc.jsonl
CHANGED
|
@@ -614,6 +614,7 @@
|
|
|
614
614
|
{"messages":[{"role":"user","content":"PWN::AI::Agent::MissionNamespace.new Usage"},{"role":"assistant","content":"`PWN::AI::Agent::MissionNamespace.new`: "}]}
|
|
615
615
|
{"messages":[{"role":"user","content":"PWN::AI::Agent::MissionNamespace.prepared? Usage"},{"role":"assistant","content":"`PWN::AI::Agent::MissionNamespace.prepared?`: "}]}
|
|
616
616
|
{"messages":[{"role":"user","content":"PWN::AI::Agent::MissionNamespace.supervise Usage"},{"role":"assistant","content":"`PWN::AI::Agent::MissionNamespace.supervise`: "}]}
|
|
617
|
+
{"messages":[{"role":"user","content":"PWN::AI::Agent::MissionNamespace.supervise_host Usage"},{"role":"assistant","content":"`PWN::AI::Agent::MissionNamespace.supervise_host`: "}]}
|
|
617
618
|
{"messages":[{"role":"user","content":"PWN::AI::Agent::MissionNamespace.close Usage"},{"role":"assistant","content":"`PWN::AI::Agent::MissionNamespace.close`: "}]}
|
|
618
619
|
{"messages":[{"role":"user","content":"PWN::AI::Agent::MissionNamespace.wait Usage"},{"role":"assistant","content":"`PWN::AI::Agent::MissionNamespace.wait`: "}]}
|
|
619
620
|
{"messages":[{"role":"user","content":"PWN::AI::Agent::Mistakes.applicable_fix? Usage"},{"role":"assistant","content":"`PWN::AI::Agent::Mistakes.applicable_fix?`: "}]}
|
|
@@ -3442,8 +3443,16 @@
|
|
|
3442
3443
|
{"messages":[{"role":"user","content":"PWN::Plugins::PS.help Usage"},{"role":"assistant","content":"`PWN::Plugins::PS.help`: "}]}
|
|
3443
3444
|
{"messages":[{"role":"user","content":"PWN::Plugins::PS.list Usage"},{"role":"assistant","content":"`PWN::Plugins::PS.list`: Supported Method Parameters\n\nproc_list_arr = PWN::Plugins::PS.list\n"}]}
|
|
3444
3445
|
{"messages":[{"role":"user","content":"PWN::Plugins::PWNLogger.authors Usage"},{"role":"assistant","content":"`PWN::Plugins::PWNLogger.authors`: Author(s)\n\n0day Inc. <support@0dayinc.com>\n"}]}
|
|
3445
|
-
{"messages":[{"role":"user","content":"PWN::Plugins::PWNLogger.create Usage"},{"role":"assistant","content":"`PWN::Plugins::PWNLogger.create`:
|
|
3446
|
+
{"messages":[{"role":"user","content":"PWN::Plugins::PWNLogger.create Usage"},{"role":"assistant","content":"`PWN::Plugins::PWNLogger.create`: "}]}
|
|
3446
3447
|
{"messages":[{"role":"user","content":"PWN::Plugins::PWNLogger.help Usage"},{"role":"assistant","content":"`PWN::Plugins::PWNLogger.help`: "}]}
|
|
3448
|
+
{"messages":[{"role":"user","content":"PWN::Plugins::PWNLogger::CurrentStdout.<< Usage"},{"role":"assistant","content":"`PWN::Plugins::PWNLogger::CurrentStdout.<<`: "}]}
|
|
3449
|
+
{"messages":[{"role":"user","content":"PWN::Plugins::PWNLogger::CurrentStdout.close Usage"},{"role":"assistant","content":"`PWN::Plugins::PWNLogger::CurrentStdout.close`: "}]}
|
|
3450
|
+
{"messages":[{"role":"user","content":"PWN::Plugins::PWNLogger::CurrentStdout.flush Usage"},{"role":"assistant","content":"`PWN::Plugins::PWNLogger::CurrentStdout.flush`: "}]}
|
|
3451
|
+
{"messages":[{"role":"user","content":"PWN::Plugins::PWNLogger::CurrentStdout.reopen Usage"},{"role":"assistant","content":"`PWN::Plugins::PWNLogger::CurrentStdout.reopen`: "}]}
|
|
3452
|
+
{"messages":[{"role":"user","content":"PWN::Plugins::PWNLogger::CurrentStdout.sync Usage"},{"role":"assistant","content":"`PWN::Plugins::PWNLogger::CurrentStdout.sync`: "}]}
|
|
3453
|
+
{"messages":[{"role":"user","content":"PWN::Plugins::PWNLogger::CurrentStdout.sync= Usage"},{"role":"assistant","content":"`PWN::Plugins::PWNLogger::CurrentStdout.sync=`: "}]}
|
|
3454
|
+
{"messages":[{"role":"user","content":"PWN::Plugins::PWNLogger::CurrentStdout.tty? Usage"},{"role":"assistant","content":"`PWN::Plugins::PWNLogger::CurrentStdout.tty?`: "}]}
|
|
3455
|
+
{"messages":[{"role":"user","content":"PWN::Plugins::PWNLogger::CurrentStdout.write Usage"},{"role":"assistant","content":"`PWN::Plugins::PWNLogger::CurrentStdout.write`: "}]}
|
|
3447
3456
|
{"messages":[{"role":"user","content":"PWN::Plugins::Packet.authors Usage"},{"role":"assistant","content":"`PWN::Plugins::Packet.authors`: Author(s)\n\n0day Inc. <support@0dayinc.com>\n"}]}
|
|
3448
3457
|
{"messages":[{"role":"user","content":"PWN::Plugins::Packet.cap_net_raw? Usage"},{"role":"assistant","content":"`PWN::Plugins::Packet.cap_net_raw?`: "}]}
|
|
3449
3458
|
{"messages":[{"role":"user","content":"PWN::Plugins::Packet.capture Usage"},{"role":"assistant","content":"`PWN::Plugins::Packet.capture`: "}]}
|