Skip to content

Commit

Permalink
Keep backwards compatability with datetime
Browse files Browse the repository at this point in the history
  • Loading branch information
NeffIsBack committed Apr 21, 2024
1 parent f649c04 commit d9ce7a4
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions nxc/protocols/ldap/kerberos.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
import random
from binascii import hexlify, unhexlify
from datetime import datetime, timedelta, UTC
from datetime import datetime, timedelta
try:
# This is only available in python >= 3.11
# if we are in a lower version, we will use the deprecated utcnow() method
from datetime import UTC
utc_failed = False
except ImportError:
utc_failed = True
from os import getenv

from impacket.krb5 import constants
Expand Down Expand Up @@ -203,7 +210,8 @@ def get_tgt_asroast(self, userName, requestPAC=True):
return None

req_body["realm"] = domain
now = datetime.now(UTC) + timedelta(days=1)
# When we drop python 3.10 support utcnow() can be removed, as it is deprecated
now = datetime.utcnow() + timedelta(days=1) if utc_failed else datetime.now(UTC) + timedelta(days=1)
req_body["till"] = KerberosTime.to_asn1(now)
req_body["rtime"] = KerberosTime.to_asn1(now)
req_body["nonce"] = random.getrandbits(31)
Expand Down

0 comments on commit d9ce7a4

Please sign in to comment.