Module: Ronin::Payloads::CLI::PayloadMethods Private

Included in:
PayloadCommand
Defined in:
lib/ronin/payloads/cli/payload_methods.rb

Overview

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

Common methods for working with payloads.

Instance Method Summary collapse

Instance Method Details

#initialize_payload(payload_class, **kwargs) ⇒ Payload

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

Parameters:

  • payload_class (Class<Payload>)

    The encoder class.

  • kwargs (Hash{Symbol => Object})

    Additional keyword arguments for Payload#initialize.

Returns:

  • (Payload)

    The initialized payload object.



85
86
87
88
89
90
91
92
93
94
# File 'lib/ronin/payloads/cli/payload_methods.rb', line 85

def initialize_payload(payload_class,**kwargs)
  payload_class.new(**kwargs)
rescue Core::Params::ParamError => error
  print_error(error.message)
  exit(1)
rescue => error
  print_exception(error)
  print_error("an unhandled exception occurred while initializing payload #{payload_class.id}")
  exit(-1)
end

#load_payload(name) ⇒ Class<Payload>

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 a payload class.

Parameters:

  • name (String)

    The payload name to load.

Returns:

  • (Class<Payload>)

    The loaded payload class.



42
43
44
45
46
47
48
49
50
51
# File 'lib/ronin/payloads/cli/payload_methods.rb', line 42

def load_payload(name)
  Payloads.load_class(name)
rescue Payloads::ClassNotFound => error
  print_error(error.message)
  exit(1)
rescue => error
  print_exception(error)
  print_error("an unhandled exception occurred while loading payload #{name}")
  exit(-1)
end

#load_payload_from(file) ⇒ Class<Payload>

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 payload from a given file.

Parameters:

  • file (String)

    The file to load the payload class from.

Returns:

  • (Class<Payload>)

    The loaded payload class.



62
63
64
65
66
67
68
69
70
71
# File 'lib/ronin/payloads/cli/payload_methods.rb', line 62

def load_payload_from(file)
  Payloads.load_class_from_file(file)
rescue Payloads::ClassNotFound => error
  print_error(error.message)
  exit(1)
rescue => error
  print_exception(error)
  print_error("an unhandled exception occurred while loading payload from file #{file}")
  exit(-1)
end

#validate_payload(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.

Validates the loaded payload.

Parameters:

  • payload (Payload)

    The payload to validate.

Raises:

  • (Ronin::Core::Params::RequiredParam)

    One of the required params was not set.

  • (ValidationError)

    Another payload validation error occurred.



108
109
110
111
112
113
114
115
116
117
# File 'lib/ronin/payloads/cli/payload_methods.rb', line 108

def validate_payload(payload)
  payload.perform_validate
rescue Core::Params::ParamError, ValidationError => error
  print_error("failed to validate the payload #{payload.class_id}: #{error.message}")
  exit(1)
rescue => error
  print_exception(error)
  print_error("an unhandled exception occurred while validating the payload #{payload.class_id}")
  exit(-1)
end