CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
rapid7

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

GitHub Repository: rapid7/metasploit-framework
Path: blob/master/lib/rex/proto/kerberos/model/kdc_response.rb
Views: 11765
1
# -*- coding: binary -*-
2
3
module Rex
4
module Proto
5
module Kerberos
6
module Model
7
# This class provides a representation of a Kerberos KDC-REP (response) data
8
# definition
9
class KdcResponse < Element
10
# @!attribute pvno
11
# @return [Integer] The protocol version number
12
attr_accessor :pvno
13
# @!attribute msg_type
14
# @return [Integer] The type of a protocol message
15
attr_accessor :msg_type
16
# @!attribute pa_data
17
# @return [Array<Rex::Proto::Kerberos::Model::PreAuthDataEntry>,nil] An array of PreAuthDataEntry. nil if not present.
18
attr_accessor :pa_data
19
# @!attribute crealm
20
# @return [String] The realm part of the client's principal identifier
21
attr_accessor :crealm
22
# @!attribute cname
23
# @return [Rex::Proto::Kerberos::Model::PrincipalName] The name part of the client's principal identifier
24
attr_accessor :cname
25
# @!attribute ticket
26
# @return [Rex::Proto::Kerberos::Model::Ticket] The issued ticket
27
attr_accessor :ticket
28
# @!attribute enc_part
29
# @return [Rex::Proto::Kerberos::Model::EncryptedData] The encrypted part of the response
30
attr_accessor :enc_part
31
32
# Decodes the Rex::Proto::Kerberos::Model::KdcResponse from an input
33
#
34
# @param input [String, OpenSSL::ASN1::ASN1Data] the input to decode from
35
# @return [self] if decoding succeeds
36
# @raise [Rex::Proto::Kerberos::Model::Error::KerberosDecodingError] if decoding doesn't succeed
37
def decode(input)
38
case input
39
when String
40
decode_string(input)
41
when OpenSSL::ASN1::ASN1Data
42
decode_asn1(input)
43
else
44
raise ::Rex::Proto::Kerberos::Model::Error::KerberosDecodingError, 'Failed to decode KdcResponse, invalid input'
45
end
46
47
self
48
end
49
50
# Rex::Proto::Kerberos::Model::KdcResponse encoding isn't supported
51
#
52
# @raise [NotImplementedError]
53
def encode
54
raise ::NotImplementedError, 'KdcResponse encoding not supported'
55
end
56
57
private
58
59
# Decodes a Rex::Proto::Kerberos::Model::KdcResponse from an String
60
#
61
# @param input [String] the input to decode from
62
def decode_string(input)
63
asn1 = OpenSSL::ASN1.decode(input)
64
65
decode_asn1(asn1)
66
end
67
68
# Decodes a Rex::Proto::Kerberos::Model::KdcResponse
69
#
70
# @param input [OpenSSL::ASN1::ASN1Data] the input to decode from
71
# @raise [Rex::Proto::Kerberos::Model::Error::KerberosDecodingError] if decoding doesn't succeed
72
def decode_asn1(input)
73
input.value[0].value.each do |val|
74
case val.tag
75
when 0
76
self.pvno = decode_pvno(val)
77
when 1
78
self.msg_type = decode_msg_type(val)
79
when 2
80
self.pa_data = decode_pa_data(val)
81
when 3
82
self.crealm = decode_crealm(val)
83
when 4
84
self.cname = decode_cname(val)
85
when 5
86
self.ticket = decode_ticket(val)
87
when 6
88
self.enc_part = decode_enc_part(val)
89
else
90
raise ::Rex::Proto::Kerberos::Model::Error::KerberosDecodingError, "Failed to decode KDC-RESPONSE SEQUENCE (#{val.tag})"
91
end
92
end
93
end
94
95
# Decodes the pvno from an OpenSSL::ASN1::ASN1Data
96
#
97
# @param input [OpenSSL::ASN1::ASN1Data] the input to decode from
98
# @return [Integer]
99
def decode_pvno(input)
100
input.value[0].value.to_i
101
end
102
103
# Decodes the msg_type from an OpenSSL::ASN1::ASN1Data
104
#
105
# @param input [OpenSSL::ASN1::ASN1Data] the input to decode from
106
# @return [Integer]
107
def decode_msg_type(input)
108
input.value[0].value.to_i
109
end
110
111
# Decodes the pa_data field
112
#
113
# @param input [OpenSSL::ASN1::ASN1Data] the input to decode from
114
# @return [Array<Rex::Proto::Kerberos::Model::PreAuthDataEntry>]
115
def decode_pa_data(input)
116
pre_auth = []
117
input.value[0].value.each do |pre_auth_data|
118
pre_auth << Rex::Proto::Kerberos::Model::PreAuthDataEntry.decode(pre_auth_data)
119
end
120
121
pre_auth
122
end
123
124
# Decodes the crealm field
125
#
126
# @param input [OpenSSL::ASN1::ASN1Data] the input to decode from
127
# @return [String]
128
def decode_crealm(input)
129
input.value[0].value
130
end
131
132
# Decodes the cname field
133
#
134
# @param input [OpenSSL::ASN1::ASN1Data] the input to decode from
135
# @return [Rex::Proto::Kerberos::Type::PrincipalName]
136
def decode_cname(input)
137
Rex::Proto::Kerberos::Model::PrincipalName.decode(input.value[0])
138
end
139
140
# Decodes the ticket field
141
#
142
# @param input [OpenSSL::ASN1::ASN1Data] the input to decode from
143
# @return [Rex::Proto::Kerberos::Type::Ticket]
144
def decode_ticket(input)
145
Rex::Proto::Kerberos::Model::Ticket.decode(input.value[0])
146
end
147
148
# Decodes the enc_part
149
#
150
# @param input [OpenSSL::ASN1::ASN1Data] the input to decode from
151
# @return [Rex::Proto::Kerberos::Model::EncryptedData]
152
def decode_enc_part(input)
153
Rex::Proto::Kerberos::Model::EncryptedData.decode(input.value[0])
154
end
155
end
156
end
157
end
158
end
159
end
160
161