|
4 | 4 | from http import HTTPStatus
|
5 | 5 | from threading import Thread
|
6 | 6 | from time import sleep
|
7 |
| -from typing import List, Optional |
| 7 | +from typing import List, Optional, Sequence |
8 | 8 | from uuid import uuid4
|
9 | 9 |
|
10 | 10 | import pytest
|
|
48 | 48 | start_machines,
|
49 | 49 | stop_machines,
|
50 | 50 | )
|
| 51 | +from monkey_island.cc.models import Agent |
51 | 52 | from monkey_island.cc.services.authentication_service.flask_resources.agent_otp import (
|
52 | 53 | MAX_OTP_REQUESTS_PER_SECOND,
|
53 | 54 | )
|
@@ -483,6 +484,12 @@ def test_agent_logout(island):
|
483 | 484 | # to boot up and finish starting services.
|
484 | 485 | # noinspection PyUnresolvedReferences
|
485 | 486 | class TestMonkeyBlackbox:
|
| 487 | + @staticmethod |
| 488 | + def assert_unique_agent_hashes(agents: Sequence[Agent]): |
| 489 | + agent_hashes = [a.sha256 for a in agents] |
| 490 | + |
| 491 | + assert len(agent_hashes) == len(set(agent_hashes)) |
| 492 | + |
486 | 493 | @staticmethod
|
487 | 494 | def run_exploitation_test(
|
488 | 495 | island_client: MonkeyIslandClient,
|
@@ -518,9 +525,25 @@ def test_credentials_reuse_ssh_key(self, island_client):
|
518 | 525 | )
|
519 | 526 |
|
520 | 527 | def test_depth_2_a(self, island_client):
|
521 |
| - TestMonkeyBlackbox.run_exploitation_test( |
522 |
| - island_client, depth_2_a_test_configuration, "Depth2A test suite" |
| 528 | + test_name = "Depth2A test suite" |
| 529 | + communication_analyzer = CommunicationAnalyzer( |
| 530 | + island_client, |
| 531 | + get_target_ips(depth_2_a_test_configuration), |
| 532 | + ) |
| 533 | + log_handler = TestLogsHandler( |
| 534 | + test_name, island_client, TestMonkeyBlackbox.get_log_dir_path() |
| 535 | + ) |
| 536 | + exploitation_test = ExploitationTest( |
| 537 | + name=test_name, |
| 538 | + island_client=island_client, |
| 539 | + test_configuration=depth_2_a_test_configuration, |
| 540 | + masque=None, |
| 541 | + analyzers=[communication_analyzer], |
| 542 | + timeout=DEFAULT_TIMEOUT_SECONDS + 30, |
| 543 | + log_handler=log_handler, |
523 | 544 | )
|
| 545 | + exploitation_test.run() |
| 546 | + assert len({a.sha256 for a in exploitation_test.agents}) == 2 |
524 | 547 |
|
525 | 548 | def test_depth_1_a(self, island_client):
|
526 | 549 | test_name = "Depth1A test suite"
|
@@ -559,20 +582,38 @@ def test_depth_1_a(self, island_client):
|
559 | 582 | log_handler = TestLogsHandler(
|
560 | 583 | test_name, island_client, TestMonkeyBlackbox.get_log_dir_path()
|
561 | 584 | )
|
562 |
| - ExploitationTest( |
| 585 | + exploitation_test = ExploitationTest( |
563 | 586 | name=test_name,
|
564 | 587 | island_client=island_client,
|
565 | 588 | test_configuration=depth_1_a_test_configuration,
|
566 | 589 | masque=masque,
|
567 | 590 | analyzers=[stolen_credentials_analyzer, communication_analyzer],
|
568 | 591 | timeout=DEFAULT_TIMEOUT_SECONDS + 30,
|
569 | 592 | log_handler=log_handler,
|
570 |
| - ).run() |
| 593 | + ) |
| 594 | + exploitation_test.run() |
| 595 | + TestMonkeyBlackbox.assert_unique_agent_hashes(exploitation_test.agents) |
571 | 596 |
|
572 | 597 | def test_depth_3_a(self, island_client):
|
573 |
| - TestMonkeyBlackbox.run_exploitation_test( |
574 |
| - island_client, depth_3_a_test_configuration, "Depth3A test suite" |
| 598 | + test_name = "Depth3A test suite" |
| 599 | + communication_analyzer = CommunicationAnalyzer( |
| 600 | + island_client, |
| 601 | + get_target_ips(depth_3_a_test_configuration), |
| 602 | + ) |
| 603 | + log_handler = TestLogsHandler( |
| 604 | + test_name, island_client, TestMonkeyBlackbox.get_log_dir_path() |
| 605 | + ) |
| 606 | + exploitation_test = ExploitationTest( |
| 607 | + name=test_name, |
| 608 | + island_client=island_client, |
| 609 | + test_configuration=depth_3_a_test_configuration, |
| 610 | + masque=None, |
| 611 | + analyzers=[communication_analyzer], |
| 612 | + timeout=DEFAULT_TIMEOUT_SECONDS, |
| 613 | + log_handler=log_handler, |
575 | 614 | )
|
| 615 | + exploitation_test.run() |
| 616 | + TestMonkeyBlackbox.assert_unique_agent_hashes(exploitation_test.agents) |
576 | 617 |
|
577 | 618 | def test_depth_4_a(self, island_client):
|
578 | 619 | TestMonkeyBlackbox.run_exploitation_test(
|
|
0 commit comments