2005-09-22 09:04:54 +00:00
|
|
|
module Rex
|
|
|
|
module Proto
|
|
|
|
module SMB
|
|
|
|
module Exceptions
|
|
|
|
|
|
|
|
|
|
|
|
class Error < ::RuntimeError
|
2006-01-27 05:28:16 +00:00
|
|
|
@@errors = {}
|
2005-09-22 09:04:54 +00:00
|
|
|
def initialize(*args)
|
|
|
|
super(*args)
|
2006-01-27 05:28:16 +00:00
|
|
|
if @@errors.size == 0
|
|
|
|
_load_errors(File.join(File.dirname(__FILE__),'errors.txt'))
|
|
|
|
end
|
2005-09-22 09:04:54 +00:00
|
|
|
end
|
2005-12-13 06:08:40 +00:00
|
|
|
|
2006-01-27 05:28:16 +00:00
|
|
|
# loads errors.txt
|
|
|
|
def _load_errors(file)
|
|
|
|
File.open(file).each { |line|
|
|
|
|
next if line =~ /^#/
|
|
|
|
code, string = line.split
|
2006-03-07 06:50:25 +00:00
|
|
|
code = [code].pack('H*').unpack('N')[0]
|
2006-01-27 05:28:16 +00:00
|
|
|
@@errors[code] = string
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
# 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-09-22 09:04:54 +00:00
|
|
|
end
|
|
|
|
|
2005-10-03 13:51:05 +00:00
|
|
|
class NoReply < Error
|
|
|
|
def to_s
|
|
|
|
"The SMB server did not reply to our request"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2005-09-22 09:04:54 +00:00
|
|
|
class ReadHeader < Error
|
|
|
|
def to_s
|
|
|
|
"The SMB response header was invalid"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
class ReadPacket < Error
|
|
|
|
def to_s
|
|
|
|
"The SMB response packet was invalid"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
class WritePacket < Error
|
|
|
|
def to_s
|
|
|
|
"The SMB packet failed to send"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2005-09-23 09:14:03 +00:00
|
|
|
class UnknownDialect < Error
|
|
|
|
def to_s
|
|
|
|
"The server uses an unsupported SMB dialect"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2005-09-23 03:43:04 +00:00
|
|
|
class InvalidPacket < Error
|
|
|
|
attr_accessor :word_count
|
|
|
|
attr_accessor :command
|
|
|
|
attr_accessor :error_code
|
|
|
|
end
|
|
|
|
|
|
|
|
class InvalidWordCount < InvalidPacket
|
|
|
|
def to_s
|
|
|
|
"The server responded with unimplemented WordCount " +
|
|
|
|
self.word_count.to_s + ' for command ' + self.command.to_s
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
class InvalidCommand < InvalidPacket
|
|
|
|
def to_s
|
|
|
|
"The server responded with unimplemented command " +
|
|
|
|
self.command.to_s + ' with WordCount ' + self.word_count.to_s
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
class InvalidType < InvalidPacket
|
|
|
|
def to_s
|
|
|
|
"The server responded with unexpected packet (Command=" +
|
|
|
|
self.command.to_s + ' WordCount=' + self.word_count.to_s + ")"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
class ErrorCode < InvalidPacket
|
2005-09-22 09:04:54 +00:00
|
|
|
def to_s
|
2005-12-13 06:08:40 +00:00
|
|
|
'The server responded with error: ' +
|
2006-01-27 05:28:16 +00:00
|
|
|
self.get_error(self.error_code) +
|
2005-12-13 06:08:40 +00:00
|
|
|
" (Command=#{self.command} WordCount=#{self.word_count})"
|
2005-09-22 09:04:54 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
class NetbiosSessionFailed < Error
|
|
|
|
def to_s
|
|
|
|
"The server refused our NetBIOS session request"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2005-09-23 09:14:03 +00:00
|
|
|
class SimpleClientError < Error
|
|
|
|
attr_accessor :source, :fatal
|
|
|
|
end
|
2005-09-23 03:43:04 +00:00
|
|
|
|
2005-09-23 09:14:03 +00:00
|
|
|
class LoginError < SimpleClientError
|
|
|
|
def to_s
|
|
|
|
"Login Failed: " + self.source
|
|
|
|
end
|
|
|
|
end
|
2005-09-23 03:43:04 +00:00
|
|
|
|
2005-09-22 09:04:54 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|