From 2f6803dc3d632ad17113cccbcd67b02450a94f37 Mon Sep 17 00:00:00 2001 From: Mike Salvatore Date: Mon, 3 May 2021 12:42:41 -0400 Subject: [PATCH 01/49] Add vulture pre-commit hook --- .pre-commit-config.yaml | 4 ++++ pyproject.toml | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index af30837fe..75c0ea28f 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -48,3 +48,7 @@ repos: rev: v0.2 hooks: - id: swimm-verify + - repo: https://github.com/jendrikseipp/vulture + rev: v2.3 + hooks: + - id: vulture diff --git a/pyproject.toml b/pyproject.toml index 0245f12a0..d67c57cf6 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -21,3 +21,7 @@ log_cli_format = "%(asctime)s [%(levelname)s] %(module)s.%(funcName)s.%(lineno)d log_cli_date_format = "%H:%M:%S" addopts = "-v --capture=sys tests" norecursedirs = "node_modules dist" + +[tool.vulture] +exclude = ["monkey/monkey_island/cc/ui"] +paths = ["."] From b41a2f2366a4385e68603c6348b7990cd46775b2 Mon Sep 17 00:00:00 2001 From: Mike Salvatore Date: Mon, 3 May 2021 13:05:42 -0400 Subject: [PATCH 02/49] travis: Fail build if vulture finds dead code --- .travis.yml | 3 +++ monkey/monkey_island/Pipfile | 1 + monkey/monkey_island/Pipfile.lock | 10 +++++++++- 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index b3f1e7428..8c7acfc3e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -63,6 +63,9 @@ script: ## Check that all python is properly formatted. Fail otherwise. - python -m black --check . +## Check that there is no dead python code +- python -m vulture . + ## Run unit tests and generate coverage data - cd monkey # This is our source dir - python -m pytest --cov=. # Have to use `python -m pytest` instead of `pytest` to add "{$builddir}/monkey/monkey" to sys.path. diff --git a/monkey/monkey_island/Pipfile b/monkey/monkey_island/Pipfile index 65eeaae4b..212e08e86 100644 --- a/monkey/monkey_island/Pipfile +++ b/monkey/monkey_island/Pipfile @@ -42,6 +42,7 @@ flake8 = "==3.9.0" pytest-cov = "*" isort = "==5.8.0" coverage = "*" +vulture = "==2.3" [requires] python_version = "3.7" diff --git a/monkey/monkey_island/Pipfile.lock b/monkey/monkey_island/Pipfile.lock index 46479e643..7e9f1be72 100644 --- a/monkey/monkey_island/Pipfile.lock +++ b/monkey/monkey_island/Pipfile.lock @@ -1,7 +1,7 @@ { "_meta": { "hash": { - "sha256": "3057235b1e85593ee307d9e5a2e0d15e26f13437bb709529303c7c900d3c7b41" + "sha256": "6734e0c45321194a1ec4ac2e91af8efb9b9dd9e7f02af146d01219dc64847a51" }, "pipfile-spec": 6, "requires": { @@ -1447,6 +1447,14 @@ "index": "pypi", "version": "==20.4.3" }, + "vulture": { + "hashes": [ + "sha256:03d5a62bcbe9ceb9a9b0575f42d71a2d414070229f2e6f95fa6e7c71aaaed967", + "sha256:f39de5e6f1df1f70c3b50da54f1c8d494159e9ca3d01a9b89eac929600591703" + ], + "index": "pypi", + "version": "==2.3" + }, "zipp": { "hashes": [ "sha256:3607921face881ba3e026887d8150cca609d517579abe052ac81fc5aeffdbd76", From 9649f90cff9ee4df5d00e3f3f4ebec34ec155a2f Mon Sep 17 00:00:00 2001 From: Mike Salvatore Date: Mon, 3 May 2021 13:22:37 -0400 Subject: [PATCH 03/49] agent: Remove unused parameter securityFlags from create_smb() --- monkey/infection_monkey/exploit/sambacry.py | 1 - 1 file changed, 1 deletion(-) diff --git a/monkey/infection_monkey/exploit/sambacry.py b/monkey/infection_monkey/exploit/sambacry.py index 72d36e234..7a4c12429 100644 --- a/monkey/infection_monkey/exploit/sambacry.py +++ b/monkey/infection_monkey/exploit/sambacry.py @@ -465,7 +465,6 @@ class SambaCryExploiter(HostExploiter): creationDisposition, fileAttributes, impersonationLevel=SMB2_IL_IMPERSONATION, - securityFlags=0, oplockLevel=SMB2_OPLOCK_LEVEL_NONE, createContexts=None, ): From 33e74b1f3e6b0bdde1e4c4149f05637978db1738 Mon Sep 17 00:00:00 2001 From: Mike Salvatore Date: Mon, 3 May 2021 13:49:27 -0400 Subject: [PATCH 04/49] agent: Use consistent naming for parameters to __exit__() Using these specific names prevents Vulture from identifying these parameters as unused. --- monkey/infection_monkey/network/firewall.py | 2 +- monkey/infection_monkey/utils/auto_new_user.py | 2 +- monkey/infection_monkey/utils/linux/users.py | 2 +- monkey/infection_monkey/utils/windows/users.py | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/monkey/infection_monkey/network/firewall.py b/monkey/infection_monkey/network/firewall.py index cddba49fe..0851a575f 100644 --- a/monkey/infection_monkey/network/firewall.py +++ b/monkey/infection_monkey/network/firewall.py @@ -31,7 +31,7 @@ class FirewallApp(object): def __enter__(self): return self - def __exit__(self, exc_type, value, traceback): + def __exit__(self, _exc_type, value, traceback): self.close() def close(self): diff --git a/monkey/infection_monkey/utils/auto_new_user.py b/monkey/infection_monkey/utils/auto_new_user.py index f3ebda0af..767237d1f 100644 --- a/monkey/infection_monkey/utils/auto_new_user.py +++ b/monkey/infection_monkey/utils/auto_new_user.py @@ -31,7 +31,7 @@ class AutoNewUser(metaclass=abc.ABCMeta): raise NotImplementedError() @abc.abstractmethod - def __exit__(self, exc_type, exc_val, exc_tb): + def __exit__(self, _exc_type, value, traceback): raise NotImplementedError() @abc.abstractmethod diff --git a/monkey/infection_monkey/utils/linux/users.py b/monkey/infection_monkey/utils/linux/users.py index 9bd3c2bf8..002c63f96 100644 --- a/monkey/infection_monkey/utils/linux/users.py +++ b/monkey/infection_monkey/utils/linux/users.py @@ -54,7 +54,7 @@ class AutoNewLinuxUser(AutoNewUser): ) return subprocess.call(command_as_new_user) - def __exit__(self, exc_type, exc_val, exc_tb): + def __exit__(self, _exc_type, value, traceback): # delete the user. commands_to_delete_user = get_linux_commands_to_delete_user(self.username) logger.debug( diff --git a/monkey/infection_monkey/utils/windows/users.py b/monkey/infection_monkey/utils/windows/users.py index 06e626783..1a2bee53c 100644 --- a/monkey/infection_monkey/utils/windows/users.py +++ b/monkey/infection_monkey/utils/windows/users.py @@ -111,7 +111,7 @@ class AutoNewWindowsUser(AutoNewUser): def get_logon_handle(self): return self.logon_handle - def __exit__(self, exc_type, exc_val, exc_tb): + def __exit__(self, _exc_type, value, traceback): # Logoff self.logon_handle.Close() From 638e70e97854ba4f9995f3374da25a80e74ef645 Mon Sep 17 00:00:00 2001 From: Shreya Date: Tue, 4 May 2021 12:00:23 +0530 Subject: [PATCH 05/49] Remove unused code in unit tests --- .../monkey_island/cc/environment/test_environment.py | 4 ---- .../cc/services/reporting/test_report.py | 1 - .../cc/services/test_bootloader_service.py | 11 ----------- 3 files changed, 16 deletions(-) diff --git a/monkey/tests/monkey_island/cc/environment/test_environment.py b/monkey/tests/monkey_island/cc/environment/test_environment.py index 6b648ddee..4c32cf137 100644 --- a/monkey/tests/monkey_island/cc/environment/test_environment.py +++ b/monkey/tests/monkey_island/cc/environment/test_environment.py @@ -63,10 +63,6 @@ class StubEnvironmentConfig(EnvironmentConfig): os.remove(self.server_config_path) -def get_server_config_file_path_test_version(): - return os.path.join(os.getcwd(), "test_config.json") - - class TestEnvironment(TestCase): class EnvironmentCredentialsNotRequired(Environment): def __init__(self): diff --git a/monkey/tests/monkey_island/cc/services/reporting/test_report.py b/monkey/tests/monkey_island/cc/services/reporting/test_report.py index cbc9777d3..989c46eed 100644 --- a/monkey/tests/monkey_island/cc/services/reporting/test_report.py +++ b/monkey/tests/monkey_island/cc/services/reporting/test_report.py @@ -21,7 +21,6 @@ NT_HASH = "a9fdfa038c4b75ebc76dc855dd74f0da" VICTIM_IP = "0.0.0.0" VICTIM_DOMAIN_NAME = "domain-name" HOSTNAME = "name-of-host" -EXPLOITER_CLASS_NAME = "exploiter-name" # Below telem constants only contain fields relevant to current tests diff --git a/monkey/tests/monkey_island/cc/services/test_bootloader_service.py b/monkey/tests/monkey_island/cc/services/test_bootloader_service.py index 81c4affff..25869fd29 100644 --- a/monkey/tests/monkey_island/cc/services/test_bootloader_service.py +++ b/monkey/tests/monkey_island/cc/services/test_bootloader_service.py @@ -2,17 +2,6 @@ from unittest import TestCase from monkey_island.cc.services.bootloader import BootloaderService -WINDOWS_VERSIONS = { - "5.0": "Windows 2000", - "5.1": "Windows XP", - "5.2": "Windows XP/server 2003", - "6.0": "Windows Vista/server 2008", - "6.1": "Windows 7/server 2008R2", - "6.2": "Windows 8/server 2012", - "6.3": "Windows 8.1/server 2012R2", - "10.0": "Windows 10/server 2016-2019", -} - MIN_GLIBC_VERSION = 2.14 From df7759e3327ff3b589ac3b9a78e646e9fd11638d Mon Sep 17 00:00:00 2001 From: Shreya Date: Tue, 4 May 2021 13:03:20 +0530 Subject: [PATCH 06/49] Remove unused variable `DETAILS_DTO` from `monkey_island/cc/services/zero_trust/test_common/monkey_finding_data.py` --- .../cc/services/zero_trust/test_common/monkey_finding_data.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/monkey/monkey_island/cc/services/zero_trust/test_common/monkey_finding_data.py b/monkey/monkey_island/cc/services/zero_trust/test_common/monkey_finding_data.py index 0e5433784..c7053ebda 100644 --- a/monkey/monkey_island/cc/services/zero_trust/test_common/monkey_finding_data.py +++ b/monkey/monkey_island/cc/services/zero_trust/test_common/monkey_finding_data.py @@ -26,8 +26,6 @@ EVENTS_DTO = [ for event in EVENTS ] -DETAILS_DTO = [] - def get_monkey_details_dto() -> MonkeyFindingDetails: monkey_details = MonkeyFindingDetails() From 9bcaa2ef8e6e8ca101ebd7cfdf3ccce342732fcb Mon Sep 17 00:00:00 2001 From: Shreya Date: Tue, 4 May 2021 13:05:41 +0530 Subject: [PATCH 07/49] Remove unused `did_exploit_type_succeed()` from `monkey_island/cc/services/reporting/report.py` --- monkey/monkey_island/cc/services/reporting/report.py | 9 --------- 1 file changed, 9 deletions(-) diff --git a/monkey/monkey_island/cc/services/reporting/report.py b/monkey/monkey_island/cc/services/reporting/report.py index ade56e64e..5a27b8933 100644 --- a/monkey/monkey_island/cc/services/reporting/report.py +++ b/monkey/monkey_island/cc/services/reporting/report.py @@ -763,12 +763,3 @@ class ReportService: if ReportService.is_latest_report_exists(): return ReportService.decode_dot_char_before_mongo_insert(mongo.db.report.find_one()) return safe_generate_regular_report() - - @staticmethod - def did_exploit_type_succeed(exploit_type): - return ( - mongo.db.edge.count( - {"exploits": {"$elemMatch": {"exploiter": exploit_type, "result": True}}}, limit=1 - ) - > 0 - ) From f32e1e0a0fbe46cfc73117513d90ddd7a0158a85 Mon Sep 17 00:00:00 2001 From: Shreya Date: Tue, 4 May 2021 13:17:12 +0530 Subject: [PATCH 08/49] Remove unused variable `is_auth` in `monkey_island/cc/services/remote_run_aws.py` --- monkey/monkey_island/cc/services/remote_run_aws.py | 1 - 1 file changed, 1 deletion(-) diff --git a/monkey/monkey_island/cc/services/remote_run_aws.py b/monkey/monkey_island/cc/services/remote_run_aws.py index 553f4c72e..3f105a547 100644 --- a/monkey/monkey_island/cc/services/remote_run_aws.py +++ b/monkey/monkey_island/cc/services/remote_run_aws.py @@ -13,7 +13,6 @@ logger = logging.getLogger(__name__) class RemoteRunAwsService: aws_instance = None - is_auth = False def __init__(self): pass From 9c629f964cb218c48d140c9b922bfbea3ca4401f Mon Sep 17 00:00:00 2001 From: Shreya Date: Tue, 4 May 2021 13:19:31 +0530 Subject: [PATCH 09/49] Remove unused variable `UPLOADS_DIR_NAME` in `monkey_island/cc/services/post_breach_files.py` --- monkey/monkey_island/cc/services/post_breach_files.py | 1 - 1 file changed, 1 deletion(-) diff --git a/monkey/monkey_island/cc/services/post_breach_files.py b/monkey/monkey_island/cc/services/post_breach_files.py index 504522d9a..626a2a56d 100644 --- a/monkey/monkey_island/cc/services/post_breach_files.py +++ b/monkey/monkey_island/cc/services/post_breach_files.py @@ -12,7 +12,6 @@ logger = logging.getLogger(__name__) # Where to find file names in config PBA_WINDOWS_FILENAME_PATH = ["monkey", "post_breach", "PBA_windows_filename"] PBA_LINUX_FILENAME_PATH = ["monkey", "post_breach", "PBA_linux_filename"] -UPLOADS_DIR_NAME = "userUploads" def remove_PBA_files(): From e4c45153ea41a9e65af50d448f806fdb803ccf0f Mon Sep 17 00:00:00 2001 From: Shreya Date: Tue, 4 May 2021 13:27:43 +0530 Subject: [PATCH 10/49] Remove unused `get_monkey_critical_services()` and `get_monkey_label_by_id()` in `monkey_island/cc/services/node.py` --- monkey/monkey_island/cc/services/node.py | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/monkey/monkey_island/cc/services/node.py b/monkey/monkey_island/cc/services/node.py index 78c165503..c906c47a9 100644 --- a/monkey/monkey_island/cc/services/node.py +++ b/monkey/monkey_island/cc/services/node.py @@ -104,17 +104,6 @@ class NodeService: return True - @staticmethod - def get_monkey_label_by_id(monkey_id): - return NodeService.get_monkey_label(NodeService.get_monkey_by_id(monkey_id)) - - @staticmethod - def get_monkey_critical_services(monkey_id): - critical_services = mongo.db.monkey.find_one( - {"_id": monkey_id}, {"critical_services": 1} - ).get("critical_services", []) - return critical_services - @staticmethod def get_monkey_label(monkey): # todo From a5481c15f81fd7edaf24838b0dd035dbc4fce578 Mon Sep 17 00:00:00 2001 From: Shreya Date: Tue, 4 May 2021 14:01:07 +0530 Subject: [PATCH 11/49] Remove unused `get_latest_attack_telem_time()` from `monkey_island/cc/services/attack/attack_report.py` --- .../cc/services/attack/attack_report.py | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/monkey/monkey_island/cc/services/attack/attack_report.py b/monkey/monkey_island/cc/services/attack/attack_report.py index 5845db502..02936b509 100644 --- a/monkey/monkey_island/cc/services/attack/attack_report.py +++ b/monkey/monkey_island/cc/services/attack/attack_report.py @@ -119,19 +119,6 @@ class AttackReportService: mongo.db.attack_report.replace_one({"name": REPORT_NAME}, report, upsert=True) return report - @staticmethod - def get_latest_attack_telem_time(): - """ - Gets timestamp of latest attack telem - :return: timestamp of latest attack telem - """ - return [ - x["timestamp"] - for x in mongo.db.telemetry.find({"telem_category": "attack"}) - .sort("timestamp", -1) - .limit(1) - ][0] - @staticmethod def get_latest_report(): """ From eeaafc9a3b07358b1a1155e72fb110350601745c Mon Sep 17 00:00:00 2001 From: Shreya Date: Tue, 4 May 2021 16:38:07 +0530 Subject: [PATCH 12/49] Remove ununsed variable `user_id_table` in `monkey_island/cc/resources/auth/user_store.py` --- monkey/monkey_island/cc/resources/auth/user_store.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/monkey/monkey_island/cc/resources/auth/user_store.py b/monkey/monkey_island/cc/resources/auth/user_store.py index a35f4b3d6..3c5217f57 100644 --- a/monkey/monkey_island/cc/resources/auth/user_store.py +++ b/monkey/monkey_island/cc/resources/auth/user_store.py @@ -6,10 +6,8 @@ from monkey_island.cc.resources.auth.auth_user import User class UserStore: users = [] username_table = {} - user_id_table = {} @staticmethod def set_users(users: List[User]): UserStore.users = users UserStore.username_table = {u.username: u for u in UserStore.users} - UserStore.user_id_table = {u.id: u for u in UserStore.users} From b1ce5d3e2e83c0a765bf0a5f120b423a97c8f4b9 Mon Sep 17 00:00:00 2001 From: Shreya Date: Tue, 4 May 2021 16:54:44 +0530 Subject: [PATCH 13/49] Remove unused variable `MAX_MONKEYS_AMOUNT_TO_CACHE` in `monkey_island/cc/models/monkey.py` --- monkey/monkey_island/cc/models/monkey.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/monkey/monkey_island/cc/models/monkey.py b/monkey/monkey_island/cc/models/monkey.py index 3bb3c57c9..fc87c4605 100644 --- a/monkey/monkey_island/cc/models/monkey.py +++ b/monkey/monkey_island/cc/models/monkey.py @@ -20,8 +20,6 @@ from monkey_island.cc.models.monkey_ttl import MonkeyTtl, create_monkey_ttl_docu from monkey_island.cc.server_utils.consts import DEFAULT_MONKEY_TTL_EXPIRY_DURATION_IN_SECONDS from monkey_island.cc.services.utils.network_utils import local_ip_addresses -MAX_MONKEYS_AMOUNT_TO_CACHE = 100 - class Monkey(Document): """ From b7535dccb0bd138984c24359afe9d83d92a75090 Mon Sep 17 00:00:00 2001 From: Shreya Date: Tue, 4 May 2021 17:14:13 +0530 Subject: [PATCH 14/49] Remove unused variables `GENERAL_CMDLINE_LINUX` and `MONKEY_CMDLINE_HTTP` in `infection_monkey/model/__init__.py` --- monkey/infection_monkey/model/__init__.py | 9 --------- 1 file changed, 9 deletions(-) diff --git a/monkey/infection_monkey/model/__init__.py b/monkey/infection_monkey/model/__init__.py index 4f6f8de4a..988edbc07 100644 --- a/monkey/infection_monkey/model/__init__.py +++ b/monkey/infection_monkey/model/__init__.py @@ -17,7 +17,6 @@ MONKEY_CMDLINE_WINDOWS = "%s %%(monkey_path)s %s" % ( MONKEY_ARG, ) MONKEY_CMDLINE_LINUX = "./%%(monkey_filename)s %s" % (MONKEY_ARG,) -GENERAL_CMDLINE_LINUX = "(cd %(monkey_directory)s && %(monkey_commandline)s)" DROPPER_CMDLINE_DETACHED_WINDOWS = "%s start cmd /c %%(dropper_path)s %s" % ( CMD_PREFIX, DROPPER_ARG, @@ -26,14 +25,6 @@ MONKEY_CMDLINE_DETACHED_WINDOWS = "%s start cmd /c %%(monkey_path)s %s" % ( CMD_PREFIX, MONKEY_ARG, ) -MONKEY_CMDLINE_HTTP = ( - '%s /c "bitsadmin /transfer Update /download /priority high %%(http_path)s %%(monkey_path)s' - '&cmd /c %%(monkey_path)s %s"' - % ( - CMD_PREFIX, - MONKEY_ARG, - ) -) DELAY_DELETE_CMD = ( "cmd /c (for /l %%i in (1,0,2) do (ping -n 60 127.0.0.1 & del /f /q %(file_path)s & " "if not exist %(file_path)s exit)) > NUL 2>&1 " From 6cc22afd9b4b63aacc98dfacf82f082de0cac460 Mon Sep 17 00:00:00 2001 From: Shreya Date: Tue, 4 May 2021 17:17:51 +0530 Subject: [PATCH 15/49] Remove unused `get_ip_for_connection()` in `infection_monkey/network/info.py` --- monkey/infection_monkey/network/info.py | 19 ------------------- 1 file changed, 19 deletions(-) diff --git a/monkey/infection_monkey/network/info.py b/monkey/infection_monkey/network/info.py index 5ada2e29f..5bdce4887 100644 --- a/monkey/infection_monkey/network/info.py +++ b/monkey/infection_monkey/network/info.py @@ -157,22 +157,3 @@ def get_interfaces_ranges(): # limit subnet scans to class C only res.append(CidrRange(cidr_range="%s/%s" % (address_str, netmask_str))) return res - - -if is_windows_os(): - - def get_ip_for_connection(target_ip): - return None - - -else: - - def get_ip_for_connection(target_ip): - try: - query_str = "ip route get %s" % target_ip - resp = check_output(query_str.split()) - substr = resp.split() - src = substr[substr.index("src") + 1] - return src - except Exception: - return None From 2f5d33844c098643c90d5ac265b705c0519b45d2 Mon Sep 17 00:00:00 2001 From: Shreya Date: Tue, 4 May 2021 17:37:08 +0530 Subject: [PATCH 16/49] Remove unused variable `PATH_TO_ACTIONS` from `infection_monkey/post_breach/post_breach_handler.py` --- monkey/infection_monkey/post_breach/post_breach_handler.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/monkey/infection_monkey/post_breach/post_breach_handler.py b/monkey/infection_monkey/post_breach/post_breach_handler.py index 315cdac0b..d2ccb2555 100644 --- a/monkey/infection_monkey/post_breach/post_breach_handler.py +++ b/monkey/infection_monkey/post_breach/post_breach_handler.py @@ -9,8 +9,6 @@ LOG = logging.getLogger(__name__) __author__ = "VakarisZ" -PATH_TO_ACTIONS = "infection_monkey.post_breach.actions." - class PostBreach(object): """ From 8391df9114a9d45e29c85d93f89f3b94a3d8f816 Mon Sep 17 00:00:00 2001 From: Shreya Date: Tue, 4 May 2021 17:39:31 +0530 Subject: [PATCH 17/49] Remove unused `check_udp_port`, `traceroute()`, `_traceroute_windows()`, and `_traceroute_linux` from `infection_monkey/network/tools.py` --- monkey/infection_monkey/network/tools.py | 65 ------------------------ 1 file changed, 65 deletions(-) diff --git a/monkey/infection_monkey/network/tools.py b/monkey/infection_monkey/network/tools.py index 2ccfeb35b..97c3ef84f 100644 --- a/monkey/infection_monkey/network/tools.py +++ b/monkey/infection_monkey/network/tools.py @@ -82,31 +82,6 @@ def check_tcp_port(ip, port, timeout=DEFAULT_TIMEOUT, get_banner=False): return True, banner -def check_udp_port(ip, port, timeout=DEFAULT_TIMEOUT): - """ - Checks if a given UDP port is open by checking if it replies to an empty message - :param ip: Target IP - :param port: Target port - :param timeout: Timeout to wait - :return: Tuple, T/F + banner - """ - sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) - sock.settimeout(timeout) - - data = None - is_open = False - - try: - sock.sendto(b"-", (ip, port)) - data, _ = sock.recvfrom(BANNER_READ) - is_open = True - except socket.error: - pass - sock.close() - - return is_open, data - - def check_tcp_ports(ip, ports, timeout=DEFAULT_TIMEOUT, get_banner=False): """ Checks whether any of the given ports are open on a target IP. @@ -189,20 +164,6 @@ def tcp_port_to_service(port): return "tcp-" + str(port) -def traceroute(target_ip, ttl=64): - """ - Traceroute for a specific IP/name. - Note, may throw exception on failure that should be handled by caller. - :param target_ip: IP/name of target - :param ttl: Max TTL - :return: Sequence of IPs in the way - """ - if sys.platform == "win32": - return _traceroute_windows(target_ip, ttl) - else: # linux based hopefully - return _traceroute_linux(target_ip, ttl) - - def _get_traceroute_bin_path(): """ Gets the path to the prebuilt traceroute executable @@ -254,32 +215,6 @@ def _parse_traceroute(output, regex, ttl): return trace_list -def _traceroute_windows(target_ip, ttl): - """ - Traceroute for a specific IP/name - Windows implementation - """ - # we'll just use tracert because that's always there - cli = ["tracert", "-d", "-w", "250", "-h", str(ttl), target_ip] - proc_obj = subprocess.Popen(cli, stdout=subprocess.PIPE) - stdout, stderr = proc_obj.communicate() - stdout = stdout.replace("\r", "") - return _parse_traceroute(stdout, IP_ADDR_RE, ttl) - - -def _traceroute_linux(target_ip, ttl): - """ - Traceroute for a specific IP/name - Linux implementation - """ - - cli = [_get_traceroute_bin_path(), "-m", str(ttl), target_ip] - proc_obj = subprocess.Popen(cli, stdout=subprocess.PIPE) - stdout, stderr = proc_obj.communicate() - - lines = _parse_traceroute(stdout, IP_ADDR_PARENTHESES_RE, ttl) - lines = [x[1:-1] if x else None for x in lines] # Removes parenthesis - return lines - - def get_interface_to_target(dst): """ :param dst: destination IP address string without port. E.G. '192.168.1.1.' From 35f4515d6e45e1f7e22f60bcad601536f85e7ce8 Mon Sep 17 00:00:00 2001 From: Shreya Date: Tue, 4 May 2021 17:50:42 +0530 Subject: [PATCH 18/49] Remove unused `get_pba()` in `infection_monkey/post_breach/pba.py` --- monkey/infection_monkey/post_breach/pba.py | 8 -------- 1 file changed, 8 deletions(-) diff --git a/monkey/infection_monkey/post_breach/pba.py b/monkey/infection_monkey/post_breach/pba.py index bf0e66ed4..563696073 100644 --- a/monkey/infection_monkey/post_breach/pba.py +++ b/monkey/infection_monkey/post_breach/pba.py @@ -37,14 +37,6 @@ class PBA(Plugin): self.command = PBA.choose_command(linux_cmd, windows_cmd) self.name = name - def get_pba(self): - """ - This method returns a PBA object based on a worm's configuration. - Return None or False if you don't want the pba to be executed. - :return: A pba object. - """ - return self - @staticmethod def should_run(class_name): """ From 0dc60051145c72e7c31f3edbff8d8a19ae5023d3 Mon Sep 17 00:00:00 2001 From: Shreya Date: Tue, 4 May 2021 17:52:58 +0530 Subject: [PATCH 19/49] Remove unused variable `os_is_linux` in `infection_monkey/post_breach/post_breach_handler.py` --- monkey/infection_monkey/post_breach/post_breach_handler.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/monkey/infection_monkey/post_breach/post_breach_handler.py b/monkey/infection_monkey/post_breach/post_breach_handler.py index d2ccb2555..ee83a1dcb 100644 --- a/monkey/infection_monkey/post_breach/post_breach_handler.py +++ b/monkey/infection_monkey/post_breach/post_breach_handler.py @@ -3,7 +3,6 @@ from multiprocessing.dummy import Pool from typing import Sequence from infection_monkey.post_breach.pba import PBA -from infection_monkey.utils.environment import is_windows_os LOG = logging.getLogger(__name__) @@ -16,7 +15,6 @@ class PostBreach(object): """ def __init__(self): - self.os_is_linux = not is_windows_os() self.pba_list = self.config_to_pba_list() def execute_all_configured(self): From 536d0bc75cfcb384f4884d88119712ae32c71893 Mon Sep 17 00:00:00 2001 From: Shreya Date: Wed, 5 May 2021 17:51:20 +0530 Subject: [PATCH 20/49] Remove unused `mongo_client` in `monkey_island/cc/server_utils/bootloader_server.py` --- monkey/monkey_island/cc/server_utils/bootloader_server.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/monkey/monkey_island/cc/server_utils/bootloader_server.py b/monkey/monkey_island/cc/server_utils/bootloader_server.py index cc2742991..fa0b21378 100644 --- a/monkey/monkey_island/cc/server_utils/bootloader_server.py +++ b/monkey/monkey_island/cc/server_utils/bootloader_server.py @@ -17,7 +17,7 @@ logger = logging.getLogger(__name__) class BootloaderHttpServer(ThreadingMixIn, HTTPServer): def __init__(self, mongo_url): - self.mongo_client = pymongo.MongoClient(mongo_url) + pymongo.MongoClient(mongo_url) server_address = ("", 5001) super().__init__(server_address, BootloaderHTTPRequestHandler) From 380afa675ac3c9d086a060c088c917937ad2c1dd Mon Sep 17 00:00:00 2001 From: Shreya Date: Wed, 5 May 2021 18:10:32 +0530 Subject: [PATCH 21/49] Remove unused `report_generating_lock` in `monkey_island/cc/resources/root.py` --- monkey/monkey_island/cc/resources/root.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/monkey/monkey_island/cc/resources/root.py b/monkey/monkey_island/cc/resources/root.py index 57d20904a..37b5da7ba 100644 --- a/monkey/monkey_island/cc/resources/root.py +++ b/monkey/monkey_island/cc/resources/root.py @@ -1,5 +1,4 @@ import logging -import threading import flask_restful from flask import jsonify, make_response, request @@ -16,9 +15,6 @@ logger = logging.getLogger(__name__) class Root(flask_restful.Resource): - def __init__(self): - self.report_generating_lock = threading.Event() - def get(self, action=None): if not action: action = request.args.get("action") From 8c97f32fbc5cd761a552d74772edfbd2b866597f Mon Sep 17 00:00:00 2001 From: Shreya Date: Wed, 5 May 2021 18:50:54 +0530 Subject: [PATCH 22/49] Remove unused `_instance_id`, `region`, `_get_instance_id()`, and `_get_region()` from `monkey_island/cc/environment/aws.py` --- monkey/monkey_island/cc/environment/aws.py | 8 -------- 1 file changed, 8 deletions(-) diff --git a/monkey/monkey_island/cc/environment/aws.py b/monkey/monkey_island/cc/environment/aws.py index c11e40436..404955537 100644 --- a/monkey/monkey_island/cc/environment/aws.py +++ b/monkey/monkey_island/cc/environment/aws.py @@ -11,14 +11,6 @@ class AwsEnvironment(Environment): super(AwsEnvironment, self).__init__(config) # Not suppressing error here on purpose. This is critical if we're on AWS env. self.aws_info = AwsInstance() - self._instance_id = self._get_instance_id() - self.region = self._get_region() - - def _get_instance_id(self): - return self.aws_info.get_instance_id() - - def _get_region(self): - return self.aws_info.get_region() def get_auth_users(self): if self._is_registered(): From edff2c5c08f04bd50eb8228c5be65db1d3835db2 Mon Sep 17 00:00:00 2001 From: Shreya Date: Wed, 5 May 2021 18:59:18 +0530 Subject: [PATCH 23/49] Remove unused `set_deployment()` in `monkey_island/cc/environment/__init__.py` --- monkey/monkey_island/cc/environment/__init__.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/monkey/monkey_island/cc/environment/__init__.py b/monkey/monkey_island/cc/environment/__init__.py index 612428428..2a3da5ad0 100644 --- a/monkey/monkey_island/cc/environment/__init__.py +++ b/monkey/monkey_island/cc/environment/__init__.py @@ -118,9 +118,6 @@ class Environment(object, metaclass=ABCMeta): deployment = self._config.deployment return deployment - def set_deployment(self, deployment: str): - self._config.deployment = deployment - @property def mongo_db_name(self): return self._MONGO_DB_NAME From c848581115bbf483b07a69458e24e080bb042ea7 Mon Sep 17 00:00:00 2001 From: Shreya Date: Wed, 5 May 2021 19:25:34 +0530 Subject: [PATCH 24/49] Remove unused `hash_secret()` from `monkey_island/cc/environment/__init__.py` --- monkey/monkey_island/cc/environment/__init__.py | 7 ------- 1 file changed, 7 deletions(-) diff --git a/monkey/monkey_island/cc/environment/__init__.py b/monkey/monkey_island/cc/environment/__init__.py index 2a3da5ad0..13d570160 100644 --- a/monkey/monkey_island/cc/environment/__init__.py +++ b/monkey/monkey_island/cc/environment/__init__.py @@ -1,4 +1,3 @@ -import hashlib import logging import os from abc import ABCMeta, abstractmethod @@ -106,12 +105,6 @@ class Environment(object, metaclass=ABCMeta): def get_auth_expiration_time(self): return self._AUTH_EXPIRATION_TIME - @staticmethod - def hash_secret(secret): - hash_obj = hashlib.sha3_512() - hash_obj.update(secret.encode("utf-8")) - return hash_obj.hexdigest() - def get_deployment(self) -> str: deployment = "unknown" if self._config and self._config.deployment: From b59213fb8bdb0b2ef23843d206f520a5198f72a1 Mon Sep 17 00:00:00 2001 From: Shreya Date: Wed, 5 May 2021 19:34:15 +0530 Subject: [PATCH 25/49] Delete unused file `monkey_island/scripts/island_password_hasher.py` --- .../scripts/island_password_hasher.py | 26 ------------------- 1 file changed, 26 deletions(-) delete mode 100644 monkey/monkey_island/scripts/island_password_hasher.py diff --git a/monkey/monkey_island/scripts/island_password_hasher.py b/monkey/monkey_island/scripts/island_password_hasher.py deleted file mode 100644 index 5330a322f..000000000 --- a/monkey/monkey_island/scripts/island_password_hasher.py +++ /dev/null @@ -1,26 +0,0 @@ -""" -Utility script for running a string through SHA3_512 hash. -Used for Monkey Island password hash, see -https://github.com/guardicore/monkey/wiki/Enabling-Monkey-Island-Password-Protection -for more details. -""" - -import argparse - -# PyCrypto is deprecated, but we use pycryptodome, which uses the exact same imports but -# is maintained. -from Crypto.Hash import SHA3_512 # noqa: DUO133 # nosec: B413 - - -def main(): - parser = argparse.ArgumentParser() - parser.add_argument("string_to_sha", help="The string to do sha for") - args = parser.parse_args() - - h = SHA3_512.new() - h.update(args.string_to_sha) - print(h.hexdigest()) - - -if __name__ == "__main__": - main() From 635418b8f5797683837cddd29c1f606258511873 Mon Sep 17 00:00:00 2001 From: Shreya Date: Thu, 6 May 2021 13:28:02 +0530 Subject: [PATCH 26/49] Remove unused `get_logon_handle()` from `infection_monkey/utils/windows/users.py` --- monkey/infection_monkey/utils/windows/users.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/monkey/infection_monkey/utils/windows/users.py b/monkey/infection_monkey/utils/windows/users.py index 1a2bee53c..6890dc170 100644 --- a/monkey/infection_monkey/utils/windows/users.py +++ b/monkey/infection_monkey/utils/windows/users.py @@ -108,9 +108,6 @@ class AutoNewWindowsUser(AutoNewUser): return exit_code - def get_logon_handle(self): - return self.logon_handle - def __exit__(self, _exc_type, value, traceback): # Logoff self.logon_handle.Close() From 3a346b511207a92b16c9df2f223ca81b9364eace Mon Sep 17 00:00:00 2001 From: Shreya Date: Thu, 6 May 2021 13:30:45 +0530 Subject: [PATCH 27/49] Remove unused `NoInheritance` in `infection_monkey/utils/plugins/pluginTests/ComboFile.py` --- .../infection_monkey/utils/plugins/pluginTests/ComboFile.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/monkey/infection_monkey/utils/plugins/pluginTests/ComboFile.py b/monkey/infection_monkey/utils/plugins/pluginTests/ComboFile.py index 6f33142cc..d4d464b33 100644 --- a/monkey/infection_monkey/utils/plugins/pluginTests/ComboFile.py +++ b/monkey/infection_monkey/utils/plugins/pluginTests/ComboFile.py @@ -1,10 +1,6 @@ from infection_monkey.utils.plugins.pluginTests.PluginTestClass import PluginTester -class NoInheritance: - pass - - class BadInit(PluginTester): def __init__(self): raise Exception("TestException") From 962e7851345a1e7baba302e9310144a3b223c60e Mon Sep 17 00:00:00 2001 From: Shreya Date: Thu, 6 May 2021 14:02:32 +0530 Subject: [PATCH 28/49] Remove unused `proxy_via` in `infection_monkey/transport/http.py` --- monkey/infection_monkey/transport/http.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/monkey/infection_monkey/transport/http.py b/monkey/infection_monkey/transport/http.py index fbddce109..ec1518c70 100644 --- a/monkey/infection_monkey/transport/http.py +++ b/monkey/infection_monkey/transport/http.py @@ -115,9 +115,6 @@ class FileServHTTPRequestHandler(http.server.BaseHTTPRequestHandler): class HTTPConnectProxyHandler(http.server.BaseHTTPRequestHandler): timeout = 30 # timeout with clients, set to None not to make persistent connection - proxy_via = ( - None # pseudonym of the proxy in Via header, set to None not to modify original Via header - ) def do_POST(self): try: From e33288a05bd78e760d17f2a94c7949046d3b9986 Mon Sep 17 00:00:00 2001 From: Shreya Date: Thu, 6 May 2021 14:09:28 +0530 Subject: [PATCH 29/49] Remove unused property `locked` in `infection_monkey/system_singleton.py` --- monkey/infection_monkey/system_singleton.py | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/monkey/infection_monkey/system_singleton.py b/monkey/infection_monkey/system_singleton.py index 9576ff9f7..3bba2766f 100644 --- a/monkey/infection_monkey/system_singleton.py +++ b/monkey/infection_monkey/system_singleton.py @@ -11,11 +11,6 @@ LOG = logging.getLogger(__name__) class _SystemSingleton(object, metaclass=ABCMeta): - @property - @abstractmethod - def locked(self): - raise NotImplementedError() - @abstractmethod def try_lock(self): raise NotImplementedError() @@ -30,10 +25,6 @@ class WindowsSystemSingleton(_SystemSingleton): self._mutex_name = r"Global\%s" % (WormConfiguration.singleton_mutex_name,) self._mutex_handle = None - @property - def locked(self): - return self._mutex_handle is not None - def try_lock(self): assert self._mutex_handle is None, "Singleton already locked" @@ -67,10 +58,6 @@ class LinuxSystemSingleton(_SystemSingleton): self._unix_sock_name = str(WormConfiguration.singleton_mutex_name) self._sock_handle = None - @property - def locked(self): - return self._sock_handle is not None - def try_lock(self): assert self._sock_handle is None, "Singleton already locked" From e59f7a587e220cc8065721706e3973f81b1e08c1 Mon Sep 17 00:00:00 2001 From: Shreya Date: Thu, 6 May 2021 14:13:55 +0530 Subject: [PATCH 30/49] Remove unused const `WMI_LDAP_CLASSES` in `infection_monkey/system_info/wmi_consts.py` --- .../system_info/wmi_consts.py | 70 ------------------- 1 file changed, 70 deletions(-) diff --git a/monkey/infection_monkey/system_info/wmi_consts.py b/monkey/infection_monkey/system_info/wmi_consts.py index 71366a466..d9b212661 100644 --- a/monkey/infection_monkey/system_info/wmi_consts.py +++ b/monkey/infection_monkey/system_info/wmi_consts.py @@ -10,73 +10,3 @@ WMI_CLASSES = { "Win32_Service", "Win32_OptionalFeature", } - -# These wmi queries are able to return data about all the users & machines in the domain. -# For these queries to work, the monkey should be run on a domain machine and -# -# monkey should run as *** SYSTEM *** !!! -# -WMI_LDAP_CLASSES = { - "ds_user": ( - "DS_sAMAccountName", - "DS_userPrincipalName", - "DS_sAMAccountType", - "ADSIPath", - "DS_userAccountControl", - "DS_objectSid", - "DS_objectClass", - "DS_memberOf", - "DS_primaryGroupID", - "DS_pwdLastSet", - "DS_badPasswordTime", - "DS_badPwdCount", - "DS_lastLogon", - "DS_lastLogonTimestamp", - "DS_lastLogoff", - "DS_logonCount", - "DS_accountExpires", - ), - "ds_group": ( - "DS_whenChanged", - "DS_whenCreated", - "DS_sAMAccountName", - "DS_sAMAccountType", - "DS_objectSid", - "DS_objectClass", - "DS_name", - "DS_memberOf", - "DS_member", - "DS_instanceType", - "DS_cn", - "DS_description", - "DS_distinguishedName", - "ADSIPath", - ), - "ds_computer": ( - "DS_dNSHostName", - "ADSIPath", - "DS_accountExpires", - "DS_adminDisplayName", - "DS_badPasswordTime", - "DS_badPwdCount", - "DS_cn", - "DS_distinguishedName", - "DS_instanceType", - "DS_lastLogoff", - "DS_lastLogon", - "DS_lastLogonTimestamp", - "DS_logonCount", - "DS_objectClass", - "DS_objectSid", - "DS_operatingSystem", - "DS_operatingSystemVersion", - "DS_primaryGroupID", - "DS_pwdLastSet", - "DS_sAMAccountName", - "DS_sAMAccountType", - "DS_servicePrincipalName", - "DS_userAccountControl", - "DS_whenChanged", - "DS_whenCreated", - ), -} From 3a8591ee007f28c8fcb39156ab75e0d8624f3fd7 Mon Sep 17 00:00:00 2001 From: Shreya Date: Thu, 6 May 2021 14:24:22 +0530 Subject: [PATCH 31/49] Remove unused `_get_traceroute_bin_path`, and `_parse_traceroute` in `infection_monkey/network/tools.py` --- monkey/infection_monkey/network/tools.py | 55 ------------------------ 1 file changed, 55 deletions(-) diff --git a/monkey/infection_monkey/network/tools.py b/monkey/infection_monkey/network/tools.py index 97c3ef84f..bb472feed 100644 --- a/monkey/infection_monkey/network/tools.py +++ b/monkey/infection_monkey/network/tools.py @@ -1,17 +1,13 @@ import logging -import re import select import socket import struct -import subprocess import sys import time from common.network.network_utils import get_host_from_network_location from infection_monkey.config import WormConfiguration from infection_monkey.network.info import get_routes, local_ips -from infection_monkey.pyinstaller_utils import get_binary_file_path -from infection_monkey.utils.environment import is_64bit_python DEFAULT_TIMEOUT = 10 BANNER_READ = 1024 @@ -164,57 +160,6 @@ def tcp_port_to_service(port): return "tcp-" + str(port) -def _get_traceroute_bin_path(): - """ - Gets the path to the prebuilt traceroute executable - - This is the traceroute utility from: http://traceroute.sourceforge.net - Its been built using the buildroot utility with the following settings: - * Statically link to musl and all other required libs - * Optimize for size - This is done because not all linux distros come with traceroute out-of-the-box, and to ensure - it behaves as expected - - :return: Path to traceroute executable - """ - return get_binary_file_path("traceroute64" if is_64bit_python() else "traceroute32") - - -def _parse_traceroute(output, regex, ttl): - """ - Parses the output of traceroute (from either Linux or Windows) - :param output: The output of the traceroute - :param regex: Regex for finding an IP address - :param ttl: Max TTL. Must be the same as the TTL used as param for traceroute. - :return: List of ips which are the hops on the way to the traceroute destination. - If a hop's IP wasn't found by traceroute, instead of an IP, the array will - contain None - """ - ip_lines = output.split("\n") - trace_list = [] - - first_line_index = None - for i in range(len(ip_lines)): - if re.search(r"^\s*1", ip_lines[i]) is not None: - first_line_index = i - break - - for i in range(first_line_index, first_line_index + ttl): - if ( - re.search(r"^\s*" + str(i - first_line_index + 1), ip_lines[i]) is None - ): # If trace is finished - break - - re_res = re.search(regex, ip_lines[i]) - if re_res is None: - ip_addr = None - else: - ip_addr = re_res.group() - trace_list.append(ip_addr) - - return trace_list - - def get_interface_to_target(dst): """ :param dst: destination IP address string without port. E.G. '192.168.1.1.' From dd1eaab6f8727395218e294431da5591e826e183 Mon Sep 17 00:00:00 2001 From: Shreya Date: Thu, 6 May 2021 15:54:58 +0530 Subject: [PATCH 32/49] Remove unused `IP_ADDR_RE`, and `IP_ADDR_PARENTHESES_RE` from `infection_monkey/network/tools.py` --- monkey/infection_monkey/network/tools.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/monkey/infection_monkey/network/tools.py b/monkey/infection_monkey/network/tools.py index bb472feed..17eae6969 100644 --- a/monkey/infection_monkey/network/tools.py +++ b/monkey/infection_monkey/network/tools.py @@ -11,8 +11,6 @@ from infection_monkey.network.info import get_routes, local_ips DEFAULT_TIMEOUT = 10 BANNER_READ = 1024 -IP_ADDR_RE = r"\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}" -IP_ADDR_PARENTHESES_RE = r"\(" + IP_ADDR_RE + r"\)" LOG = logging.getLogger(__name__) SLEEP_BETWEEN_POLL = 0.5 From adb90d14af3c6f0db5ce7e8ea37c6097d91c06f5 Mon Sep 17 00:00:00 2001 From: Shreya Date: Thu, 6 May 2021 16:16:20 +0530 Subject: [PATCH 33/49] Remove unused `_mode` in `infection_monkey/monkeyfs.py` --- monkey/infection_monkey/monkeyfs.py | 1 - 1 file changed, 1 deletion(-) diff --git a/monkey/infection_monkey/monkeyfs.py b/monkey/infection_monkey/monkeyfs.py index 31b2e6007..392717c35 100644 --- a/monkey/infection_monkey/monkeyfs.py +++ b/monkey/infection_monkey/monkeyfs.py @@ -15,7 +15,6 @@ class VirtualFile(BytesIO): if not name.startswith(MONKEYFS_PREFIX): name = MONKEYFS_PREFIX + name self.name = name - self._mode = mode if name in VirtualFile._vfs: super(VirtualFile, self).__init__(self._vfs[name]) else: From 1cd746ce7685228540d81b1d4775ef93a9b88cb4 Mon Sep 17 00:00:00 2001 From: Shreya Date: Thu, 6 May 2021 16:19:38 +0530 Subject: [PATCH 34/49] Remove unused `_dropper_path` and `_depth` in `infection_monkey/monkey.py` --- monkey/infection_monkey/monkey.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/monkey/infection_monkey/monkey.py b/monkey/infection_monkey/monkey.py index c81a62517..7e188b74d 100644 --- a/monkey/infection_monkey/monkey.py +++ b/monkey/infection_monkey/monkey.py @@ -56,12 +56,10 @@ class InfectionMonkey(object): self._default_tunnel = None self._args = args self._network = None - self._dropper_path = None self._exploiters = None self._fingerprint = None self._default_server = None self._default_server_port = None - self._depth = 0 self._opts = None self._upgrading_to_64 = False @@ -92,7 +90,6 @@ class InfectionMonkey(object): self._keep_running = True self._network = NetworkScanner() - self._dropper_path = sys.argv[0] if self._default_server: if self._default_server not in WormConfiguration.command_servers: From 5f8547a7eeb14d09ce65a4124d885b8f4710720b Mon Sep 17 00:00:00 2001 From: Shreya Date: Thu, 6 May 2021 16:33:37 +0530 Subject: [PATCH 35/49] Remove unused `set_vulnerable_port_from_url()` from `infection_monkey/exploit/web_rce.py` --- monkey/infection_monkey/exploit/web_rce.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/monkey/infection_monkey/exploit/web_rce.py b/monkey/infection_monkey/exploit/web_rce.py index dafa6164a..7f268b18f 100644 --- a/monkey/infection_monkey/exploit/web_rce.py +++ b/monkey/infection_monkey/exploit/web_rce.py @@ -578,9 +578,6 @@ class WebRCE(HostExploiter): LOG.debug("Target's machine type was not set. Using win-32 dropper path.") return self._config.dropper_target_path_win_32 - def set_vulnerable_port_from_url(self, url): - self.vulnerable_port = HTTPTools.get_port_from_url(url) - def get_target_url(self): """ This method allows "configuring" the way in which a vulnerable URL is picked. From 0c3e385c867480007e6424d9aae393334598bf4f Mon Sep 17 00:00:00 2001 From: Shreya Date: Thu, 6 May 2021 16:46:23 +0530 Subject: [PATCH 36/49] Remove unused `check_if_port_open` in `infection_monkey/exploit/web_rce.py` --- monkey/infection_monkey/exploit/web_rce.py | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/monkey/infection_monkey/exploit/web_rce.py b/monkey/infection_monkey/exploit/web_rce.py index 7f268b18f..5620c425a 100644 --- a/monkey/infection_monkey/exploit/web_rce.py +++ b/monkey/infection_monkey/exploit/web_rce.py @@ -25,7 +25,7 @@ from infection_monkey.model import ( RUN_MONKEY, WGET_HTTP_UPLOAD, ) -from infection_monkey.network.tools import check_tcp_port, tcp_port_to_service +from infection_monkey.network.tools import tcp_port_to_service from infection_monkey.telemetry.attack.t1197_telem import T1197Telem from infection_monkey.telemetry.attack.t1222_telem import T1222Telem @@ -188,13 +188,6 @@ class WebRCE(HostExploiter): return valid_ports - def check_if_port_open(self, port): - is_open, _ = check_tcp_port(self.host.ip_addr, port) - if not is_open: - LOG.info("Port %d is closed on %r, skipping", port, self.host) - return False - return True - def get_command(self, path, http_path, commands): try: if "linux" in self.host.os["type"]: From e30c37f3ca2ca0d37f7163bd64884d24e4efa7b7 Mon Sep 17 00:00:00 2001 From: Shreya Date: Thu, 6 May 2021 16:49:54 +0530 Subject: [PATCH 37/49] Remove unused `DceRpcException` in `infection_monkey/exploit/tools/wmi_tools.py` --- monkey/infection_monkey/exploit/tools/wmi_tools.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/monkey/infection_monkey/exploit/tools/wmi_tools.py b/monkey/infection_monkey/exploit/tools/wmi_tools.py index b6d96aa82..21abfa440 100644 --- a/monkey/infection_monkey/exploit/tools/wmi_tools.py +++ b/monkey/infection_monkey/exploit/tools/wmi_tools.py @@ -10,10 +10,6 @@ __author__ = "itamar" LOG = logging.getLogger(__name__) -class DceRpcException(Exception): - pass - - class AccessDeniedException(Exception): def __init__(self, host, username, password, domain): super(AccessDeniedException, self).__init__( From 67d7ad88341c1c53a2244c633519e510cf4bb7e2 Mon Sep 17 00:00:00 2001 From: Shreya Date: Thu, 6 May 2021 16:51:40 +0530 Subject: [PATCH 38/49] Remove unused `SAMBACRY_MONKEY_COPY_FILENAME_32` and `SAMBACRY_MONKEY_COPY_FILENAME_64` in `infection_monkey/exploit/sambacry.py` --- monkey/infection_monkey/exploit/sambacry.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/monkey/infection_monkey/exploit/sambacry.py b/monkey/infection_monkey/exploit/sambacry.py index 7a4c12429..11a2ab9c5 100644 --- a/monkey/infection_monkey/exploit/sambacry.py +++ b/monkey/infection_monkey/exploit/sambacry.py @@ -73,10 +73,6 @@ class SambaCryExploiter(HostExploiter): SAMBACRY_MONKEY_FILENAME_32 = "monkey32" # Monkey filename on share (64 bit) SAMBACRY_MONKEY_FILENAME_64 = "monkey64" - # Monkey copy filename on share (32 bit) - SAMBACRY_MONKEY_COPY_FILENAME_32 = "monkey32_2" - # Monkey copy filename on share (64 bit) - SAMBACRY_MONKEY_COPY_FILENAME_64 = "monkey64_2" # Supported samba port SAMBA_PORT = 445 From aed9c4ae564ce412874ae7ac5bd758c377464e61 Mon Sep 17 00:00:00 2001 From: Shreya Date: Thu, 6 May 2021 16:54:11 +0530 Subject: [PATCH 39/49] Remove unused `should_exploit` in `infection_monkey/config.py` and `infection_monkey/example.conf` --- monkey/infection_monkey/config.py | 1 - monkey/infection_monkey/example.conf | 1 - 2 files changed, 2 deletions(-) diff --git a/monkey/infection_monkey/config.py b/monkey/infection_monkey/config.py index 349c12f0d..ad37bf837 100644 --- a/monkey/infection_monkey/config.py +++ b/monkey/infection_monkey/config.py @@ -188,7 +188,6 @@ class Configuration(object): # exploiters config ########################### - should_exploit = True skip_exploit_if_file_exist = False ms08_067_exploit_attempts = 5 diff --git a/monkey/infection_monkey/example.conf b/monkey/infection_monkey/example.conf index cf9d2ed70..b27f2f3cc 100644 --- a/monkey/infection_monkey/example.conf +++ b/monkey/infection_monkey/example.conf @@ -1,5 +1,4 @@ { - "should_exploit": true, "command_servers": [ "192.0.2.0:5000" ], From 81f785ea7423f9649e40bbd423385e6366b73549 Mon Sep 17 00:00:00 2001 From: Shreya Date: Thu, 6 May 2021 16:58:03 +0530 Subject: [PATCH 40/49] Remove unused `OTHER` in `common/utils/exploit_enum.py` --- monkey/common/utils/exploit_enum.py | 1 - 1 file changed, 1 deletion(-) diff --git a/monkey/common/utils/exploit_enum.py b/monkey/common/utils/exploit_enum.py index 3aff53121..daac36e1b 100644 --- a/monkey/common/utils/exploit_enum.py +++ b/monkey/common/utils/exploit_enum.py @@ -3,5 +3,4 @@ from enum import Enum class ExploitType(Enum): VULNERABILITY = 1 - OTHER = 8 BRUTE_FORCE = 9 From df8f9c81e65dee1c447d6ba403e91ccd947bc3ea Mon Sep 17 00:00:00 2001 From: Shreya Date: Thu, 6 May 2021 17:03:17 +0530 Subject: [PATCH 41/49] Remove unused `format_time()` in `common/utils/attack_utils.py` --- monkey/common/utils/attack_utils.py | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/monkey/common/utils/attack_utils.py b/monkey/common/utils/attack_utils.py index 98b6361c4..ef1cba65f 100644 --- a/monkey/common/utils/attack_utils.py +++ b/monkey/common/utils/attack_utils.py @@ -42,13 +42,3 @@ class UsageEnum(Enum): # Dict that describes what BITS job was used for BITS_UPLOAD_STRING = "BITS job was used to upload monkey to a remote system." - - -def format_time(time): - return "%s-%s %s:%s:%s" % ( - time.date().month, - time.date().day, - time.time().hour, - time.time().minute, - time.time().second, - ) From 9b6ecd508cbf57b0c6574213d136a93021d93dad Mon Sep 17 00:00:00 2001 From: Shreya Date: Thu, 6 May 2021 17:05:24 +0530 Subject: [PATCH 42/49] Remove unused `SCOUTSUITE_COLLECTOR` in `common/common_consts/system_info_collectors_names.py` --- monkey/common/common_consts/system_info_collectors_names.py | 1 - 1 file changed, 1 deletion(-) diff --git a/monkey/common/common_consts/system_info_collectors_names.py b/monkey/common/common_consts/system_info_collectors_names.py index c93cb2537..175a054e1 100644 --- a/monkey/common/common_consts/system_info_collectors_names.py +++ b/monkey/common/common_consts/system_info_collectors_names.py @@ -4,4 +4,3 @@ ENVIRONMENT_COLLECTOR = "EnvironmentCollector" PROCESS_LIST_COLLECTOR = "ProcessListCollector" MIMIKATZ_COLLECTOR = "MimikatzCollector" AZURE_CRED_COLLECTOR = "AzureCollector" -SCOUTSUITE_COLLECTOR = "ScoutSuiteCollector" From 897a92b96133a8a98496e2df1cec3b7ec6d8d4dc Mon Sep 17 00:00:00 2001 From: Shreya Date: Thu, 6 May 2021 17:25:08 +0530 Subject: [PATCH 43/49] Remove unused `run_command` in `common/cmd/cmd_runner.py` --- monkey/common/cmd/cmd_runner.py | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/monkey/common/cmd/cmd_runner.py b/monkey/common/cmd/cmd_runner.py index efd9d7bf0..48c004c86 100644 --- a/monkey/common/cmd/cmd_runner.py +++ b/monkey/common/cmd/cmd_runner.py @@ -2,7 +2,6 @@ import logging import time from abc import abstractmethod -from common.cmd.cmd import Cmd from common.cmd.cmd_result import CmdResult from common.cmd.cmd_status import CmdStatus @@ -36,16 +35,6 @@ class CmdRunner(object): def __init__(self, is_linux): self.is_linux = is_linux - def run_command(self, command_line, timeout=DEFAULT_TIMEOUT): - """ - Runs the given command on the remote machine - :param command_line: The command line to run - :param timeout: Timeout in seconds for command. - :return: Command result - """ - c_id = self.run_command_async(command_line) - return self.wait_commands([Cmd(self, c_id)], timeout)[1] - @staticmethod def run_multiple_commands(instances, inst_to_cmd, inst_n_cmd_res_to_res): """ From 6c80335509c5f56bf13fc1eec1d01c2d4f896866 Mon Sep 17 00:00:00 2001 From: Shreya Date: Thu, 6 May 2021 17:25:24 +0530 Subject: [PATCH 44/49] Remove unused `get_regions`, `get_session`, and `test_client` in `common/cloud/aws/aws_service.py` --- monkey/common/cloud/aws/aws_service.py | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/monkey/common/cloud/aws/aws_service.py b/monkey/common/cloud/aws/aws_service.py index dd4b1cb24..2764c8238 100644 --- a/monkey/common/cloud/aws/aws_service.py +++ b/monkey/common/cloud/aws/aws_service.py @@ -2,7 +2,6 @@ import logging import boto3 import botocore -from botocore.exceptions import ClientError from common.cloud.aws.aws_instance import AwsInstance @@ -53,22 +52,6 @@ class AwsService(object): client_type, region_name=region if region is not None else AwsService.region ) - @staticmethod - def get_session(): - return boto3.session.Session() - - @staticmethod - def get_regions(): - return AwsService.get_session().get_available_regions("ssm") - - @staticmethod - def test_client(): - try: - AwsService.get_client("ssm").describe_instance_information() - return True - except ClientError: - return False - @staticmethod def get_instances(): """ From 060b7fd921525553d133db2b623c80418a4c4051 Mon Sep 17 00:00:00 2001 From: Shreya Date: Thu, 6 May 2021 22:27:52 +0530 Subject: [PATCH 45/49] Remove unused `TEST_SALT` from `tests/monkey_island/cc/environment/test_user_creds.py` --- monkey/tests/monkey_island/cc/environment/test_user_creds.py | 1 - 1 file changed, 1 deletion(-) diff --git a/monkey/tests/monkey_island/cc/environment/test_user_creds.py b/monkey/tests/monkey_island/cc/environment/test_user_creds.py index 802c13416..7d83ba59f 100644 --- a/monkey/tests/monkey_island/cc/environment/test_user_creds.py +++ b/monkey/tests/monkey_island/cc/environment/test_user_creds.py @@ -2,7 +2,6 @@ from monkey_island.cc.environment.user_creds import UserCreds TEST_USER = "Test" TEST_HASH = "abc1231234" -TEST_SALT = b"$2b$12$JA7GdT1iyfIsquF2cTZv2." def test_bool_true(): From 55208fd0be9dffa54ff5d9f970bbee77607b81e4 Mon Sep 17 00:00:00 2001 From: Shreya Date: Thu, 6 May 2021 22:40:10 +0530 Subject: [PATCH 46/49] Add CHANGELOG entry for Vulture fixes --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9c0c2a833..b2150b874 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -27,6 +27,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - Zerologon exploiter writes runtime artifacts to a secure temporary directory instead of $HOME. #1143 - Authentication mechanism to use bcrypt on server side. #1139 +- Removed relevant dead code as reported by Vulture. #1149 ### Fixed - Attempted to delete a directory when monkey config reset was called. #1054 From e1ef807c2c142065af12ca0b5b80de578ae843e6 Mon Sep 17 00:00:00 2001 From: Shreya Date: Thu, 6 May 2021 22:42:28 +0530 Subject: [PATCH 47/49] Remove unused import in infection_monkey/network/info.py --- monkey/infection_monkey/network/info.py | 1 - 1 file changed, 1 deletion(-) diff --git a/monkey/infection_monkey/network/info.py b/monkey/infection_monkey/network/info.py index 5bdce4887..474281f68 100644 --- a/monkey/infection_monkey/network/info.py +++ b/monkey/infection_monkey/network/info.py @@ -2,7 +2,6 @@ import itertools import socket import struct from random import randint # noqa: DUO102 -from subprocess import check_output import netifaces import psutil From e8947a375a714d5c868d9d6df2a9a53c801a617d Mon Sep 17 00:00:00 2001 From: Mike Salvatore Date: Thu, 6 May 2021 19:51:23 -0400 Subject: [PATCH 48/49] Add a whitelist for vulture --- .flake8 | 3 +- whitelist.py | 186 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 187 insertions(+), 2 deletions(-) create mode 100644 whitelist.py diff --git a/.flake8 b/.flake8 index 1f81c9edc..c7cd1da1d 100644 --- a/.flake8 +++ b/.flake8 @@ -1,7 +1,7 @@ [flake8] ## Warn about linter issues. -exclude = monkey/monkey_island/cc/ui +exclude = monkey/monkey_island/cc/ui,whitelist.py show-source = True max-complexity = 10 max-line-length = 100 @@ -15,4 +15,3 @@ statistics = True ### --count will print the total number of errors. count = True - diff --git a/whitelist.py b/whitelist.py new file mode 100644 index 000000000..ad346ff0b --- /dev/null +++ b/whitelist.py @@ -0,0 +1,186 @@ +""" +Everything in this file is what Vulture found as dead code but either isn't really +dead or is kept deliberately. Referencing these in a file like this makes sure that +Vulture doesn't mark these as dead again. +""" + + +fake_monkey_dir_path # unused variable (monkey/tests/infection_monkey/post_breach/actions/test_users_custom_pba.py:37) +set_os_linux # unused variable (monkey/tests/infection_monkey/post_breach/actions/test_users_custom_pba.py:37) +fake_monkey_dir_path # unused variable (monkey/tests/infection_monkey/post_breach/actions/test_users_custom_pba.py:57) +set_os_windows # unused variable (monkey/tests/infection_monkey/post_breach/actions/test_users_custom_pba.py:57) +fake_monkey_dir_path # unused variable (monkey/tests/infection_monkey/post_breach/actions/test_users_custom_pba.py:77) +set_os_linux # unused variable (monkey/tests/infection_monkey/post_breach/actions/test_users_custom_pba.py:77) +fake_monkey_dir_path # unused variable (monkey/tests/infection_monkey/post_breach/actions/test_users_custom_pba.py:92) +set_os_windows # unused variable (monkey/tests/infection_monkey/post_breach/actions/test_users_custom_pba.py:92) +fake_monkey_dir_path # unused variable (monkey/tests/infection_monkey/post_breach/actions/test_users_custom_pba.py:107) +set_os_linux # unused variable (monkey/tests/infection_monkey/post_breach/actions/test_users_custom_pba.py:107) +fake_monkey_dir_path # unused variable (monkey/tests/infection_monkey/post_breach/actions/test_users_custom_pba.py:122) +set_os_windows # unused variable (monkey/tests/infection_monkey/post_breach/actions/test_users_custom_pba.py:122) +patch_new_user_classes # unused variable (monkey/tests/infection_monkey/utils/test_auto_new_user_factory.py:25) +patch_new_user_classes # unused variable (monkey/tests/infection_monkey/utils/test_auto_new_user_factory.py:31) +mock_home_env # unused variable (monkey/tests/monkey_island/cc/server_utils/test_island_logger.py:20) +configure_resources # unused function (monkey/tests/monkey_island/cc/environment/test_environment.py:26) +change_to_mongo_mock # unused function (monkey/monkey_island/cc/test_common/fixtures/mongomock_fixtures.py:9) +uses_database # unused function (monkey/monkey_island/cc/test_common/fixtures/mongomock_fixtures.py:16) +datas # unused variable (monkey/monkey_island/pyinstaller_hooks/hook-stix2.py:9) +test_key # unused variable (monkey/monkey_island/cc/services/zero_trust/zero_trust_report/finding_service.py:20) +pillars # unused variable (monkey/monkey_island/cc/services/zero_trust/zero_trust_report/finding_service.py:21) +CLEAN_UNKNOWN # unused variable (monkey/monkey_island/cc/services/utils/node_states.py:9) +CLEAN_LINUX # unused variable (monkey/monkey_island/cc/services/utils/node_states.py:10) +CLEAN_WINDOWS # unused variable (monkey/monkey_island/cc/services/utils/node_states.py:11) +EXPLOITED_LINUX # unused variable (monkey/monkey_island/cc/services/utils/node_states.py:12) +EXPLOITED_WINDOWS # unused variable (monkey/monkey_island/cc/services/utils/node_states.py:13) +ISLAND_MONKEY_LINUX # unused variable (monkey/monkey_island/cc/services/utils/node_states.py:15) +ISLAND_MONKEY_LINUX_RUNNING # unused variable (monkey/monkey_island/cc/services/utils/node_states.py:16) +ISLAND_MONKEY_LINUX_STARTING # unused variable (monkey/monkey_island/cc/services/utils/node_states.py:17) +ISLAND_MONKEY_WINDOWS # unused variable (monkey/monkey_island/cc/services/utils/node_states.py:18) +ISLAND_MONKEY_WINDOWS_RUNNING # unused variable (monkey/monkey_island/cc/services/utils/node_states.py:19) +ISLAND_MONKEY_WINDOWS_STARTING # unused variable (monkey/monkey_island/cc/services/utils/node_states.py:20) +MANUAL_LINUX # unused variable (monkey/monkey_island/cc/services/utils/node_states.py:21) +MANUAL_LINUX_RUNNING # unused variable (monkey/monkey_island/cc/services/utils/node_states.py:22) +MANUAL_WINDOWS # unused variable (monkey/monkey_island/cc/services/utils/node_states.py:23) +MANUAL_WINDOWS_RUNNING # unused variable (monkey/monkey_island/cc/services/utils/node_states.py:24) +MONKEY_LINUX # unused variable (monkey/monkey_island/cc/services/utils/node_states.py:25) +MONKEY_WINDOWS # unused variable (monkey/monkey_island/cc/services/utils/node_states.py:27) +MONKEY_WINDOWS_RUNNING # unused variable (monkey/monkey_island/cc/services/utils/node_states.py:28) +MONKEY_WINDOWS_STARTING # unused variable (monkey/monkey_island/cc/services/utils/node_states.py:29) +MONKEY_LINUX_STARTING # unused variable (monkey/monkey_island/cc/services/utils/node_states.py:30) +MONKEY_WINDOWS_OLD # unused variable (monkey/monkey_island/cc/services/utils/node_states.py:31) +MONKEY_LINUX_OLD # unused variable (monkey/monkey_island/cc/services/utils/node_states.py:32) +_.credential_type # unused attribute (monkey/monkey_island/cc/services/reporting/issue_processing/exploit_processing/processors/cred_exploit.py:19) +_.credential_type # unused attribute (monkey/monkey_island/cc/services/reporting/issue_processing/exploit_processing/processors/cred_exploit.py:22) +_.credential_type # unused attribute (monkey/monkey_island/cc/services/reporting/issue_processing/exploit_processing/processors/cred_exploit.py:25) +_.password_restored # unused attribute (monkey/monkey_island/cc/services/reporting/issue_processing/exploit_processing/processors/zerologon.py:11) +credential_type # unused variable (monkey/monkey_island/cc/services/reporting/issue_processing/exploit_processing/exploiter_report_info.py:18) +password_restored # unused variable (monkey/monkey_island/cc/services/reporting/issue_processing/exploit_processing/exploiter_report_info.py:23) +SSH # unused variable (monkey/monkey_island/cc/services/reporting/issue_processing/exploit_processing/exploiter_descriptor_enum.py:30) +SAMBACRY # unused variable (monkey/monkey_island/cc/services/reporting/issue_processing/exploit_processing/exploiter_descriptor_enum.py:31) +ELASTIC # unused variable (monkey/monkey_island/cc/services/reporting/issue_processing/exploit_processing/exploiter_descriptor_enum.py:32) +MS08_067 # unused variable (monkey/monkey_island/cc/services/reporting/issue_processing/exploit_processing/exploiter_descriptor_enum.py:35) +SHELLSHOCK # unused variable (monkey/monkey_island/cc/services/reporting/issue_processing/exploit_processing/exploiter_descriptor_enum.py:36) +STRUTS2 # unused variable (monkey/monkey_island/cc/services/reporting/issue_processing/exploit_processing/exploiter_descriptor_enum.py:39) +WEBLOGIC # unused variable (monkey/monkey_island/cc/services/reporting/issue_processing/exploit_processing/exploiter_descriptor_enum.py:40) +HADOOP # unused variable (monkey/monkey_island/cc/services/reporting/issue_processing/exploit_processing/exploiter_descriptor_enum.py:43) +MSSQL # unused variable (monkey/monkey_island/cc/services/reporting/issue_processing/exploit_processing/exploiter_descriptor_enum.py:44) +VSFTPD # unused variable (monkey/monkey_island/cc/services/reporting/issue_processing/exploit_processing/exploiter_descriptor_enum.py:45) +DRUPAL # unused variable (monkey/monkey_island/cc/services/reporting/issue_processing/exploit_processing/exploiter_descriptor_enum.py:48) +_.do_POST # unused method (monkey/monkey_island/cc/server_utils/bootloader_server.py:26) +PbaResults # unused class (monkey/monkey_island/cc/models/pba_results.py:4) +internet_access # unused variable (monkey/monkey_island/cc/models/monkey.py:43) +config_error # unused variable (monkey/monkey_island/cc/models/monkey.py:53) +pba_results # unused variable (monkey/monkey_island/cc/models/monkey.py:55) +command_control_channel # unused variable (monkey/monkey_island/cc/models/monkey.py:58) +meta # unused variable (monkey/monkey_island/cc/models/zero_trust/finding.py:37) +meta # unused variable (monkey/monkey_island/cc/models/monkey_ttl.py:34) +expire_at # unused variable (monkey/monkey_island/cc/models/monkey_ttl.py:36) +meta # unused variable (monkey/monkey_island/cc/models/config.py:11) +meta # unused variable (monkey/monkey_island/cc/models/creds.py:9) +meta # unused variable (monkey/monkey_island/cc/models/edge.py:5) +Config # unused class (monkey/monkey_island/cc/models/config.py:4) +Creds # unused class (monkey/monkey_island/cc/models/creds.py:4) +_.do_CONNECT # unused method (monkey/infection_monkey/transport/http.py:151) +_.do_POST # unused method (monkey/infection_monkey/transport/http.py:122) +_.do_HEAD # unused method (monkey/infection_monkey/transport/http.py:61) +_.do_GET # unused method (monkey/infection_monkey/transport/http.py:38) +_.do_POST # unused method (monkey/infection_monkey/transport/http.py:34) +_.do_GET # unused method (monkey/infection_monkey/exploit/weblogic.py:237) +ElasticFinger # unused class (monkey/infection_monkey/network/elasticfinger.py:18) +HTTPFinger # unused class (monkey/infection_monkey/network/httpfinger.py:9) +MySQLFinger # unused class (monkey/infection_monkey/network/mysqlfinger.py:13) +SSHFinger # unused class (monkey/infection_monkey/network/sshfinger.py:15) +ClearCommandHistory # unused class (monkey/infection_monkey/post_breach/actions/clear_command_history.py:11) +AccountDiscovery # unused class (monkey/infection_monkey/post_breach/actions/discover_accounts.py:8) +ModifyShellStartupFiles # unused class (monkey/infection_monkey/post_breach/actions/modify_shell_startup_files.py:11) +Timestomping # unused class (monkey/infection_monkey/post_breach/actions/timestomping.py:6) +SignedScriptProxyExecution # unused class (monkey/infection_monkey/post_breach/actions/use_signed_scripts.py:15) +AwsCollector # unused class (monkey/infection_monkey/system_info/collectors/aws_collector.py:15) +EnvironmentCollector # unused class (monkey/infection_monkey/system_info/collectors/environment_collector.py:19) +HostnameCollector # unused class (monkey/infection_monkey/system_info/collectors/hostname_collector.py:10) +ProcessListCollector # unused class (monkey/infection_monkey/system_info/collectors/process_list_collector.py:18) +_.coinit_flags # unused attribute (monkey/infection_monkey/system_info/windows_info_collector.py:11) +_.representations # unused attribute (monkey/monkey_island/cc/app.py:180) +_.log_message # unused method (monkey/infection_monkey/transport/http.py:188) +_.log_message # unused method (monkey/infection_monkey/transport/http.py:109) +_.version_string # unused method (monkey/infection_monkey/transport/http.py:148) +_.version_string # unused method (monkey/infection_monkey/transport/http.py:27) +_.close_connection # unused attribute (monkey/infection_monkey/transport/http.py:57) +protocol_version # unused variable (monkey/infection_monkey/transport/http.py:24) +hiddenimports # unused variable (monkey/infection_monkey/pyinstaller_hooks/hook-infection_monkey.exploit.py:3) +hiddenimports # unused variable (monkey/infection_monkey/pyinstaller_hooks/hook-infection_monkey.network.py:3) +hiddenimports # unused variable (monkey/infection_monkey/pyinstaller_hooks/hook-infection_monkey.post_breach.actions.py:4) +hiddenimports # unused variable (monkey/infection_monkey/pyinstaller_hooks/hook-infection_monkey.system_info.collectors.py:4) +_.wShowWindow # unused attribute (monkey/infection_monkey/monkey.py:345) +_.dwFlags # unused attribute (monkey/infection_monkey/monkey.py:344) +_.do_get # unused method (monkey/infection_monkey/exploit/zerologon_utils/remote_shell.py:79) +_.do_exit # unused method (monkey/infection_monkey/exploit/zerologon_utils/remote_shell.py:96) +_.prompt # unused attribute (monkey/infection_monkey/exploit/zerologon_utils/remote_shell.py:108) +_.prompt # unused attribute (monkey/infection_monkey/exploit/zerologon_utils/remote_shell.py:125) +keytab # unused variable (monkey/infection_monkey/exploit/zerologon_utils/options.py:16) +no_pass # unused variable (monkey/infection_monkey/exploit/zerologon_utils/options.py:18) +ts # unused variable (monkey/infection_monkey/exploit/zerologon_utils/options.py:25) +opnum # unused variable (monkey/infection_monkey/exploit/zerologon.py:466) +structure # unused variable (monkey/infection_monkey/exploit/zerologon.py:467) +structure # unused variable (monkey/infection_monkey/exploit/zerologon.py:478) +_._port # unused attribute (monkey/infection_monkey/exploit/win_ms08_067.py:123) +oid_set # unused variable (monkey/infection_monkey/exploit/tools/wmi_tools.py:96) +export_monkey_telems # unused variable (monkey/infection_monkey/config.py:282) +NoInternetError # unused class (monkey/common/utils/exceptions.py:33) +_.__isabstractmethod__ # unused attribute (monkey/common/utils/code_utils.py:11) +MIMIKATZ # unused variable (monkey/common/utils/attack_utils.py:21) +MIMIKATZ_WINAPI # unused variable (monkey/common/utils/attack_utils.py:25) +DROPPER # unused variable (monkey/common/utils/attack_utils.py:29) +pytest_addoption # unused function (envs/os_compatibility/conftest.py:4) +pytest_addoption # unused function (envs/monkey_zoo/blackbox/conftest.py:4) +pytest_runtest_setup # unused function (envs/monkey_zoo/blackbox/conftest.py:47) +config_value_list # unused variable (envs/monkey_zoo/blackbox/config_templates/smb_pth.py:10) +_.dashboard_name # unused attribute (monkey/monkey_island/cc/services/zero_trust/scoutsuite/scoutsuite_rule_service.py:13) +_.checked_items # unused attribute (monkey/monkey_island/cc/services/zero_trust/scoutsuite/scoutsuite_rule_service.py:14) +_.flagged_items # unused attribute (monkey/monkey_island/cc/services/zero_trust/scoutsuite/scoutsuite_rule_service.py:15) +_.rationale # unused attribute (monkey/monkey_island/cc/services/zero_trust/scoutsuite/scoutsuite_rule_service.py:17) +_.remediation # unused attribute (monkey/monkey_island/cc/services/zero_trust/scoutsuite/scoutsuite_rule_service.py:18) +_.compliance # unused attribute (monkey/monkey_island/cc/services/zero_trust/scoutsuite/scoutsuite_rule_service.py:19) +_.references # unused attribute (monkey/monkey_island/cc/services/zero_trust/scoutsuite/scoutsuite_rule_service.py:20) +ACM # unused variable (monkey/monkey_island/cc/services/zero_trust/scoutsuite/consts/service_consts.py:8) +AWSLAMBDA # unused variable (monkey/monkey_island/cc/services/zero_trust/scoutsuite/consts/service_consts.py:9) +DIRECTCONNECT # unused variable (monkey/monkey_island/cc/services/zero_trust/scoutsuite/consts/service_consts.py:14) +EFS # unused variable (monkey/monkey_island/cc/services/zero_trust/scoutsuite/consts/service_consts.py:16) +ELASTICACHE # unused variable (monkey/monkey_island/cc/services/zero_trust/scoutsuite/consts/service_consts.py:17) +EMR # unused variable (monkey/monkey_island/cc/services/zero_trust/scoutsuite/consts/service_consts.py:20) +KMS # unused variable (monkey/monkey_island/cc/services/zero_trust/scoutsuite/consts/service_consts.py:22) +ROUTE53 # unused variable (monkey/monkey_island/cc/services/zero_trust/scoutsuite/consts/service_consts.py:25) +SECRETSMANAGER # unused variable (monkey/monkey_island/cc/services/zero_trust/scoutsuite/consts/service_consts.py:31) +RDS_SNAPSHOT_PUBLIC # unused variable (monkey/monkey_island/cc/services/zero_trust/scoutsuite/consts/rule_names/rds_rules.py:17) +dashboard_name # unused variable (monkey/monkey_island/cc/models/zero_trust/scoutsuite_rule.py:18) +checked_items # unused variable (monkey/monkey_island/cc/models/zero_trust/scoutsuite_rule.py:19) +flagged_items # unused variable (monkey/monkey_island/cc/models/zero_trust/scoutsuite_rule.py:20) +rationale # unused variable (monkey/monkey_island/cc/models/zero_trust/scoutsuite_rule.py:22) +remediation # unused variable (monkey/monkey_island/cc/models/zero_trust/scoutsuite_rule.py:23) +compliance # unused variable (monkey/monkey_island/cc/models/zero_trust/scoutsuite_rule.py:24) +references # unused variable (monkey/monkey_island/cc/models/zero_trust/scoutsuite_rule.py:25) +ALIBABA # unused variable (monkey/common/cloud/scoutsuite_consts.py:8) +ORACLE # unused variable (monkey/common/cloud/scoutsuite_consts.py:9) +ALIBABA # unused variable (monkey/common/cloud/environment_names.py:10) +IBM # unused variable (monkey/common/cloud/environment_names.py:11) +DigitalOcean # unused variable (monkey/common/cloud/environment_names.py:12) +_.aws_info # unused attribute (monkey/monkey_island/cc/environment/aws.py:13) + + +# these are not needed for it to work, but may be useful extra information to understand what's going on +WINDOWS_PBA_TYPE # unused variable (monkey/monkey_island/cc/resources/pba_file_upload.py:23) +WINDOWS_TTL # unused variable (monkey/infection_monkey/network/ping_scanner.py:17) +wlist # unused variable (monkey/infection_monkey/transport/tcp.py:28) +wlist # unused variable (monkey/infection_monkey/transport/http.py:176) +charset # unused variable (monkey/infection_monkey/network/mysqlfinger.py:81) +salt # unused variable (monkey/infection_monkey/network/mysqlfinger.py:78) +thread_id # unused variable (monkey/infection_monkey/network/mysqlfinger.py:61) + + +# leaving this since there's a TODO related to it +_.get_wmi_info # unused method (monkey/infection_monkey/system_info/windows_info_collector.py:63) + + +# not 100% sure about these? are these being/will be used somewhere else? +LOG_DIR_NAME # unused variable (envs/monkey_zoo/blackbox/log_handlers/test_logs_handler.py:8) +delete_logs # unused function (envs/monkey_zoo/blackbox/test_blackbox.py:85) +MongoQueryJSONEncoder # unused class (envs/monkey_zoo/blackbox/utils/json_encoder.py:6) From 69af8a8662368211bc6f74efb945f6ebf730d0b2 Mon Sep 17 00:00:00 2001 From: Mike Salvatore Date: Fri, 7 May 2021 08:12:09 -0400 Subject: [PATCH 49/49] island: Remove MongoClient() call from BootloaderHttpServer --- monkey/monkey_island/cc/server_utils/bootloader_server.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/monkey/monkey_island/cc/server_utils/bootloader_server.py b/monkey/monkey_island/cc/server_utils/bootloader_server.py index fa0b21378..d43d9318b 100644 --- a/monkey/monkey_island/cc/server_utils/bootloader_server.py +++ b/monkey/monkey_island/cc/server_utils/bootloader_server.py @@ -3,7 +3,6 @@ from http.server import BaseHTTPRequestHandler, HTTPServer from socketserver import ThreadingMixIn from urllib import parse -import pymongo import requests import urllib3 @@ -17,7 +16,6 @@ logger = logging.getLogger(__name__) class BootloaderHttpServer(ThreadingMixIn, HTTPServer): def __init__(self, mongo_url): - pymongo.MongoClient(mongo_url) server_address = ("", 5001) super().__init__(server_address, BootloaderHTTPRequestHandler)