Class: Rex::Proto::Kerberos::Model::KrbCred

Inherits:
Element
  • Object
show all
Defined in:
lib/rex/proto/kerberos/model/krb_cred.rb

Overview

This class provides a representation of a Kerberos KRB-CRED message definition.

Constant Summary

Constants included from Rex::Proto::Kerberos::Model

AP_REP, AP_REQ, AS_REP, AS_REQ, AUTHENTICATOR, ENC_AP_REP_PART, ENC_KRB_CRED_PART, KRB_CRED, KRB_ERROR, TGS_REP, TGS_REQ, TICKET, VERSION

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Element

attr_accessor, attributes, #attributes, decode, #initialize

Constructor Details

This class inherits a constructor from Rex::Proto::Kerberos::Model::Element

Instance Attribute Details

#enc_partRex::Proto::Kerberos::Model::EncryptedData

Returns Encrypted KRB-CRED blob.

Returns:



21
22
23
# File 'lib/rex/proto/kerberos/model/krb_cred.rb', line 21

def enc_part
  @enc_part
end

#msg_typeInteger

Returns The type of a protocol message.

Returns:

  • (Integer)

    The type of a protocol message



15
16
17
# File 'lib/rex/proto/kerberos/model/krb_cred.rb', line 15

def msg_type
  @msg_type
end

#pvnoInteger

Returns The protocol version number.

Returns:

  • (Integer)

    The protocol version number



12
13
14
# File 'lib/rex/proto/kerberos/model/krb_cred.rb', line 12

def pvno
  @pvno
end

#ticketsArray<Rex::Proto::Kerberos::Model::Ticket>

Returns Tickets encapsulated in this message.

Returns:



18
19
20
# File 'lib/rex/proto/kerberos/model/krb_cred.rb', line 18

def tickets
  @tickets
end

Class Method Details

.load_credential_from_file(file_path) ⇒ Rex::Proto::Kerberos::Model::KrbCred

Loads a KrbCred from a kirbi file

Parameters:

  • file_path (String)

    the path to load the file from

Returns:



67
68
69
70
71
72
73
# File 'lib/rex/proto/kerberos/model/krb_cred.rb', line 67

def self.load_credential_from_file(file_path)
  unless File.readable?(file_path.to_s)
    raise ::ArgumentError, "Failed to load kirbi file '#{file_path}'"
  end

  decode(File.binread(file_path))
end

Instance Method Details

#==(other) ⇒ Object



23
24
25
26
27
28
# File 'lib/rex/proto/kerberos/model/krb_cred.rb', line 23

def ==(other)
  pvno == other.pvno &&
    msg_type == other.msg_type &&
    tickets == other.tickets &&
    enc_part == other.enc_part
end

#decode(input) ⇒ self

Decodes the Rex::Proto::Kerberos::Model::KrbCred from an input

Parameters:

  • input (String, OpenSSL::ASN1::ASN1Data)

    the input to decode from

Returns:

  • (self)

    if decoding succeeds

Raises:



35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/rex/proto/kerberos/model/krb_cred.rb', line 35

def decode(input)
  case input
  when String
    decode_string(input)
  when OpenSSL::ASN1::Sequence
    decode_asn1(input)
  else
    raise ::Rex::Proto::Kerberos::Model::Error::KerberosDecodingError, 'Failed to decode KrbCred, invalid input'
  end

  self
end

#encodeObject

Rex::Proto::Kerberos::Model::KrbCred encoding isn’t supported

Raises:

  • (NotImplementedError)


51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/rex/proto/kerberos/model/krb_cred.rb', line 51

def encode
  elems = []
  elems << OpenSSL::ASN1::ASN1Data.new([encode_pvno], 0, :CONTEXT_SPECIFIC)
  elems << OpenSSL::ASN1::ASN1Data.new([encode_msg_type], 1, :CONTEXT_SPECIFIC)
  elems << OpenSSL::ASN1::ASN1Data.new([encode_tickets], 2, :CONTEXT_SPECIFIC)
  elems << OpenSSL::ASN1::ASN1Data.new([encode_enc_part], 3, :CONTEXT_SPECIFIC)

  seq = OpenSSL::ASN1::Sequence.new(elems)
  seq_asn1 = OpenSSL::ASN1::ASN1Data.new([seq], KRB_CRED, :APPLICATION)

  seq_asn1.to_der
end

#save_credential_to_file(file_path) ⇒ Integer

Saves a KrbCred to a kirbi file

Parameters:

  • file_path (String)

    the path to save the file to

Returns:

  • (Integer)

    The length written



78
79
80
# File 'lib/rex/proto/kerberos/model/krb_cred.rb', line 78

def save_credential_to_file(file_path)
  File.binwrite(file_path, encode)
end