2014-12-14 22:26:18 +00:00
|
|
|
# -*- coding: binary -*-
|
|
|
|
|
|
|
|
module Rex
|
|
|
|
module Proto
|
|
|
|
module Kerberos
|
|
|
|
module Model
|
2014-12-15 01:18:30 +00:00
|
|
|
class KrbError < Element
|
|
|
|
# @!attribute pvno
|
|
|
|
# @return [Fixnum] The protocol version number
|
|
|
|
attr_accessor :pvno
|
|
|
|
# @!attribute msg_type
|
|
|
|
# @return [Fixnum] The type of a protocol message
|
|
|
|
attr_accessor :msg_type
|
|
|
|
# @!attribute ctime
|
|
|
|
# @return [Time] The current time of the client's host
|
|
|
|
attr_accessor :ctime
|
|
|
|
# @!attribute cusec
|
|
|
|
# @return [Fixnum] The microseconds part of the client timestamp
|
|
|
|
attr_accessor :cusec
|
|
|
|
# @!attribute stime
|
|
|
|
# @return [Time] The current time of the server
|
|
|
|
attr_accessor :stime
|
|
|
|
# @!attribute susec
|
|
|
|
# @return [Fixnum] The microseconds part of the server timestamp
|
|
|
|
attr_accessor :susec
|
|
|
|
# @!attribute error_code
|
|
|
|
# @return [Fixnum] The error request returned by kerberos or the server when a request fails
|
|
|
|
attr_accessor :error_code
|
|
|
|
# @!attribute crealm
|
|
|
|
# @return [String] The realm part of the client's principal identifier
|
|
|
|
attr_accessor :crealm
|
|
|
|
# @!attribute cname
|
2014-12-15 03:01:09 +00:00
|
|
|
# @return [Rex::Proto::Kerberos::Model::PrincipalName] The name part of the client's principal identifier
|
2014-12-15 01:18:30 +00:00
|
|
|
attr_accessor :cname
|
|
|
|
# @!attribute realm
|
|
|
|
# @return [String] The realm part of the server's principal identifier
|
|
|
|
attr_accessor :realm
|
|
|
|
# @!attribute sname
|
2014-12-15 03:01:09 +00:00
|
|
|
# @return [Rex::Proto::Kerberos::Model::PrincipalName] The name part of the server's identity
|
2014-12-15 01:18:30 +00:00
|
|
|
attr_accessor :sname
|
|
|
|
# @!attribute e_data
|
|
|
|
# @return [String] additional data about the error (ASN.1 encoded data)
|
|
|
|
attr_accessor :e_data
|
|
|
|
|
2014-12-15 01:23:21 +00:00
|
|
|
# Decodes the Rex::Proto::Kerberos::Model::KrbError from an input
|
2014-12-15 01:18:30 +00:00
|
|
|
#
|
|
|
|
# @param input [String, OpenSSL::ASN1::ASN1Data] the input to decode from
|
|
|
|
# @return [self] if decoding succeeds
|
|
|
|
# @raise [RuntimeError] if decoding doesn't succeed
|
|
|
|
def decode(input)
|
|
|
|
case input
|
|
|
|
when String
|
|
|
|
decode_string(input)
|
|
|
|
when OpenSSL::ASN1::ASN1Data
|
|
|
|
decode_asn1(input)
|
|
|
|
else
|
|
|
|
raise ::RuntimeError, 'Failed to decode KRB Error, invalid input'
|
|
|
|
end
|
|
|
|
|
|
|
|
self
|
|
|
|
end
|
2014-12-14 22:26:18 +00:00
|
|
|
|
2014-12-15 01:18:30 +00:00
|
|
|
def encode
|
|
|
|
raise ::RuntimeError, 'KrbError encoding not supported'
|
|
|
|
end
|
2014-12-14 22:26:18 +00:00
|
|
|
|
2014-12-15 01:18:30 +00:00
|
|
|
private
|
2014-12-14 22:26:18 +00:00
|
|
|
|
2014-12-15 01:23:21 +00:00
|
|
|
# Decodes a Rex::Proto::Kerberos::Model::KrbError from an String
|
2014-12-15 01:18:30 +00:00
|
|
|
#
|
|
|
|
# @param input [String] the input to decode from
|
|
|
|
def decode_string(input)
|
|
|
|
asn1 = OpenSSL::ASN1.decode(input)
|
2014-12-14 22:26:18 +00:00
|
|
|
|
2014-12-15 01:18:30 +00:00
|
|
|
decode_asn1(asn1)
|
|
|
|
end
|
2014-12-14 22:26:18 +00:00
|
|
|
|
2014-12-15 01:23:21 +00:00
|
|
|
# Decodes a Rex::Proto::Kerberos::Model::KrbError
|
2014-12-15 01:18:30 +00:00
|
|
|
#
|
|
|
|
# @param input [OpenSSL::ASN1::ASN1Data] the input to decode from
|
|
|
|
# @raise [RuntimeError] if decoding doesn't succeed
|
|
|
|
def decode_asn1(input)
|
|
|
|
input.value[0].value.each do |val|
|
|
|
|
case val.tag
|
|
|
|
when 0
|
|
|
|
self.pvno = decode_pvno(val)
|
|
|
|
when 1
|
|
|
|
self.msg_type = decode_msg_type(val)
|
|
|
|
when 2
|
|
|
|
self.ctime = decode_ctime(val)
|
|
|
|
when 3
|
|
|
|
self.cusec = decode_cusec(val)
|
|
|
|
when 4
|
|
|
|
self.stime = decode_stime(val)
|
|
|
|
when 5
|
|
|
|
self.susec = decode_susec(val)
|
|
|
|
when 6
|
|
|
|
self.error_code = decode_error_code(val)
|
|
|
|
when 7
|
|
|
|
self.crealm = decode_crealm(val)
|
|
|
|
when 8
|
|
|
|
self.cname = decode_cname(val)
|
|
|
|
when 9
|
|
|
|
self.realm = decode_realm(val)
|
|
|
|
when 10
|
|
|
|
self.sname = decode_sname(val)
|
|
|
|
when 12
|
|
|
|
self.e_data = decode_e_data(val)
|
|
|
|
else
|
|
|
|
raise ::RuntimeError, 'Failed to decode KRB-ERROR SEQUENCE'
|
2014-12-14 22:26:18 +00:00
|
|
|
end
|
|
|
|
end
|
2014-12-15 01:18:30 +00:00
|
|
|
end
|
2014-12-14 22:26:18 +00:00
|
|
|
|
2014-12-15 01:18:30 +00:00
|
|
|
# Decodes the pvno from an OpenSSL::ASN1::ASN1Data
|
|
|
|
#
|
|
|
|
# @param input [OpenSSL::ASN1::ASN1Data] the input to decode from
|
|
|
|
# @return [Fixnum]
|
|
|
|
def decode_pvno(input)
|
|
|
|
input.value[0].value.to_i
|
|
|
|
end
|
2014-12-14 22:26:18 +00:00
|
|
|
|
2014-12-15 01:18:30 +00:00
|
|
|
# Decodes the msg_type from an OpenSSL::ASN1::ASN1Data
|
|
|
|
#
|
|
|
|
# @param input [OpenSSL::ASN1::ASN1Data] the input to decode from
|
|
|
|
# @return [Fixnum]
|
|
|
|
def decode_msg_type(input)
|
|
|
|
input.value[0].value.to_i
|
|
|
|
end
|
2014-12-14 22:26:18 +00:00
|
|
|
|
2014-12-15 01:18:30 +00:00
|
|
|
# Decodes the ctime field
|
|
|
|
#
|
|
|
|
# @param input [OpenSSL::ASN1::ASN1Data] the input to decode from
|
|
|
|
# @return [Time]
|
|
|
|
def decode_ctime(input)
|
|
|
|
input.value[0].value
|
|
|
|
end
|
2014-12-14 22:26:18 +00:00
|
|
|
|
2014-12-15 01:18:30 +00:00
|
|
|
# Decodes the cusec field
|
|
|
|
#
|
|
|
|
# @param input [OpenSSL::ASN1::ASN1Data] the input to decode from
|
|
|
|
# @return [Fixnum]
|
|
|
|
def decode_cusec(input)
|
|
|
|
input.value[0].value
|
|
|
|
end
|
2014-12-14 22:26:18 +00:00
|
|
|
|
2014-12-15 01:18:30 +00:00
|
|
|
# Decodes the stime field
|
|
|
|
#
|
|
|
|
# @param input [OpenSSL::ASN1::ASN1Data] the input to decode from
|
|
|
|
# @return [Time]
|
|
|
|
def decode_stime(input)
|
|
|
|
input.value[0].value
|
|
|
|
end
|
2014-12-14 22:26:18 +00:00
|
|
|
|
2014-12-15 01:18:30 +00:00
|
|
|
# Decodes the susec field
|
|
|
|
#
|
|
|
|
# @param input [OpenSSL::ASN1::ASN1Data] the input to decode from
|
|
|
|
# @return [Fixnum]
|
|
|
|
def decode_susec(input)
|
|
|
|
input.value[0].value.to_i
|
|
|
|
end
|
2014-12-14 22:26:18 +00:00
|
|
|
|
2014-12-15 01:18:30 +00:00
|
|
|
# Decodes the error_code field
|
|
|
|
#
|
|
|
|
# @param input [OpenSSL::ASN1::ASN1Data] the input to decode from
|
|
|
|
# @return [Fixnum]
|
|
|
|
def decode_error_code(input)
|
|
|
|
input.value[0].value.to_i
|
|
|
|
end
|
2014-12-14 22:26:18 +00:00
|
|
|
|
2014-12-15 01:18:30 +00:00
|
|
|
# Decodes the crealm field
|
|
|
|
#
|
|
|
|
# @param input [OpenSSL::ASN1::ASN1Data] the input to decode from
|
|
|
|
# @return [String]
|
|
|
|
def decode_crealm(input)
|
|
|
|
input.value[0].value
|
|
|
|
end
|
2014-12-14 22:26:18 +00:00
|
|
|
|
2014-12-15 01:18:30 +00:00
|
|
|
# Decodes the cname field
|
|
|
|
#
|
|
|
|
# @param input [OpenSSL::ASN1::ASN1Data] the input to decode from
|
2014-12-15 03:01:09 +00:00
|
|
|
# @return [Rex::Proto::Kerberos::Model::PrincipalName]
|
2014-12-15 01:18:30 +00:00
|
|
|
def decode_cname(input)
|
2014-12-15 01:23:21 +00:00
|
|
|
Rex::Proto::Kerberos::Model::PrincipalName.decode(input.value[0])
|
2014-12-15 01:18:30 +00:00
|
|
|
end
|
2014-12-14 22:26:18 +00:00
|
|
|
|
2014-12-15 01:18:30 +00:00
|
|
|
# Decodes the realm field
|
|
|
|
#
|
|
|
|
# @param input [OpenSSL::ASN1::ASN1Data] the input to decode from
|
|
|
|
# @return [String]
|
|
|
|
def decode_realm(input)
|
|
|
|
input.value[0].value
|
|
|
|
end
|
2014-12-14 22:26:18 +00:00
|
|
|
|
2014-12-15 01:18:30 +00:00
|
|
|
# Decodes the sname field
|
|
|
|
#
|
|
|
|
# @param input [OpenSSL::ASN1::ASN1Data] the input to decode from
|
2014-12-15 03:01:09 +00:00
|
|
|
# @return [Rex::Proto::Kerberos::Model::PrincipalName]
|
2014-12-15 01:18:30 +00:00
|
|
|
def decode_sname(input)
|
2014-12-15 01:23:21 +00:00
|
|
|
Rex::Proto::Kerberos::Model::PrincipalName.decode(input.value[0])
|
2014-12-15 01:18:30 +00:00
|
|
|
end
|
2014-12-14 23:23:37 +00:00
|
|
|
|
2014-12-15 01:18:30 +00:00
|
|
|
# Decodes the e_data from an OpenSSL::ASN1::ASN1Data
|
|
|
|
#
|
|
|
|
# @param input [OpenSSL::ASN1::ASN1Data] the input to decode from
|
|
|
|
# @return [String]
|
|
|
|
def decode_e_data(input)
|
|
|
|
input.value[0].value
|
2014-12-14 22:26:18 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|