pwn 0.5.702 → 0.5.703

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5e0f1934072cdfc2dd334d22bcd15774e5756a0bd02bb68962759ceb2e436b98
4
- data.tar.gz: b092c265b35a9000293ce787252452c8045c4604677a3bd5416a2e4e732c2cce
3
+ metadata.gz: c7cea05c0bbdbb5df99c258d696c234071a44592665732086943b8e85a23e047
4
+ data.tar.gz: 9991f785d11bfe591e4391615e5898f7f5e6a16c0c51de732db9e6f172bdd282
5
5
  SHA512:
6
- metadata.gz: 61bdd9c6f370aa44f1cb3e5b00a928cd57acb5f1a40154769079ecec39ac4f0d8ce81c8daac5c5a1f5040b96cff7b7503de230645920531a854f10762bf75058
7
- data.tar.gz: bc978a06cf9dd7e109696b6e95bfba64dcbc73d3092a9fbdcfe19cdf488dcec0b3c463866a90703050705fdf01bdd0f6a34e93c5f02812631682669499632461
6
+ metadata.gz: 319e5f02eba56e735bbf1497347750f3bbedc906919d2d96e6313c89c87dd2f439c100317f6d2c19a86b47ff8d390c15581b44b6de8ad1b45629245e4f5acb24
7
+ data.tar.gz: 899c8e1bc7374a8a8fbee9c940a4650bfed391a7c787ce9e59b3a1a5ba2d2a2978b24629df31d1d35ed067445f95ced484f04cfc85093212065ac96fde60f338
@@ -39,6 +39,7 @@ PWN::AI::Agent::ToolGuard.present(opts)
39
39
  - `shell_bash`
40
40
  - `shell_name`
41
41
  - `protect_http`
42
+ - `protect_core_constants`
42
43
  - `coerce_args`
43
44
  - `invalid_payload`
44
45
  - `host_load`
@@ -934,10 +934,14 @@ module PWN
934
934
  nil
935
935
  end
936
936
 
937
+ PAYLOAD_SHA256 = Digest::SHA256
938
+
937
939
  private_class_method def self.payload_sig(opts = {})
938
- Digest::SHA256.hexdigest("#{opts[:name]}|#{opts[:args]}")[0, 16]
940
+ blob = "#{opts[:name]}|#{opts[:args]}"
941
+ PAYLOAD_SHA256.hexdigest(blob)[0, 16]
939
942
  rescue StandardError
940
- "nosig-#{opts[:name]}"
943
+ key = "#{opts[:name]}|#{opts[:args]}"
944
+ "#{opts[:name]}-#{key.hash.abs.to_s(16)[0, 12]}"
941
945
  end
942
946
 
943
947
  private_class_method def self.note_same_payload!(opts = {})
@@ -60,23 +60,34 @@ module PWN
60
60
  end
61
61
 
62
62
  # RestClient uses HTTP::CookieJar. pwn_eval in TOPLEVEL_BINDING can
63
- # assign HTTP = "/path/http" (a mkdir) and then every provider hop
64
- # TypeErrors: "path is not a class/module".
63
+ # assign HTTP = "/path/http" or Digest = "(self.we" and then every
64
+ # provider hop / payload_sig TypeErrors.
65
+ CORE_CONSTS = %i[HTTP Digest JSON URI Timeout].freeze
66
+
65
67
  public_class_method def self.protect_http!
66
- if Object.const_defined?(:HTTP, false)
67
- cur = Object.const_get(:HTTP)
68
- @http_mod = cur if cur.is_a?(Module) && @http_mod.nil?
69
- return cur if cur.is_a?(Module)
68
+ protect_core_constants!
69
+ end
70
+
71
+ public_class_method def self.protect_core_constants!
72
+ @core_mods ||= {}
73
+ CORE_CONSTS.each do |name|
74
+ if Object.const_defined?(name, false)
75
+ cur = Object.const_get(name, false)
76
+ @core_mods[name] = cur if cur.is_a?(Module) && @core_mods[name].nil?
77
+ next if cur.is_a?(Module)
78
+
79
+ Object.send(:remove_const, name)
80
+ end
81
+ next unless @core_mods[name].is_a?(Module)
82
+ next if Object.const_defined?(name, false) && Object.const_get(name, false).equal?(@core_mods[name])
70
83
 
71
- Object.send(:remove_const, :HTTP)
84
+ Object.const_set(name, @core_mods[name])
72
85
  end
73
- if @http_mod.is_a?(Module)
74
- Object.const_set(:HTTP, @http_mod)
75
- return @http_mod
86
+ unless Object.const_defined?(:HTTP, false) && Object.const_get(:HTTP, false).is_a?(Module)
87
+ require 'http/cookie_jar'
88
+ @core_mods[:HTTP] = Object.const_get(:HTTP) if Object.const_defined?(:HTTP) && Object.const_get(:HTTP).is_a?(Module)
76
89
  end
77
- require 'http/cookie_jar'
78
- @http_mod = Object.const_get(:HTTP) if Object.const_defined?(:HTTP) && Object.const_get(:HTTP).is_a?(Module)
79
- @http_mod
90
+ @core_mods
80
91
  rescue StandardError
81
92
  nil
82
93
  end
data/lib/pwn/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module PWN
4
- VERSION = '0.5.702'
4
+ VERSION = '0.5.703'
5
5
  end
@@ -48,6 +48,19 @@ describe 'PWN::AI::Agent::Tools ruby_eval' do
48
48
  expect { HTTP::CookieJar }.not_to raise_error
49
49
  end
50
50
 
51
+ it 'restores Digest if the payload assigns Digest so later payload_sig still hashes' do
52
+ entry = PWN::AI::Agent::Registry.lookup(name: 'pwn_eval')
53
+ result = entry.handler.call(code: 'Digest = "(self.we"')
54
+ expect(result[:error]).to be_nil
55
+ expect(Digest).to be_a(Module)
56
+ expect(Digest::SHA256.hexdigest('x')).to be_a(String)
57
+ a = PWN::AI::Agent::Loop.send(:payload_sig, name: 'pwn_eval', args: '{"code":"1"}')
58
+ b = PWN::AI::Agent::Loop.send(:payload_sig, name: 'pwn_eval', args: '{"code":"2"}')
59
+ expect(a).not_to eq(b)
60
+ expect(a).not_to match(/nosig-/)
61
+ expect(b).not_to match(/nosig-/)
62
+ end
63
+
51
64
  it 'enforces a timeout on pwn_eval and reports timeout after Ns' do
52
65
  tmp = Dir.mktmpdir
53
66
  stub_const('PWN::AI::Agent::Mistakes::MISTAKES_FILE', File.join(tmp, 'mistakes.json'))
@@ -729,6 +729,7 @@
729
729
  {"messages":[{"role":"user","content":"PWN::AI::Agent::ToolGuard.payload_spent Usage"},{"role":"assistant","content":"`PWN::AI::Agent::ToolGuard.payload_spent`: "}]}
730
730
  {"messages":[{"role":"user","content":"PWN::AI::Agent::ToolGuard.placeholder? Usage"},{"role":"assistant","content":"`PWN::AI::Agent::ToolGuard.placeholder?`: "}]}
731
731
  {"messages":[{"role":"user","content":"PWN::AI::Agent::ToolGuard.present? Usage"},{"role":"assistant","content":"`PWN::AI::Agent::ToolGuard.present?`: "}]}
732
+ {"messages":[{"role":"user","content":"PWN::AI::Agent::ToolGuard.protect_core_constants! Usage"},{"role":"assistant","content":"`PWN::AI::Agent::ToolGuard.protect_core_constants!`: "}]}
732
733
  {"messages":[{"role":"user","content":"PWN::AI::Agent::ToolGuard.protect_http! Usage"},{"role":"assistant","content":"`PWN::AI::Agent::ToolGuard.protect_http!`: "}]}
733
734
  {"messages":[{"role":"user","content":"PWN::AI::Agent::ToolGuard.reset_timeout_budget Usage"},{"role":"assistant","content":"`PWN::AI::Agent::ToolGuard.reset_timeout_budget`: "}]}
734
735
  {"messages":[{"role":"user","content":"PWN::AI::Agent::ToolGuard.reset_timeout_budget! Usage"},{"role":"assistant","content":"`PWN::AI::Agent::ToolGuard.reset_timeout_budget!`: "}]}
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pwn
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.702
4
+ version: 0.5.703
5
5
  platform: ruby
6
6
  authors:
7
7
  - 0day Inc.