Agent: Change readme if condition in RansomwarePayload.cleanup()

If the _readme_incomplete flag is set but no readme file has been left
in the target directory, do not leave a new readme file. This can happen
if the thread is forcefully killed between the time when the flag is set
and the file is first created. The cleanup function is only concerned
with cleaning up incomplete files, not ensuring the existence of the
file under all circumstances.
This commit is contained in:
Mike Salvatore 2021-11-30 11:35:04 -05:00
parent 789a6691c1
commit a5fc0bc393
1 changed files with 4 additions and 1 deletions

View File

@ -74,7 +74,10 @@ class RansomwarePayload:
logger.warning(f"An error occurred while attempting to leave a README.txt file: {ex}")
def cleanup(self):
if self._readme_incomplete:
# This cleanup function is only concerned with cleaning up and replacing *incomplete*
# README.txt files; its goal is not to ensure the existence of a README file. Therefore,
# only retry if a README.txt file actually exists.
if self._readme_incomplete and self._readme_file_path.exists():
logger.info(
"The process of leaving a README.txt was interrupted. Removing the corrupt file "
"and trying again."