From a989e5543a18c3cb09c2d0b4f470c1580916f80d Mon Sep 17 00:00:00 2001 From: Mike Salvatore Date: Mon, 7 Feb 2022 12:07:45 -0500 Subject: [PATCH] Island: Format fingerprinter config with options --- monkey/monkey_island/cc/services/config.py | 13 +++++++++++-- .../monkey_island/cc/services/test_config.py | 13 ++++++++----- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/monkey/monkey_island/cc/services/config.py b/monkey/monkey_island/cc/services/config.py index a0af1632c..163c9d1da 100644 --- a/monkey/monkey_island/cc/services/config.py +++ b/monkey/monkey_island/cc/services/config.py @@ -538,10 +538,19 @@ class ConfigService: @staticmethod def _format_fingerprinters_from_flat_config(config: Dict): flat_fingerprinter_classes_field = "finger_classes" + flat_http_ports_field = "HTTP_PORTS" + + formatted_fingerprinters = [ + {"name": f, "options": {}} for f in sorted(config[flat_fingerprinter_classes_field]) + ] + + if "HTTPFinger" in config[flat_fingerprinter_classes_field]: + for fp in formatted_fingerprinters: + if fp["name"] == "HTTPFinger": + fp["options"] = {"http_ports": sorted(config[flat_http_ports_field])} + break - formatted_fingerprinters = config[flat_fingerprinter_classes_field] config.pop(flat_fingerprinter_classes_field) - return formatted_fingerprinters @staticmethod diff --git a/monkey/tests/unit_tests/monkey_island/cc/services/test_config.py b/monkey/tests/unit_tests/monkey_island/cc/services/test_config.py index 3ad02a7a6..fe8ec639e 100644 --- a/monkey/tests/unit_tests/monkey_island/cc/services/test_config.py +++ b/monkey/tests/unit_tests/monkey_island/cc/services/test_config.py @@ -147,11 +147,14 @@ def test_format_config_for_agent__network_scan(flat_monkey_config): "timeout_ms": 1000, }, "fingerprinters": [ - "SMBFinger", - "SSHFinger", - "HTTPFinger", - "MSSQLFinger", - "ElasticFinger", + {"name": "ElasticFinger", "options": {}}, + { + "name": "HTTPFinger", + "options": {"http_ports": [80, 443, 7001, 8008, 8080, 9200]}, + }, + {"name": "MSSQLFinger", "options": {}}, + {"name": "SMBFinger", "options": {}}, + {"name": "SSHFinger", "options": {}}, ], } ConfigService.format_flat_config_for_agent(flat_monkey_config)