Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/lib/rex/proto/kerberos/keytab/krb5_keytab.rb
Views: 11766
# -*- coding: binary -*-12require 'bindata'34# Models for or Krb5 keytab5module Rex::Proto::Kerberos::Keytab6class Krb5KeytabCountedOctetString < BinData::Primitive7endian :big8search_prefix :krb5_keytab910# @!attribute [rw] len11# @return [Integer]12uint16 :len, value: -> { data.length }1314# @!attribute [rw] data15# @return [String]16string :data, read_length: :len1718def get19data.snapshot20end2122def set(v)23self.data = v24end25end2627class Krb5KeytabKeyblock < BinData::Record28endian :big29search_prefix :krb5_keytab3031# @!attribute [rw] enctype32# @return [Integer] The encryption type33# @see Rex::Proto::Kerberos::Crypto::Encryption34uint16 :enctype3536# @return [KeytabCountedOctetString]37counted_octet_string :data38end3940class Krb5KeytabEpoch < BinData::Primitive41endian :big42search_prefix :krb5_keytab4344# @!attribute [rw] epoch45# @return [Integer]46uint32 :epoch4748def get49Time.at(epoch)50end5152def set(v)53self.epoch = v.to_i54end55end5657class Krb5KeytabEntry < BinData::Record58endian :big59search_prefix :krb5_keytab6061# @return [Integer] The number of bytes for the len field62LEN_FIELD_BYTE_SIZE = 46364# @!attribute [rw] len65# @return [Integer] The number of remaining bytes for this record. The length does not include the 4 bytes for this field66int32 :len,67value: -> {68size = [69count_of_components,70realm,71components,72name_type,73timestamp,74vno8,75keyblock,76vno,77flags78].sum { |field| field.to_binary_s.bytes.count }7980size81}8283# @!attribute [rw] count_of_components84# @return [Integer]85uint16 :count_of_components, value: -> { components.length }8687# @!attribute [rw] realm#88# @return [CountedOctetString]89counted_octet_string :realm9091# @!attribute [rw] components92# @return [Array<CountedOctetString>] The components in the principal name, which can be joined by slashes93# to represent the SPN94array :components, initial_length: :count_of_components, type: :counted_octet_string9596# @!attribute [rw] name_type97# @return [Integer]98# @see Rex::Proto::Kerberos::Model::NameType99uint32 :name_type100101# @!attribute [rw] timestamp102# @return [Integer] The time the key entry was created; Can be 0 for keytabs generated by ktpass103epoch :timestamp104105# @!attribute [rw] vno8106# @return [Integer] The lower 8 bits of the version number of the key107uint8 :vno8108109# @!attribute [rw] keyblock110# @return [KeytabKeyBlock]111keyblock :keyblock112113# @!attribute [rw] vno114# @return [Integer]115uint32 :vno,116initial_value: -> { vno8.to_i },117# only present if >= 4 bytes left in entry118onlyif: -> { ((len + LEN_FIELD_BYTE_SIZE) - vno.rel_offset) >= 4 }119120# @!attribute [rw] flags121# @return [Integer]122uint32 :flags,123# only present if >= 4 bytes left in entry124onlyif: -> { ((len + LEN_FIELD_BYTE_SIZE) - flags.rel_offset) >= 4 }125126# @return [String] The principal associated with this key tab entry127def principal128"#{components.to_a.join('/')}@#{realm}"129end130end131132# Definition from:133# https://web.mit.edu/kerberos/krb5-devel/doc/basic/keytab_def.html134# http://www.ioplex.com/utilities/keytab.txt135# http://web.mit.edu/freebsd/head/crypto/heimdal/doc/doxyout/krb5/html/krb5_fileformats.html136#137class Krb5Keytab < BinData::Record138endian :big139search_prefix :krb5_keytab140141# Older keytab version 0x501 not currently supported142# @!attribute [r] file_format_version143# @return [Integer]144uint16 :file_format_version, asserted_value: 0x502145146# @!attribute [rw] key_entries147# @return [Array<KeytabEntry>] the keytab entries148array :key_entries, type: :entry, read_until: :eof149end150end151152153