Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2269 remove find monkeys in db #2391

Merged
merged 6 commits into from
Oct 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ Changelog](https://keepachangelog.com/en/1.0.0/).
- "/api/island-configuration" endpoint. #2003
- "-t/--tunnel" from agent command line arguments. #2216
- "/api/monkey-control/neets-to-stop". #2261
- "GET /api/test/monkey" endpoint. #2269
- "GET /api/test/log" endpoint. #2269

### Fixed
- A bug in network map page that caused delay of telemetry log loading. #1545
Expand Down
19 changes: 2 additions & 17 deletions envs/monkey_zoo/blackbox/island_client/monkey_island_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
GET_AGENTS_ENDPOINT = "api/agents"
GET_LOG_ENDPOINT = "api/agent-logs"
GET_MACHINES_ENDPOINT = "api/machines"
MONKEY_TEST_ENDPOINT = "api/test/monkey"
TELEMETRY_TEST_ENDPOINT = "api/test/telemetry"
LOGGER = logging.getLogger(__name__)

Expand Down Expand Up @@ -139,14 +138,6 @@ def _reset_island_mode(self):
LOGGER.error("Failed to reset island mode")
assert False

def find_monkeys_in_db(self, query):
if query is None:
raise TypeError
response = self.requests.get(
MONKEY_TEST_ENDPOINT, MonkeyIslandClient.form_find_query_for_request(query)
)
return MonkeyIslandClient.get_test_query_results(response)

def find_telems_in_db(self, query: dict):
if query is None:
raise TypeError
Expand All @@ -155,12 +146,6 @@ def find_telems_in_db(self, query: dict):
)
return MonkeyIslandClient.get_test_query_results(response)

def get_all_monkeys_from_db(self):
response = self.requests.get(
MONKEY_TEST_ENDPOINT, MonkeyIslandClient.form_find_query_for_request(None)
)
return MonkeyIslandClient.get_test_query_results(response)

def get_agents(self) -> Sequence[Agent]:
response = self.requests.get(GET_AGENTS_ENDPOINT)

Expand All @@ -186,5 +171,5 @@ def get_test_query_results(response):
return json.loads(response.content)["results"]

def is_all_monkeys_dead(self):
query = {"dead": False}
return len(self.find_monkeys_in_db(query)) == 0
agents = self.get_agents()
return all((a.stop_time is not None for a in agents))
20 changes: 11 additions & 9 deletions envs/os_compatibility/test_compatibility.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
from ipaddress import IPv4Address
from typing import Collection

import pytest

from envs.monkey_zoo.blackbox.island_client.monkey_island_client import MonkeyIslandClient
Expand Down Expand Up @@ -40,18 +43,17 @@ def island_client(island):
@pytest.mark.usefixtures("island_client")
# noinspection PyUnresolvedReferences
class TestOSCompatibility(object):
def test_os_compat(self, island_client):
def test_os_compat(self, island_client: MonkeyIslandClient):
print()
all_monkeys = island_client.get_all_monkeys_from_db()
ips_that_communicated = []
for monkey in all_monkeys:
for ip in monkey["ip_addresses"]:
if ip in machine_list:
ips_that_communicated.append(ip)
break
ips_that_communicated = self._get_agent_ips(island_client)
for ip, os in machine_list.items():
if ip not in ips_that_communicated:
if IPv4Address(ip) not in ips_that_communicated:
print("{} didn't communicate to island".format(os))

if len(ips_that_communicated) < len(machine_list):
assert False

def _get_agent_ips(self, island_client: MonkeyIslandClient) -> Collection[IPv4Address]:
agents = island_client.get_agents()
machines = island_client.get_machines()
return {i.ip for a in agents for i in machines[a.machine_id].network_interfaces}
4 changes: 0 additions & 4 deletions monkey/monkey_island/cc/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@
from monkey_island.cc.resources.AbstractResource import AbstractResource
from monkey_island.cc.resources.attack.attack_report import AttackReport
from monkey_island.cc.resources.auth import Authenticate, Register, RegistrationStatus, init_jwt
from monkey_island.cc.resources.blackbox.log_blackbox_endpoint import LogBlackboxEndpoint
from monkey_island.cc.resources.blackbox.monkey_blackbox_endpoint import MonkeyBlackboxEndpoint
from monkey_island.cc.resources.blackbox.telemetry_blackbox_endpoint import (
TelemetryBlackboxEndpoint,
)
Expand Down Expand Up @@ -207,8 +205,6 @@ def init_restful_endpoints(api: FlaskDIWrapper):
# API Spec: Fix all the following endpoints, see comments in the resource classes
# Note: Preferably, the API will provide a rich feature set and allow access to all of the
# necessary data. This would make these endpoints obsolete.
api.add_resource(MonkeyBlackboxEndpoint)
api.add_resource(LogBlackboxEndpoint)
api.add_resource(TelemetryBlackboxEndpoint)


Expand Down

This file was deleted.

This file was deleted.