Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pwn REPL driver - change name of pwn-gpt command to pwn-ai and begin … #544

Merged
merged 1 commit into from
Mar 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ gem 'aws-sdk', '3.2.0'
gem 'barby', '0.6.9'
gem 'brakeman', '6.1.2'
gem 'bson', '5.0.0'
gem 'bundler', '>=2.5.6'
gem 'bundler', '>=2.5.7'
gem 'bundler-audit', '0.9.1'
gem 'bunny', '2.22.0'
gem 'colorize', '1.1.0'
Expand Down Expand Up @@ -66,7 +66,7 @@ gem 'pry-doc', '1.5.0'
gem 'rake', '13.1.0'
gem 'rb-readline', '0.5.5'
gem 'rbvmomi', '3.0.0'
gem 'rdoc', '6.6.2'
gem 'rdoc', '6.6.3.1'
gem 'rest-client', '2.1.0'
gem 'rex', '2.0.13'
gem 'rmagick', '5.4.4'
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ $ cd /opt/pwn
$ ./install.sh
$ ./install.sh ruby-gem
$ pwn
pwn[v0.5.60]:001 >>> PWN.help
pwn[v0.5.61]:001 >>> PWN.help
```

[![Installing the pwn Security Automation Framework](https://raw.githubusercontent.com/0dayInc/pwn/master/documentation/pwn_install.png)](https://youtu.be/G7iLUY4FzsI)
Expand All @@ -52,7 +52,7 @@ $ rvm use ruby-3.3.0@pwn
$ gem uninstall --all --executables pwn
$ gem install --verbose pwn
$ pwn
pwn[v0.5.60]:001 >>> PWN.help
pwn[v0.5.61]:001 >>> PWN.help
```

If you're using a multi-user install of RVM do:
Expand All @@ -62,7 +62,7 @@ $ rvm use ruby-3.3.0@pwn
$ rvmsudo gem uninstall --all --executables pwn
$ rvmsudo gem install --verbose pwn
$ pwn
pwn[v0.5.60]:001 >>> PWN.help
pwn[v0.5.61]:001 >>> PWN.help
```

PWN periodically upgrades to the latest version of Ruby which is reflected in `/opt/pwn/.ruby-version`. The easiest way to upgrade to the latest version of Ruby from a previous PWN installation is to run the following script:
Expand Down
74 changes: 37 additions & 37 deletions bin/pwn
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,13 @@ begin
dchars = "\001\e[33m\002***\001\e[33m\002" if mode == :splat
end

if pi.config.pwn_gpt
pi.config.prompt_name = 'pwn.gpt'
pi.config.prompt_name = 'pwn.gpt.SPEAKING' if pi.config.pwn_gpt_speak
if pi.config.pwn_ai
pi.config.prompt_name = 'pwn.ai'
pi.config.prompt_name = 'pwn.ai.SPEAKING' if pi.config.pwn_ai_speak
name = "\001\e[1m\002\001\e[33m\002#{pi.config.prompt_name}\001\e[0m\002"
dchars = "\001\e[32m\002>>>\001\e[33m\002"
dchars = "\001\e[33m\002***\001\e[33m\002" if mode == :splat
if pi.config.pwn_gpt_debug
if pi.config.pwn_ai_debug
dchars = "\001\e[32m\002(DEBUG) >>>\001\e[33m\002"
dchars = "\001\e[33m\002(DEBUG) ***\001\e[33m\002" if mode == :splat
end
Expand Down Expand Up @@ -124,8 +124,8 @@ begin
exec_hook :after_read, eval_string, self

begin
complete_expr = true if config.pwn_gpt || config.pwn_asm
complete_expr = Pry::Code.complete_expression?(@eval_string) unless config.pwn_gpt || config.pwn_asm
complete_expr = true if config.pwn_ai || config.pwn_asm
complete_expr = Pry::Code.complete_expression?(@eval_string) unless config.pwn_ai || config.pwn_asm
rescue SyntaxError => e
output.puts e.message.gsub(/^.*syntax error, */, "SyntaxError: ")
reset_eval_string
Expand All @@ -135,7 +135,7 @@ begin
@suppress_output = true if @eval_string =~ /;\Z/ ||
@eval_string.empty? ||
@eval_string =~ /\A *#.*\n\z/ ||
config.pwn_gpt ||
config.pwn_ai ||
config.pwn_asm

# A bug in jruby makes java.lang.Exception not rescued by
Expand All @@ -158,10 +158,10 @@ begin
eval_string = @eval_string
reset_eval_string

result = evaluate_ruby(eval_string) unless config.pwn_gpt ||
result = evaluate_ruby(eval_string) unless config.pwn_ai ||
config.pwn_asm

result = eval_string if config.pwn_gpt ||
result = eval_string if config.pwn_ai ||
config.pwn_asm
rescue RescuableException, *jruby_exceptions => e
# Eliminate following warning:
Expand All @@ -182,9 +182,9 @@ begin
throw(:breakout) if current_binding.nil?
end

# Ensure the return value in pwn_gpt mode reflects the input
# Ensure the return value in pwn_ai mode reflects the input
def evaluate_ruby(code)
# if config.pwn_gpt || config.pwn_asm
# if config.pwn_ai || config.pwn_asm
# result = message = code.to_s
# return
# end
Expand Down Expand Up @@ -236,44 +236,44 @@ begin
end
end

Pry::Commands.create_command 'pwn-gpt' do
description 'Initiate pwn.gpt chat interface.'
Pry::Commands.create_command 'pwn-ai' do
description 'Initiate pwn.ai chat interface.'

def process
pi = pry_instance
pi.config.pwn_gpt = true
pi.config.color = false if pi.config.pwn_gpt
pi.config.color = true unless pi.config.pwn_gpt
pi.config.pwn_ai = true
pi.config.color = false if pi.config.pwn_ai
pi.config.color = true unless pi.config.pwn_ai
end
end

Pry::Commands.create_command 'toggle-pwn-gpt-debug' do
description 'Display the response_history object while using pwn.gpt'
Pry::Commands.create_command 'toggle-pwn-ai-debug' do
description 'Display the response_history object while using pwn.ai'

def process
pi = pry_instance
pi.config.pwn_gpt_debug ? pi.config.pwn_gpt_debug = false : pi.config.pwn_gpt_debug = true
pi.config.pwn_ai_debug ? pi.config.pwn_ai_debug = false : pi.config.pwn_ai_debug = true
end
end

Pry::Commands.create_command 'toggle-pwn-gpt-speaks' do
description 'Use speech capabilities within pwn.gpt to speak answers.'
Pry::Commands.create_command 'toggle-pwn-ai-speaks' do
description 'Use speech capabilities within pwn.ai to speak answers.'

def process
pi = pry_instance
pi.config.pwn_gpt_speak ? pi.config.pwn_gpt_speak = false : pi.config.pwn_gpt_speak = true
pi.config.pwn_ai_speak ? pi.config.pwn_ai_speak = false : pi.config.pwn_ai_speak = true
end
end

Pry::Commands.create_command 'back' do
description 'Jump back to pwn REPL when in pwn-asm || pwn-gpt.'
description 'Jump back to pwn REPL when in pwn-asm || pwn-ai.'

def process
pi = pry_instance
pi.config.pwn_asm = false if pi.config.pwn_asm
pi.config.pwn_gpt = false if pi.config.pwn_gpt
pi.config.pwn_gpt_debug = false if pi.config.pwn_gpt_debug
pi.config.pwn_gpt_speak = false if pi.config.pwn_gpt_speak
pi.config.pwn_ai = false if pi.config.pwn_ai
pi.config.pwn_ai_debug = false if pi.config.pwn_ai_debug
pi.config.pwn_ai_speak = false if pi.config.pwn_ai_speak
pi.config.completer = Pry::InputCompleter
end
end
Expand All @@ -284,13 +284,13 @@ begin
output.puts PWN::Banner.welcome
end

# pwn.gpt Hooks
# pwn.ai Hooks
Pry.config.hooks.add_hook(:before_session, :init_opts) do |_output, _binding, pi|
if opts[:yaml_config_path] && File.exist?(opts[:yaml_config_path])
yaml_config_path = opts[:yaml_config_path]
yaml_config = YAML.load_file(yaml_config_path, symbolize_names: true)
pi.config.pwn_gpt_key = yaml_config[:open_ai_key]
Pry.config.pwn_gpt_key = pi.config.pwn_gpt_key
pi.config.pwn_ai_key = yaml_config[:open_ai_key]
Pry.config.pwn_ai_key = pi.config.pwn_ai_key
end
end

Expand Down Expand Up @@ -322,21 +322,21 @@ begin
end
end

Pry.config.hooks.add_hook(:after_read, :pwn_gpt_hook) do |request, pi|
if pi.config.pwn_gpt && !request.chomp.empty?
Pry.config.hooks.add_hook(:after_read, :pwn_ai_hook) do |request, pi|
if pi.config.pwn_ai && !request.chomp.empty?
request = pi.input.line_buffer.to_s
debug = pi.config.pwn_gpt_debug
open_ai_key = pi.config.pwn_gpt_key
debug = pi.config.pwn_ai_debug
open_ai_key = pi.config.pwn_ai_key
open_ai_key ||= ''
if open_ai_key.empty?
open_ai_key = PWN::Plugins::AuthenticationHelper.mask_password(
prompt: 'OpenAI API Key'
)
pi.config.pwn_gpt_key = open_ai_key
pi.config.pwn_ai_key = open_ai_key
end

response_history = pi.config.pwn_gpt_response_history
speak_answer = pi.config.pwn_gpt_speak
response_history = pi.config.pwn_ai_response_history
speak_answer = pi.config.pwn_ai_speak
response = PWN::Plugins::OpenAI.chat(
token: open_ai_key,
request: request.chomp,
Expand All @@ -360,7 +360,7 @@ begin
pp response_history
puts "\nresponse_history[:choices] Length: #{response_history[:choices].length}\n" unless response_history.nil?
end
pi.config.pwn_gpt_response_history = response_history
pi.config.pwn_ai_response_history = response_history
end
end

Expand Down
2 changes: 2 additions & 0 deletions etc/pwn.yaml.EXAMPLE
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
# ai_engine: 'openai' || 'ollama'
ai_engine: 'openai'
open_ai_key: 'OPEN_AI_API_KEY'
2 changes: 1 addition & 1 deletion lib/pwn/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module PWN
VERSION = '0.5.60'
VERSION = '0.5.61'
end