Skip to content

Commit 082dca3

Browse files
Remove usage of pkg_resources (fortra#2036)
* Remove usage of `pkg_resources` Currently, a warning is emitted on each run: UserWarning: pkg_resources is deprecated as an API. See https://setuptools.pypa.io/en/latest/pkg_resources.html. The pkg_resources package is slated for removal as early as 2025-11-30. Refrain from using this package or pin to Setuptools<81. This patch removes all usage of that package. Fixes fortra#1645. * Add necessary dependencies to setup.py and requirements.txt * Remove fallback to `importlib_resources`
1 parent 21792db commit 082dca3

File tree

4 files changed

+13
-9
lines changed

4 files changed

+13
-9
lines changed

impacket/examples/ntlmrelayx/attacks/__init__.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
# Dirk-jan Mollema (@_dirkjan) / Fox-IT (https://www.fox-it.com)
1818
#
1919
import os, sys
20-
import pkg_resources
20+
from importlib.resources import files
2121
from impacket import LOG
2222
from threading import Thread
2323

@@ -47,7 +47,8 @@ def __init__(self, config, client, username):
4747
def run(self):
4848
raise RuntimeError('Virtual Function')
4949

50-
for file in pkg_resources.resource_listdir('impacket.examples.ntlmrelayx', 'attacks'):
50+
attacks_path = files('impacket.examples.ntlmrelayx').joinpath('attacks')
51+
for file in [f.name for f in attacks_path.iterdir() if f.is_file()]:
5152
if file.find('__') >= 0 or file.endswith('.py') is False:
5253
continue
5354
# This seems to be None in some case (py3 only)

impacket/examples/ntlmrelayx/clients/__init__.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
# Author:
1616
# Alberto Solino (@agsolino)
1717
#
18-
import os, sys, pkg_resources
18+
import os, sys
19+
from importlib.resources import files
1920
from impacket import LOG
2021

2122
PROTOCOL_CLIENTS = {}
@@ -94,7 +95,8 @@ def isAdmin(self):
9495
# By default, raise exception
9596
raise RuntimeError('Virtual Function')
9697

97-
for file in pkg_resources.resource_listdir('impacket.examples.ntlmrelayx', 'clients'):
98+
clients_path = files('impacket.examples.ntlmrelayx').joinpath('clients')
99+
for file in [f.name for f in clients_path.iterdir() if f.is_file()]:
98100
if file.find('__') >= 0 or file.endswith('.py') is False:
99101
continue
100102
# This seems to be None in some case (py3 only)

impacket/examples/ntlmrelayx/servers/socksplugins/__init__.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,12 @@
1010
#
1111
import os
1212
import sys
13-
import pkg_resources
13+
from importlib.resources import files
1414

1515
SOCKS_RELAYS = set()
1616

17-
for file in pkg_resources.resource_listdir('impacket.examples.ntlmrelayx.servers', 'socksplugins'):
17+
socksplugins_path = files('impacket.examples.ntlmrelayx.servers').joinpath('socksplugins')
18+
for file in [f.name for f in socksplugins_path.iterdir() if f.is_file()]:
1819
if file.find('__') >= 0 or file.endswith('.py') is False:
1920
continue
2021
# This seems to be None in some case (py3 only)

impacket/version.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@
99
# for more information.
1010
#
1111

12-
import pkg_resources
12+
from importlib.metadata import version as get_version, PackageNotFoundError
1313
from impacket import __path__
1414

1515

1616
try:
17-
version = pkg_resources.get_distribution('impacket').version
18-
except pkg_resources.DistributionNotFound:
17+
version = get_version('impacket')
18+
except PackageNotFoundError:
1919
version = "?"
2020
print("Cannot determine Impacket version. "
2121
"If running from source you should at least run \"python setup.py egg_info\"")

0 commit comments

Comments
 (0)