From 55d3fd5bd8b16e49bc9073c161aef3ac89096cdb Mon Sep 17 00:00:00 2001 From: VakarisZ Date: Tue, 28 Apr 2020 17:54:12 +0300 Subject: [PATCH 1/3] More improvement on telemetry fabrication logging --- envs/monkey_zoo/blackbox/README.md | 1 + .../blackbox/tests/performance/utils/telem_parser.py | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/envs/monkey_zoo/blackbox/README.md b/envs/monkey_zoo/blackbox/README.md index 334dbf3ac..e800537de 100644 --- a/envs/monkey_zoo/blackbox/README.md +++ b/envs/monkey_zoo/blackbox/README.md @@ -32,4 +32,5 @@ To run telemetry performance test follow these steps: 1. Run `telem_parser.py` scrip with working directory set to `monkey\envs\monkey_zoo\blackbox` 2. Pass integer to indicate the multiplier. For example running `telem_parser.py 4` will replicate telemetries 4 times. + 3. If you're using pycharm check "Emulate terminal in output console" on debug/run configuraion. 3. Run blackbox tests, telemetry performance test will run as part of it. diff --git a/envs/monkey_zoo/blackbox/tests/performance/utils/telem_parser.py b/envs/monkey_zoo/blackbox/tests/performance/utils/telem_parser.py index 049454a32..df7e9f5be 100644 --- a/envs/monkey_zoo/blackbox/tests/performance/utils/telem_parser.py +++ b/envs/monkey_zoo/blackbox/tests/performance/utils/telem_parser.py @@ -24,7 +24,7 @@ class TelemParser: telems = TelemParser.get_all_telemetries() telem_contents = [json.loads(telem['content']) for telem in telems] monkeys = self.get_monkeys_from_telems(telem_contents) - for i in tqdm(range(self.multiplier), desc="Batch of fabricated telemetries"): + for i in tqdm(range(self.multiplier), desc="Batch of fabricated telemetries", position=1): for monkey in monkeys: monkey.change_fake_data() fake_telem_batch = copy.deepcopy(telems) @@ -34,7 +34,7 @@ class TelemParser: @staticmethod def fabricate_monkeys_in_telems(telems: List[Dict], monkeys: List[FakeMonkey]): - for telem in tqdm(telems, desc="Teletry"): + for telem in tqdm(telems, desc="Telemetries fabricated", position=2): for monkey in monkeys: if monkey.on_island: continue @@ -51,7 +51,7 @@ class TelemParser: @staticmethod def save_teletries_to_files(telems: List[Dict]): - for telem in telems: + for telem in (tqdm(telems, desc="Telemetries saved to files", position=3)): TelemParser.save_telemetry_to_file(telem) @staticmethod From 1352747c4eff1b0bc3c69da0b12abbdab3be45e2 Mon Sep 17 00:00:00 2001 From: VakarisZ Date: Wed, 29 Apr 2020 10:39:10 +0300 Subject: [PATCH 2/3] Removed debugging comments --- envs/monkey_zoo/blackbox/test_blackbox.py | 116 +++++++++++----------- 1 file changed, 59 insertions(+), 57 deletions(-) diff --git a/envs/monkey_zoo/blackbox/test_blackbox.py b/envs/monkey_zoo/blackbox/test_blackbox.py index 3c4b5e3df..c0a7caf3d 100644 --- a/envs/monkey_zoo/blackbox/test_blackbox.py +++ b/envs/monkey_zoo/blackbox/test_blackbox.py @@ -9,6 +9,8 @@ from envs.monkey_zoo.blackbox.island_client.island_config_parser import IslandCo from envs.monkey_zoo.blackbox.island_client.monkey_island_client import MonkeyIslandClient from envs.monkey_zoo.blackbox.log_handlers.test_logs_handler import TestLogsHandler from envs.monkey_zoo.blackbox.tests.exploitation import ExploitationTest +from envs.monkey_zoo.blackbox.tests.performance.map_generation import MapGenerationTest +from envs.monkey_zoo.blackbox.tests.performance.report_generation import ReportGenerationTest from envs.monkey_zoo.blackbox.tests.performance.telemetry_performance_test import TelemetryPerformanceTest from envs.monkey_zoo.blackbox.utils import gcp_machine_handlers @@ -24,11 +26,11 @@ LOGGER = logging.getLogger(__name__) @pytest.fixture(autouse=True, scope='session') def GCPHandler(request): GCPHandler = gcp_machine_handlers.GCPHandler() - #GCPHandler.start_machines(" ".join(GCP_TEST_MACHINE_LIST)) - #wait_machine_bootup() + GCPHandler.start_machines(" ".join(GCP_TEST_MACHINE_LIST)) + wait_machine_bootup() def fin(): - #GCPHandler.stop_machines(" ".join(GCP_TEST_MACHINE_LIST)) + GCPHandler.stop_machines(" ".join(GCP_TEST_MACHINE_LIST)) pass request.addfinalizer(fin) @@ -90,60 +92,60 @@ class TestMonkeyBlackbox(object): def test_server_online(self, island_client): assert island_client.get_api_status() is not None - #def test_ssh_exploiter(self, island_client): - # TestMonkeyBlackbox.run_exploitation_test(island_client, "SSH.conf", "SSH_exploiter_and_keys") -# - #def test_hadoop_exploiter(self, island_client): - # TestMonkeyBlackbox.run_exploitation_test(island_client, "HADOOP.conf", "Hadoop_exploiter", 6 * 60) -# - #def test_mssql_exploiter(self, island_client): - # TestMonkeyBlackbox.run_exploitation_test(island_client, "MSSQL.conf", "MSSQL_exploiter") -# - #def test_smb_and_mimikatz_exploiters(self, island_client): - # TestMonkeyBlackbox.run_exploitation_test(island_client, "SMB_MIMIKATZ.conf", "SMB_exploiter_mimikatz") -# - #def test_smb_pth(self, island_client): - # TestMonkeyBlackbox.run_exploitation_test(island_client, "SMB_PTH.conf", "SMB_PTH") -# - #def test_elastic_exploiter(self, island_client): - # TestMonkeyBlackbox.run_exploitation_test(island_client, "ELASTIC.conf", "Elastic_exploiter") -# - #def test_struts_exploiter(self, island_client): - # TestMonkeyBlackbox.run_exploitation_test(island_client, "STRUTS2.conf", "Strtuts2_exploiter") -# - #def test_weblogic_exploiter(self, island_client): - # TestMonkeyBlackbox.run_exploitation_test(island_client, "WEBLOGIC.conf", "Weblogic_exploiter") -# - #def test_shellshock_exploiter(self, island_client): - # TestMonkeyBlackbox.run_exploitation_test(island_client, "SHELLSHOCK.conf", "Shellschock_exploiter") -# - #def test_tunneling(self, island_client): - # TestMonkeyBlackbox.run_exploitation_test(island_client, "TUNNELING.conf", "Tunneling_exploiter", 15 * 60) -# - #def test_wmi_and_mimikatz_exploiters(self, island_client): - # TestMonkeyBlackbox.run_exploitation_test(island_client, "WMI_MIMIKATZ.conf", "WMI_exploiter,_mimikatz") -# - #def test_wmi_pth(self, island_client): - # TestMonkeyBlackbox.run_exploitation_test(island_client, "WMI_PTH.conf", "WMI_PTH") -# - #def test_report_generation_performance(self, island_client): - # """ - # This test includes the SSH + Elastic + Hadoop + MSSQL machines all in one test - # for a total of 8 machines including the Monkey Island. -# - # Is has 2 analyzers - the regular one which checks all the Monkeys - # and the Timing one which checks how long the report took to execute - # """ - # TestMonkeyBlackbox.run_performance_test(ReportGenerationTest, - # island_client, - # "PERFORMANCE.conf", - # timeout_in_seconds=10*60) -# - #def test_map_generation_performance(self, island_client): - # TestMonkeyBlackbox.run_performance_test(MapGenerationTest, - # island_client, - # "PERFORMANCE.conf", - # timeout_in_seconds=10*60) + def test_ssh_exploiter(self, island_client): + TestMonkeyBlackbox.run_exploitation_test(island_client, "SSH.conf", "SSH_exploiter_and_keys") + + def test_hadoop_exploiter(self, island_client): + TestMonkeyBlackbox.run_exploitation_test(island_client, "HADOOP.conf", "Hadoop_exploiter", 6 * 60) + + def test_mssql_exploiter(self, island_client): + TestMonkeyBlackbox.run_exploitation_test(island_client, "MSSQL.conf", "MSSQL_exploiter") + + def test_smb_and_mimikatz_exploiters(self, island_client): + TestMonkeyBlackbox.run_exploitation_test(island_client, "SMB_MIMIKATZ.conf", "SMB_exploiter_mimikatz") + + def test_smb_pth(self, island_client): + TestMonkeyBlackbox.run_exploitation_test(island_client, "SMB_PTH.conf", "SMB_PTH") + + def test_elastic_exploiter(self, island_client): + TestMonkeyBlackbox.run_exploitation_test(island_client, "ELASTIC.conf", "Elastic_exploiter") + + def test_struts_exploiter(self, island_client): + TestMonkeyBlackbox.run_exploitation_test(island_client, "STRUTS2.conf", "Strtuts2_exploiter") + + def test_weblogic_exploiter(self, island_client): + TestMonkeyBlackbox.run_exploitation_test(island_client, "WEBLOGIC.conf", "Weblogic_exploiter") + + def test_shellshock_exploiter(self, island_client): + TestMonkeyBlackbox.run_exploitation_test(island_client, "SHELLSHOCK.conf", "Shellschock_exploiter") + + def test_tunneling(self, island_client): + TestMonkeyBlackbox.run_exploitation_test(island_client, "TUNNELING.conf", "Tunneling_exploiter", 15 * 60) + + def test_wmi_and_mimikatz_exploiters(self, island_client): + TestMonkeyBlackbox.run_exploitation_test(island_client, "WMI_MIMIKATZ.conf", "WMI_exploiter,_mimikatz") + + def test_wmi_pth(self, island_client): + TestMonkeyBlackbox.run_exploitation_test(island_client, "WMI_PTH.conf", "WMI_PTH") + + def test_report_generation_performance(self, island_client): + """ + This test includes the SSH + Elastic + Hadoop + MSSQL machines all in one test + for a total of 8 machines including the Monkey Island. + + Is has 2 analyzers - the regular one which checks all the Monkeys + and the Timing one which checks how long the report took to execute + """ + TestMonkeyBlackbox.run_performance_test(ReportGenerationTest, + island_client, + "PERFORMANCE.conf", + timeout_in_seconds=10*60) + + def test_map_generation_performance(self, island_client): + TestMonkeyBlackbox.run_performance_test(MapGenerationTest, + island_client, + "PERFORMANCE.conf", + timeout_in_seconds=10*60) def test_telem_performance(self, island_client): TelemetryPerformanceTest(island_client).test_telemetry_performance() From 1a784791fdcc1a79f0cb816f67b7dff73c1919e8 Mon Sep 17 00:00:00 2001 From: VakarisZ Date: Wed, 29 Apr 2020 11:17:08 +0300 Subject: [PATCH 3/3] Fixed a typo in supported_request_method.py filename --- .../monkey_zoo/blackbox/island_client/monkey_island_requests.py | 2 +- ...{supported_reuqest_method.py => supported_request_method.py} | 0 .../blackbox/tests/performance/endpoint_performance_test.py | 2 +- .../blackbox/tests/performance/telemetry_performance_test.py | 2 +- 4 files changed, 3 insertions(+), 3 deletions(-) rename envs/monkey_zoo/blackbox/island_client/{supported_reuqest_method.py => supported_request_method.py} (100%) diff --git a/envs/monkey_zoo/blackbox/island_client/monkey_island_requests.py b/envs/monkey_zoo/blackbox/island_client/monkey_island_requests.py index edcffe674..babc9c7a0 100644 --- a/envs/monkey_zoo/blackbox/island_client/monkey_island_requests.py +++ b/envs/monkey_zoo/blackbox/island_client/monkey_island_requests.py @@ -5,7 +5,7 @@ from datetime import timedelta import requests import functools -from envs.monkey_zoo.blackbox.island_client.supported_reuqest_method import SupportedRequestMethod +from envs.monkey_zoo.blackbox.island_client.supported_request_method import SupportedRequestMethod import logging diff --git a/envs/monkey_zoo/blackbox/island_client/supported_reuqest_method.py b/envs/monkey_zoo/blackbox/island_client/supported_request_method.py similarity index 100% rename from envs/monkey_zoo/blackbox/island_client/supported_reuqest_method.py rename to envs/monkey_zoo/blackbox/island_client/supported_request_method.py diff --git a/envs/monkey_zoo/blackbox/tests/performance/endpoint_performance_test.py b/envs/monkey_zoo/blackbox/tests/performance/endpoint_performance_test.py index 5b8a43227..798f490af 100644 --- a/envs/monkey_zoo/blackbox/tests/performance/endpoint_performance_test.py +++ b/envs/monkey_zoo/blackbox/tests/performance/endpoint_performance_test.py @@ -2,7 +2,7 @@ import logging from envs.monkey_zoo.blackbox.analyzers.performance_analyzer import PerformanceAnalyzer from envs.monkey_zoo.blackbox.island_client.monkey_island_client import MonkeyIslandClient -from envs.monkey_zoo.blackbox.island_client.supported_reuqest_method import SupportedRequestMethod +from envs.monkey_zoo.blackbox.island_client.supported_request_method import SupportedRequestMethod from envs.monkey_zoo.blackbox.tests.basic_test import BasicTest from envs.monkey_zoo.blackbox.tests.performance.performance_test_config import PerformanceTestConfig diff --git a/envs/monkey_zoo/blackbox/tests/performance/telemetry_performance_test.py b/envs/monkey_zoo/blackbox/tests/performance/telemetry_performance_test.py index 719ec5806..4086a234e 100644 --- a/envs/monkey_zoo/blackbox/tests/performance/telemetry_performance_test.py +++ b/envs/monkey_zoo/blackbox/tests/performance/telemetry_performance_test.py @@ -6,7 +6,7 @@ from tqdm import tqdm from envs.monkey_zoo.blackbox.analyzers.performance_analyzer import PerformanceAnalyzer from envs.monkey_zoo.blackbox.island_client.monkey_island_client import MonkeyIslandClient -from envs.monkey_zoo.blackbox.island_client.supported_reuqest_method import SupportedRequestMethod +from envs.monkey_zoo.blackbox.island_client.supported_request_method import SupportedRequestMethod from envs.monkey_zoo.blackbox.tests.performance.performance_test_config import PerformanceTestConfig from envs.monkey_zoo.blackbox.tests.performance.utils.telem_parser import TelemParser