2005-07-09 21:18:49 +00:00
|
|
|
require 'msf/core'
|
2005-06-04 18:55:20 +00:00
|
|
|
|
2005-05-21 17:57:00 +00:00
|
|
|
module Msf
|
|
|
|
|
2005-06-04 18:55:20 +00:00
|
|
|
###
|
|
|
|
#
|
2005-11-02 16:49:45 +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
|
|
|
###
|
|
|
|
#
|
2005-11-02 16:49:45 +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.
|
|
|
|
#
|
|
|
|
###
|
|
|
|
class OptionValidateError < ArgumentError
|
|
|
|
include Exception
|
|
|
|
|
2005-06-04 21:01:17 +00:00
|
|
|
def initialize(options = [])
|
2005-06-04 19:45:47 +00:00
|
|
|
@options = options
|
|
|
|
end
|
|
|
|
|
|
|
|
def to_s
|
2005-06-04 21:01:17 +00:00
|
|
|
"The following options failed to validate: #{options.join(', ')}."
|
2005-06-04 19:45:47 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
attr_reader :options
|
|
|
|
end
|
|
|
|
|
2005-11-02 16:49:45 +00:00
|
|
|
###
|
|
|
|
#
|
|
|
|
# This exception is raised when something failed to validate properly.
|
|
|
|
#
|
|
|
|
###
|
2005-07-13 18:06:12 +00:00
|
|
|
class ValidationError < ArgumentError
|
|
|
|
include Exception
|
|
|
|
|
|
|
|
def to_s
|
|
|
|
"One or more requirements could not be validated."
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2006-02-21 03:10:58 +00: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
|
|
|
|
#
|
|
|
|
##
|
|
|
|
|
2005-11-02 16:49:45 +00:00
|
|
|
###
|
|
|
|
#
|
|
|
|
# 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
|
2005-07-10 19:35:46 +00:00
|
|
|
|
|
|
|
def to_s
|
|
|
|
"A encoding exception occurred."
|
|
|
|
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
|
2005-07-10 19:35:46 +00:00
|
|
|
def to_s
|
|
|
|
"A valid encoding key could not be found."
|
|
|
|
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
|
|
|
|
|
2005-07-10 19:35:46 +00:00
|
|
|
def to_s
|
|
|
|
"Encoding failed due to a bad character (index=#{index}, char=#{sprintf("0x%.2x", char)})"
|
|
|
|
end
|
|
|
|
|
2005-05-21 17:57:00 +00:00
|
|
|
attr_reader :buf, :index, :stub_size, :char
|
|
|
|
end
|
|
|
|
|
2005-11-02 16:49:45 +00:00
|
|
|
###
|
|
|
|
#
|
|
|
|
# This exception is raised when no encoders succeed to encode a buffer.
|
|
|
|
#
|
|
|
|
###
|
2005-07-13 18:06:12 +00:00
|
|
|
class NoEncodersSucceededError < EncodingError
|
|
|
|
|
|
|
|
def to_s
|
|
|
|
"No encoders encoded the buffer successfully."
|
|
|
|
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 to_s
|
|
|
|
"A valid opcode permutation could not be found."
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2005-06-04 19:45:47 +00:00
|
|
|
##
|
|
|
|
#
|
|
|
|
# Exploit exceptions
|
|
|
|
#
|
|
|
|
##
|
|
|
|
|
2005-11-02 16:49:45 +00:00
|
|
|
###
|
|
|
|
#
|
|
|
|
# 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 to_s
|
|
|
|
"An exploitation error occurred."
|
|
|
|
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 to_s
|
|
|
|
"An auxiliary error occurred."
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2005-11-02 16:49:45 +00:00
|
|
|
###
|
|
|
|
#
|
|
|
|
# This exception is raised if a target was not specified when attempting to
|
|
|
|
# exploit something.
|
|
|
|
#
|
|
|
|
###
|
2005-07-13 18:06:12 +00:00
|
|
|
class MissingTargetError < ArgumentError
|
|
|
|
include ExploitError
|
|
|
|
|
|
|
|
def to_s
|
|
|
|
"A target has not been selected."
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2005-11-02 16:49:45 +00:00
|
|
|
###
|
|
|
|
#
|
|
|
|
# This exception is raised if a payload was not specified when attempting to
|
|
|
|
# exploit something.
|
|
|
|
#
|
|
|
|
###
|
2005-07-13 18:06:12 +00:00
|
|
|
class MissingPayloadError < ArgumentError
|
|
|
|
include ExploitError
|
|
|
|
|
|
|
|
def to_s
|
|
|
|
"A payload has not been selected."
|
|
|
|
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
|
|
|
|
|
|
|
|
def to_s
|
|
|
|
"A valid action has not been selected."
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2005-11-02 16:49:45 +00:00
|
|
|
###
|
|
|
|
#
|
|
|
|
# This exception is raised if an incompatible payload was specified when
|
|
|
|
# attempting to exploit something.
|
|
|
|
#
|
|
|
|
###
|
2005-07-13 18:06:12 +00:00
|
|
|
class IncompatiblePayloadError < ArgumentError
|
|
|
|
include ExploitError
|
|
|
|
|
|
|
|
def initialize(pname = nil)
|
|
|
|
@pname = pname
|
|
|
|
end
|
|
|
|
|
|
|
|
def to_s
|
|
|
|
"#{pname} is not a compatible payload."
|
|
|
|
end
|
|
|
|
|
2005-11-02 16:49:45 +00:00
|
|
|
#
|
|
|
|
# The name of the payload that was used.
|
|
|
|
#
|
2005-07-13 18:06:12 +00:00
|
|
|
attr_reader :pname
|
|
|
|
end
|
|
|
|
|
2006-08-26 02:13:25 +00:00
|
|
|
class NoCompatiblePayloadError < ArgumentError
|
|
|
|
include Exception
|
|
|
|
end
|
|
|
|
|
2005-07-13 18:06:12 +00:00
|
|
|
##
|
|
|
|
#
|
|
|
|
# NOP exceptions
|
|
|
|
#
|
|
|
|
##
|
|
|
|
|
2005-11-02 16:49:45 +00:00
|
|
|
###
|
|
|
|
#
|
|
|
|
# This exception is raised to indicate that a general NOP error occurred.
|
|
|
|
#
|
|
|
|
###
|
2005-07-13 18:06:12 +00:00
|
|
|
module NopError
|
|
|
|
include Exception
|
|
|
|
|
|
|
|
def to_s
|
|
|
|
"A NOP generator error occurred."
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2005-11-02 16:49:45 +00:00
|
|
|
###
|
|
|
|
#
|
|
|
|
# This exception is raised when no NOP generators succeed at generating a
|
|
|
|
# sled.
|
|
|
|
#
|
|
|
|
###
|
2005-07-13 18:06:12 +00:00
|
|
|
class NoNopsSucceededError < RuntimeError
|
|
|
|
include NopError
|
|
|
|
|
|
|
|
def to_s
|
|
|
|
"No NOP generators succeeded."
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2006-04-02 22:33:34 +00:00
|
|
|
##
|
|
|
|
#
|
|
|
|
# Plugin exceptions
|
|
|
|
#
|
|
|
|
##
|
|
|
|
|
|
|
|
class PluginLoadError < RuntimeError
|
|
|
|
include Exception
|
|
|
|
attr_accessor :reason
|
|
|
|
|
|
|
|
def initialize(reason='')
|
|
|
|
self.reason = reason
|
|
|
|
super
|
|
|
|
end
|
|
|
|
|
|
|
|
def to_s
|
|
|
|
"This plugin failed to load: #{reason.to_s}"
|
|
|
|
end
|
|
|
|
end
|
2005-07-13 18:06:12 +00:00
|
|
|
|
2008-10-19 21:03:39 +00:00
|
|
|
end
|