Skip to content

Commit 013c23f

Browse files
committed
Fix negative timestamps when using secretsdump local on windows
1 parent 0ceec09 commit 013c23f

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

impacket/examples/secretsdump.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1458,8 +1458,13 @@ def nt_time_to_datetime(self, nt_time):
14581458
# NT Time is in 100-nanosecond intervals since 1601-01-01 (UTC)
14591459
# The difference between 1601 and 1970 is 11644473600 seconds
14601460
nt_time = int.from_bytes(nt_time, byteorder='little') # Convert byte string to integer
1461-
unix_time = (nt_time - 116444736000000000) // 10000000 # Convert to Unix time (seconds)
1462-
return datetime.utcfromtimestamp(unix_time)
1461+
1462+
# datetime on windows can't handle negative timestamps (i.e. before 1970), therefore we must return the 0 time directly
1463+
if nt_time == 0:
1464+
return datetime(1601, 1, 1, 0, 0, 0)
1465+
else:
1466+
unix_time = (nt_time - 116444736000000000) // 10000000 # Convert to Unix time (seconds)
1467+
return datetime.utcfromtimestamp(unix_time)
14631468

14641469
def MD5(self, data):
14651470
md5 = hashlib.new('md5')

0 commit comments

Comments
 (0)