Introduce Rex::Proto::Rmi::DecodeError

bug/bundler_fix
jvazquez-r7 2015-04-05 18:15:04 -05:00
parent 3570fc586f
commit 85a70d401b
No known key found for this signature in database
GPG Key ID: 38D99152B9352D83
11 changed files with 31 additions and 30 deletions

View File

@ -89,7 +89,7 @@ module Msf
data = safe_get_once(nsock)
begin
ack = Rex::Proto::Rmi::Model::ProtocolAck.decode(StringIO.new(data))
rescue ::RuntimeError
rescue Rex::Proto::Rmi::DecodeError
return nil
end
@ -110,7 +110,7 @@ module Msf
begin
return_data = Rex::Proto::Rmi::Model::ReturnData.decode(StringIO.new(data))
rescue ::RuntimeError
rescue Rex::Proto::Rmi::DecodeError
return nil
end

View File

@ -4,5 +4,6 @@
# http://docs.oracle.com/javase/7/docs/platform/rmi/spec/rmi-protocol.html
require 'rex/proto/rmi/exception'
require 'rex/proto/rmi/decode_error'
require 'rex/proto/rmi/model'

View File

@ -20,11 +20,11 @@ module Rex
#
# @param io [IO] the IO to read from
# @return [String]
# @raise [RuntimeError] if fails to decode the message id
# @raise [Rex::Proto::Rmi::DecodeError] if fails to decode the message id
def decode_message_id(io)
message_id = read_byte(io)
unless message_id == CALL_MESSAGE
raise ::RuntimeError, 'Failed to decode Call message id'
raise Rex::Proto::Rmi::DecodeError, 'Failed to decode Call message id'
end
message_id

View File

@ -22,11 +22,11 @@ module Rex
#
# @param io [IO] the IO to read from
# @return [String]
# @raise [RuntimeError] if fails to decode stream id
# @raise [Rex::Proto::Rmi::DecodeError] if fails to decode stream id
def decode_stream_id(io)
stream_id = read_byte(io)
unless stream_id == DGC_ACK_MESSAGE
raise ::RuntimeError, 'Failed to decode DgcAck stream id'
raise Rex::Proto::Rmi::DecodeError, 'Failed to decode DgcAck stream id'
end
stream_id

View File

@ -83,10 +83,10 @@ module Rex
#
# @param io [IO] the IO to read from
# @return [Fixnum]
# @raise [RuntimeError] if the byte can't be read from io
# @raise [Rex::Proto::Rmi::DecodeError] if the byte can't be read from io
def read_byte(io)
raw = io.read(1)
raise ::RuntimeError, 'Failed to read byte' unless raw
raise Rex::Proto::Rmi::DecodeError, 'Failed to read byte' unless raw
raw.unpack('c')[0]
end
@ -95,12 +95,12 @@ module Rex
#
# @param io [IO] the IO to read from
# @return [Fixnum]
# @raise [RuntimeError] if the short can't be read from io
# @raise [Rex::Proto::Rmi::DecodeError] if the short can't be read from io
def read_short(io)
raw = io.read(2)
unless raw && raw.length == 2
raise ::RuntimeError, 'Failed to read short'
raise Rex::Proto::Rmi::DecodeError, 'Failed to read short'
end
raw.unpack('s>')[0]
@ -110,12 +110,12 @@ module Rex
#
# @param io [IO] the IO to read from
# @return [Fixnum]
# @raise [RuntimeError] if the int can't be read from io
# @raise [Rex::Proto::Rmi::DecodeError] if the int can't be read from io
def read_int(io)
raw = io.read(4)
unless raw && raw.length == 4
raise ::RuntimeError, 'Failed to read int'
raise Rex::Proto::Rmi::DecodeError, 'Failed to read int'
end
raw.unpack('l>')[0]
@ -125,12 +125,12 @@ module Rex
#
# @param io [IO] the IO to read from
# @return [Fixnum]
# @raise [RuntimeError] if the long can't be read from io
# @raise [Rex::Proto::Rmi::DecodeError] if the long can't be read from io
def read_long(io)
raw = io.read(8)
unless raw && raw.length == 8
raise ::RuntimeError, 'Failed to read long'
raise Rex::Proto::Rmi::DecodeError, 'Failed to read long'
end
raw.unpack('q>')[0]
@ -141,12 +141,12 @@ module Rex
# @param io [IO] the IO to read from
# @param length [Fixnum] the string length
# @return [String]
# @raise [RuntimeError] if the string can't be read from io
# @raise [Rex::Proto::Rmi::DecodeError] if the string can't be read from io
def read_string(io, length)
raw = io.read(length)
unless raw && raw.length == length
raise ::RuntimeError, 'Failed to read string'
raise Rex::Proto::Rmi::DecodeError, 'Failed to read string'
end
raw

View File

@ -23,11 +23,11 @@ module Rex
#
# @param io [IO] the IO to read from
# @return [String]
# @raise [RuntimeError] if fails to decode signature
# @raise [Rex::Proto::Rmi::DecodeError] if fails to decode signature
def decode_signature(io)
signature = read_string(io, 4)
unless signature == SIGNATURE
raise ::RuntimeError, 'Failed to decode OutputHeader signature'
raise Rex::Proto::Rmi::DecodeError, 'Failed to decode OutputHeader signature'
end
signature
@ -47,13 +47,13 @@ module Rex
#
# @param io [IO] the IO to read from
# @return [Fixnum]
# @raise [RuntimeError] if fails to decode the protocol
# @raise [Rex::Proto::Rmi::DecodeError] if fails to decode the protocol
def decode_protocol(io)
valid_protocols = [STREAM_PROTOCOL, SINGLE_OP_PROTOCOL, MULTIPLEX_PROTOCOL]
protocol = read_byte(io)
unless valid_protocols.include?(protocol)
raise ::RuntimeError, 'Failed to decode OutputHeader protocol'
raise Rex::Proto::Rmi::DecodeError, 'Failed to decode OutputHeader protocol'
end
protocol

View File

@ -18,11 +18,11 @@ module Rex
#
# @param io [IO] the IO to read from
# @return [String]
# @raise [RuntimeError] if fails to decode stream id
# @raise [Rex::Proto::Rmi::DecodeError] if fails to decode stream id
def decode_stream_id(io)
stream_id = read_byte(io)
unless stream_id == PING_MESSAGE
raise ::RuntimeError, 'Failed to decode Ping stream id'
raise Rex::Proto::Rmi::DecodeError, 'Failed to decode Ping stream id'
end
stream_id

View File

@ -18,11 +18,11 @@ module Rex
#
# @param io [IO] the IO to read from
# @return [String]
# @raise [RuntimeError] if fails to decode stream id
# @raise [Rex::Proto::Rmi::DecodeError] if fails to decode stream id
def decode_stream_id(io)
stream_id = read_byte(io)
unless stream_id == PING_ACK
raise ::RuntimeError, 'Failed to decode PingAck stream id'
raise Rex::Proto::Rmi::DecodeError, 'Failed to decode PingAck stream id'
end
stream_id

View File

@ -26,11 +26,11 @@ module Rex
#
# @param io [IO] the IO to read from
# @return [String]
# @raise [RuntimeError] if fails to decode stream id
# @raise [Rex::Proto::Rmi::DecodeError] if fails to decode stream id
def decode_stream_id(io)
stream_id = read_byte(io)
unless stream_id == PROTOCOL_ACK
raise ::RuntimeError, 'Failed to decode ProtocolAck stream id'
raise Rex::Proto::Rmi::DecodeError, 'Failed to decode ProtocolAck stream id'
end
stream_id

View File

@ -20,11 +20,11 @@ module Rex
#
# @param io [IO] the IO to read from
# @return [String]
# @raise [RuntimeError] if fails to decode the stream id
# @raise [Rex::Proto::Rmi::DecodeError] if fails to decode the stream id
def decode_stream_id(io)
stream_id = read_byte(io)
unless stream_id == RETURN_DATA
raise ::RuntimeError, 'Failed to decode ReturnData stream id'
raise Rex::Proto::Rmi::DecodeError, 'Failed to decode ReturnData stream id'
end
stream_id

View File

@ -84,11 +84,11 @@ module Rex
#
# @param io [IO] the IO to read from
# @return [String]
# @raise [RuntimeError] if fails to decode the return code
# @raise [Rex::Proto::Rmi::DecodeError] if fails to decode the return code
def decode_code(io)
code = read_byte(io)
unless code == RETURN_VALUE || code == RETURN_EXCEPTION
raise ::RuntimeError, 'Failed to decode the ReturnValue code'
raise Rex::Proto::Rmi::DecodeError, 'Failed to decode the ReturnValue code'
end
code