2005-12-13 06:22:56 +00:00
|
|
|
module Rex
|
|
|
|
module Proto
|
|
|
|
module DCERPC
|
|
|
|
module Exceptions
|
|
|
|
|
|
|
|
class Error < ::RuntimeError
|
2006-01-27 05:29:06 +00:00
|
|
|
@@errors = {}
|
2005-12-13 06:22:56 +00:00
|
|
|
def initialize(*args)
|
|
|
|
super(*args)
|
2006-01-27 05:29:06 +00:00
|
|
|
if @@errors.size == 0
|
|
|
|
_load_errors(File.join(File.dirname(__FILE__),'errors.txt'))
|
|
|
|
end
|
2005-12-13 06:22:56 +00:00
|
|
|
end
|
|
|
|
|
2006-01-27 05:29:06 +00:00
|
|
|
# loads errors.txt
|
|
|
|
def _load_errors(file)
|
|
|
|
File.open(file).each { |line|
|
|
|
|
next if line =~ /^#/
|
|
|
|
code, string = line.split
|
|
|
|
code = [code].pack('H*').unpack('L')[0]
|
|
|
|
@@errors[code] = string
|
|
|
|
}
|
|
|
|
end
|
2005-12-13 06:22:56 +00:00
|
|
|
|
2006-01-27 05:29:06 +00:00
|
|
|
# returns an error string if it exists, otherwise just the error code
|
|
|
|
def get_error (error)
|
|
|
|
string = ''
|
|
|
|
if @@errors[error]
|
|
|
|
string = @@errors[error]
|
|
|
|
else
|
|
|
|
string = sprintf('0x%.8x',error)
|
|
|
|
end
|
|
|
|
end
|
2005-12-13 06:22:56 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
class Fault < Error
|
|
|
|
attr_accessor :fault
|
2006-01-27 05:29:06 +00:00
|
|
|
def to_s
|
|
|
|
'DCERPC FAULT => ' + get_error(self.fault)
|
|
|
|
end
|
2005-12-13 06:22:56 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
class NoResponse < Error
|
2006-01-27 05:29:06 +00:00
|
|
|
def to_s
|
|
|
|
'no response from dcerpc service'
|
|
|
|
end
|
2005-12-13 06:22:56 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
class InvalidPacket < Error
|
2006-01-27 05:29:06 +00:00
|
|
|
def initialize(message = nil)
|
|
|
|
@message = message
|
|
|
|
end
|
|
|
|
|
|
|
|
def to_s
|
|
|
|
str = 'Invalid packet.'
|
|
|
|
if (@message)
|
|
|
|
str += " #{@message}"
|
|
|
|
end
|
|
|
|
end
|
2005-12-13 06:22:56 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|