Skip to content

Commit 74dcabf

Browse files
committed
Add the definitions for KERB-SUPERSEDED-BY-USER
1 parent a847038 commit 74dcabf

File tree

3 files changed

+88
-1
lines changed

3 files changed

+88
-1
lines changed

lib/rex/proto/kerberos/model.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,9 @@ module NameType
5151
NT_UID = 5
5252
end
5353

54-
# From padata - https://www.iana.org/assignments/kerberos-parameters/kerberos-parameters.xhtml
54+
# See:
55+
# * https://www.iana.org/assignments/kerberos-parameters/kerberos-parameters.xhtml#pre-authentication
56+
# * https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-kile/ae60c948-fda8-45c2-b1d1-a71b484dd1f7
5557

5658
module PreAuthType
5759
PA_TGS_REQ = 1
@@ -65,6 +67,7 @@ module PreAuthType
6567
PA_FOR_USER = 129
6668
PA_SUPPORTED_ETYPES = 165
6769
PA_PAC_OPTIONS = 167
70+
KERB_SUPERSEDED_BY_USER = 170
6871
end
6972

7073
module AuthorizationDataType
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
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 KERB-SUPERSEDED-BY-USER
8+
# message as defined in [MS-KILE 2.2.13](https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-kile/79170b21-ad15-4a1b-99c4-84b3992d9e70).
9+
class KerbSupersededByUser < Element
10+
11+
attr_accessor :principal_name
12+
13+
attr_accessor :realm
14+
15+
def ==(other)
16+
realm == other.realm && principal_name == other.principal_name
17+
end
18+
19+
def decode(input)
20+
case input
21+
when String
22+
decode_string(input)
23+
when OpenSSL::ASN1::Sequence
24+
decode_asn1(input)
25+
else
26+
raise ::Rex::Proto::Kerberos::Model::Error::KerberosDecodingError, 'Failed to decode KerbSupersededByUser, invalid input'
27+
end
28+
29+
self
30+
end
31+
32+
def encode
33+
principal_name_asn1 = OpenSSL::ASN1::ASN1Data.new([encode_principal_name], 1, :CONTEXT_SPECIFIC)
34+
realm_asn1 = OpenSSL::ASN1::ASN1Data.new([encode_realm], 2, :CONTEXT_SPECIFIC)
35+
seq = OpenSSL::ASN1::Sequence.new([principal_name_asn1, realm_asn1])
36+
37+
seq.to_der
38+
end
39+
40+
private
41+
42+
def decode_string(input)
43+
asn1 = OpenSSL::ASN1.decode(input)
44+
45+
decode_asn1(asn1)
46+
end
47+
48+
# Decodes a Rex::Proto::Kerberos::Model::KerbSupersededByUser from an
49+
# OpenSSL::ASN1::Sequence
50+
#
51+
# @param input [OpenSSL::ASN1::Sequence] the input to decode from
52+
def decode_asn1(input)
53+
seq_values = input.value
54+
self.principal_name = decode_principal_name(seq_values[0])
55+
self.realm = decode_realm(seq_values[1])
56+
end
57+
58+
def decode_principal_name(input)
59+
PrincipalName.decode(input.value[0])
60+
end
61+
62+
# Decodes the realm from an OpenSSL::ASN1::ASN1Data
63+
#
64+
# @param input [OpenSSL::ASN1::ASN1Data] the input to decode from
65+
# @return [Array<String>]
66+
def decode_realm(input)
67+
input.value[0].value
68+
end
69+
70+
def encode_principal_name
71+
self.principal_name.encode
72+
end
73+
74+
def encode_realm
75+
OpenSSL::ASN1::OctetString.new(self.realm)
76+
end
77+
end
78+
end
79+
end
80+
end
81+
end

lib/rex/proto/kerberos/model/pre_auth_data_entry.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@ def decoded_value
7676
when Rex::Proto::Kerberos::Model::PreAuthType::PA_FOR_USER
7777
decoded = OpenSSL::ASN1.decode(self.value)
7878
PreAuthForUser.decode(decoded)
79+
when Rex::Proto::Kerberos::Model::PreAuthType::KERB_SUPERSEDED_BY_USER
80+
decoded = OpenSSL::ASN1.decode(self.value)
81+
KerbSupersededByUser.decode(decoded)
7982
else
8083
# Unknown type - just ignore for now
8184
end

0 commit comments

Comments
 (0)