2014-12-18 23:40:06 +00:00
|
|
|
# -*- coding: binary -*-
|
|
|
|
|
2014-12-18 05:16:58 +00:00
|
|
|
module Rex
|
|
|
|
module Proto
|
|
|
|
module Kerberos
|
|
|
|
module CredentialCache
|
2014-12-18 23:12:58 +00:00
|
|
|
# This class provides a representation of a Principal stored in the Kerberos Credential Cache.
|
2014-12-18 06:30:47 +00:00
|
|
|
class Principal < Element
|
2014-12-18 23:12:58 +00:00
|
|
|
# @!attribute name_type
|
|
|
|
# @return [Fixnum]
|
2014-12-18 06:30:47 +00:00
|
|
|
attr_accessor :name_type
|
2014-12-18 23:12:58 +00:00
|
|
|
# @!attribute realm
|
|
|
|
# @return [String]
|
2014-12-18 06:30:47 +00:00
|
|
|
attr_accessor :realm
|
2014-12-18 23:12:58 +00:00
|
|
|
# @!attribute components
|
|
|
|
# @return [Array<String>]
|
2014-12-18 06:30:47 +00:00
|
|
|
attr_accessor :components
|
|
|
|
|
2014-12-18 23:12:58 +00:00
|
|
|
# Encodes the Rex::Proto::Kerberos::CredentialCache::Principal into an String
|
|
|
|
#
|
|
|
|
# @return [String] encoded principal
|
2014-12-18 06:30:47 +00:00
|
|
|
def encode
|
|
|
|
encoded = ''
|
|
|
|
encoded << encode_name_type
|
2014-12-18 22:31:46 +00:00
|
|
|
encoded << [components.length].pack('N')
|
2014-12-18 06:30:47 +00:00
|
|
|
encoded << encode_realm
|
|
|
|
encoded << encode_components
|
|
|
|
|
|
|
|
encoded
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2014-12-18 23:12:58 +00:00
|
|
|
# Encodes the name_type field
|
|
|
|
#
|
|
|
|
# @return [String]
|
2014-12-18 06:30:47 +00:00
|
|
|
def encode_name_type
|
2014-12-18 22:31:46 +00:00
|
|
|
[name_type].pack('N')
|
2014-12-18 06:30:47 +00:00
|
|
|
end
|
|
|
|
|
2014-12-18 23:12:58 +00:00
|
|
|
# Encodes the realm field
|
|
|
|
#
|
|
|
|
# @return [String]
|
2014-12-18 06:30:47 +00:00
|
|
|
def encode_realm
|
2014-12-18 22:31:46 +00:00
|
|
|
encoded = ''
|
|
|
|
encoded << [realm.length].pack('N')
|
2014-12-18 06:30:47 +00:00
|
|
|
encoded << realm
|
2014-12-18 22:31:46 +00:00
|
|
|
|
|
|
|
encoded
|
2014-12-18 06:30:47 +00:00
|
|
|
end
|
|
|
|
|
2014-12-18 23:12:58 +00:00
|
|
|
# Encodes the components field
|
|
|
|
#
|
|
|
|
# @return [String]
|
2014-12-18 06:30:47 +00:00
|
|
|
def encode_components
|
|
|
|
encoded = ''
|
|
|
|
|
|
|
|
components.each do |c|
|
2014-12-18 22:31:46 +00:00
|
|
|
encoded << [c.length].pack('N')
|
2014-12-18 06:30:47 +00:00
|
|
|
encoded << c
|
|
|
|
end
|
|
|
|
|
|
|
|
encoded
|
|
|
|
end
|
|
|
|
|
2014-12-18 05:16:58 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|