Class: Ronin::Payloads::Payload

Inherits:
Object
  • Object
show all
Includes:
Cacheable, Model::HasDescription, Model::HasLicense, Model::HasName, Model::HasVersion, Parameters, Controls::Behaviors, Model::TargetsArch, Model::TargetsOS, UI::Output::Helpers
Defined in:
lib/ronin/payloads/payload.rb

Direct Known Subclasses

BinaryPayload, WebPayload

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Controls::Behaviors

#behaviors, #control, #control_helper, #control_model, #load_original!

Methods included from Model::TargetsOS

included

Methods included from Model::TargetsArch

included

Constructor Details

#initialize(attributes = {}) { ... } ⇒ Payload

Creates a new Payload object.

Parameters:

  • attributes (Array) (defaults to: {})

    Additional attributes to initialize the payload with.

Yields:

  • If a block is given, it will be evaluated in the newly created Payload object.



92
93
94
95
96
97
98
99
100
101
# File 'lib/ronin/payloads/payload.rb', line 92

def initialize(attributes={},&block)
  super(attributes)

  initialize_params(attributes)

  @built = false
  @deployed = false

  instance_eval(&block) if block
end

Instance Attribute Details

#exploitObject

The exploit to deploy with



77
78
79
# File 'lib/ronin/payloads/payload.rb', line 77

def exploit
  @exploit
end

#raw_payloadObject

The raw payload



80
81
82
# File 'lib/ronin/payloads/payload.rb', line 80

def raw_payload
  @raw_payload
end

Class Method Details

.written_by(name) ⇒ Array<Payload>

Finds all payloads written by a specific author.

Parameters:

  • name (String)

    The name of the author.

Returns:

  • (Array<Payload>)

    The payload written by the author.



112
113
114
# File 'lib/ronin/payloads/payload.rb', line 112

def self.written_by(name)
  all(self.authors.name.like => "%#{name}%")
end

.written_for(name) ⇒ Array<Payload>

Finds all payloads written for a specific organization.

Parameters:

  • name (String)

    The name of the organization.

Returns:

  • (Array<Payload>)

    The payloads written for the organization.



125
126
127
# File 'lib/ronin/payloads/payload.rb', line 125

def self.written_for(name)
  all(self.authors.organization.like => "%#{name}%")
end

Instance Method Details

#author(attributes = {}) {|author| ... } ⇒ Object

Adds a new author to the payload.

Examples:

author :name => 'Anonymous',
       :email => '[email protected]',
       :organization => 'Anonymous LLC'

Parameters:

  • attributes (Hash) (defaults to: {})

    Additional attributes to create the PayloadAuthor object with.

Yields:

  • (author)

    If a block is given, it will be passed the newly created author object.

Yield Parameters:

  • author (PayloadAuthor)

    The author object tied to the payload.



147
148
149
# File 'lib/ronin/payloads/payload.rb', line 147

def author(attributes={},&block)
  self.authors << PayloadAuthor.new(attributes,&block)
end

#build!(options = {}) {|payload| ... } ⇒ String

Builds the payload.

Parameters:

  • options (Hash) (defaults to: {})

    Additional options to build the payload with and use as parameters.

Yields:

  • (payload)

    If a block is given, it will be yielded the result of the payload building.

Yield Parameters:

  • payload (String)

    The built payload.

Returns:

  • (String)

    The built payload.



176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
# File 'lib/ronin/payloads/payload.rb', line 176

def build!(options={},&block)
  self.params = options

  print_debug "Payload parameters: #{self.params.inspect}"

  @built = false
  @raw_payload = ''

  print_info "Building payload ..."

  build()

  print_info "Payload built!"

  @built = true

  if block
    if block.arity == 1
      block.call(self)
    else
      block.call()
    end
  end

  return self
end

#built?Boolean

Returns Specifies whether the payload is built.

Returns:

  • (Boolean)

    Specifies whether the payload is built.



155
156
157
# File 'lib/ronin/payloads/payload.rb', line 155

def built?
  @built == true
end

#deploy! {|payload| ... } ⇒ Object

Verifies the built payload and deploys the payload.

Yields:

  • (payload)

    If a block is given, it will be passed the deployed payload.

Yield Parameters:

  • payload (Payload)

    The deployed payload.



232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
# File 'lib/ronin/payloads/payload.rb', line 232

def deploy!(&block)
  # verify the payload
  verify!

  print_info "Deploying payload ..."
  @deployed = false

  deploy()

  print_info "Payload deployed!"
  @deployed = true
  
  if block
    if block.arity == 1
      block.call(self)
    else
      block.call()
    end
  end

  return self
end

#deployed?Boolean

Returns Specifies whether the payload has previously been deployed.

Returns:

  • (Boolean)

    Specifies whether the payload has previously been deployed.



219
220
221
# File 'lib/ronin/payloads/payload.rb', line 219

def deployed?
  @deployed == true
end

#inspectString

Inspects the contents of the payload.

Returns:

  • (String)

    The inspected payload.



277
278
279
280
281
282
# File 'lib/ronin/payloads/payload.rb', line 277

def inspect
  str = "#{self.class}: #{self}"
  str << " #{self.params.inspect}" unless self.params.empty?

  return "#<#{str}>"
end

#to_sString

Converts the payload to a String.

Returns:

  • (String)

    The name and version of the payload.



261
262
263
264
265
266
267
268
269
# File 'lib/ronin/payloads/payload.rb', line 261

def to_s
  if (self.name && self.version)
    "#{self.name} #{self.version}"
  elsif self.name
    self.name
  elsif self.version
    self.version
  end
end

#verify!Object

Verifies the payload is properly configured and ready to be deployed.



207
208
209
210
211
212
213
# File 'lib/ronin/payloads/payload.rb', line 207

def verify!
  print_info "Verifying payload ..."

  verify

  print_info "Payload verified!"
end