Class: Ronin::Payloads::Payload
- Inherits:
-
Object
- Object
- Ronin::Payloads::Payload
- Includes:
- Core::Metadata::Authors, Core::Metadata::Description, Core::Metadata::ID, Core::Metadata::References, Core::Metadata::Summary, Core::Params::Mixin, Support::CLI::Printing
- Defined in:
- lib/ronin/payloads/payload.rb
Overview
The Payload class allows for describing payloads, which are delivered via exploits, purely in Ruby. Payloads contain metadata about the payload and methods which define the functionality of the payload. Payloads may also be coupled with exploits, or chained together with other payloads.
Payload API Methods
- initialize - Initializes a new instance of the payload.
- build - contains the logic to build the payload. The
built payload must be stored in the
@payload
instance variable. - prelaunch - contains additional logic that runs before the payload has been launched by the exploit.
- postlaunch - contains additional logic that runs after the payload has been launched by the exploit.
- cleanup - contains additional logic to cleanup or shutdown the payload.
Example
module Ronin
module Payloads
class MyPayload < Payload
register 'my_payload'
summary 'My first payload'
description <<~EOS
This is my first payload.
Bla bla bla bla.
EOS
'John Smith'
'John Smith', email: '...', twitter: '...'
param :foo, desc: 'Simple param'
param :bar, Integer, desc: 'A param iwth a typo'
def build
@payload = "..."
end
def prelaunch
# ...
end
def postlaunch
# ...
end
def cleanup
# ...
end
end
end
end
Direct Known Subclasses
BinaryPayload, ColdFusionPayload, CommandPayload, GroovyPayload, HTMLPayload, JSPPayload, JavaPayload, JavaScriptPayload, NodeJSPayload, PHPPayload, PowerShellPayload, PythonPayload, RubyPayload, SQLPayload, URLPayload, XMLPayload
Instance Attribute Summary collapse
-
#encoders ⇒ Encoders::Pipeline
readonly
The payload's encoder pipeline.
-
#payload ⇒ Object
readonly
The built payload.
String Methods collapse
-
#bytesize ⇒ Integer
(also: #size)
The size of the payload in bytes.
-
#length ⇒ Integer
The number of characters in the payload.
-
#to_s ⇒ String
(also: #to_str)
Converts the payload into a String.
Payload API Methods collapse
-
#build ⇒ Object
abstract
Builds the payload.
-
#cleanup ⇒ Object
abstract
Placeholder method to clean up the payload.
-
#postlaunch ⇒ Object
abstract
Placeholder method that runs after the payload is launched by the exploit.
-
#prelaunch ⇒ Object
abstract
Placeholder method that runs before the payload is launched by the exploit.
-
#validate ⇒ Object
abstract
Place holder method for additional validation logic.
Class Method Summary collapse
-
.encoder_class(new_encoder_class = nil) ⇒ Class<Encoders::Encoder>
Gets or sets the payload encoder base class that is compatible with the payload.
-
.payload_type ⇒ Symbol
private
Returns the type or kind of payload.
-
.register(payload_id) ⇒ Object
Registers the payload with Ronin::Payloads.
Instance Method Summary collapse
-
#built? ⇒ Boolean
Determines whether the payload was built.
-
#built_payload ⇒ String
The built payload String.
-
#encode_payload ⇒ String
Encodes the built payload.
-
#encoded_payload ⇒ String
The encoded payload.
-
#initialize(encoders: nil, **kwargs) ⇒ Payload
constructor
Initializes the payload.
-
#perform_build ⇒ Object
Builds the payload.
-
#perform_cleanup ⇒ Object
Performs the cleanup step.
-
#perform_postlaunch ⇒ Object
Performs the post-launch step.
-
#perform_prelaunch ⇒ Object
Performs the prelaunch step.
-
#perform_validate ⇒ Object
Validates that the payload is ready to be built.
-
#rebuild_payload ⇒ String
Forcibly rebuilds the payload.
-
#reencode_payload ⇒ String
Forcibly re-encodes the payload.
Constructor Details
#initialize(encoders: nil, **kwargs) ⇒ Payload
Initializes the payload.
179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 |
# File 'lib/ronin/payloads/payload.rb', line 179 def initialize(encoders: nil, **kwargs) super(**kwargs) @encoders = Encoders::Pipeline.new if encoders encoders.each do |encoder| unless encoder.kind_of?(self.class.encoder_class) raise(IncompatibleEncoder,"encoder for payload #{self.class} was not of type #{self.class.encoder_class}: #{encoder.inspect}") end @encoders << encoder end end end |
Instance Attribute Details
#encoders ⇒ Encoders::Pipeline (readonly)
The payload's encoder pipeline.
167 168 169 |
# File 'lib/ronin/payloads/payload.rb', line 167 def encoders @encoders end |
#payload ⇒ Object (readonly)
The built payload
162 163 164 |
# File 'lib/ronin/payloads/payload.rb', line 162 def payload @payload end |
Class Method Details
.encoder_class(new_encoder_class = nil) ⇒ Class<Encoders::Encoder>
Gets or sets the payload encoder base class that is compatible with the payload.
135 136 137 138 139 140 141 142 143 144 145 |
# File 'lib/ronin/payloads/payload.rb', line 135 def self.encoder_class(new_encoder_class=nil) if new_encoder_class @encoder_class = new_encoder_class else @encoder_class ||= if superclass < ClassMethods superclass.encoder_class else Encoders::Encoder end end end |
.payload_type ⇒ Symbol
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.
This is used internally to map an payload class to a printable type.
Returns the type or kind of payload.
157 158 159 |
# File 'lib/ronin/payloads/payload.rb', line 157 def self.payload_type :payload end |
.register(payload_id) ⇒ Object
The given id
must match the file name.
Registers the payload with Ronin::Payloads.
120 121 122 123 |
# File 'lib/ronin/payloads/payload.rb', line 120 def self.register(payload_id) id(payload_id) Payloads.register(payload_id,self) end |
Instance Method Details
#build ⇒ Object
Builds the payload.
399 400 |
# File 'lib/ronin/payloads/payload.rb', line 399 def build end |
#built? ⇒ Boolean
Determines whether the payload was built.
217 218 219 |
# File 'lib/ronin/payloads/payload.rb', line 217 def built? !(@payload.nil? || @payload.empty?) end |
#built_payload ⇒ String
This method will lazy-build the payload if unbuilt.
The built payload String.
246 247 248 249 250 |
# File 'lib/ronin/payloads/payload.rb', line 246 def built_payload perform_build unless built? return @payload end |
#bytesize ⇒ Integer Also known as: size
The size of the payload in bytes.
360 361 362 |
# File 'lib/ronin/payloads/payload.rb', line 360 def bytesize encoded_payload.bytesize end |
#cleanup ⇒ Object
Placeholder method to clean up the payload.
425 426 |
# File 'lib/ronin/payloads/payload.rb', line 425 def cleanup end |
#encode_payload ⇒ String
This method will return a new, potentially different, String each time.
Encodes the built payload.
273 274 275 |
# File 'lib/ronin/payloads/payload.rb', line 273 def encode_payload @encoders.encode(built_payload) end |
#encoded_payload ⇒ String
This method will lazy build then lazy encode the payload and save the result.
The encoded payload.
289 290 291 |
# File 'lib/ronin/payloads/payload.rb', line 289 def encoded_payload @encoded_payload ||= encode_payload end |
#length ⇒ Integer
The number of characters in the payload.
351 352 353 |
# File 'lib/ronin/payloads/payload.rb', line 351 def length encoded_payload.length end |
#perform_build ⇒ Object
Builds the payload.
228 229 230 231 232 233 234 235 236 |
# File 'lib/ronin/payloads/payload.rb', line 228 def perform_build @payload = nil build unless built? raise(PayloadNotBuilt,"the payload was not built for some reason: #{inspect}") end end |
#perform_cleanup ⇒ Object
Performs the cleanup step.
337 338 339 340 |
# File 'lib/ronin/payloads/payload.rb', line 337 def perform_cleanup cleanup @payload = nil end |
#perform_postlaunch ⇒ Object
Performs the post-launch step.
326 327 328 |
# File 'lib/ronin/payloads/payload.rb', line 326 def perform_postlaunch postlaunch end |
#perform_prelaunch ⇒ Object
Performs the prelaunch step.
315 316 317 |
# File 'lib/ronin/payloads/payload.rb', line 315 def perform_prelaunch prelaunch end |
#perform_validate ⇒ Object
Validates that the payload is ready to be built.
206 207 208 209 210 |
# File 'lib/ronin/payloads/payload.rb', line 206 def perform_validate validate_params @encoders.validate validate end |
#postlaunch ⇒ Object
Placeholder method that runs after the payload is launched by the exploit.
417 418 |
# File 'lib/ronin/payloads/payload.rb', line 417 def postlaunch end |
#prelaunch ⇒ Object
Placeholder method that runs before the payload is launched by the exploit.
408 409 |
# File 'lib/ronin/payloads/payload.rb', line 408 def prelaunch end |
#rebuild_payload ⇒ String
Forcibly rebuilds the payload.
258 259 260 261 |
# File 'lib/ronin/payloads/payload.rb', line 258 def rebuild_payload @payload = nil perform_build end |
#reencode_payload ⇒ String
This will re-encode the built payload and update #encoded_payload.
Forcibly re-encodes the payload.
304 305 306 |
# File 'lib/ronin/payloads/payload.rb', line 304 def reencode_payload @encoded_payload = encode_payload end |
#to_s ⇒ String Also known as: to_str
Converts the payload into a String.
374 375 376 |
# File 'lib/ronin/payloads/payload.rb', line 374 def to_s encoded_payload end |
#validate ⇒ Object
Place holder method for additional validation logic.
391 392 |
# File 'lib/ronin/payloads/payload.rb', line 391 def validate end |