fortra / impacket

Impacket is a collection of Python classes for working with network protocols.
https://www.coresecurity.com
Other
13.45k stars 3.57k forks source link

datetime.datetime.utcnow() is deprecated in impacket-GetNPUsers #1827

Open CookieThump opened 1 week ago

CookieThump commented 1 week ago

Configuration

impacket version: Impacket v0.12.0 - Copyright Fortra, LLC and its affiliated companies

Python version: Python 3.12.6

Target OS: Distributor ID: Kali Description: Kali GNU/Linux Rolling Release: 2024.3 Codename: kali-rolling

Issue

impacket-GetNPUsers uses datetime.datetime.utcnow() in GetNPUsers.py in line 165. Any usage of datetime.datetime.utcnow() throws the following deprecation warning in Python 3.12

DeprecationWarning: datetime.datetime.utcnow() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.now(datetime.UTC).

related: https://github.com/dbt-labs/dbt-core/issues/9791

Expected Behavior This shouldn't happen

Steps To Reproduce Run impacket-GetNPUsers with Python 3.12

Solution

Replace line 165 in impacket-GetNPUsers now = datetime.datetime.utcnow() + datetime.timedelta(days=1) with now = datetime.datetime.now(datetime.timezone.utc).replace(tzinfo=None) + datetime.timedelta(days=1)

exploide commented 1 week ago

There are further places in the code invoking deprecated functions.

1695 fixes this if it ever gets merged.