Land #6145, better RPC exception handling

bug/bundler_fix
William Vu 2015-10-30 13:25:52 -05:00
commit f8a39ecc21
No known key found for this signature in database
GPG Key ID: 68BD00CE25866743
3 changed files with 34 additions and 7 deletions

View File

@ -57,7 +57,7 @@ require 'rex/proto/smb/exceptions'
case self.handle.protocol
when 'ncacn_ip_tcp'
if self.socket.type? != 'tcp'
raise "ack, #{self.handle.protocol} requires socket type tcp, not #{self.socket.type?}!"
raise ::Rex::Proto::DCERPC::Exceptions::InvalidSocket, "ack, #{self.handle.protocol} requires socket type tcp, not #{self.socket.type?}!"
end
when 'ncacn_np'
if self.socket.class == Rex::Proto::SMB::SimpleClient::OpenPipe
@ -65,11 +65,11 @@ require 'rex/proto/smb/exceptions'
elsif self.socket.type? == 'tcp'
self.smb_connect()
else
raise "ack, #{self.handle.protocol} requires socket type tcp, not #{self.socket.type?}!"
raise ::Rex::Proto::DCERPC::Exceptions::InvalidSocket, "ack, #{self.handle.protocol} requires socket type tcp, not #{self.socket.type?}!"
end
# No support ncacn_ip_udp (is it needed now that its ripped from Vista?)
else
raise "Unsupported protocol : #{self.handle.protocol}"
raise ::Rex::Proto::DCERPC::Exceptions::InvalidSocket, "Unsupported protocol : #{self.handle.protocol}"
end
end
@ -255,7 +255,7 @@ require 'rex/proto/smb/exceptions'
bind, context = Rex::Proto::DCERPC::Packet.make_bind(*self.handle.uuid)
end
raise 'make_bind failed' if !bind
raise ::Rex::Proto::DCERPC::Exceptions::BindError, 'make_bind failed' if !bind
self.write(bind)
raw_response = self.read()
@ -264,11 +264,11 @@ require 'rex/proto/smb/exceptions'
self.last_response = response
if response.type == 12 or response.type == 15
if self.last_response.ack_result[context] == 2
raise "Could not bind to #{self.handle}"
raise ::Rex::Proto::DCERPC::Exceptions::BindError, "Could not bind to #{self.handle}"
end
self.context = context
else
raise "Could not bind to #{self.handle}"
raise ::Rex::Proto::DCERPC::Exceptions::BindError, "Could not bind to #{self.handle}"
end
end

View File

@ -132,6 +132,32 @@ class NoResponse < Error
end
end
class BindError < Error
def initialize(message=nil)
@message = message
end
def to_s
str = 'Failed to bind.'
if @message
str += " #{@message}"
end
end
end
class InvalidSocket < Error
def initialize(message=nil)
@message = message
end
def to_s
str = 'Invalid Socket.'
if @message
str += " #{@message}"
end
end
end
class InvalidPacket < Error
def initialize(message = nil)
@message = message

View File

@ -99,7 +99,8 @@ class Metasploit3 < Msf::Auxiliary
print_status("#{peer} - Executing the command...")
begin
return psexec(execute)
rescue Rex::Proto::SMB::Exceptions::Error => exec_command_error
rescue Rex::Proto::DCERPC::Exceptions::Error, Rex::Proto::SMB::Exceptions::Error => exec_command_error
elog("#{e.class} #{e.message}\n#{e.backtrace * "\n"}", 'rex', LEV_3)
print_error("#{peer} - Unable to execute specified command: #{exec_command_error}")
return false
end