Class: Ronin::Payloads::CLI::Commands::Build Private

Inherits:
PayloadCommand show all
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

FormatOption::FORMATS

Instance Attribute Summary collapse

Attributes included from FormatOption

#format

Attributes inherited from PayloadCommand

#payload, #payload_class

Instance Method Summary collapse

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.

Parameters:

  • kwargs (Hash{Symbol => Object})

    Additional keyword arguments.



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_idsArray<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.

Returns:

  • (Array<String>)


100
101
102
# File 'lib/ronin/payloads/cli/commands/build.rb', line 100

def encoder_ids
  @encoder_ids
end

#encoder_paramsHash{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.

Returns:

  • (Hash{String => Hash{String => String}})


105
106
107
# File 'lib/ronin/payloads/cli/commands/build.rb', line 105

def encoder_params
  @encoder_params
end

Instance Method Details

#build_payloadObject

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.message}"
  exit(-1)
rescue => error
  print_exception(error)
  print_error "an unhandled exception occurred while building the payload #{@payload.class_id}"
  exit(-1)
end

#built_payloadString

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.

Returns:

  • (String)


180
181
182
# File 'lib/ronin/payloads/cli/commands/build.rb', line 180

def built_payload
  @payload.built_payload
end

#encoded_payloadString

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.

Returns:

  • (String)


189
190
191
# File 'lib/ronin/payloads/cli/commands/build.rb', line 189

def encoded_payload
  @payload.encoded_payload
end

#initialize_payloadObject

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_encodersObject

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

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.

Parameters:

  • name (String, nil) (defaults to: nil)

    The name of the payload to load.



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 options[:output] then write_payload
  else                     print_payload
  end
end

#write_payloadObject

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(options[:output],format_data(encoded_payload))
end