Skip to content

Commit 9d3bc4d

Browse files
committed
Formating and ruff
1 parent 3eaa163 commit 9d3bc4d

1 file changed

Lines changed: 31 additions & 33 deletions

File tree

nxc/modules/interface.py

Lines changed: 31 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,22 @@
33
from impacket.dcerpc.v5 import rrp
44
from impacket.examples.secretsdump import RemoteOperations
55
from impacket.dcerpc.v5.rpcrt import DCERPCException
6+
import contextlib
7+
68

79
class NXCModule:
8-
'''
10+
"""
911
Retrieve the list of network interfaces info (Name, IP Address, Subnet Mask, Default Gateway) from remote Windows registry'
1012
Module by Sant0rryu : @Sant0rryu
11-
'''
12-
name = 'interface'
13-
description = 'Retrieve the list of network interfaces info (Name, IP Address, Subnet Mask, Default Gateway) from remote Windows registry'
14-
supported_protocols = ['smb']
13+
"""
14+
name = "interface"
15+
description = "Retrieve the list of network interfaces info (Name, IP Address, Subnet Mask, Default Gateway) from remote Windows registry"
16+
supported_protocols = ["smb"]
1517
opsec_safe = True
1618
multiple_hosts = True
1719

1820
def options(self, context, module_options):
19-
pass
21+
"""No options"""
2022

2123
def on_admin_login(self, context, connection):
2224
self.output = "Name: {} | IP Address: {} | SubnetMask: {} | Gateway: {}"
@@ -26,58 +28,54 @@ def on_admin_login(self, context, connection):
2628

2729
if remoteOps._RemoteOperations__rrp:
2830
ans = rrp.hOpenLocalMachine(remoteOps._RemoteOperations__rrp)
29-
regHandle = ans['phKey']
31+
regHandle = ans["phKey"]
3032

31-
ans = rrp.hBaseRegOpenKey(remoteOps._RemoteOperations__rrp, regHandle, 'SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Parameters\\Interfaces')
32-
keyHandle = ans['phkResult']
33+
ans = rrp.hBaseRegOpenKey(remoteOps._RemoteOperations__rrp, regHandle, "SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Parameters\\Interfaces")
34+
keyHandle = ans["phkResult"]
3335

3436
interface = {}
3537
subKeys = []
3638
i = 0
3739
while True:
3840
try:
3941
key = rrp.hBaseRegEnumKey(remoteOps._RemoteOperations__rrp, keyHandle, i)
40-
subKeys.append(key['lpNameOut'][:-1])
42+
subKeys.append(key["lpNameOut"][:-1])
4143
i += 1
4244
except Exception:
4345
break
4446

4547
for subKey in subKeys:
4648
try:
47-
interfaceKey = 'SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Parameters\\Interfaces\\{}'.format(subKey)
49+
interfaceKey = f"SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Parameters\\Interfaces\\{subKey}"
4850
ans = rrp.hBaseRegOpenKey(remoteOps._RemoteOperations__rrp, regHandle, interfaceKey)
49-
interfaceHandle = ans['phkResult']
50-
51-
#Retrieve IPAddress
52-
ip_address = rrp.hBaseRegQueryValue(remoteOps._RemoteOperations__rrp, interfaceHandle, 'IPAddress')
53-
interface[subKey] = {'IPAddress' : str(ip_address[1])}
51+
interfaceHandle = ans["phkResult"]
5452

55-
#Retrieve SubnetMask
56-
subnetmask = rrp.hBaseRegQueryValue(remoteOps._RemoteOperations__rrp, interfaceHandle, 'SubnetMask')
57-
interface[subKey]['SubnetMask'] = str(subnetmask[1])
53+
# Retrieve IPAddress
54+
ip_address = rrp.hBaseRegQueryValue(remoteOps._RemoteOperations__rrp, interfaceHandle, "IPAddress")
55+
interface[subKey] = {"IPAddress": str(ip_address[1])}
5856

57+
# Retrieve SubnetMask
58+
subnetmask = rrp.hBaseRegQueryValue(remoteOps._RemoteOperations__rrp, interfaceHandle, "SubnetMask")
59+
interface[subKey]["SubnetMask"] = str(subnetmask[1])
5960

60-
#Retrieve DefaultGateway
61-
defaultgateway = rrp.hBaseRegQueryValue(remoteOps._RemoteOperations__rrp, interfaceHandle, 'DefaultGateway')
62-
interface[subKey]['DefaultGateway'] = str(defaultgateway[1])
61+
# Retrieve DefaultGateway
62+
defaultgateway = rrp.hBaseRegQueryValue(remoteOps._RemoteOperations__rrp, interfaceHandle, "DefaultGateway")
63+
interface[subKey]["DefaultGateway"] = str(defaultgateway[1])
6364

64-
#Retrieve Interace Name
65-
interfaceNameKey = 'SYSTEM\\ControlSet001\\Control\\Network\\' + '{4D36E972-E325-11CE-BFC1-08002BE10318}' + '\\{}\\Connection'.format(subKey)
65+
# Retrieve Interace Name
66+
interfaceNameKey = "SYSTEM\\ControlSet001\\Control\\Network\\" + "{4D36E972-E325-11CE-BFC1-08002BE10318}" + f"\\{subKey}\\Connection"
6667
ans = rrp.hBaseRegOpenKey(remoteOps._RemoteOperations__rrp, regHandle, interfaceNameKey)
67-
interfaceNameHandle = ans['phkResult']
68-
name = rrp.hBaseRegQueryValue(remoteOps._RemoteOperations__rrp, interfaceNameHandle, 'Name')
69-
interface[subKey]['Name'] = str(name[1])
70-
68+
interfaceNameHandle = ans["phkResult"]
69+
name = rrp.hBaseRegQueryValue(remoteOps._RemoteOperations__rrp, interfaceNameHandle, "Name")
70+
interface[subKey]["Name"] = str(name[1])
7171

72-
context.log.highlight(self.output.format(interface[subKey]['Name'], interface[subKey]['IPAddress'], interface[subKey]['SubnetMask'], interface[subKey]['DefaultGateway']))
72+
context.log.highlight(self.output.format(interface[subKey]["Name"], interface[subKey]["IPAddress"], interface[subKey]["SubnetMask"], interface[subKey]["DefaultGateway"]))
7373

7474
except DCERPCException:
7575
continue
7676

77-
try:
77+
with contextlib.suppress(Exception):
7878
remoteOps.finish()
79-
except Exception:
80-
pass
8179

8280
except DCERPCException as e:
83-
context.log.error(f"Failed to connect to the target: {str(e)}")
81+
context.log.error(f"Failed to connect to the target: {e!s}")

0 commit comments

Comments
 (0)