Skip to content

Commit f3e60e5

Browse files
committed
refactor(kerberos): unify AES etype handling and use f-strings
1 parent 358c4ad commit f3e60e5

2 files changed

Lines changed: 10 additions & 33 deletions

File tree

nxc/protocols/ldap.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1027,8 +1027,6 @@ def kerberoasting(self):
10271027

10281028
return
10291029

1030-
1031-
10321030
# Building the search filter
10331031
searchFilter = "(&(servicePrincipalName=*)(!(objectCategory=computer)))"
10341032
attributes = [
@@ -1484,5 +1482,3 @@ def bloodhound(self):
14841482
if each_file.startswith(self.output_filename.split("/")[-1]) and each_file.endswith("json"):
14851483
z.write(each_file)
14861484
os.remove(each_file)
1487-
1488-

nxc/protocols/ldap/kerberos.py

Lines changed: 10 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -111,41 +111,22 @@ def output_tgs_from_asrep(self, asrep_blob, spn, fd=None):
111111
etype = enc['etype']
112112
cipher = enc['cipher'].asOctets()
113113

114-
if etype == constants.EncryptionTypes.rc4_hmac.value: # 23
114+
service = spn.split('/')[0]
115+
spn_fmt = spn.replace(":", "~")
116+
117+
if etype == constants.EncryptionTypes.rc4_hmac.value: # 23
115118
chk = hexlify(cipher[:16]).decode()
116119
data = hexlify(cipher[16:]).decode()
117-
entry = "$krb5tgs${}$*{}${}${}*${}${}".format(
118-
etype,
119-
spn.split('/')[0],
120-
realm,
121-
spn.replace(":", "~"),
122-
chk,
123-
data,
124-
)
120+
entry = f"$krb5tgs${etype}*{service}${realm}${spn_fmt}*${chk}${data}"
125121

126-
elif etype == constants.EncryptionTypes.aes128_cts_hmac_sha1_96.value: # 17
122+
elif etype in (
123+
constants.EncryptionTypes.aes128_cts_hmac_sha1_96.value, # 17
124+
constants.EncryptionTypes.aes256_cts_hmac_sha1_96.value, # 18
125+
):
127126
chk = hexlify(cipher[-12:]).decode()
128127
data = hexlify(cipher[:-12]).decode()
129-
entry = "$krb5tgs${}${}${}$*{}*${}${}".format(
130-
etype,
131-
spn.split('/')[0],
132-
realm,
133-
spn.replace(":", "~"),
134-
chk,
135-
data,
136-
)
128+
entry = f"$krb5tgs${etype}${service}${realm}$*{spn_fmt}*${chk}${data}"
137129

138-
elif etype == constants.EncryptionTypes.aes256_cts_hmac_sha1_96.value: # 18
139-
chk = hexlify(cipher[-12:]).decode()
140-
data = hexlify(cipher[:-12]).decode()
141-
entry = "$krb5tgs${}${}${}$*{}*${}${}".format(
142-
etype,
143-
spn.split('/')[0],
144-
realm,
145-
spn.replace(":", "~"),
146-
chk,
147-
data,
148-
)
149130
else:
150131
self.logger.fail(f"[{spn}] etype {etype} not supported")
151132
return None

0 commit comments

Comments
 (0)