Class: Rex::Proto::Kerberos::Model::EncryptedData

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

Overview

This class provides a representation of an encrypted message.

Constant Summary

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

AD_IF_RELEVANT, AP_REQ, AS_REP, AS_REQ, AUTHENTICATOR, ERROR_CODES, KDC_OPTION_ALLOW_POST_DATE, KDC_OPTION_ENC_TKT_IN_SKEY, KDC_OPTION_FORWARDABLE, KDC_OPTION_FORWARDED, KDC_OPTION_POST_DATED, KDC_OPTION_PROXIABLE, KDC_OPTION_PROXY, KDC_OPTION_RENEW, KDC_OPTION_RENEWABLE, KDC_OPTION_RENEWABLE_OK, KDC_OPTION_RESERVED, KDC_OPTION_UNUSED_10, KDC_OPTION_UNUSED_11, KDC_OPTION_UNUSED_7, KDC_OPTION_UNUSED_9, KDC_OPTION_VALIDATE, KRB_ERROR, NT_PRINCIPAL, NT_SRV_HST, NT_SRV_INST, NT_SRV_XHST, NT_UID, NT_UNKNOWN, PA_ENC_TIMESTAMP, PA_PAC_REQUEST, PA_PW_SALT, PA_TGS_REQ, TGS_REP, TGS_REQ, TICKET, VERSION

Constants included from Crypto

Crypto::ENC_AS_RESPONSE, Crypto::ENC_KDC_REQUEST_BODY, Crypto::ENC_TGS_RESPONSE, Crypto::RC4_HMAC, Crypto::RSA_MD5

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Element

attr_accessor, attributes, #attributes, decode, #initialize

Methods included from Crypto::RsaMd5

#checksum_rsa_md5

Methods included from Crypto::Rc4Hmac

#decrypt_rc4_hmac, #encrypt_rc4_hmac

Constructor Details

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

Instance Attribute Details

#cipherString

Returns The enciphered text.

Returns:

  • (String)

    The enciphered text



17
18
19
# File 'lib/rex/proto/kerberos/model/encrypted_data.rb', line 17

def cipher
  @cipher
end

#etypeObject

Returns the value of attribute etype.



11
12
13
# File 'lib/rex/proto/kerberos/model/encrypted_data.rb', line 11

def etype
  @etype
end

#kvnoFixnum

Returns The version number of the key.

Returns:

  • (Fixnum)

    The version number of the key



14
15
16
# File 'lib/rex/proto/kerberos/model/encrypted_data.rb', line 14

def kvno
  @kvno
end

#name_typeFixnum

Returns The encryption algorithm.

Returns:

  • (Fixnum)

    The encryption algorithm



11
# File 'lib/rex/proto/kerberos/model/encrypted_data.rb', line 11

attr_accessor :etype

Instance Method Details

#decode(input) ⇒ self

Decodes a Rex::Proto::Kerberos::Model::EncryptedData

Parameters:

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

    the input to decode from

Returns:

  • (self)

Raises:



24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/rex/proto/kerberos/model/encrypted_data.rb', line 24

def decode(input)
  case input
  when String
    decode_string(input)
  when OpenSSL::ASN1::Sequence
    decode_asn1(input)
  else
    raise ::RuntimeError, 'Failed to decode EncryptedData Name, invalid input'
  end

  self
end

#decrypt(key, msg_type) ⇒ String

Decrypts the cipher with etype encryption schema

Parameters:

  • key (String)

    the key to decrypt

  • msg_type (Fixnum)

    the message type

Returns:

  • (String)

    the decrypted 'cipher`

Raises:



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/rex/proto/kerberos/model/encrypted_data.rb', line 65

def decrypt(key, msg_type)
  if cipher.nil? || cipher.empty?
    return ''
  end

  res = ''
  case etype
  when RC4_HMAC
    res = decrypt_rc4_hmac(cipher, key, msg_type)
    raise ::RuntimeError, 'EncryptedData failed to decrypt' if res.length < 8
    res = res[8, res.length - 1]
  else
    raise ::NotImplementedError, 'EncryptedData schema is not supported'
  end

  res
end

#encodeString

Encodes a Rex::Proto::Kerberos::Model::EncryptedData into an ASN.1 String

Returns:

  • (String)


40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/rex/proto/kerberos/model/encrypted_data.rb', line 40

def encode
  elems = []
  etype_asn1 = OpenSSL::ASN1::ASN1Data.new([encode_etype], 0, :CONTEXT_SPECIFIC)
  elems << etype_asn1

  if kvno
    kvno_asn1 = OpenSSL::ASN1::ASN1Data.new([encode_kvno], 1, :CONTEXT_SPECIFIC)
    elems << kvno_asn1
  end

  cipher_asn1 = OpenSSL::ASN1::ASN1Data.new([encode_cipher], 2, :CONTEXT_SPECIFIC)
  elems << cipher_asn1

  seq = OpenSSL::ASN1::Sequence.new(elems)

  seq.to_der
end