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/crypto.rb
Views: 11704
# -*- coding: binary -*-1# frozen_string_literal: true23require 'rex/proto/kerberos/crypto/rc4_hmac'4require 'rex/proto/kerberos/crypto/rsa_md5'56module Rex7module Proto8module Kerberos9module Crypto10# https://datatracker.ietf.org/doc/html/rfc4120#section-7.5.1 - A unique number used as part of encryption to make certain types of11# cryptographic attacks harder12module KeyUsage13AS_REQ_PA_ENC_TIMESTAMP = 114KDC_REP_TICKET = 215AS_REP_ENCPART = 316TGS_REQ_KDC_REQ_BODY_AUTHDATA_SESSION_KEY = 417TGS_REQ_KDC_REQ_BODY_AUTHDATA_SUB_KEY = 518TGS_REQ_PA_TGS_REQ_AP_REQ_AUTHENTICATOR_CHKSUM = 619TGS_REQ_PA_TGS_REQ_AP_REQ_AUTHENTICATOR = 720TGS_REP_ENCPART_SESSION_KEY = 821TGS_REP_ENCPART_AUTHENTICATOR_SUB_KEY = 922AP_REQ_AUTHENTICATOR_CHKSUM = 1023AP_REQ_AUTHENTICATOR = 1124AP_REP_ENCPART = 1225KRB_PRIV_ENCPART = 1326KRB_CRED_ENCPART = 1427KRB_SAFE_CHKSUM = 1528KERB_NON_KERB_SALT = 1629KERB_NON_KERB_CKSUM_SALT = 1730GSS_ACCEPTOR_SEAL = 2231GSS_ACCEPTOR_SIGN = 2332GSS_INITIATOR_SEAL = 2433GSS_INITIATOR_SIGN = 2534end3536module Checksum37RSA_MD5 = 738MD5_DES = 839SHA1_DES3 = 1240SHA1_AES128 = 1541SHA1_AES256 = 1642HMAC_MD5 = -1384344def self.from_checksum_type(ctype)45checksummers = {46RSA_MD5 => Rex::Proto::Kerberos::Crypto::RsaMd5,47MD5_DES => Rex::Proto::Kerberos::Crypto::DesCbcMd5,48SHA1_DES3 => Rex::Proto::Kerberos::Crypto::Des3CbcSha1,49SHA1_AES128 => Rex::Proto::Kerberos::Crypto::Aes128CtsSha1,50SHA1_AES256 => Rex::Proto::Kerberos::Crypto::Aes256CtsSha1,51HMAC_MD5 => Rex::Proto::Kerberos::Crypto::Rc4Hmac,520xffffff76 => Rex::Proto::Kerberos::Crypto::Rc4Hmac, # Negative 138 two's complement53}54result = checksummers[ctype]55raise ::NotImplementedError, 'Checksum type is not supported' if result == nil5657result.new58end5960end6162# https://www.iana.org/assignments/kerberos-parameters/kerberos-parameters.xhtml63module Encryption64DES_CBC_CRC = 165DES_CBC_MD4 = 266DES_CBC_MD5 = 367DES3_CBC_SHA1 = 1668AES128 = 1769AES256 = 1870RC4_HMAC = 237172# Mapping of encryption type numbers to the human readable text description by IANA73# https://www.iana.org/assignments/kerberos-parameters/kerberos-parameters.xhtml74IANA_NAMES = {75DES_CBC_CRC => 'des-cbc-crc',76DES_CBC_MD4 => 'des-cbc-md4',77DES_CBC_MD5 => 'des-cbc-md5',78DES3_CBC_SHA1 => 'des3-cbc-sha1-kd',79AES128 => 'aes128-cts-hmac-sha1-96',80AES256 => 'aes256-cts-hmac-sha1-96',81RC4_HMAC => 'rc4-hmac'82}8384# The default etypes to offer to the Kerberos server when none is provided85DefaultOfferedEtypes = [AES256, AES128, RC4_HMAC, DES_CBC_MD5, DES3_CBC_SHA1]86PkinitEtypes = [AES256, AES128]8788# The individual etype used by an encryptor when none is provided89DefaultEncryptionType = RC4_HMAC9091ENCRYPTORS = {92DES_CBC_MD5 => Rex::Proto::Kerberos::Crypto::DesCbcMd5,93DES3_CBC_SHA1 => Rex::Proto::Kerberos::Crypto::Des3CbcSha1,94RC4_HMAC => Rex::Proto::Kerberos::Crypto::Rc4Hmac,95AES128 => Rex::Proto::Kerberos::Crypto::Aes128CtsSha1,96AES256 => Rex::Proto::Kerberos::Crypto::Aes256CtsSha1,97}98private_constant :ENCRYPTORS99100SUPPORTED_ENCRYPTIONS = ENCRYPTORS.keys101102#103# Return a string representation of the constant for a number104#105# @param [Integer] code106def self.const_name(code)107(self.constants - [:DefaultEncryptionType]).each do |c|108return c.to_s if self.const_get(c) == code109end110return nil111end112113# Return a integer value for the given encryption const name114#115# @param [String] const_name116def self.value_for(const_name)117self.const_get(const_name)118end119120# @param [Integer] etype121# @return [Rex::Proto::Kerberos::Crypto::BlockCipherBase]122def self.from_etype(etype)123result = ENCRYPTORS[etype]124raise ::NotImplementedError, "EncryptedData schema #{etype.inspect} is not supported" if result == nil125126result.new127end128end129end130end131end132end133134135