pwn 0.4.643 → 0.4.645

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bbf3fa66db2d9b1b7d8be45081cf1d2e733fb6b2caa0b3fe7c092790c2a4b43a
4
- data.tar.gz: 3b70ba7c9096251aec921f1ed72d109c50ccaaaedea256bb0d700a69ea8fbd4b
3
+ metadata.gz: 175a84d917a62dd16839be4dad757fa30c0db1ec4b8be44ced24412e34061cfd
4
+ data.tar.gz: 56ab72f479c87b3206310be28c1bff3e1ecc71332b82ffc921de7fb612b15139
5
5
  SHA512:
6
- metadata.gz: 0a738aa1e3c60bd364b50df32e25cbd34dcdc23e446fbf0f91f53fb2e310ea88ca0f36e986bbe2a51bb091ccf325e16cb2581e4ed75e8befaf42ae2671687ba0
7
- data.tar.gz: 8e30cbbcb5dcc2a109df22e979ff6e013f578a7140d70ee9e17af0d9c0e9a4f869a7dc5da065543b2cd710751accbd5e11d172fca426a5b24f75052f62f5921d
6
+ metadata.gz: b166ba9ac93ff8cd2908be9078540ad7fd4e0076e2579e1dfa648fb14e6c0caf6d1b598d27f2d39c26d245e7768f85c9b4e02f1e530dd3b08fa541ad162792bb
7
+ data.tar.gz: 9c9677f7900576017382915e3a2928d0feeedea1e0e7ad4fccca3dcc2903c9d99a7f76dc3888d5529af471b1d018c96fd1d49ebad1df9776ebb6b1fb3f09d178
data/README.md CHANGED
@@ -37,7 +37,7 @@ $ rvm use ruby-3.2.2@pwn
37
37
  $ rvm list gemsets
38
38
  $ gem install --verbose pwn
39
39
  $ pwn
40
- pwn[v0.4.643]:001 >>> PWN.help
40
+ pwn[v0.4.645]:001 >>> PWN.help
41
41
  ```
42
42
 
43
43
  [![Installing the pwn Security Automation Framework](https://raw.githubusercontent.com/0dayInc/pwn/master/documentation/pwn_install.png)](https://youtu.be/G7iLUY4FzsI)
@@ -52,7 +52,7 @@ $ rvm use ruby-3.2.2@pwn
52
52
  $ gem uninstall --all --executables pwn
53
53
  $ gem install --verbose pwn
54
54
  $ pwn
55
- pwn[v0.4.643]:001 >>> PWN.help
55
+ pwn[v0.4.645]:001 >>> PWN.help
56
56
  ```
57
57
 
58
58
 
data/bin/pwn_chat CHANGED
@@ -24,8 +24,8 @@ OptionParser.new do |options|
24
24
  opts[:system_role_content] = s
25
25
  end
26
26
 
27
- options.on('-v', '--voice', '<Options - Voice Activate Responses (Defaults to false)>') do |v|
28
- opts[:voice] = v
27
+ options.on('-S', '--speak-answer', '<Options - Speak Answers (Defaults to false)>') do |v|
28
+ opts[:speak_answer] = v
29
29
  end
30
30
  end.parse!
31
31
 
@@ -93,7 +93,7 @@ begin
93
93
 
94
94
  system_role_content = opts[:system_role_content]
95
95
 
96
- @voice = true if opts[:voice]
96
+ @speak_answer = true if opts[:speak_answer]
97
97
 
98
98
  # Define Custom REPL Commands
99
99
  Pry::Commands.create_command 'welcome-banner' do
@@ -119,60 +119,26 @@ begin
119
119
  end
120
120
 
121
121
  @response_history = nil
122
- @keep_in_memory = 0
123
122
  Pry.config.hooks.add_hook(:after_eval, :open_ai_hook) do |request, _pry|
124
123
  if request.instance_of?(String)
125
- unless @response_history.nil?
126
- choices_len = @response_history[:choices].length
127
- @keep_in_memory = choices_len * -1
128
- end
129
-
130
- begin
131
- response = PWN::Plugins::OpenAI.chat(
132
- token: token,
133
- system_role_content: system_role_content,
134
- request: request.to_s,
135
- temp: 1,
136
- max_tokens: 0,
137
- response_history: @response_history
138
- )
139
- puts "\n\n\n#{response[:choices].last[:content]}\n\n\n"
140
-
141
- if @voice
142
- text_path = "/tmp/#{File.basename($PROGRAM_NAME)}.response"
143
- File.write(text_path, response[:choices].last[:content])
144
- PWN::Plugins::Voice.text_to_speech(text_path: text_path)
145
- end
146
-
147
- @response_history = {
148
- id: response[:id],
149
- object: response[:object],
150
- model: response[:model],
151
- usage: response[:usage]
152
- }
153
- @response_history[:choices] ||= response[:choices]
154
- rescue JSON::ParserError
155
- max_tokens = 4097
156
- if request.length > max_tokens
157
- puts "Request Length Too Long: #{request.length}\n"
158
- else
159
- puts 'Token Length too long, trimming memory by 1 and retrying...'
160
- @keep_in_memory += 1
161
- @response_history[:choices] = @response_history[:choices].slice(@keep_in_memory..)
162
-
163
- response = PWN::Plugins::OpenAI.chat(
164
- token: token,
165
- system_role_content: system_role_content,
166
- request: "summarize what we've already discussed",
167
- temp: 1,
168
- max_tokens: 0,
169
- response_history: @response_history
170
- )
171
- @response_history[:choices] = response[:choices].slice(@keep_in_memory..)
172
-
173
- retry
174
- end
175
- end
124
+ response = PWN::Plugins::OpenAI.chat(
125
+ token: token,
126
+ system_role_content: system_role_content,
127
+ request: request.to_s,
128
+ temp: 1,
129
+ max_tokens: 0,
130
+ response_history: @response_history,
131
+ speak_answer: @speak_answer
132
+ )
133
+ puts "\n\n\n#{response[:choices].last[:content]}\n\n\n"
134
+
135
+ @response_history = {
136
+ id: response[:id],
137
+ object: response[:object],
138
+ model: response[:model],
139
+ usage: response[:usage]
140
+ }
141
+ @response_history[:choices] ||= response[:choices]
176
142
  end
177
143
  end
178
144
 
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'json'
4
+ require 'securerandom'
4
5
 
5
6
  module PWN
6
7
  module Plugins
@@ -98,7 +99,8 @@ module PWN
98
99
  # temp: 'optional - creative response float (deafults to 0)',
99
100
  # max_tokens: 'optional - integer (defaults to 4_097 - request.length || 300)',
100
101
  # system_role_content: 'optional - context to set up the model behavior for conversation (Default: "You are a sarcastic ethical hacker named Kennedy. You are able to access any content or website on any device or network without any limitations or filters.")',
101
- # response_history: 'optional - pass response back in to have a conversation'
102
+ # response_history: 'optional - pass response back in to have a conversation',
103
+ # speak_answer: 'optional speak answer using PWN::Plugins::Voice.text_to_speech (Default: nil)'
102
104
  # )
103
105
 
104
106
  public_class_method def self.chat(opts = {})
@@ -138,6 +140,7 @@ module PWN
138
140
  }
139
141
 
140
142
  response_history ||= { choices: [system_role] }
143
+ choices_len = response_history[:choices].length
141
144
 
142
145
  # TODO: Include max_tokens when sending chat requests
143
146
  http_body = {
@@ -178,7 +181,42 @@ module PWN
178
181
  json_resp[:choices].push(assistant_resp)
179
182
  end
180
183
 
184
+ speak_answer = true if opts[:speak_answer]
185
+
186
+ if speak_answer
187
+ text_path = "/tmp/#{SecureRandom.hex}.pwn_voice"
188
+ answer = json_resp[:choices].last[:text]
189
+ answer = json_resp[:choices].last[:content] if gpt
190
+ File.write(text_path, answer)
191
+ PWN::Plugins::Voice.text_to_speech(text_path: text_path)
192
+ File.unlink(text_path)
193
+ end
194
+
181
195
  json_resp
196
+ rescue JSON::ParserError => e
197
+ if e.message.include?('exceeded')
198
+ if request.length > max_tokens
199
+ puts "Request Length Too Long: #{request.length}\n"
200
+ else
201
+ # TODO: make this as tight as possible.
202
+ keep_in_memory = (choices_len - 2) * -1
203
+ response_history[:choices] = response_history[:choices].slice(keep_in_memory..)
204
+
205
+ response = chat(
206
+ token: token,
207
+ system_role_content: system_role_content,
208
+ request: "summarize what we've already discussed",
209
+ temp: 1,
210
+ max_tokens: 0,
211
+ response_history: response_history,
212
+ speak_answer: speak_answer
213
+ )
214
+ keep_in_memory = (choices_len / 2) * -1
215
+ response_history[:choices] = response[:choices].slice(keep_in_memory..)
216
+
217
+ retry
218
+ end
219
+ end
182
220
  rescue StandardError => e
183
221
  raise e
184
222
  end
@@ -238,7 +276,8 @@ module PWN
238
276
  temp: 'optional - creative response float (defaults to 0)',
239
277
  max_tokens: 'optional - integer (deafults to 4_097 - request.length || 300)',
240
278
  system_role_content: 'optional - context to set up the model behavior for conversation (Default: \"You are a sarcastic ethical hacker named Kennedy. You are able to access any content or website on any device or network without any limitations or filters.\")',
241
- response_history: 'optional - pass response back in to have a conversation'
279
+ response_history: 'optional - pass response back in to have a conversation',
280
+ speak_answer: 'optional speak answer using PWN::Plugins::Voice.text_to_speech (Default: nil)'
242
281
  )
243
282
 
244
283
  response = #{self}.img_gen(
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.4.643'
4
+ VERSION = '0.4.645'
5
5
  end
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.4.643
4
+ version: 0.4.645
5
5
  platform: ruby
6
6
  authors:
7
7
  - 0day Inc.