diff --git a/envs/monkey_zoo/blackbox/analyzers/__init__.py b/envs/monkey_zoo/blackbox/analyzers/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/envs/monkey_zoo/blackbox/analyzers/communication_analyzer.py b/envs/monkey_zoo/blackbox/analyzers/communication_analyzer.py new file mode 100644 index 000000000..3afb528f7 --- /dev/null +++ b/envs/monkey_zoo/blackbox/analyzers/communication_analyzer.py @@ -0,0 +1,16 @@ + +class CommunicationAnalyzer(object): + + def __init__(self, island_client, machines): + self.island_client = island_client + self.machines = machines + + def analyze_test_results(self): + for machine in self.machines: + if self.did_monkey_communicate_back(machine): + print("Monkey from {} communicated back".format(machine)) + + def did_monkey_communicate_back(self, monkey_ip): + request = self.island_client.send_get_request("api/telemetry", {'telem_category': 'state'}) + + diff --git a/envs/monkey_zoo/blackbox/monkey_island_client.py b/envs/monkey_zoo/blackbox/monkey_island_client.py index c2cde2506..662ad71b8 100644 --- a/envs/monkey_zoo/blackbox/monkey_island_client.py +++ b/envs/monkey_zoo/blackbox/monkey_island_client.py @@ -49,3 +49,10 @@ class MonkeyIslandClient(object): def run_monkey_local(self): resp = self.request_json("api/local-monkey", dict_data={"action": "run"}) print(resp.text) + + def send_get_request(self, endpoint, data): + resp = requests.get(self.addr + endpoint, + headers={"Authorization": "JWT " + self.token}, + params=data, + verify=False) + return resp diff --git a/envs/monkey_zoo/blackbox/test_blackbox.py b/envs/monkey_zoo/blackbox/test_blackbox.py index 15f0f276c..708cbca24 100644 --- a/envs/monkey_zoo/blackbox/test_blackbox.py +++ b/envs/monkey_zoo/blackbox/test_blackbox.py @@ -4,6 +4,7 @@ import unittest import pytest from envs.monkey_zoo.blackbox.monkey_island_client import MonkeyIslandClient +from envs.monkey_zoo.blackbox.analyzers.communication_analyzer import CommunicationAnalyzer def generic_blackbox_test_case(client, config_file_path, analyzers): @@ -34,7 +35,8 @@ class TestMonkeyBlackbox(unittest.TestCase): def test_ssh_exec(self): client = MonkeyIslandClient(self.island) conf_file_name = "SSH.conf" - generic_blackbox_test_case(client, get_conf_file_path(conf_file_name), []) + generic_blackbox_test_case(client, get_conf_file_path(conf_file_name), + [CommunicationAnalyzer(client, ["10.2.2.41", "10.2.2.42"])]) def get_conf_file_path(conf_file_name):