Skip to content

Commit 837f9a0

Browse files
committed
Fix "tries" logic due to merge and beautify code
1 parent 2e73007 commit 837f9a0

4 files changed

Lines changed: 15 additions & 6 deletions

File tree

nxc/protocols/smb/atexec.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,9 +194,12 @@ def execute_handler(self, command, fileless=False):
194194
if tries > self.__tries:
195195
self.logger.fail("ATEXEC: Could not retrieve output file, it may have been detected by AV. Please increase the number of tries with the option '--get-output-tries'. If it is still failing, try the 'wmi' protocol or another exec method")
196196
break
197-
if str(e).find("STATUS_BAD_NETWORK_NAME") > 0:
197+
if "STATUS_BAD_NETWORK_NAME" in str(e):
198198
self.logger.fail(f"ATEXEC: Getting the output file failed - target has blocked access to the share: {self.__share} (but the command may have executed!)")
199199
break
200+
elif "STATUS_VIRUS_INFECTED" in str(e):
201+
self.logger.fail("Command did not run because a virus was detected")
202+
break
200203
# When executing powershell and the command is still running, we get a sharing violation
201204
# We can use that information to wait longer than if the file is not found (probably av or something)
202205
if "STATUS_SHARING_VIOLATION" in str(e):

nxc/protocols/smb/mmcexec.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,9 +260,12 @@ def get_output_remote(self):
260260
if tries > self.__tries:
261261
self.logger.fail("MMCEXEC: Could not retrieve output file, it may have been detected by AV. Please increase the number of tries with the option '--get-output-tries'. If it is still failing, try the 'wmi' protocol or another exec method")
262262
break
263-
if str(e).find("STATUS_BAD_NETWORK_NAME") > 0:
263+
if "STATUS_BAD_NETWORK_NAME" in str(e):
264264
self.logger.fail(f"MMCEXEC: Getting the output file failed - target has blocked access to the share: {self.__share} (but the command may have executed!)")
265265
break
266+
elif "STATUS_VIRUS_INFECTED" in str(e):
267+
self.logger.fail("Command did not run because a virus was detected")
268+
break
266269
# When executing powershell and the command is still running, we get a sharing violation
267270
# We can use that information to wait longer than if the file is not found (probably av or something)
268271
if "STATUS_SHARING_VIOLATION" in str(e):

nxc/protocols/smb/smbexec.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,9 +149,12 @@ def get_output_remote(self):
149149
if tries > self.__tries:
150150
self.logger.fail("SMBEXEC: Could not retrieve output file, it may have been detected by AV. Please increase the number of tries with the option '--get-output-tries'. If it is still failing, try the 'wmi' protocol or another exec method")
151151
break
152-
if str(e).find("STATUS_BAD_NETWORK_NAME") > 0:
152+
if "STATUS_BAD_NETWORK_NAME" in str(e):
153153
self.logger.fail(f"SMBEXEC: Getting the output file failed - target has blocked access to the share: {self.__share} (but the command may have executed!)")
154154
break
155+
elif "STATUS_VIRUS_INFECTED" in str(e):
156+
self.logger.fail("Command did not run because a virus was detected")
157+
break
155158
# When executing powershell and the command is still running, we get a sharing violation
156159
# We can use that information to wait longer than if the file is not found (probably av or something)
157160
if "STATUS_SHARING_VIOLATION" in str(e):

nxc/protocols/smb/wmiexec.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,24 +152,24 @@ def get_output_remote(self):
152152
if tries > self.__tries:
153153
self.logger.fail("wmiexec: Could not retrieve output file, it may have been detected by AV. If it is still failing, try the 'wmi' protocol or another exec method")
154154
break
155-
elif str(e).find("STATUS_BAD_NETWORK_NAME") > 0:
155+
elif "STATUS_BAD_NETWORK_NAME" in str(e):
156156
self.logger.fail(f"SMB connection: target has blocked {self.__share} access (maybe command executed!)")
157157
break
158-
elif str(e).find("STATUS_VIRUS_INFECTED") >= 0:
158+
elif "STATUS_VIRUS_INFECTED" in str(e):
159159
self.logger.fail("Command did not run because a virus was detected")
160160
break
161161
# When executing powershell and the command is still running, we get a sharing violation
162162
# We can use that information to wait longer than if the file is not found (probably av or something)
163163
elif "STATUS_SHARING_VIOLATION" in str(e):
164164
self.logger.info(f"File {self.__share}\\{self.__output} is still in use with {self.__tries - tries} left, retrying...")
165165
sleep(1)
166+
tries += 1
166167
elif "STATUS_OBJECT_NAME_NOT_FOUND" in str(e):
167168
self.logger.info(f"File {self.__share}\\{self.__output} not found with {self.__tries - tries} left, deducting 10 tries and retrying...")
168169
tries += 10
169170
sleep(1)
170171
else:
171172
self.logger.debug(f"Exception when trying to read output file: {e}")
172-
tries += 1
173173

174174
if self.__outputBuffer:
175175
self.logger.debug(f"Deleting file {self.__share}\\{self.__output}")

0 commit comments

Comments
 (0)