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/credential_cache/krb5_ccache.rb
Views: 11766
# -*- coding: binary -*-12require 'bindata'34require 'rex/proto/kerberos/credential_cache/primitive'5require 'rex/proto/kerberos/credential_cache/krb5_ccache_credential'6require 'rex/proto/kerberos/credential_cache/krb5_ccache_principal'78module Rex::Proto::Kerberos::CredentialCache9# see: https://web.mit.edu/kerberos/krb5-devel/doc/formats/ccache_file_format.html10class Krb5Ccache < BinData::Record11endian :big12search_prefix :krb5_ccache13unregister_self1415uint8 :magic, asserted_value: 516uint8 :version, asserted_value: 41718struct :header, onlyif: -> { version == 4 } do19endian :big2021uint16 :header_length, initial_length: -> { header_fields.num_bytes }22buffer :header_fields, length: :header_length do23array read_until: :eof do24uint16 :field_type25uint16 :field_length, initial_value: -> { field_value.num_bytes }26choice :field_value, selection: :field_type do27struct 1 do # time offset of the KDC relative to the client28int32 :seconds29int32 :microseconds30end31string :default, read_length: :field_length32end33end34end35end3637principal :default_principal38array :credentials, type: :credential, read_until: :eof3940# the other kerberos models use #encode so alias that for simplicity41alias_method :encode, :to_binary_s4243# @param [Rex::Proto::Kerberos::Model::KdcResponse] res The KDC response44# @param [Rex::Proto::Kerberos::Model::EncKdcResponse] enc_res The encrypted KDC response45# @return [Rex::Proto::Kerberos::CredentialCache::Krb5Ccache]46def self.from_responses(res, enc_res)47self.new(48default_principal: {49name_type: res.cname.name_type, # NT_PRINCIPAL50realm: res.crealm,51components: res.cname.name_string52},53credentials: [54{55client: {56name_type: res.cname.name_type,57realm: res.crealm,58components: res.cname.name_string59},60server: {61name_type: enc_res.sname.name_type,62realm: enc_res.srealm,63components: enc_res.sname.name_string64},65keyblock: {66enctype: enc_res.key.type,67data: enc_res.key.value68},69authtime: enc_res.auth_time,70starttime: enc_res.start_time,71endtime: enc_res.end_time,72renew_till: enc_res.renew_till,73ticket_flags: enc_res.flags.to_i,74ticket: res.ticket.encode75}76]77)78end79end80end818283