Skip to content

Commit 9a05487

Browse files
Merge pull request Pennyw0rth#271 from Pennyw0rth/neff-asreproast
Fixing Pennyw0rth#263
2 parents 60db634 + 0d84189 commit 9a05487

2 files changed

Lines changed: 23 additions & 21 deletions

File tree

nxc/protocols/ldap.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ def kerberos_login(self, domain, username, password="", ntlm_hash="", aesKey="",
330330
if hash_tgt:
331331
self.logger.highlight(f"{hash_tgt}")
332332
with open(self.args.asreproast, "a+") as hash_asreproast:
333-
hash_asreproast.write(hash_tgt + "\n")
333+
hash_asreproast.write(f"{hash_tgt}\n")
334334
return False
335335

336336
kerb_pass = next(s for s in [self.nthash, password, aesKey] if s) if not all(s == "" for s in [self.nthash, password, aesKey]) else ""
@@ -436,7 +436,7 @@ def plaintext_login(self, domain, username, password):
436436
if hash_tgt:
437437
self.logger.highlight(f"{hash_tgt}")
438438
with open(self.args.asreproast, "a+") as hash_asreproast:
439-
hash_asreproast.write(hash_tgt + "\n")
439+
hash_asreproast.write(f"{hash_tgt}\n")
440440
return False
441441

442442
try:
@@ -525,7 +525,7 @@ def hash_login(self, domain, username, ntlm_hash):
525525
if hash_tgt:
526526
self.logger.highlight(f"{hash_tgt}")
527527
with open(self.args.asreproast, "a+") as hash_asreproast:
528-
hash_asreproast.write(hash_tgt + "\n")
528+
hash_asreproast.write(f"{hash_tgt}\n")
529529
return False
530530

531531
try:
@@ -893,7 +893,7 @@ def asreproast(self):
893893
"lastLogon",
894894
]
895895
resp = self.search(search_filter, attributes, 0)
896-
if resp == []:
896+
if resp is None:
897897
self.logger.highlight("No entries found!")
898898
elif resp:
899899
answers = []
@@ -937,10 +937,10 @@ def asreproast(self):
937937
if len(answers) > 0:
938938
for user in answers:
939939
hash_TGT = KerberosAttacks(self).get_tgt_asroast(user[0])
940-
hash_TGT = KerberosAttacks(self).get_tgt_asroast(user[0])
941-
self.logger.highlight(f"{hash_TGT}")
942-
with open(self.args.asreproast, "a+") as hash_asreproast:
943-
hash_asreproast.write(hash_TGT + "\n")
940+
if hash_TGT:
941+
self.logger.highlight(f"{hash_TGT}")
942+
with open(self.args.asreproast, "a+") as hash_asreproast:
943+
hash_asreproast.write(f"{hash_TGT}\n")
944944
return True
945945
else:
946946
self.logger.highlight("No entries found!")

nxc/protocols/ldap/kerberos.py

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
import random
22
from binascii import hexlify, unhexlify
33
from datetime import datetime, timedelta
4+
import traceback
5+
try:
6+
# This is only available in python >= 3.11
7+
# if we are in a lower version, we will use the deprecated utcnow() method
8+
from datetime import UTC
9+
utc_failed = False
10+
except ImportError:
11+
utc_failed = True
412
from os import getenv
513

614
from impacket.krb5 import constants
7-
from impacket.krb5.asn1 import (
8-
TGS_REP,
9-
AS_REQ,
10-
KERB_PA_PAC_REQUEST,
11-
KRB_ERROR,
12-
AS_REP,
13-
seq_set,
14-
seq_set_iter,
15-
)
15+
from impacket.krb5.asn1 import TGS_REP, AS_REQ, AS_REP, KERB_PA_PAC_REQUEST, KRB_ERROR, seq_set, seq_set_iter
1616
from impacket.krb5.ccache import CCache
1717
from impacket.krb5.kerberosv5 import sendReceive, KerberosError, getKerberosTGT
1818
from impacket.krb5.types import KerberosTime, Principal
@@ -211,7 +211,8 @@ def get_tgt_asroast(self, userName, requestPAC=True):
211211
return None
212212

213213
req_body["realm"] = domain
214-
now = datetime.utcnow() + timedelta(days=1)
214+
# When we drop python 3.10 support utcnow() can be removed, as it is deprecated
215+
now = datetime.utcnow() + timedelta(days=1) if utc_failed else datetime.now(UTC) + timedelta(days=1)
215216
req_body["till"] = KerberosTime.to_asn1(now)
216217
req_body["rtime"] = KerberosTime.to_asn1(now)
217218
req_body["nonce"] = random.getrandbits(31)
@@ -235,10 +236,11 @@ def get_tgt_asroast(self, userName, requestPAC=True):
235236
message = encoder.encode(as_req)
236237
r = sendReceive(message, domain, self.kdcHost)
237238
elif e.getErrorCode() == constants.ErrorCodes.KDC_ERR_KEY_EXPIRED.value:
238-
return "Password of user " + userName + " expired but user doesn't require pre-auth"
239+
return f"Password of user {userName} expired but user doesn't require pre-auth"
239240
else:
240-
nxc_logger.debug(e)
241-
return False
241+
nxc_logger.fail(e)
242+
nxc_logger.debug(traceback.format_exc())
243+
return None
242244

243245
# This should be the PREAUTH_FAILED packet or the actual TGT if the target principal has the
244246
# 'Do not require Kerberos preauthentication' set

0 commit comments

Comments
 (0)