Merge branch '420/blackbox' of https://github.com/guardicore/monkey into 420/blackbox

This commit is contained in:
Shay Nehmad 2019-08-29 18:48:39 +03:00
commit a0d932908f
4 changed files with 26 additions and 1 deletions

View File

@ -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'})

View File

@ -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

View File

@ -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):