diff --git a/monkey/monkey_island/cc/services/bootloader.py b/monkey/monkey_island/cc/services/bootloader.py deleted file mode 100644 index 05bdac8f1..000000000 --- a/monkey/monkey_island/cc/services/bootloader.py +++ /dev/null @@ -1,71 +0,0 @@ -from typing import Dict, List - -from bson import ObjectId - -from monkey_island.cc.database import mongo -from monkey_island.cc.services.node import NodeCreationException, NodeService -from monkey_island.cc.services.utils.bootloader_config import ( - MIN_GLIBC_VERSION, - SUPPORTED_WINDOWS_VERSIONS, -) -from monkey_island.cc.services.utils.node_states import NodeStates - - -class BootloaderService: - @staticmethod - def parse_bootloader_telem(telem: Dict) -> bool: - telem["ips"] = BootloaderService.remove_local_ips(telem["ips"]) - if telem["os_version"] == "": - telem["os_version"] = "Unknown OS" - - telem_id = BootloaderService.get_mongo_id_for_bootloader_telem(telem) - mongo.db.bootloader_telems.update({"_id": telem_id}, {"$setOnInsert": telem}, upsert=True) - - will_monkey_run = BootloaderService.is_os_compatible(telem) - try: - node = NodeService.get_or_create_node_from_bootloader_telem(telem, will_monkey_run) - except NodeCreationException: - # Didn't find the node, but allow monkey to run anyways - return True - - node_group = BootloaderService.get_next_node_state(node, telem["system"], will_monkey_run) - if "group" not in node or node["group"] != node_group.value: - NodeService.set_node_group(node["_id"], node_group) - return will_monkey_run - - @staticmethod - def get_next_node_state(node: Dict, system: str, will_monkey_run: bool) -> NodeStates: - group_keywords = [system, "monkey"] - if "group" in node and node["group"] == "island": - group_keywords.extend(["island", "starting"]) - else: - group_keywords.append("starting") if will_monkey_run else group_keywords.append("old") - node_group = NodeStates.get_by_keywords(group_keywords) - return node_group - - @staticmethod - def get_mongo_id_for_bootloader_telem(bootloader_telem) -> ObjectId: - ip_hash = hex(hash(str(bootloader_telem["ips"])))[3:15] - hostname_hash = hex(hash(bootloader_telem["hostname"]))[3:15] - return ObjectId(ip_hash + hostname_hash) - - @staticmethod - def is_os_compatible(bootloader_data) -> bool: - if bootloader_data["system"] == "windows": - return BootloaderService.is_windows_version_supported(bootloader_data["os_version"]) - elif bootloader_data["system"] == "linux": - return BootloaderService.is_glibc_supported(bootloader_data["glibc_version"]) - - @staticmethod - def is_windows_version_supported(windows_version) -> bool: - return SUPPORTED_WINDOWS_VERSIONS.get(windows_version, True) - - @staticmethod - def is_glibc_supported(glibc_version_string) -> bool: - glibc_version_string = glibc_version_string.lower() - glibc_version = glibc_version_string.split(" ")[-1] - return glibc_version >= str(MIN_GLIBC_VERSION) and "eglibc" not in glibc_version_string - - @staticmethod - def remove_local_ips(ip_list) -> List[str]: - return [i for i in ip_list if not i.startswith("127")] diff --git a/monkey/monkey_island/cc/services/utils/bootloader_config.py b/monkey/monkey_island/cc/services/utils/bootloader_config.py deleted file mode 100644 index f1eaf9368..000000000 --- a/monkey/monkey_island/cc/services/utils/bootloader_config.py +++ /dev/null @@ -1,11 +0,0 @@ -MIN_GLIBC_VERSION = 2.14 - -SUPPORTED_WINDOWS_VERSIONS = { - "xp_or_lower": False, - "vista": False, - "vista_sp1": False, - "vista_sp2": True, - "windows7": True, - "windows7_sp1": True, - "windows8_or_greater": True, -} diff --git a/monkey/tests/unit_tests/monkey_island/cc/services/test_bootloader_service.py b/monkey/tests/unit_tests/monkey_island/cc/services/test_bootloader_service.py deleted file mode 100644 index 25869fd29..000000000 --- a/monkey/tests/unit_tests/monkey_island/cc/services/test_bootloader_service.py +++ /dev/null @@ -1,24 +0,0 @@ -from unittest import TestCase - -from monkey_island.cc.services.bootloader import BootloaderService - -MIN_GLIBC_VERSION = 2.14 - - -class TestBootloaderService(TestCase): - def test_is_glibc_supported(self): - str1 = "ldd (Ubuntu EGLIBC 2.15-0ubuntu10) 2.15" - str2 = "ldd (GNU libc) 2.12" - str3 = "ldd (GNU libc) 2.28" - str4 = "ldd (Ubuntu GLIBC 2.23-0ubuntu11) 2.23" - self.assertTrue( - not BootloaderService.is_glibc_supported(str1) - and not BootloaderService.is_glibc_supported(str2) - and BootloaderService.is_glibc_supported(str3) - and BootloaderService.is_glibc_supported(str4) - ) - - def test_remove_local_ips(self): - ips = ["127.1.1.1", "127.0.0.1", "192.168.56.1"] - ips = BootloaderService.remove_local_ips(ips) - self.assertEqual(["192.168.56.1"], ips)