metasploit-framework/lib/rex/proto/kerberos/model/kdc_response.rb

141 lines
4.8 KiB
Ruby
Raw Normal View History

2014-12-10 15:54:57 +00:00
# -*- coding: binary -*-
module Rex
module Proto
module Kerberos
module Model
# This class provides a representation of a Kerberos KDC-REQ (response) data
# definition
2014-12-15 01:18:30 +00:00
class KdcResponse < 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 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 ticket
2014-12-15 03:01:09 +00:00
# @return [Rex::Proto::Kerberos::Model::Ticket] The issued ticket
2014-12-15 01:18:30 +00:00
attr_accessor :ticket
2014-12-15 03:01:09 +00:00
# @!attribute enc_part
# @return [Rex::Proto::Kerberos::Model::EncryptedData] The encrypted part of the response
2014-12-15 01:18:30 +00:00
attr_accessor :enc_part
2014-12-15 01:09:41 +00:00
2014-12-15 03:01:09 +00:00
# Decodes the Rex::Proto::Kerberos::Model::KdcResponse 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
2014-12-15 03:01:09 +00:00
raise ::RuntimeError, 'Failed to decode KdcResponse, invalid input'
2014-12-15 01:09:41 +00:00
end
2014-12-15 01:18:30 +00:00
self
end
2014-12-15 01:09:41 +00:00
# Rex::Proto::Kerberos::Model::KdcResponse encoding isn't supported
#
2014-12-24 01:59:37 +00:00
# @raise [NotImplementedError]
2014-12-15 01:18:30 +00:00
def encode
2014-12-24 01:59:37 +00:00
raise ::NotImplementedError, 'KdcResponse encoding not supported'
2014-12-15 01:18:30 +00:00
end
2014-12-15 01:09:41 +00:00
2014-12-15 01:18:30 +00:00
private
2014-12-15 01:09:41 +00:00
2014-12-15 03:01:09 +00:00
# Decodes a Rex::Proto::Kerberos::Model::KdcResponse 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)
decode_asn1(asn1)
end
2014-12-15 01:09:41 +00:00
2014-12-15 03:01:09 +00:00
# Decodes a Rex::Proto::Kerberos::Model::KdcResponse
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 3
self.crealm = decode_crealm(val)
when 4
self.cname = decode_cname(val)
when 5
self.ticket = decode_ticket(val)
when 6
self.enc_part = decode_enc_part(val)
else
raise ::RuntimeError, 'Failed to decode KDC-RESPONSE SEQUENCE'
2014-12-15 01:09:41 +00:00
end
end
2014-12-15 01:18:30 +00:00
end
2014-12-15 01:09:41 +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-15 01:09:41 +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-15 01:09:41 +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-15 01:09:41 +00:00
2014-12-15 01:18:30 +00:00
# Decodes the cname field
#
# @param input [OpenSSL::ASN1::ASN1Data] the input to decode from
# @return [Rex::Proto::Kerberos::Type::PrincipalName]
def decode_cname(input)
Rex::Proto::Kerberos::Model::PrincipalName.decode(input.value[0])
end
2014-12-15 03:01:09 +00:00
# Decodes the ticket field
#
# @param input [OpenSSL::ASN1::ASN1Data] the input to decode from
# @return [Rex::Proto::Kerberos::Type::Ticket]
def decode_ticket(input)
Rex::Proto::Kerberos::Model::Ticket.decode(input.value[0])
end
# Decodes the enc_part
#
# @param input [OpenSSL::ASN1::ASN1Data] the input to decode from
# @return [Rex::Proto::Kerberos::Model::EncryptedData]
def decode_enc_part(input)
Rex::Proto::Kerberos::Model::EncryptedData.decode(input.value[0])
end
end
end
end
end
end