Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/lib/msf/core/exception.rb
Views: 11777
# -*- coding: binary -*-1require 'rex/exceptions'2module Msf34###5#6# Mixin that should be included in all exceptions that can be raised from the7# framework so that they can be universally caught. Framework exceptions8# automatically extended Rex exceptions9#10###11module Exception12include Rex::Exception13end1415###16#17# This exception is raised when one or more options failed18# to pass data store validation. The list of option names19# can be obtained through the options attribute.20#21# A human readable error can be associated with each option,22# which can contain additional detail / context on why the23# option validation failed.24#25###26class OptionValidateError < ArgumentError2728include Exception2930def initialize(options = [], reasons: {}, message: nil)31if options.is_a?(Hash)32@options = options.keys33@reasons = options34else35@options = options36@reasons = reasons37end38@reasons = @reasons.transform_values { |value| Array(value) }3940super(message || "The following options failed to validate: #{@options.join(', ')}.")41end4243attr_reader :options, :reasons44end4546###47#48# This exception is raised when something failed to validate properly.49#50###51class ValidationError < ArgumentError52include Exception5354def initialize(msg="One or more requirements could not be validated.")55super(msg)56end57end5859###60#61# This exception is raised when the module cache is invalidated. It is62# handled internally by the ModuleManager.63#64###65class ModuleCacheInvalidated < RuntimeError66end6768##69#70# Encoding exceptions71#72##7374###75#76# This exception is raised to indicate that an encoding error of some sort has77# occurred.78#79###80class EncodingError < RuntimeError81include Exception8283def initialize(msg = "An encoding exception occurred.")84super(msg)85end86end8788###89#90# Thrown when an encoder fails to find a viable encoding key.91#92###93class NoKeyError < EncodingError94def initialize(msg="A valid encoding key could not be found.")95super(msg)96end97end9899###100#101# Thrown when an encoder fails to encode a buffer due to a bad character.102#103###104class BadcharError < EncodingError105def initialize(buf = nil, index = nil, stub_size = nil, char = nil)106@buf = buf107@index = index108@stub_size = stub_size109@char = char110end111112def to_s113# Deal with elements of a String being an instance of String instead of114# Integer in ruby 1.9.115if (char.respond_to? :ord)116c = char.ord117else118c = char119end120if (c)121return "Encoding failed due to a bad character (index=#{index}, char=#{sprintf("0x%.2x", c)})"122else123return "Encoding failed due to a nil character"124end125end126127attr_reader :buf, :index, :stub_size, :char128end129130###131#132# This exception is raised when no encoders succeed to encode a buffer.133#134###135class NoEncodersSucceededError < EncodingError136def initialize(msg="No encoders encoded the buffer successfully.")137super(msg)138end139end140141###142#143# Thrown when an encoder fails to generate a valid opcode sequence.144#145###146class BadGenerateError < EncodingError147def initialize(msg="A valid opcode permutation could not be found.")148super(msg)149end150end151152##153#154# Exploit exceptions155#156##157158###159#160# This exception is raised to indicate a general exploitation error.161#162###163module ExploitError164include Exception165166def initialize(msg="An exploitation error occurred.")167super(msg)168end169end170171###172#173# This exception is raised to indicate a general auxiliary error.174#175###176module AuxiliaryError177include Exception178179def initialize(msg="An auxiliary error occurred.")180super(msg)181end182end183184###185#186# This exception is raised if a target was not specified when attempting to187# exploit something.188#189###190class MissingTargetError < ArgumentError191include ExploitError192193def initialize(msg="A target has not been selected.")194super(msg)195end196end197198###199#200# This exception is raised if a payload was not specified when attempting to201# exploit something.202#203###204class MissingPayloadError < ArgumentError205include ExploitError206207def initialize(msg="A payload has not been selected.")208super(msg)209end210end211212###213#214# This exception is raised if a valid action was not specified when attempting to215# run an auxiliary module.216#217###218class MissingActionError < ArgumentError219include AuxiliaryError220attr_accessor :reason221222def initialize(reason='')223@reason = reason224super("Invalid action: #{@reason}")225end226end227228###229#230# This exception is raised if an incompatible payload was specified when231# attempting to exploit something.232#233###234class IncompatiblePayloadError < ArgumentError235include ExploitError236237def initialize(pname = nil)238@pname = pname239super("#{pname} is not a compatible payload.")240end241242#243# The name of the payload that was used.244#245attr_reader :pname246end247248class NoCompatiblePayloadError < ArgumentError249include Exception250end251252##253#254# NOP exceptions255#256##257258###259#260# This exception is raised to indicate that a general NOP error occurred.261#262###263module NopError264include Exception265266def initialize(msg="A NOP generator error occurred.")267super(msg)268end269end270271###272#273# This exception is raised when no NOP generators succeed at generating a274# sled.275#276###277class NoNopsSucceededError < RuntimeError278include NopError279280def initialize(msg="No NOP generators succeeded.")281super(msg)282end283end284285##286#287# Plugin exceptions288#289##290291class PluginLoadError < RuntimeError292include Exception293attr_accessor :reason294295def initialize(reason='')296@reason = reason297super("This plugin failed to load: #{reason}")298end299end300301##302#303# This exception is raised if a payload option string exceeds the maximum304# allowed size during the payload generation.305#306##307class PayloadItemSizeError < ArgumentError308include Exception309310def initialize(item = nil, max_size = nil)311@item = item312@max_size = max_size313end314315def to_s316"Option value: #{item.slice(0..30)} is too big (Current length: #{item.length}, Maximum length: #{max_size})."317end318319attr_reader :item # The content of the payload option (for example a URL)320attr_reader :max_size # The maximum allowed size of the payload option321end322323end324325326