Skip to content

Commit

Permalink
fix: Updating the use of datetime.datetime.utcnow() to datetime.datet…
Browse files Browse the repository at this point in the history
…ime.now(datetime.timezone.utc) since it is deprecated
  • Loading branch information
yungcero committed Sep 11, 2024
1 parent db53482 commit 8d69229
Show file tree
Hide file tree
Showing 16 changed files with 35 additions and 35 deletions.
2 changes: 1 addition & 1 deletion examples/GetNPUsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ def getTGT(self, userName, requestPAC=True):

reqBody['realm'] = domain

now = datetime.datetime.utcnow() + datetime.timedelta(days=1)
now = datetime.datetime.now(datetime.timezone.utc) + datetime.timedelta(days=1)
reqBody['till'] = KerberosTime.to_asn1(now)
reqBody['rtime'] = KerberosTime.to_asn1(now)
reqBody['nonce'] = random.getrandbits(31)
Expand Down
2 changes: 1 addition & 1 deletion examples/addcomputer.py
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ def LDAP3KerberosLogin(self, connection, user, password, domain='', lmhash='', n
authenticator['authenticator-vno'] = 5
authenticator['crealm'] = domain
seq_set(authenticator, 'cname', userName.components_to_asn1)
now = datetime.datetime.utcnow()
now = datetime.datetime.now(datetime.timezone.utc)

authenticator['cusec'] = now.microsecond
authenticator['ctime'] = KerberosTime.to_asn1(now)
Expand Down
2 changes: 1 addition & 1 deletion examples/dacledit.py
Original file line number Diff line number Diff line change
Expand Up @@ -873,7 +873,7 @@ def ldap3_kerberos_login(connection, target, user, password, domain='', lmhash='
authenticator['authenticator-vno'] = 5
authenticator['crealm'] = domain
seq_set(authenticator, 'cname', userName.components_to_asn1)
now = datetime.datetime.utcnow()
now = datetime.datetime.now(datetime.timezone.utc)

authenticator['cusec'] = now.microsecond
authenticator['ctime'] = KerberosTime.to_asn1(now)
Expand Down
4 changes: 2 additions & 2 deletions examples/getPac.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ def dump(self):

seq_set(authenticator, 'cname', clientName.components_to_asn1)

now = datetime.datetime.utcnow()
now = datetime.datetime.now(datetime.timezone.utc)
authenticator['cusec'] = now.microsecond
authenticator['ctime'] = KerberosTime.to_asn1(now)

Expand Down Expand Up @@ -238,7 +238,7 @@ def dump(self):
seq_set(reqBody, 'sname', serverName.components_to_asn1)
reqBody['realm'] = str(decodedTGT['crealm'])

now = datetime.datetime.utcnow() + datetime.timedelta(days=1)
now = datetime.datetime.now(datetime.timezone.utc) + datetime.timedelta(days=1)

reqBody['till'] = KerberosTime.to_asn1(now)
reqBody['nonce'] = random.getrandbits(31)
Expand Down
12 changes: 6 additions & 6 deletions examples/getST.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ def doS4U2ProxyWithAdditionalTicket(self, tgt, cipher, oldSessionKey, sessionKey

seq_set(authenticator, 'cname', clientName.components_to_asn1)

now = datetime.datetime.utcnow()
now = datetime.datetime.now(datetime.timezone.utc)
authenticator['cusec'] = now.microsecond
authenticator['ctime'] = KerberosTime.to_asn1(now)

Expand Down Expand Up @@ -336,7 +336,7 @@ def doS4U2ProxyWithAdditionalTicket(self, tgt, cipher, oldSessionKey, sessionKey
myTicket = ticket.to_asn1(TicketAsn1())
seq_set_iter(reqBody, 'additional-tickets', (myTicket,))

now = datetime.datetime.utcnow() + datetime.timedelta(days=1)
now = datetime.datetime.now(datetime.timezone.utc) + datetime.timedelta(days=1)

reqBody['till'] = KerberosTime.to_asn1(now)
reqBody['nonce'] = random.getrandbits(31)
Expand Down Expand Up @@ -377,7 +377,7 @@ def doS4U(self, tgt, cipher, oldSessionKey, sessionKey, nthash, aesKey, kdcHost)

seq_set(authenticator, 'cname', clientName.components_to_asn1)

now = datetime.datetime.utcnow()
now = datetime.datetime.now(datetime.timezone.utc)
authenticator['cusec'] = now.microsecond
authenticator['ctime'] = KerberosTime.to_asn1(now)

Expand Down Expand Up @@ -474,7 +474,7 @@ def doS4U(self, tgt, cipher, oldSessionKey, sessionKey, nthash, aesKey, kdcHost)
seq_set(reqBody, 'sname', serverName.components_to_asn1)
reqBody['realm'] = str(decodedTGT['crealm'])

now = datetime.datetime.utcnow() + datetime.timedelta(days=1)
now = datetime.datetime.now(datetime.timezone.utc) + datetime.timedelta(days=1)

reqBody['till'] = KerberosTime.to_asn1(now)
reqBody['nonce'] = random.getrandbits(31)
Expand Down Expand Up @@ -604,7 +604,7 @@ def doS4U(self, tgt, cipher, oldSessionKey, sessionKey, nthash, aesKey, kdcHost)

seq_set(authenticator, 'cname', clientName.components_to_asn1)

now = datetime.datetime.utcnow()
now = datetime.datetime.now(datetime.timezone.utc)
authenticator['cusec'] = now.microsecond
authenticator['ctime'] = KerberosTime.to_asn1(now)

Expand Down Expand Up @@ -656,7 +656,7 @@ def doS4U(self, tgt, cipher, oldSessionKey, sessionKey, nthash, aesKey, kdcHost)
myTicket = ticket.to_asn1(TicketAsn1())
seq_set_iter(reqBody, 'additional-tickets', (myTicket,))

now = datetime.datetime.utcnow() + datetime.timedelta(days=1)
now = datetime.datetime.now(datetime.timezone.utc) + datetime.timedelta(days=1)

reqBody['till'] = KerberosTime.to_asn1(now)
reqBody['nonce'] = random.getrandbits(31)
Expand Down
4 changes: 2 additions & 2 deletions examples/goldenPac.py
Original file line number Diff line number Diff line change
Expand Up @@ -720,7 +720,7 @@ def getKerberosTGS(self, serverName, domain, kdcHost, tgt, cipher, sessionKey, a
seq_set(reqBody, 'sname', serverName.components_to_asn1)
reqBody['realm'] = decodedTGT['crealm'].prettyPrint()

now = datetime.datetime.utcnow() + datetime.timedelta(days=1)
now = datetime.datetime.now(datetime.timezone.utc) + datetime.timedelta(days=1)

reqBody['till'] = KerberosTime.to_asn1(now)
reqBody['nonce'] = random.SystemRandom().getrandbits(31)
Expand All @@ -746,7 +746,7 @@ def getKerberosTGS(self, serverName, domain, kdcHost, tgt, cipher, sessionKey, a

seq_set(authenticator, 'cname', clientName.components_to_asn1)

now = datetime.datetime.utcnow()
now = datetime.datetime.now(datetime.timezone.utc)
authenticator['cusec'] = now.microsecond
authenticator['ctime'] = KerberosTime.to_asn1(now)

Expand Down
2 changes: 1 addition & 1 deletion examples/owneredit.py
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ def ldap3_kerberos_login(connection, target, user, password, domain='', lmhash='
authenticator['authenticator-vno'] = 5
authenticator['crealm'] = domain
seq_set(authenticator, 'cname', userName.components_to_asn1)
now = datetime.datetime.utcnow()
now = datetime.datetime.now(datetime.timezone.utc)

authenticator['cusec'] = now.microsecond
authenticator['ctime'] = KerberosTime.to_asn1(now)
Expand Down
2 changes: 1 addition & 1 deletion examples/raiseChild.py
Original file line number Diff line number Diff line change
Expand Up @@ -907,7 +907,7 @@ def makeGolden(tgt, originalCipher, sessionKey, ntHash, aesKey, extraSid):
encTicketPart = decoder.decode(plainText, asn1Spec = EncTicketPart())[0]

# Let's extend the ticket's validity a lil bit
tenYearsFromNow = datetime.datetime.utcnow() + datetime.timedelta(days=365*10)
tenYearsFromNow = datetime.datetime.now(datetime.timezone.utc) + datetime.timedelta(days=365*10)
encTicketPart['endtime'] = KerberosTime.to_asn1(tenYearsFromNow)
encTicketPart['renew-till'] = KerberosTime.to_asn1(tenYearsFromNow)
#print encTicketPart.prettyPrint()
Expand Down
2 changes: 1 addition & 1 deletion examples/rbcd.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ def ldap3_kerberos_login(connection, target, user, password, domain='', lmhash='
authenticator['authenticator-vno'] = 5
authenticator['crealm'] = domain
seq_set(authenticator, 'cname', userName.components_to_asn1)
now = datetime.datetime.utcnow()
now = datetime.datetime.now(datetime.timezone.utc)

authenticator['cusec'] = now.microsecond
authenticator['ctime'] = KerberosTime.to_asn1(now)
Expand Down
14 changes: 7 additions & 7 deletions examples/ticketer.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ def createBasicValidationInfo(self):
# 1) KERB_VALIDATION_INFO
kerbdata = KERB_VALIDATION_INFO()

aTime = timegm(datetime.datetime.utcnow().timetuple())
aTime = timegm(datetime.datetime.now(datetime.timezone.utc).timetuple())
unixTime = self.getFileTime(aTime)

kerbdata['LogonTime']['dwLowDateTime'] = unixTime & 0xffffffff
Expand Down Expand Up @@ -487,7 +487,7 @@ def getKerberosS4U2SelfU2U(self):

seq_set(authenticator, 'cname', clientName.components_to_asn1)

now = datetime.datetime.utcnow()
now = datetime.datetime.now(datetime.timezone.utc)
authenticator['cusec'] = now.microsecond
authenticator['ctime'] = KerberosTime.to_asn1(now)

Expand Down Expand Up @@ -576,7 +576,7 @@ def getKerberosS4U2SelfU2U(self):
seq_set(reqBody, 'sname', serverName.components_to_asn1)
reqBody['realm'] = str(decodedTGT['crealm'])

now = datetime.datetime.utcnow() + datetime.timedelta(days=1)
now = datetime.datetime.now(datetime.timezone.utc) + datetime.timedelta(days=1)

reqBody['till'] = KerberosTime.to_asn1(now)
reqBody['nonce'] = random.getrandbits(31)
Expand All @@ -597,7 +597,7 @@ def getKerberosS4U2SelfU2U(self):
def customizeTicket(self, kdcRep, pacInfos):
logging.info('Customizing ticket for %s/%s' % (self.__domain, self.__target))

ticketDuration = datetime.datetime.utcnow() + datetime.timedelta(hours=int(self.__options.duration))
ticketDuration = datetime.datetime.now(datetime.timezone.utc) + datetime.timedelta(hours=int(self.__options.duration))

if self.__options.impersonate:
# Doing Sapphire Ticket
Expand Down Expand Up @@ -715,8 +715,8 @@ def customizeTicket(self, kdcRep, pacInfos):
encTicketPart['transited'] = noValue
encTicketPart['transited']['tr-type'] = 0
encTicketPart['transited']['contents'] = ''
encTicketPart['authtime'] = KerberosTime.to_asn1(datetime.datetime.utcnow())
encTicketPart['starttime'] = KerberosTime.to_asn1(datetime.datetime.utcnow())
encTicketPart['authtime'] = KerberosTime.to_asn1(datetime.datetime.now(datetime.timezone.utc))
encTicketPart['starttime'] = KerberosTime.to_asn1(datetime.datetime.now(datetime.timezone.utc))
# Let's extend the ticket's validity a lil bit
encTicketPart['endtime'] = KerberosTime.to_asn1(ticketDuration)
encTicketPart['renew-till'] = KerberosTime.to_asn1(ticketDuration)
Expand Down Expand Up @@ -840,7 +840,7 @@ def customizeTicket(self, kdcRep, pacInfos):
encRepPart['last-req'] = noValue
encRepPart['last-req'][0] = noValue
encRepPart['last-req'][0]['lr-type'] = 0
encRepPart['last-req'][0]['lr-value'] = KerberosTime.to_asn1(datetime.datetime.utcnow())
encRepPart['last-req'][0]['lr-value'] = KerberosTime.to_asn1(datetime.datetime.now(datetime.timezone.utc))
encRepPart['nonce'] = 123456789
encRepPart['key-expiration'] = KerberosTime.to_asn1(ticketDuration)
flags = []
Expand Down
14 changes: 7 additions & 7 deletions impacket/krb5/kerberosv5.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ def getKerberosTGT(clientName, password, domain, lmhash, nthash, aesKey='', kdcH

reqBody['realm'] = domain

now = datetime.datetime.utcnow() + datetime.timedelta(days=1)
now = datetime.datetime.now(datetime.timezone.utc) + datetime.timedelta(days=1)
reqBody['till'] = KerberosTime.to_asn1(now)
reqBody['rtime'] = KerberosTime.to_asn1(now)
reqBody['nonce'] = rand.getrandbits(31)
Expand Down Expand Up @@ -266,7 +266,7 @@ def getKerberosTGT(clientName, password, domain, lmhash, nthash, aesKey='', kdcH
# Let's build the timestamp
timeStamp = PA_ENC_TS_ENC()

now = datetime.datetime.utcnow()
now = datetime.datetime.now(datetime.timezone.utc)
timeStamp['patimestamp'] = KerberosTime.to_asn1(now)
timeStamp['pausec'] = now.microsecond

Expand Down Expand Up @@ -312,7 +312,7 @@ def getKerberosTGT(clientName, password, domain, lmhash, nthash, aesKey='', kdcH

reqBody['realm'] = domain

now = datetime.datetime.utcnow() + datetime.timedelta(days=1)
now = datetime.datetime.now(datetime.timezone.utc) + datetime.timedelta(days=1)
reqBody['till'] = KerberosTime.to_asn1(now)
reqBody['rtime'] = KerberosTime.to_asn1(now)
reqBody['nonce'] = rand.getrandbits(31)
Expand Down Expand Up @@ -396,7 +396,7 @@ def getKerberosTGS(serverName, domain, kdcHost, tgt, cipher, sessionKey, renew =

seq_set(authenticator, 'cname', clientName.components_to_asn1)

now = datetime.datetime.utcnow()
now = datetime.datetime.now(datetime.timezone.utc)
authenticator['cusec'] = now.microsecond
authenticator['ctime'] = KerberosTime.to_asn1(now)

Expand Down Expand Up @@ -438,7 +438,7 @@ def getKerberosTGS(serverName, domain, kdcHost, tgt, cipher, sessionKey, renew =
seq_set(reqBody, 'sname', serverName.components_to_asn1)
reqBody['realm'] = domain

now = datetime.datetime.utcnow() + datetime.timedelta(days=1)
now = datetime.datetime.now(datetime.timezone.utc) + datetime.timedelta(days=1)

reqBody['till'] = KerberosTime.to_asn1(now)
reqBody['nonce'] = rand.getrandbits(31)
Expand Down Expand Up @@ -519,7 +519,7 @@ def getKerberosType3(cipher, sessionKey, auth_data):
encAPRepPart['subkey'].clear()
encAPRepPart = encAPRepPart.clone()

now = datetime.datetime.utcnow()
now = datetime.datetime.now(datetime.timezone.utc)
encAPRepPart['cusec'] = now.microsecond
encAPRepPart['ctime'] = KerberosTime.to_asn1(now)
encAPRepPart['seq-number'] = sequenceNumber
Expand Down Expand Up @@ -645,7 +645,7 @@ def getKerberosType1(username, password, domain, lmhash, nthash, aesKey='', TGT
authenticator['authenticator-vno'] = 5
authenticator['crealm'] = domain
seq_set(authenticator, 'cname', userName.components_to_asn1)
now = datetime.datetime.utcnow()
now = datetime.datetime.now(datetime.timezone.utc)

authenticator['cusec'] = now.microsecond
authenticator['ctime'] = KerberosTime.to_asn1(now)
Expand Down
2 changes: 1 addition & 1 deletion impacket/krb5/kpasswd.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ def createKPasswdRequest(principal, domain, newPasswd, tgs, cipher, sessionKey,
sequenceNumber = int.from_bytes(get_random_bytes(4), "big")

if now is None:
now = datetime.datetime.utcnow()
now = datetime.datetime.now(datetime.timezone.utc)

if not isinstance(newPasswd, bytes):
newPasswd = newPasswd.encode("utf-8")
Expand Down
2 changes: 1 addition & 1 deletion impacket/ldap/ldap.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ def kerberosLogin(self, user, password, domain='', lmhash='', nthash='', aesKey=
authenticator['authenticator-vno'] = 5
authenticator['crealm'] = domain
seq_set(authenticator, 'cname', userName.components_to_asn1)
now = datetime.datetime.utcnow()
now = datetime.datetime.now(datetime.timezone.utc)

authenticator['cusec'] = now.microsecond
authenticator['ctime'] = KerberosTime.to_asn1(now)
Expand Down
2 changes: 1 addition & 1 deletion impacket/smb.py
Original file line number Diff line number Diff line change
Expand Up @@ -3251,7 +3251,7 @@ def kerberos_login(self, user, password, domain = '', lmhash = '', nthash = '',
authenticator['authenticator-vno'] = 5
authenticator['crealm'] = domain
seq_set(authenticator, 'cname', userName.components_to_asn1)
now = datetime.datetime.utcnow()
now = datetime.datetime.now(datetime.timezone.utc)

authenticator['cusec'] = now.microsecond
authenticator['ctime'] = KerberosTime.to_asn1(now)
Expand Down
2 changes: 1 addition & 1 deletion impacket/smb3.py
Original file line number Diff line number Diff line change
Expand Up @@ -797,7 +797,7 @@ def kerberosLogin(self, user, password, domain = '', lmhash = '', nthash = '', a
authenticator['authenticator-vno'] = 5
authenticator['crealm'] = domain
seq_set(authenticator, 'cname', userName.components_to_asn1)
now = datetime.datetime.utcnow()
now = datetime.datetime.now(datetime.timezone.utc)

authenticator['cusec'] = now.microsecond
authenticator['ctime'] = KerberosTime.to_asn1(now)
Expand Down
2 changes: 1 addition & 1 deletion impacket/tds.py
Original file line number Diff line number Diff line change
Expand Up @@ -818,7 +818,7 @@ def kerberosLogin(self, database, username, password='', domain='', hashes=None,
authenticator['authenticator-vno'] = 5
authenticator['crealm'] = domain
seq_set(authenticator, 'cname', userName.components_to_asn1)
now = datetime.datetime.utcnow()
now = datetime.datetime.now(datetime.timezone.utc)

authenticator['cusec'] = now.microsecond
authenticator['ctime'] = KerberosTime.to_asn1(now)
Expand Down

0 comments on commit 8d69229

Please sign in to comment.