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.



114
115
116
117
118
119
# File 'lib/ronin/payloads/cli/commands/build.rb', line 114

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>)


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

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}})


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

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.



165
166
167
168
169
170
171
172
173
174
# File 'lib/ronin/payloads/cli/commands/build.rb', line 165

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)


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

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)


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

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.



158
159
160
# File 'lib/ronin/payloads/cli/commands/build.rb', line 158

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.



144
145
146
147
148
149
150
151
152
153
# File 'lib/ronin/payloads/cli/commands/build.rb', line 144

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.



204
205
206
# File 'lib/ronin/payloads/cli/commands/build.rb', line 204

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.



127
128
129
130
131
132
133
134
135
136
137
138
# File 'lib/ronin/payloads/cli/commands/build.rb', line 127

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.



197
198
199
# File 'lib/ronin/payloads/cli/commands/build.rb', line 197

def write_payload
  File.binwrite(options[:output],format_data(encoded_payload))
end