def __init__(self): self.workspace = fuzzy_string(8) self.registration_token = fuzzy_string(25) self.agent_token = fuzzy_string(64) self.agent_id = random.randint(1, 1000) self.websocket_port = random.randint(1025, 65535) self.client = None self.app_config = { "SECURITY_TOKEN_AUTHENTICATION_HEADER": 'Authorization', "SECRET_KEY": 'SECRET_KEY', } self.changes_queue = Queue()
def __init__(self, is_ssl: bool = False, has_base_route: bool = False): self.workspaces = [ fuzzy_string(8) for _ in range(0, random.randint(2, 6)) ] self.registration_token = f"{random.randint(0, 999999):06}" self.agent_token = fuzzy_string(64) self.agent_id = random.randint(1, 1000) self.websocket_port = random.randint(1025, 65535) self.is_ssl = is_ssl self.ssl_cert_path = Path(__file__).parent.parent / "data" self.client = None self.base_route = f"{fuzzy_string(24)}" if has_base_route else None self.app_config = { "SECURITY_TOKEN_AUTHENTICATION_HEADER": "Authorization", "SECRET_KEY": "SECRET_KEY", } self.changes_queue = Queue() self.ws_data = {}
async def test_merge_config( test_config: FaradayTestConfig, # noqa F811 tmp_default_config, # noqa F811 test_logger_handler, # noqa F811 test_logger_folder, # noqa F811 ): configuration.set(Sections.SERVER, "api_port", str(test_config.client.port)) configuration.set(Sections.SERVER, "websocket_port", str(test_config.client.port)) if test_config.base_route: configuration.set(Sections.SERVER, "base_route", test_config.base_route) configuration.set(Sections.SERVER, "ssl", str(test_config.is_ssl)) if test_config.is_ssl: configuration.set(Sections.SERVER, "ssl_cert", str(test_config.ssl_cert_path / "ok.crt")) configuration.set(Sections.SERVER, "host", "localhost") else: configuration.set(Sections.SERVER, "host", test_config.client.host) configuration.set(Sections.SERVER, "workspaces", test_config.workspaces_str()) random_workspace_name = fuzzy_string(15) configuration.set(Sections.SERVER, "workspace", random_workspace_name) test_config.workspaces = [random_workspace_name] + test_config.workspaces configuration.set(Sections.TOKENS, "registration", test_config.registration_token) configuration.set(Sections.TOKENS, "agent", test_config.agent_token) path_to_basic_executor = Path(__file__).parent.parent / "data" / "basic_executor.py" configuration.set(Sections.AGENT, "executors", "ex1,ex2,ex3,ex4") for executor_name in ["ex1", "ex3", "ex4"]: executor_section = Sections.EXECUTOR_DATA.format(executor_name) params_section = Sections.EXECUTOR_PARAMS.format(executor_name) for section in [executor_section, params_section]: if section not in configuration: configuration.add_section(section) configuration.set(executor_section, "cmd", "python {}".format(path_to_basic_executor)) configuration.set(Sections.EXECUTOR_PARAMS.format("ex1"), "param1", "True") configuration.set(Sections.EXECUTOR_PARAMS.format("ex1"), "param2", "False") configuration.set(Sections.EXECUTOR_PARAMS.format("ex3"), "param3", "False") configuration.set(Sections.EXECUTOR_PARAMS.format("ex3"), "param4", "False") tmp_default_config.save() dispatcher = Dispatcher(test_config.client.session, tmp_default_config.config_file_path) test_config.ws_data["run_data"] = {"agent_id": 1} test_config.ws_data["ws_responses"] = [{"error": "'action' key is mandatory in this websocket connection"}] test_config.executors = get_merge_executors() await dispatcher.register() await dispatcher.connect() assert len(test_config.ws_data["ws_responses"]) == 0
from faraday_agent_dispatcher.utils.url_utils import api_url from tests.data.basic_executor import host_data, vuln_data from tests.utils.text_utils import fuzzy_string import os from pathlib import Path from requests import Session import subprocess import time reset_config(EXAMPLE_CONFIG_FILENAME) HOST = config.get(Sections.SERVER, "host") API_PORT = config.get(Sections.SERVER, "api_port") WS_PORT = config.get(Sections.SERVER, "websocket_port") WORKSPACE = fuzzy_string( 6).lower() # TODO FIX WHEN FARADAY ACCEPTS CAPITAL FIRST LETTER AGENT_NAME = fuzzy_string(6) EXECUTOR_NAME = fuzzy_string(6) USER = os.getenv("FARADAY_USER") EMAIL = os.getenv("FARADAY_EMAIL") PASS = os.getenv("FARADAY_PASSWORD") CONFIG_DIR = "./config_file.ini" LOGGER_DIR = "./logs" agent_ok_status_keys_set = { 'create_date', 'creator', 'id', 'name', 'token', 'is_online', 'active', 'status', 'update_date' }
from tests.data.basic_executor import host_data, vuln_data from tests.utils.text_utils import fuzzy_string import os from pathlib import Path from requests import Session import subprocess import time reset_config(EXAMPLE_CONFIG_FILENAME) HOST = config.get(Sections.SERVER, "host") API_PORT = config.get(Sections.SERVER, "api_port") WS_PORT = config.get(Sections.SERVER, "websocket_port") # TODO FIX WHEN FARADAY ACCEPTS CAPITAL FIRST LETTER WORKSPACE = fuzzy_string(6).lower() AGENT_NAME = fuzzy_string(6) EXECUTOR_NAME = fuzzy_string(6) SSL = "false" USER = os.getenv("FARADAY_USER") EMAIL = os.getenv("FARADAY_EMAIL") PASS = os.getenv("FARADAY_PASSWORD") LOGGER_DIR = Path("./logs") agent_ok_status_keys_set = { "create_date", "creator", "id", "name",