Skip to content

Commit 7b3deba

Browse files
committed
Use contextlib instead of empty try&except
1 parent e3ef313 commit 7b3deba

1 file changed

Lines changed: 3 additions & 7 deletions

File tree

nxc/modules/webdav.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from impacket.smb3structs import FILE_READ_DATA
55
from impacket.smbconnection import SessionError
66
from impacket.nmb import NetBIOSError
7+
import contextlib
78

89

910
class NXCModule:
@@ -32,8 +33,6 @@ def on_login(self, context, connection):
3233
Check whether the 'DAV RPC Service' pipe exists within the 'IPC$' share. This indicates
3334
that the WebClient service is running on the target.
3435
"""
35-
remote_file = None
36-
3736
try:
3837
remote_file = RemoteFile(connection.conn, "DAV RPC Service", "IPC$", access=FILE_READ_DATA)
3938
remote_file.open_file()
@@ -56,8 +55,5 @@ def on_login(self, context, connection):
5655
return
5756

5857
finally:
59-
if remote_file is not None:
60-
try:
61-
remote_file.close()
62-
except Exception:
63-
pass
58+
with contextlib.suppress(Exception):
59+
remote_file.close()

0 commit comments

Comments
 (0)