Files
metasploit-gs/lib/msf/core/exception.rb
T

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

325 lines
6.0 KiB
Ruby
Raw Normal View History

# -*- coding: binary -*-
2020-09-22 02:56:51 +01:00
require 'rex/exceptions'
2005-05-21 17:57:00 +00:00
module Msf
2005-06-04 18:55:20 +00:00
###
#
# Mixin that should be included in all exceptions that can be raised from the
2005-06-04 18:55:20 +00:00
# framework so that they can be universally caught. Framework exceptions
# automatically extended Rex exceptions
#
###
module Exception
include Rex::Exception
2005-05-21 17:57:00 +00:00
end
2005-06-04 19:45:47 +00:00
###
#
# This exception is raised when one or more options failed
2005-06-04 19:45:47 +00:00
# to pass data store validation. The list of option names
# can be obtained through the options attribute.
#
2021-06-03 11:43:09 +01:00
# A human readable error can be associated with each option,
# which can contain additional detail / context on why the
# option validation failed.
#
2005-06-04 19:45:47 +00:00
###
class OptionValidateError < ArgumentError
2021-06-03 11:43:09 +01:00
2005-06-04 19:45:47 +00:00
include Exception
2021-06-03 11:43:09 +01:00
def initialize(options = [], reasons: {}, message: nil)
if options.is_a?(Hash)
@options = options.keys
@reasons = options
else
@options = options
@reasons = reasons
end
@reasons = @reasons.transform_values { |value| Array(value) }
super(message || "The following options failed to validate: #{@options.join(', ')}.")
2005-06-04 19:45:47 +00:00
end
2021-06-03 11:43:09 +01:00
attr_reader :options, :reasons
2005-06-04 19:45:47 +00:00
end
###
#
# This exception is raised when something failed to validate properly.
#
###
class ValidationError < ArgumentError
include Exception
def initialize(msg="One or more requirements could not be validated.")
super(msg)
end
end
###
#
2019-03-11 22:08:52 -05:00
# This exception is raised when the module cache is invalidated. It is
# handled internally by the ModuleManager.
#
###
class ModuleCacheInvalidated < RuntimeError
end
2005-06-04 19:45:47 +00:00
##
#
# Encoding exceptions
#
##
###
#
# This exception is raised to indicate that an encoding error of some sort has
# occurred.
#
###
2005-06-04 18:55:20 +00:00
class EncodingError < RuntimeError
include Exception
def initialize(msg = "An encoding exception occurred.")
super(msg)
end
2005-06-04 18:55:20 +00:00
end
###
#
2005-05-21 17:57:00 +00:00
# Thrown when an encoder fails to find a viable encoding key.
#
###
2005-06-04 18:55:20 +00:00
class NoKeyError < EncodingError
def initialize(msg="A valid encoding key could not be found.")
super(msg)
end
2005-05-21 17:57:00 +00:00
end
###
#
# Thrown when an encoder fails to encode a buffer due to a bad character.
#
###
2005-06-04 18:55:20 +00:00
class BadcharError < EncodingError
2005-06-04 21:01:17 +00:00
def initialize(buf = nil, index = nil, stub_size = nil, char = nil)
2005-05-21 17:57:00 +00:00
@buf = buf
@index = index
@stub_size = stub_size
@char = char
end
2013-08-30 16:28:33 -05:00
def to_s
# Deal with elements of a String being an instance of String instead of
# Integer in ruby 1.9.
if (char.respond_to? :ord)
c = char.ord
2011-11-20 12:10:08 +11:00
else
c = char
end
if (c)
return "Encoding failed due to a bad character (index=#{index}, char=#{sprintf("0x%.2x", c)})"
else
return "Encoding failed due to a nil character"
end
end
2013-08-30 16:28:33 -05:00
2005-05-21 17:57:00 +00:00
attr_reader :buf, :index, :stub_size, :char
end
###
#
# This exception is raised when no encoders succeed to encode a buffer.
#
###
class NoEncodersSucceededError < EncodingError
def initialize(msg="No encoders encoded the buffer successfully.")
super(msg)
end
end
2006-04-26 05:14:55 +00:00
###
#
# Thrown when an encoder fails to generate a valid opcode sequence.
#
###
class BadGenerateError < EncodingError
def initialize(msg="A valid opcode permutation could not be found.")
super(msg)
2006-04-26 05:14:55 +00:00
end
end
2005-06-04 19:45:47 +00:00
##
#
# Exploit exceptions
#
##
###
#
# This exception is raised to indicate a general exploitation error.
#
###
2005-06-04 21:01:17 +00:00
module ExploitError
2005-06-04 18:55:20 +00:00
include Exception
2005-06-04 21:01:17 +00:00
def initialize(msg="An exploitation error occurred.")
super(msg)
2005-06-04 21:01:17 +00:00
end
2005-05-21 17:57:00 +00:00
end
2006-03-09 17:28:37 +00:00
###
#
# This exception is raised to indicate a general auxiliary error.
#
###
module AuxiliaryError
include Exception
def initialize(msg="An auxiliary error occurred.")
super(msg)
2006-03-09 17:28:37 +00:00
end
end
###
#
# This exception is raised if a target was not specified when attempting to
# exploit something.
#
###
class MissingTargetError < ArgumentError
include ExploitError
def initialize(msg="A target has not been selected.")
super(msg)
end
end
###
#
# This exception is raised if a payload was not specified when attempting to
# exploit something.
#
###
class MissingPayloadError < ArgumentError
include ExploitError
def initialize(msg="A payload has not been selected.")
super(msg)
end
end
2006-03-09 17:28:37 +00:00
###
#
# This exception is raised if a valid action was not specified when attempting to
# run an auxiliary module.
#
###
class MissingActionError < ArgumentError
include AuxiliaryError
2014-12-04 17:07:59 -06:00
attr_accessor :reason
def initialize(reason='')
@reason = reason
super("Invalid action: #{@reason}")
2006-03-09 17:28:37 +00:00
end
end
###
#
# This exception is raised if an incompatible payload was specified when
# attempting to exploit something.
#
###
class IncompatiblePayloadError < ArgumentError
include ExploitError
def initialize(pname = nil)
@pname = pname
super("#{pname} is not a compatible payload.")
end
#
# The name of the payload that was used.
#
attr_reader :pname
end
2006-08-26 02:13:25 +00:00
class NoCompatiblePayloadError < ArgumentError
include Exception
end
##
#
# NOP exceptions
#
##
###
#
# This exception is raised to indicate that a general NOP error occurred.
#
###
module NopError
include Exception
def initialize(msg="A NOP generator error occurred.")
super(msg)
end
end
###
#
# This exception is raised when no NOP generators succeed at generating a
# sled.
#
###
class NoNopsSucceededError < RuntimeError
include NopError
def initialize(msg="No NOP generators succeeded.")
super(msg)
end
end
2006-04-02 22:33:34 +00:00
##
#
# Plugin exceptions
#
##
class PluginLoadError < RuntimeError
include Exception
attr_accessor :reason
def initialize(reason='')
@reason = reason
super("This plugin failed to load: #{reason}")
2006-04-02 22:33:34 +00:00
end
end
##
#
# This exception is raised if a payload option string exceeds the maximum
# allowed size during the payload generation.
#
##
class PayloadItemSizeError < ArgumentError
include Exception
def initialize(item = nil, max_size = nil)
@item = item
@max_size = max_size
end
def to_s
"Option value: #{item.slice(0..30)} is too big (Current length: #{item.length}, Maximum length: #{max_size})."
end
attr_reader :item # The content of the payload option (for example a URL)
attr_reader :max_size # The maximum allowed size of the payload option
end
end