Island, UT: Remove Bootloader endpoint

This commit is contained in:
Ilija Lazoroski 2022-01-31 18:21:04 +01:00
parent add449c5f4
commit b5c51bedc1
5 changed files with 1 additions and 165 deletions

View File

@ -18,7 +18,6 @@ from monkey_island.cc.resources.blackbox.monkey_blackbox_endpoint import MonkeyB
from monkey_island.cc.resources.blackbox.telemetry_blackbox_endpoint import (
TelemetryBlackboxEndpoint,
)
from monkey_island.cc.resources.bootloader import Bootloader
from monkey_island.cc.resources.client_run import ClientRun
from monkey_island.cc.resources.configuration_export import ConfigurationExport
from monkey_island.cc.resources.configuration_import import ConfigurationImport
@ -127,7 +126,6 @@ def init_api_resources(api):
"/api/monkey/<string:guid>",
"/api/monkey/<string:guid>/<string:config_format>",
)
api.add_resource(Bootloader, "/api/bootloader/<string:os>")
api.add_resource(LocalRun, "/api/local-monkey")
api.add_resource(ClientRun, "/api/client-monkey")
api.add_resource(Telemetry, "/api/telemetry", "/api/telemetry/<string:monkey_guid>")

View File

@ -1,41 +0,0 @@
import json
from typing import Dict
import flask_restful
from flask import make_response, request
from monkey_island.cc.services.bootloader import BootloaderService
class Bootloader(flask_restful.Resource):
# Used by monkey. can't secure.
def post(self, os):
if os == "linux":
data = Bootloader._get_request_contents_linux(request.data)
elif os == "windows":
data = Bootloader._get_request_contents_windows(request.data)
else:
return make_response({"status": "OS_NOT_FOUND"}, 404)
result = BootloaderService.parse_bootloader_telem(data)
if result:
return make_response({"status": "RUN"}, 200)
else:
return make_response({"status": "ABORT"}, 200)
@staticmethod
def _get_request_contents_linux(request_data: bytes) -> Dict[str, str]:
parsed_data = json.loads(
request_data.decode()
.replace('"\n', "")
.replace("\n", "")
.replace('NAME="', "")
.replace('":",', '":"",')
)
return parsed_data
@staticmethod
def _get_request_contents_windows(request_data: bytes) -> Dict[str, str]:
return json.loads(request_data.decode("utf-16", "ignore"))

View File

@ -1,6 +1,5 @@
import socket
from datetime import datetime, timedelta
from typing import Dict
from bson import ObjectId
@ -10,7 +9,7 @@ from monkey_island.cc.database import mongo
from monkey_island.cc.models import Monkey
from monkey_island.cc.services.edge.displayed_edge import DisplayedEdgeService
from monkey_island.cc.services.edge.edge import EdgeService
from monkey_island.cc.services.utils.network_utils import is_local_ips, local_ip_addresses
from monkey_island.cc.services.utils.network_utils import local_ip_addresses
from monkey_island.cc.services.utils.node_states import NodeStates
@ -209,59 +208,6 @@ class NodeService:
)
return mongo.db.node.find_one({"_id": new_node_insert_result.inserted_id})
@staticmethod
def create_node_from_bootloader_telem(bootloader_telem: Dict, will_monkey_run: bool):
new_node_insert_result = mongo.db.node.insert_one(
{
"ip_addresses": bootloader_telem["ips"],
"domain_name": bootloader_telem["hostname"],
"will_monkey_run": will_monkey_run,
"exploited": False,
"creds": [],
"os": {
"type": bootloader_telem["system"],
"version": bootloader_telem["os_version"],
},
}
)
return mongo.db.node.find_one({"_id": new_node_insert_result.inserted_id})
@staticmethod
def get_or_create_node_from_bootloader_telem(
bootloader_telem: Dict, will_monkey_run: bool
) -> Dict:
if is_local_ips(bootloader_telem["ips"]):
raise NodeCreationException("Bootloader ran on island, no need to create new node.")
new_node = mongo.db.node.find_one({"ip_addresses": {"$in": bootloader_telem["ips"]}})
# Temporary workaround to not create a node after monkey finishes
monkey_node = mongo.db.monkey.find_one({"ip_addresses": {"$in": bootloader_telem["ips"]}})
if monkey_node:
# Don't create new node, monkey node is already present
return monkey_node
if new_node is None:
new_node = NodeService.create_node_from_bootloader_telem(
bootloader_telem, will_monkey_run
)
if bootloader_telem["tunnel"]:
dst_node = NodeService.get_node_or_monkey_by_ip(bootloader_telem["tunnel"])
else:
dst_node = NodeService.get_monkey_island_node()
src_label = NodeService.get_label_for_endpoint(new_node["_id"])
dst_label = NodeService.get_label_for_endpoint(dst_node["id"])
edge = EdgeService.get_or_create_edge(
src_node_id=new_node["_id"],
dst_node_id=dst_node["id"],
src_label=src_label,
dst_label=dst_label,
)
edge.tunnel = bool(bootloader_telem["tunnel"])
edge.ip_address = bootloader_telem["ips"][0]
edge.group = NodeStates.get_by_keywords(["island"]).value
edge.save()
return new_node
@staticmethod
def get_or_create_node(ip_address, domain_name=""):
new_node = mongo.db.node.find_one({"ip_addresses": ip_address})

View File

@ -1,66 +0,0 @@
from unittest import TestCase
from monkey_island.cc.resources.bootloader import Bootloader
class TestBootloader(TestCase):
def test_get_request_contents_linux(self):
data_without_tunnel = (
b'{"system":"linux", '
b'"os_version":"NAME="Ubuntu"\n", '
b'"glibc_version":"ldd (Ubuntu GLIBC 2.23-0ubuntu11) 2.23\n", '
b'"hostname":"test-TEST", '
b'"tunnel":false, '
b'"ips": ["127.0.0.1", "10.0.2.15", "192.168.56.5"]}'
)
data_with_tunnel = (
b'{"system":"linux", '
b'"os_version":"NAME="Ubuntu"\n", '
b'"glibc_version":"ldd (Ubuntu GLIBC 2.23-0ubuntu11) 2.23\n", '
b'"hostname":"test-TEST", '
b'"tunnel":"192.168.56.1:5002", '
b'"ips": ["127.0.0.1", "10.0.2.15", "192.168.56.5"]}'
)
result1 = Bootloader._get_request_contents_linux(data_without_tunnel)
self.assertTrue(result1["system"] == "linux")
self.assertTrue(result1["os_version"] == "Ubuntu")
self.assertTrue(result1["glibc_version"] == "ldd (Ubuntu GLIBC 2.23-0ubuntu11) 2.23")
self.assertTrue(result1["hostname"] == "test-TEST")
self.assertFalse(result1["tunnel"])
self.assertTrue(result1["ips"] == ["127.0.0.1", "10.0.2.15", "192.168.56.5"])
result2 = Bootloader._get_request_contents_linux(data_with_tunnel)
self.assertTrue(result2["system"] == "linux")
self.assertTrue(result2["os_version"] == "Ubuntu")
self.assertTrue(result2["glibc_version"] == "ldd (Ubuntu GLIBC 2.23-0ubuntu11) 2.23")
self.assertTrue(result2["hostname"] == "test-TEST")
self.assertTrue(result2["tunnel"] == "192.168.56.1:5002")
self.assertTrue(result2["ips"] == ["127.0.0.1", "10.0.2.15", "192.168.56.5"])
def test_get_request_contents_windows(self):
windows_data = (
b'{\x00"\x00s\x00y\x00s\x00t\x00e\x00m\x00"\x00:\x00"\x00w\x00i\x00n\x00d\x00o'
b'\x00w\x00s\x00"\x00,\x00 \x00"\x00o\x00s\x00_\x00v\x00e\x00r\x00s\x00i\x00o\x00n'
b'\x00"\x00:\x00"\x00w\x00i\x00n\x00d\x00o\x00w\x00s\x008\x00_\x00o\x00r\x00_\x00g\x00r'
b'\x00e\x00a\x00t\x00e\x00r\x00"\x00,\x00 '
b'\x00"\x00h\x00o\x00s\x00t\x00n\x00a\x00m\x00e\x00"'
b'\x00:\x00"\x00D\x00E\x00S\x00K\x00T\x00O\x00P\x00-\x00P\x00J\x00H\x00U\x003\x006'
b'\x00B\x00"'
b'\x00,\x00 \x00"\x00t\x00u\x00n\x00n\x00e\x00l\x00"\x00:\x00f\x00a\x00l\x00s\x00e'
b"\x00,\x00 "
b'\x00"\x00i\x00p\x00s\x00"\x00:\x00 \x00['
b'\x00"\x001\x009\x002\x00.\x001\x006\x008\x00.\x005'
b'\x006\x00.\x001\x00"\x00,\x00 '
b'\x00"\x001\x009\x002\x00.\x001\x006\x008\x00.\x002\x004\x009'
b'\x00.\x001\x00"\x00,\x00 '
b'\x00"\x001\x009\x002\x00.\x001\x006\x008\x00.\x002\x001\x007\x00.'
b'\x001\x00"\x00]\x00}\x00'
)
result = Bootloader._get_request_contents_windows(windows_data)
self.assertTrue(result["system"] == "windows")
self.assertTrue(result["os_version"] == "windows8_or_greater")
self.assertTrue(result["hostname"] == "DESKTOP-PJHU36B")
self.assertFalse(result["tunnel"])
self.assertTrue(result["ips"] == ["192.168.56.1", "192.168.249.1", "192.168.217.1"])

View File

@ -68,7 +68,6 @@ VSFTPD # unused variable (monkey/monkey_island/cc/services/reporting/issue_proc
DRUPAL # unused variable (monkey/monkey_island/cc/services/reporting/issue_processing/exploit_processing/exploiter_descriptor_enum.py:48)
POWERSHELL # (\monkey\monkey_island\cc\services\reporting\issue_processing\exploit_processing\exploiter_descriptor_enum.py:52)
ExploiterDescriptorEnum.LOG4SHELL
_.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)