Skip to content

Commit 6c07fa8

Browse files
committed
Convert while loop to for loop
1 parent 34e7d9f commit 6c07fa8

1 file changed

Lines changed: 6 additions & 8 deletions

File tree

nxc/protocols/smb.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1178,26 +1178,24 @@ def output(sessions):
11781178
self.logger.highlight(row)
11791179
else:
11801180
self.logger.info(f"No active session found for specified user(s) using the Remote Registry service on {self.hostname}.")
1181-
1181+
11821182
# Bind to the Remote Registry Pipe
11831183
rpctransport = transport.SMBTransport(self.conn.getRemoteName(), self.conn.getRemoteHost(), filename=r"\winreg", smb_connection=self.conn)
1184-
binding_attempts = 2
1185-
while True:
1184+
for binding_attempts in range(2, 0, -1):
11861185
dce = rpctransport.get_dce_rpc()
1187-
1186+
11881187
try:
11891188
dce.connect()
11901189
dce.bind(rrp.MSRPC_UUID_RRP)
11911190
break
1192-
except Exception as e:
1191+
except SessionError as e:
11931192
self.logger.debug(f"Could not bind to the Remote Registry on {self.hostname}: {e}")
1194-
if binding_attempts == 1:
1193+
if binding_attempts == 1: # Last attempt
11951194
self.logger.info(f"The Remote Registry service seems to be disabled on {self.hostname}.")
11961195
return
1197-
1196+
11981197
# STATUS_PIPE_NOT_AVAILABLE : Waiting 1 second for the service to start (if idle and set to 'Automatic' startup type)
11991198
sleep(1)
1200-
binding_attempts -= 1
12011199

12021200
# Open HKU hive
12031201
try:

0 commit comments

Comments
 (0)