Class: Ronin::Payloads::CLI::Commands::Build Private
- Inherits:
-
PayloadCommand
- Object
- Core::CLI::Command
- Ronin::Payloads::CLI::Command
- PayloadCommand
- Ronin::Payloads::CLI::Commands::Build
- Includes:
- Core::CLI::Options::Param, EncoderMethods, FormatOption
- Defined in:
- lib/ronin/payloads/cli/commands/build.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Loads and builds a payload.
Usage
ronin-payloads build [options] {-f FILE | NAME}
Options
-f, --file FILE The payload file to load
-F hex|c|shell|powershell|xml|html|js|ruby,
--format Formats the outputed data
-p, --param NAME=VALUE Sets a param
-o, --output FILE Output file to write the built payload to
-E, --encoder ENCODER Adds the encoder to the payload
--encoder-param ENCODER.NAME=VALUE
Sets a param for one of the encoders
-D, --debug Enables debugging messages
-h, --help Print help information
Arguments
[NAME] The payload name to load
Constant Summary
Constants included from FormatOption
Instance Attribute Summary collapse
-
#encoder_ids ⇒ Array<String>
readonly
private
The encoder names to load.
-
#encoder_params ⇒ Hash{String => Hash{String => String}}
readonly
private
The params for the encoders.
Attributes included from FormatOption
Attributes inherited from PayloadCommand
Instance Method Summary collapse
-
#build_payload ⇒ Object
private
Builds the PayloadCommand#payload.
-
#built_payload ⇒ String
private
The built payload.
-
#encoded_payload ⇒ String
private
The built and encoded payload.
-
#initialize(**kwargs) ⇒ Build
constructor
private
Initializes the
ronin-payloads build
command. -
#initialize_payload ⇒ Object
private
Initializes the payload with
--param
and--encoder
options. -
#load_encoders ⇒ Object
private
Loads the encoders using #encoder_ids which are populated by the
-E,--encoder
option. -
#print_payload ⇒ Object
private
Prints the built and optionally encoded payload.
-
#run(name = nil) ⇒ Object
private
Runs the
ronin-payloads build
command. -
#write_payload ⇒ Object
private
Writes the built and optionally encoded payload to the output file.
Methods included from EncoderMethods
#encoder_type, #initialize_encoder, #load_encoder, #load_encoder_from, #validate_encoder
Methods included from FormatOption
#format_data, included, #print_data
Methods inherited from PayloadCommand
#load_payload, #load_payload_from, #validate_payload
Methods included from PayloadMethods
#load_payload, #load_payload_from, #validate_payload
Constructor Details
#initialize(**kwargs) ⇒ Build
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Initializes the ronin-payloads build
command.
113 114 115 116 117 118 |
# File 'lib/ronin/payloads/cli/commands/build.rb', line 113 def initialize(**kwargs) super(**kwargs) @encoder_ids = [] @encoder_params = Hash.new { |hash,key| hash[key] = {} } end |
Instance Attribute Details
#encoder_ids ⇒ Array<String> (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
The encoder names to load.
100 101 102 |
# File 'lib/ronin/payloads/cli/commands/build.rb', line 100 def encoder_ids @encoder_ids end |
#encoder_params ⇒ Hash{String => Hash{String => String}} (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
The params for the encoders.
105 106 107 |
# File 'lib/ronin/payloads/cli/commands/build.rb', line 105 def encoder_params @encoder_params end |
Instance Method Details
#build_payload ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Builds the PayloadCommand#payload.
164 165 166 167 168 169 170 171 172 173 |
# File 'lib/ronin/payloads/cli/commands/build.rb', line 164 def build_payload @payload.perform_build rescue PayloadError => error print_error "failed to build the payload #{@payload_class.id}: #{error.}" exit(-1) rescue => error print_exception(error) print_error "an unhandled exception occurred while building the payload #{@payload.class_id}" exit(-1) end |
#built_payload ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
The built payload.
180 181 182 |
# File 'lib/ronin/payloads/cli/commands/build.rb', line 180 def built_payload @payload.built_payload end |
#encoded_payload ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
The built and encoded payload.
189 190 191 |
# File 'lib/ronin/payloads/cli/commands/build.rb', line 189 def encoded_payload @payload.encoded_payload end |
#initialize_payload ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Initializes the payload with --param
and --encoder
options.
157 158 159 |
# File 'lib/ronin/payloads/cli/commands/build.rb', line 157 def initialize_payload super(params: @params, encoders: @encoders) end |
#load_encoders ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Loads the encoders using #encoder_ids which are populated by
the -E,--encoder
option.
143 144 145 146 147 148 149 150 151 152 |
# File 'lib/ronin/payloads/cli/commands/build.rb', line 143 def load_encoders @encoders = @encoder_ids.map do |encoder_id| encoder_class = load_encoder(encoder_id) params = @encoder_params[encoder_id] encoder = initialize_encoder(encoder_class, params: params) validate_encoder(encoder) encoder end end |
#print_payload ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Prints the built and optionally encoded payload.
203 204 205 |
# File 'lib/ronin/payloads/cli/commands/build.rb', line 203 def print_payload print_data(@payload.encode_payload) end |
#run(name = nil) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Runs the ronin-payloads build
command.
126 127 128 129 130 131 132 133 134 135 136 137 |
# File 'lib/ronin/payloads/cli/commands/build.rb', line 126 def run(name=nil) super(name) load_encoders initialize_payload validate_payload build_payload if [:output] then write_payload else print_payload end end |
#write_payload ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Writes the built and optionally encoded payload to the output file.
196 197 198 |
# File 'lib/ronin/payloads/cli/commands/build.rb', line 196 def write_payload File.binwrite([:output],format_data(encoded_payload)) end |