metasploit-framework/lib/msf/core/exceptions.rb

306 lines
4.9 KiB
Ruby
Raw Normal View History

# -*- coding: binary -*-
require 'msf/core'
module Msf
###
#
# Mixin that should be included in all exceptions that can be raised from the
# framework so that they can be universally caught. Framework exceptions
# automatically extended Rex exceptions
#
###
module Exception
2013-08-30 21:28:33 +00:00
include Rex::Exception
end
###
#
# This exception is raised when one or more options failed
# to pass data store validation. The list of option names
# can be obtained through the options attribute.
#
###
class OptionValidateError < ArgumentError
2013-08-30 21:28:33 +00:00
include Exception
2013-08-30 21:28:33 +00:00
def initialize(options = [])
@options = options
end
2013-08-30 21:28:33 +00:00
def to_s
"The following options failed to validate: #{options.join(', ')}."
end
2013-08-30 21:28:33 +00:00
attr_reader :options
end
###
#
# This exception is raised when something failed to validate properly.
#
###
class ValidationError < ArgumentError
2013-08-30 21:28:33 +00:00
include Exception
2013-08-30 21:28:33 +00:00
def to_s
"One or more requirements could not be validated."
end
end
###
#
# This exception is raised when the module cache is invalidated. It is
# handled internally by the ModuleManager.
#
###
class ModuleCacheInvalidated < RuntimeError
end
##
#
# Encoding exceptions
#
##
###
#
# This exception is raised to indicate that an encoding error of some sort has
# occurred.
#
###
class EncodingError < RuntimeError
2013-08-30 21:28:33 +00:00
include Exception
2013-08-30 21:28:33 +00:00
def to_s
"An encoding exception occurred."
end
end
###
#
# Thrown when an encoder fails to find a viable encoding key.
#
###
class NoKeyError < EncodingError
2013-08-30 21:28:33 +00:00
def to_s
"A valid encoding key could not be found."
end
end
###
#
# Thrown when an encoder fails to encode a buffer due to a bad character.
#
###
class BadcharError < EncodingError
2013-08-30 21:28:33 +00:00
def initialize(buf = nil, index = nil, stub_size = nil, char = nil)
@buf = buf
@index = index
@stub_size = stub_size
@char = char
end
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
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
attr_reader :buf, :index, :stub_size, :char
end
###
#
# This exception is raised when no encoders succeed to encode a buffer.
#
###
class NoEncodersSucceededError < EncodingError
2013-08-30 21:28:33 +00:00
def to_s
"No encoders encoded the buffer successfully."
end
end
###
#
# Thrown when an encoder fails to generate a valid opcode sequence.
#
###
class BadGenerateError < EncodingError
2013-08-30 21:28:33 +00:00
def to_s
"A valid opcode permutation could not be found."
end
end
##
#
# Exploit exceptions
#
##
###
#
# This exception is raised to indicate a general exploitation error.
#
###
module ExploitError
2013-08-30 21:28:33 +00:00
include Exception
2013-08-30 21:28:33 +00:00
def to_s
"An exploitation error occurred."
end
end
###
#
# This exception is raised to indicate a general auxiliary error.
#
###
module AuxiliaryError
2013-08-30 21:28:33 +00:00
include Exception
2013-08-30 21:28:33 +00:00
def to_s
"An auxiliary error occurred."
end
end
###
#
# This exception is raised if a target was not specified when attempting to
# exploit something.
#
###
class MissingTargetError < ArgumentError
2013-08-30 21:28:33 +00:00
include ExploitError
2013-08-30 21:28:33 +00:00
def to_s
"A target has not been selected."
end
end
###
#
# This exception is raised if a payload was not specified when attempting to
# exploit something.
#
###
class MissingPayloadError < ArgumentError
2013-08-30 21:28:33 +00:00
include ExploitError
2013-08-30 21:28:33 +00:00
def to_s
"A payload has not been selected."
end
end
###
#
# This exception is raised if a valid action was not specified when attempting to
# run an auxiliary module.
#
###
class MissingActionError < ArgumentError
2013-08-30 21:28:33 +00:00
include AuxiliaryError
attr_accessor :reason
def initialize(reason='')
self.reason = reason
super
end
2013-08-30 21:28:33 +00:00
def to_s
"Invalid action: #{reason}"
2013-08-30 21:28:33 +00:00
end
end
###
#
# This exception is raised if an incompatible payload was specified when
# attempting to exploit something.
#
###
class IncompatiblePayloadError < ArgumentError
2013-08-30 21:28:33 +00:00
include ExploitError
2013-08-30 21:28:33 +00:00
def initialize(pname = nil)
@pname = pname
end
2013-08-30 21:28:33 +00:00
def to_s
"#{pname} is not a compatible payload."
end
2013-08-30 21:28:33 +00:00
#
# The name of the payload that was used.
#
attr_reader :pname
end
class NoCompatiblePayloadError < ArgumentError
2013-08-30 21:28:33 +00:00
include Exception
end
##
#
# NOP exceptions
#
##
###
#
# This exception is raised to indicate that a general NOP error occurred.
#
###
module NopError
2013-08-30 21:28:33 +00:00
include Exception
2013-08-30 21:28:33 +00:00
def to_s
"A NOP generator error occurred."
end
end
###
#
# This exception is raised when no NOP generators succeed at generating a
# sled.
#
###
class NoNopsSucceededError < RuntimeError
2013-08-30 21:28:33 +00:00
include NopError
2013-08-30 21:28:33 +00:00
def to_s
"No NOP generators succeeded."
end
end
##
#
# Plugin exceptions
#
##
class PluginLoadError < RuntimeError
2013-08-30 21:28:33 +00:00
include Exception
attr_accessor :reason
2013-08-30 21:28:33 +00:00
def initialize(reason='')
self.reason = reason
super
end
2011-11-20 01:10:08 +00:00
2013-08-30 21:28:33 +00:00
def to_s
"This plugin failed to load: #{reason}"
end
end
end