lib/ronin/exploits/cli/commands/run.rb in ronin-exploits-1.0.0 vs lib/ronin/exploits/cli/commands/run.rb in ronin-exploits-1.0.1
- old
+ new
@@ -1,5 +1,6 @@
+# frozen_string_literal: true
#
# ronin-exploits - A Ruby library for ronin-rb that provides exploitation and
# payload crafting functionality.
#
# Copyright (c) 2007-2023 Hal Brodigan (postmodern.mod3 at gmail.com)
@@ -90,11 +91,11 @@
desc: 'Builds the exploit but does not launch it'
# Payload options
option :payload_file, value: {
type: String,
- usage: 'FILE',
+ usage: 'FILE'
},
desc: 'Load the payload from the given Ruby file'
option :read_payload, value: {
type: String,
usage: 'FILE'
@@ -128,31 +129,31 @@
option :encoder_file, value: {
type: String,
usage: 'FILE'
},
desc: 'Load the payload encoder from the Ruby file' do |file|
- @load_encoders << [:file, file]
+ @encoders_to_load << [:file, file]
end
option :encoder, short: '-E',
value: {
type: String,
usage: 'NAME'
},
desc: 'Loads the payload encoder by name' do |name|
- @load_encoders << [:name, name]
+ @encoders_to_load << [:name, name]
end
option :encoder_param, value: {
type: /\A[^\.\=\s]+\.[^=\s]+=.+\z/,
usage: 'ENCODER.NAME=VALUE'
},
- desc: 'Sets a param on the ENCODER' do
+ desc: 'Sets a param on the ENCODER' do |str|
prefix, value = str.split('=',2)
- ecndoer, name = prefix.split('.',2)
+ encoder, name = prefix.split('.',2)
- @encodeer_params[encoder][name] = value
+ @encoder_params[encoder][name.to_sym] = value
end
# Target options
option :target, short: '-t',
value: {
@@ -219,23 +220,43 @@
description 'Runs an exploit'
man_page 'ronin-exploits-run.1'
+ # Thte encoder names and paths to load.
#
+ # @return [Array<(Symbol, String)>]
+ attr_reader :encoders_to_load
+
+ # The encoder params.
+ #
+ # @return [Hash{String => Hash{String => String}}]
+ attr_reader :encoder_params
+
+ # The payload params.
+ #
+ # @return [Hash{Hash{String => String}]
+ attr_reader :payload_params
+
+ # The keyword arguments to select a target with.
+ #
+ # @return [Hash{Hash{Symbol => Object}]
+ attr_reader :target_kwargs
+
+ #
# Initializes the `ronin-exploits run` command.
#
# @param [Hash{Symbol => Object}] kwargs
# Additional keyword arguments.
#
def initialize(**kwargs)
super(**kwargs)
- @load_encoders = []
- @encoder_params = Hash.new { |hash,key| hash[key] = {} }
- @payload_params = {}
- @target_kwargs = {}
+ @encoders_to_load = []
+ @encoder_params = Hash.new { |hash,key| hash[key] = {} }
+ @payload_params = {}
+ @target_kwargs = {}
end
#
# Runs the `ronin-exploits run` command.
#
@@ -266,11 +287,11 @@
#
# Loads the payload encoder classes specified by `--encoder` or
# `--encoder-file`.
#
def load_encoders
- @encoder_classes = @load_encoders.map do |(type,value)|
+ @encoder_classes = @encoders_to_load.map do |(type,value)|
case type
in :name then load_encoder(value)
in :file then load_encoder_from(value)
end
end
@@ -425,19 +446,17 @@
#
# Performs the cleanup stage of the exploit.
#
def perform_cleanup
- begin
- @exploit.perform_cleanup
- rescue ExploitError => error
- print_error "failed to cleanup exploit #{@exploit.class_id}: #{error.message}"
- exit(1)
- rescue => error
- print_exception(error)
- print_error "an unhandled exception occurred while cleaning up the exploit #{@exploit.class_id}"
- exit(-1)
- end
+ @exploit.perform_cleanup
+ rescue ExploitError => error
+ print_error "failed to cleanup exploit #{@exploit.class_id}: #{error.message}"
+ exit(1)
+ rescue => error
+ print_exception(error)
+ print_error "an unhandled exception occurred while cleaning up the exploit #{@exploit.class_id}"
+ exit(-1)
end
end
end
end