From 5696c3e5368119b21c618ceb34646c7fe2dec7df Mon Sep 17 00:00:00 2001 From: Shay Nehmad Date: Mon, 31 Aug 2020 18:06:08 +0300 Subject: [PATCH] Some more easy noqas or invalid escape fixes --- monkey/infection_monkey/main.py | 3 ++- monkey/infection_monkey/model/__init__.py | 2 +- monkey/infection_monkey/network/ping_scanner.py | 2 +- monkey/infection_monkey/network/sshfinger.py | 2 +- .../job_scheduling/windows_job_scheduling.py | 2 +- monkey/infection_monkey/transport/__init__.py | 2 +- monkey/infection_monkey/transport/tcp.py | 2 +- monkey/infection_monkey/utils/hidden_files.py | 4 ++-- .../infection_monkey/utils/windows/hidden_files.py | 12 ++++++------ 9 files changed, 16 insertions(+), 15 deletions(-) diff --git a/monkey/infection_monkey/main.py b/monkey/infection_monkey/main.py index cad4a00c0..e4698a462 100644 --- a/monkey/infection_monkey/main.py +++ b/monkey/infection_monkey/main.py @@ -7,8 +7,9 @@ import sys import traceback from multiprocessing import freeze_support +# dummy import for pyinstaller # noinspection PyUnresolvedReferences -import infection_monkey.post_breach # dummy import for pyinstaller +import infection_monkey.post_breach # noqa: F401 from common.version import get_version from infection_monkey.config import EXTERNAL_CONFIG_FILE, WormConfiguration from infection_monkey.dropper import MonkeyDrops diff --git a/monkey/infection_monkey/model/__init__.py b/monkey/infection_monkey/model/__init__.py index e7ab94495..4f3f2c27d 100644 --- a/monkey/infection_monkey/model/__init__.py +++ b/monkey/infection_monkey/model/__init__.py @@ -1,4 +1,4 @@ -from infection_monkey.model.host import VictimHost +from infection_monkey.model.host import VictimHost # noqa: F401 __author__ = 'itamar' diff --git a/monkey/infection_monkey/network/ping_scanner.py b/monkey/infection_monkey/network/ping_scanner.py index f35533f0c..27c814593 100644 --- a/monkey/infection_monkey/network/ping_scanner.py +++ b/monkey/infection_monkey/network/ping_scanner.py @@ -12,7 +12,7 @@ __author__ = 'itamar' PING_COUNT_FLAG = "-n" if "win32" == sys.platform else "-c" PING_TIMEOUT_FLAG = "-w" if "win32" == sys.platform else "-W" -TTL_REGEX_STR = '(?<=TTL\=)[0-9]+' +TTL_REGEX_STR = r'(?<=TTL\=)[0-9]+' LINUX_TTL = 64 WINDOWS_TTL = 128 diff --git a/monkey/infection_monkey/network/sshfinger.py b/monkey/infection_monkey/network/sshfinger.py index a686d7fbd..909e75429 100644 --- a/monkey/infection_monkey/network/sshfinger.py +++ b/monkey/infection_monkey/network/sshfinger.py @@ -6,7 +6,7 @@ from infection_monkey.network.tools import check_tcp_port SSH_PORT = 22 SSH_SERVICE_DEFAULT = 'tcp-22' -SSH_REGEX = 'SSH-\d\.\d-OpenSSH' +SSH_REGEX = r'SSH-\d\.\d-OpenSSH' TIMEOUT = 10 BANNER_READ = 1024 LINUX_DIST_SSH = ['ubuntu', 'debian'] diff --git a/monkey/infection_monkey/post_breach/job_scheduling/windows_job_scheduling.py b/monkey/infection_monkey/post_breach/job_scheduling/windows_job_scheduling.py index fe3dad525..017203821 100644 --- a/monkey/infection_monkey/post_breach/job_scheduling/windows_job_scheduling.py +++ b/monkey/infection_monkey/post_breach/job_scheduling/windows_job_scheduling.py @@ -1,5 +1,5 @@ SCHEDULED_TASK_NAME = 'monkey-spawn-cmd' -SCHEDULED_TASK_COMMAND = 'C:\windows\system32\cmd.exe' +SCHEDULED_TASK_COMMAND = r'C:\windows\system32\cmd.exe' # Commands from: https://github.com/redcanaryco/atomic-red-team/blob/master/atomics/T1053.005/T1053.005.md diff --git a/monkey/infection_monkey/transport/__init__.py b/monkey/infection_monkey/transport/__init__.py index c3df1cb01..97d6a232b 100644 --- a/monkey/infection_monkey/transport/__init__.py +++ b/monkey/infection_monkey/transport/__init__.py @@ -1 +1 @@ -from infection_monkey.transport.http import HTTPServer, LockedHTTPServer +from infection_monkey.transport.http import HTTPServer, LockedHTTPServer # noqa: F401 diff --git a/monkey/infection_monkey/transport/tcp.py b/monkey/infection_monkey/transport/tcp.py index aa7ce253e..928f4b079 100644 --- a/monkey/infection_monkey/transport/tcp.py +++ b/monkey/infection_monkey/transport/tcp.py @@ -65,7 +65,7 @@ class TcpProxy(TransportProxyBase): dest = socket.socket(socket.AF_INET, socket.SOCK_STREAM) try: dest.connect((self.dest_host, self.dest_port)) - except socket.error as ex: + except socket.error: source.close() dest.close() continue diff --git a/monkey/infection_monkey/utils/hidden_files.py b/monkey/infection_monkey/utils/hidden_files.py index 46d8e136b..863680085 100644 --- a/monkey/infection_monkey/utils/hidden_files.py +++ b/monkey/infection_monkey/utils/hidden_files.py @@ -5,8 +5,8 @@ from infection_monkey.utils.linux.hidden_files import ( get_linux_commands_to_delete, get_linux_commands_to_hide_files, get_linux_commands_to_hide_folders) from infection_monkey.utils.windows.hidden_files import ( - get_winAPI_to_hide_files, get_windows_commands_to_delete, - get_windows_commands_to_hide_files, get_windows_commands_to_hide_folders) + get_windows_commands_to_delete, get_windows_commands_to_hide_files, + get_windows_commands_to_hide_folders) def get_commands_to_hide_files(): diff --git a/monkey/infection_monkey/utils/windows/hidden_files.py b/monkey/infection_monkey/utils/windows/hidden_files.py index 6199fa88d..d192bbb76 100644 --- a/monkey/infection_monkey/utils/windows/hidden_files.py +++ b/monkey/infection_monkey/utils/windows/hidden_files.py @@ -52,12 +52,12 @@ def get_winAPI_to_hide_files(): fileFlags = win32file.FILE_ATTRIBUTE_HIDDEN # make hidden _ = win32file.CreateFile(HIDDEN_FILE_WINAPI, - fileAccess, - 0, # sharing mode: 0 => can't be shared - None, # security attributes - fileCreation, - fileFlags, - 0) # template file + fileAccess, + 0, # sharing mode: 0 => can't be shared + None, # security attributes + fileCreation, + fileFlags, + 0) # template file return "Succesfully created hidden file: {}".format(HIDDEN_FILE_WINAPI), True except Exception as err: