forked from p15670423/monkey
Island: replace get_island_port() with constant
This commit is contained in:
parent
ee285b6fbd
commit
c4d7bf7030
|
@ -12,7 +12,6 @@ logger = logging.getLogger(__name__)
|
|||
|
||||
|
||||
class Environment(object, metaclass=ABCMeta):
|
||||
_ISLAND_PORT = 5000
|
||||
_DEBUG_SERVER = False
|
||||
_AUTH_EXPIRATION_TIME = timedelta(minutes=30)
|
||||
|
||||
|
@ -33,9 +32,6 @@ class Environment(object, metaclass=ABCMeta):
|
|||
def get_config(self) -> EnvironmentConfig:
|
||||
return self._config
|
||||
|
||||
def get_island_port(self):
|
||||
return self._ISLAND_PORT
|
||||
|
||||
def is_debug(self):
|
||||
return self._DEBUG_SERVER
|
||||
|
||||
|
|
|
@ -10,6 +10,8 @@ from typing import Tuple
|
|||
import gevent.hub
|
||||
from gevent.pywsgi import WSGIServer
|
||||
|
||||
from monkey_island.cc.server_utils.consts import ISLAND_PORT
|
||||
|
||||
# Add the monkey_island directory to the path, to make sure imports that don't start with
|
||||
# "monkey_island." work.
|
||||
MONKEY_ISLAND_DIR_BASE_PATH = str(Path(__file__).parent.parent)
|
||||
|
@ -152,7 +154,7 @@ def _start_island_server(should_setup_only, config_options: IslandConfigOptions)
|
|||
)
|
||||
else:
|
||||
http_server = WSGIServer(
|
||||
("0.0.0.0", env_singleton.env.get_island_port()),
|
||||
("0.0.0.0", ISLAND_PORT),
|
||||
app,
|
||||
certfile=config_options.crt_path,
|
||||
keyfile=config_options.key_path,
|
||||
|
@ -178,12 +180,7 @@ def _log_init_info():
|
|||
logger.info(f"version: {get_version()}")
|
||||
logger.info(
|
||||
"Listening on the following URLs: {}".format(
|
||||
", ".join(
|
||||
[
|
||||
"https://{}:{}".format(x, env_singleton.env.get_island_port())
|
||||
for x in local_ip_addresses()
|
||||
]
|
||||
)
|
||||
", ".join(["https://{}:{}".format(x, ISLAND_PORT) for x in local_ip_addresses()])
|
||||
)
|
||||
)
|
||||
MonkeyDownload.log_executable_hashes()
|
||||
|
|
|
@ -7,7 +7,7 @@ import requests
|
|||
import urllib3
|
||||
|
||||
from common.common_consts.timeouts import SHORT_REQUEST_TIMEOUT
|
||||
from monkey_island.cc.environment import Environment
|
||||
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
|
||||
|
@ -49,4 +49,4 @@ class BootloaderHTTPRequestHandler(BaseHTTPRequestHandler):
|
|||
|
||||
@staticmethod
|
||||
def get_bootloader_resource_url(server_ip):
|
||||
return "https://" + server_ip + ":" + str(Environment._ISLAND_PORT) + "/api/bootloader/"
|
||||
return "https://" + server_ip + ":" + str(ISLAND_PORT) + "/api/bootloader/"
|
||||
|
|
|
@ -51,3 +51,5 @@ DEFAULT_CERTIFICATE_PATHS = {
|
|||
}
|
||||
|
||||
GEVENT_EXCEPTION_LOG = "gevent_exceptions.log"
|
||||
|
||||
ISLAND_PORT = 5000
|
||||
|
|
|
@ -5,7 +5,6 @@ import logging
|
|||
|
||||
from jsonschema import Draft4Validator, validators
|
||||
|
||||
import monkey_island.cc.environment.environment_singleton as env_singleton
|
||||
from common.config_value_paths import (
|
||||
AWS_KEYS_PATH,
|
||||
EXPORT_MONKEY_TELEMS_PATH,
|
||||
|
@ -19,6 +18,7 @@ from common.config_value_paths import (
|
|||
USER_LIST_PATH,
|
||||
)
|
||||
from monkey_island.cc.database import mongo
|
||||
from monkey_island.cc.server_utils.consts import ISLAND_PORT
|
||||
from monkey_island.cc.server_utils.encryption import get_datastore_encryptor
|
||||
from monkey_island.cc.services.config_manipulator import update_config_per_mode
|
||||
from monkey_island.cc.services.config_schema.config_schema import SCHEMA
|
||||
|
@ -264,11 +264,11 @@ class ConfigService:
|
|||
def set_server_ips_in_config(config):
|
||||
ips = local_ip_addresses()
|
||||
config["internal"]["island_server"]["command_servers"] = [
|
||||
"%s:%d" % (ip, env_singleton.env.get_island_port()) for ip in ips
|
||||
"%s:%d" % (ip, ISLAND_PORT) for ip in ips
|
||||
]
|
||||
config["internal"]["island_server"]["current_server"] = "%s:%d" % (
|
||||
ips[0],
|
||||
env_singleton.env.get_island_port(),
|
||||
ISLAND_PORT,
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
|
|
|
@ -5,9 +5,8 @@ import stat
|
|||
import subprocess
|
||||
from shutil import copyfile
|
||||
|
||||
import monkey_island.cc.environment.environment_singleton as env_singleton
|
||||
from monkey_island.cc.resources.monkey_download import get_monkey_executable
|
||||
from monkey_island.cc.server_utils.consts import MONKEY_ISLAND_ABS_PATH
|
||||
from monkey_island.cc.server_utils.consts import ISLAND_PORT, MONKEY_ISLAND_ABS_PATH
|
||||
from monkey_island.cc.services.utils.network_utils import local_ip_addresses
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
@ -45,7 +44,7 @@ class LocalMonkeyRunService:
|
|||
# run the monkey
|
||||
try:
|
||||
ip = local_ip_addresses()[0]
|
||||
port = env_singleton.env.get_island_port()
|
||||
port = ISLAND_PORT
|
||||
|
||||
args = [dest_path, "m0nk3y", "-s", f"{ip}:{port}"]
|
||||
subprocess.Popen(args, cwd=LocalMonkeyRunService.DATA_DIR)
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
import pytest
|
||||
|
||||
from monkey_island.cc.environment import Environment
|
||||
from monkey_island.cc.services.config import ConfigService
|
||||
|
||||
|
||||
|
@ -17,7 +16,6 @@ def PORT():
|
|||
@pytest.fixture
|
||||
def config(monkeypatch, IPS, PORT):
|
||||
monkeypatch.setattr("monkey_island.cc.services.config.local_ip_addresses", lambda: IPS)
|
||||
monkeypatch.setattr(Environment, "_ISLAND_PORT", PORT)
|
||||
config = ConfigService.get_default_config(True)
|
||||
return config
|
||||
|
||||
|
|
|
@ -11,11 +11,8 @@ class MockClass:
|
|||
|
||||
|
||||
@pytest.fixture(scope="function", autouse=True)
|
||||
def mock_port_in_env_singleton(monkeypatch, PORT):
|
||||
mock_singleton = MockClass()
|
||||
mock_singleton.env = MockClass()
|
||||
mock_singleton.env.get_island_port = lambda: PORT
|
||||
monkeypatch.setattr("monkey_island.cc.services.config.env_singleton", mock_singleton)
|
||||
def mock_port(monkeypatch, PORT):
|
||||
monkeypatch.setattr("monkey_island.cc.services.config.ISLAND_PORT", PORT)
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("uses_encryptor")
|
||||
|
|
Loading…
Reference in New Issue