Island: Remove Bootloader server
This commit is contained in:
parent
c3e66debc8
commit
fbd36e5b41
|
@ -3,7 +3,6 @@ import json
|
|||
import logging
|
||||
import sys
|
||||
from pathlib import Path
|
||||
from threading import Thread
|
||||
|
||||
import gevent.hub
|
||||
from gevent.pywsgi import WSGIServer
|
||||
|
@ -22,7 +21,6 @@ from monkey_island.cc.app import init_app # noqa: E402
|
|||
from monkey_island.cc.arg_parser import IslandCmdArgs # noqa: E402
|
||||
from monkey_island.cc.arg_parser import parse_cli_args # noqa: E402
|
||||
from monkey_island.cc.resources.monkey_download import MonkeyDownload # noqa: E402
|
||||
from monkey_island.cc.server_utils.bootloader_server import BootloaderHttpServer # noqa: E402
|
||||
from monkey_island.cc.server_utils.consts import ( # noqa: E402
|
||||
GEVENT_EXCEPTION_LOG,
|
||||
MONGO_CONNECTION_TIMEOUT,
|
||||
|
@ -137,8 +135,6 @@ def _start_island_server(should_setup_only, config_options: IslandConfigOptions)
|
|||
logger.warning("Setup only flag passed. Exiting.")
|
||||
return
|
||||
|
||||
bootloader_server_thread = _start_bootloader_server()
|
||||
|
||||
logger.info(
|
||||
f"Using certificate path: {config_options.crt_path}, and key path: "
|
||||
f"{config_options.key_path}."
|
||||
|
@ -155,16 +151,6 @@ def _start_island_server(should_setup_only, config_options: IslandConfigOptions)
|
|||
_log_init_info()
|
||||
http_server.serve_forever()
|
||||
|
||||
bootloader_server_thread.join()
|
||||
|
||||
|
||||
def _start_bootloader_server() -> Thread:
|
||||
bootloader_server_thread = Thread(target=BootloaderHttpServer().serve_forever, daemon=True)
|
||||
|
||||
bootloader_server_thread.start()
|
||||
|
||||
return bootloader_server_thread
|
||||
|
||||
|
||||
def _log_init_info():
|
||||
MonkeyDownload.log_executable_hashes()
|
||||
|
|
|
@ -1,52 +0,0 @@
|
|||
import logging
|
||||
from http.server import BaseHTTPRequestHandler, HTTPServer
|
||||
from socketserver import ThreadingMixIn
|
||||
from urllib import parse
|
||||
|
||||
import requests
|
||||
import urllib3
|
||||
|
||||
from common.common_consts.timeouts import SHORT_REQUEST_TIMEOUT
|
||||
from monkey_island.cc.server_utils.consts import ISLAND_PORT
|
||||
|
||||
# Disable "unverified certificate" warnings when sending requests to island
|
||||
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning) # noqa: DUO131
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class BootloaderHttpServer(ThreadingMixIn, HTTPServer):
|
||||
def __init__(self):
|
||||
server_address = ("", 5001)
|
||||
super().__init__(server_address, BootloaderHTTPRequestHandler)
|
||||
|
||||
|
||||
class BootloaderHTTPRequestHandler(BaseHTTPRequestHandler):
|
||||
def do_POST(self):
|
||||
content_length = int(self.headers["Content-Length"])
|
||||
post_data = self.rfile.read(content_length).decode()
|
||||
island_server_path = BootloaderHTTPRequestHandler.get_bootloader_resource_url(
|
||||
self.request.getsockname()[0]
|
||||
)
|
||||
island_server_path = parse.urljoin(island_server_path, self.path[1:])
|
||||
# The island server doesn't always have a correct SSL cert installed
|
||||
# (By default it comes with a self signed one),
|
||||
# that's why we're not verifying the cert in this request.
|
||||
r = requests.post( # noqa: DUO123
|
||||
url=island_server_path, data=post_data, verify=False, timeout=SHORT_REQUEST_TIMEOUT
|
||||
)
|
||||
|
||||
try:
|
||||
if r.status_code != 200:
|
||||
self.send_response(404)
|
||||
else:
|
||||
self.send_response(200)
|
||||
self.end_headers()
|
||||
self.wfile.write(r.content)
|
||||
except Exception as e:
|
||||
logger.error("Failed to respond to bootloader: {}".format(e))
|
||||
finally:
|
||||
self.connection.close()
|
||||
|
||||
@staticmethod
|
||||
def get_bootloader_resource_url(server_ip):
|
||||
return "https://" + server_ip + ":" + str(ISLAND_PORT) + "/api/bootloader/"
|
Loading…
Reference in New Issue