|
7 | 7 | import pytest
|
8 | 8 | import requests
|
9 | 9 |
|
| 10 | +from common.types import OTP |
10 | 11 | from envs.monkey_zoo.blackbox.analyzers.communication_analyzer import CommunicationAnalyzer
|
11 | 12 | from envs.monkey_zoo.blackbox.analyzers.zerologon_analyzer import ZerologonAnalyzer
|
| 13 | +from envs.monkey_zoo.blackbox.island_client.agent_requests import AgentRequests |
12 | 14 | from envs.monkey_zoo.blackbox.island_client.i_monkey_island_requests import IMonkeyIslandRequests
|
13 | 15 | from envs.monkey_zoo.blackbox.island_client.monkey_island_client import (
|
| 16 | + GET_AGENT_EVENTS_ENDPOINT, |
14 | 17 | GET_AGENTS_ENDPOINT,
|
15 | 18 | GET_MACHINES_ENDPOINT,
|
16 | 19 | ISLAND_LOG_ENDPOINT,
|
@@ -93,8 +96,8 @@ def monkey_island_requests(island) -> IMonkeyIslandRequests:
|
93 | 96 | def island_client(monkey_island_requests):
|
94 | 97 | client_established = False
|
95 | 98 | try:
|
96 |
| - requests = ReauthorizingMonkeyIslandRequests(monkey_island_requests) |
97 |
| - island_client_object = MonkeyIslandClient(requests) |
| 99 | + reauthorizing_island_requests = ReauthorizingMonkeyIslandRequests(monkey_island_requests) |
| 100 | + island_client_object = MonkeyIslandClient(reauthorizing_island_requests) |
98 | 101 | client_established = island_client_object.get_api_status()
|
99 | 102 | except Exception:
|
100 | 103 | logging.exception("Got an exception while trying to establish connection to the Island.")
|
@@ -186,6 +189,103 @@ def make_request():
|
186 | 189 | assert response_codes.count(HTTPStatus.TOO_MANY_REQUESTS) == 1
|
187 | 190 |
|
188 | 191 |
|
| 192 | +UUID = "00000000-0000-0000-0000-000000000000" |
| 193 | +AGENT_BINARIES_ENDPOINT = "/api/agent-binaries/os" |
| 194 | +AGENT_EVENTS_ENDPOINT = "/api/agent-events" |
| 195 | +AGENT_HEARTBEAT_ENDPOINT = f"/api/agent/{UUID}/heartbeat" |
| 196 | +PUT_LOG_ENDPOINT = f"/api/agent-logs/{UUID}" |
| 197 | +GET_AGENT_PLUGINS_ENDPOINT = "/api/agent-plugins/host/type/name" |
| 198 | +GET_AGENT_SIGNALS_ENDPOINT = f"/api/agent-signals/{UUID}" |
| 199 | + |
| 200 | + |
| 201 | +def test_island__cannot_access_nonisland_endpoints(island): |
| 202 | + island_requests = MonkeyIslandRequests(island) |
| 203 | + island_requests.login() |
| 204 | + |
| 205 | + assert island_requests.get(AGENT_BINARIES_ENDPOINT).status_code == HTTPStatus.FORBIDDEN |
| 206 | + assert ( |
| 207 | + island_requests.post(AGENT_EVENTS_ENDPOINT, data=None).status_code == HTTPStatus.FORBIDDEN |
| 208 | + ) |
| 209 | + assert ( |
| 210 | + island_requests.post(AGENT_HEARTBEAT_ENDPOINT, data=None).status_code |
| 211 | + == HTTPStatus.FORBIDDEN |
| 212 | + ) |
| 213 | + assert island_requests.put(PUT_LOG_ENDPOINT, data=None).status_code == HTTPStatus.FORBIDDEN |
| 214 | + assert island_requests.get(GET_AGENT_PLUGINS_ENDPOINT).status_code == HTTPStatus.FORBIDDEN |
| 215 | + assert ( |
| 216 | + island_requests.get("/api/agent-plugins/plugin-type/plugin-name/manifest").status_code |
| 217 | + == HTTPStatus.FORBIDDEN |
| 218 | + ) |
| 219 | + assert island_requests.get(GET_AGENT_SIGNALS_ENDPOINT).status_code == HTTPStatus.FORBIDDEN |
| 220 | + assert island_requests.post(GET_AGENTS_ENDPOINT, data=None).status_code == HTTPStatus.FORBIDDEN |
| 221 | + |
| 222 | + |
| 223 | +GET_AGENT_OTP_ENDPOINT = "/api/agent-otp" |
| 224 | +REQUESTS_AGENT_ID = "00000000-0000-0000-0000-000000000001" |
| 225 | +TERMINATE_AGENTS_ENDPOINT = "/api/agent-signals/terminate-all-agents" |
| 226 | +CLEAR_SIMULATION_DATA_ENDPOINT = "/api/clear-simulation-data" |
| 227 | +MONKEY_EXPLOITATION_ENDPOINT = "/api/exploitations/monkey" |
| 228 | +GET_ISLAND_LOG_ENDPOINT = "/api/island/log" |
| 229 | +ISLAND_MODE_ENDPOINT = "/api/island/mode" |
| 230 | +ISLAND_RUN_ENDPOINT = "/api/local-monkey" |
| 231 | +GET_NODES_ENDPOINT = "/api/nodes" |
| 232 | +PROPAGATION_CREDENTIALS_ENDPOINT = "/api/propagation-credentials" |
| 233 | +GET_RANSOMWARE_REPORT_ENDPOINT = "/api/report/ransomware" |
| 234 | +REMOTE_RUN_ENDPOINT = "/api/remote-monkey" |
| 235 | +GET_REPORT_STATUS_ENDPOINT = "/api/report-generation-status" |
| 236 | +RESET_AGENT_CONFIG_ENDPOINT = "/api/reset-agent-configuration" |
| 237 | +GET_SECURITY_REPORT_ENDPOINT = "/api/report/security" |
| 238 | +GET_ISLAND_VERSION_ENDPOINT = "/api/island/version" |
| 239 | +PUT_AGENT_CONFIG_ENDPOINT = "/api/agent-configuration" |
| 240 | + |
| 241 | + |
| 242 | +def test_agent__cannot_access_nonagent_endpoints(island): |
| 243 | + island_requests = MonkeyIslandRequests(island) |
| 244 | + island_requests.login() |
| 245 | + response = island_requests.get(GET_AGENT_OTP_ENDPOINT) |
| 246 | + print(f"response: {response.json()}") |
| 247 | + otp = response.json()["otp"] |
| 248 | + |
| 249 | + agent_requests = AgentRequests(island, REQUESTS_AGENT_ID, OTP(otp)) |
| 250 | + agent_requests.login() |
| 251 | + |
| 252 | + assert agent_requests.get(GET_AGENT_EVENTS_ENDPOINT).status_code == HTTPStatus.FORBIDDEN |
| 253 | + assert agent_requests.get(PUT_LOG_ENDPOINT).status_code == HTTPStatus.FORBIDDEN |
| 254 | + assert ( |
| 255 | + agent_requests.post(TERMINATE_AGENTS_ENDPOINT, data=None).status_code |
| 256 | + == HTTPStatus.FORBIDDEN |
| 257 | + ) |
| 258 | + assert agent_requests.get(GET_AGENTS_ENDPOINT).status_code == HTTPStatus.FORBIDDEN |
| 259 | + assert ( |
| 260 | + agent_requests.post(CLEAR_SIMULATION_DATA_ENDPOINT, data=None).status_code |
| 261 | + == HTTPStatus.FORBIDDEN |
| 262 | + ) |
| 263 | + assert agent_requests.get(MONKEY_EXPLOITATION_ENDPOINT).status_code == HTTPStatus.FORBIDDEN |
| 264 | + assert agent_requests.get(GET_ISLAND_LOG_ENDPOINT).status_code == HTTPStatus.FORBIDDEN |
| 265 | + assert agent_requests.get(ISLAND_MODE_ENDPOINT).status_code == HTTPStatus.FORBIDDEN |
| 266 | + assert agent_requests.put(ISLAND_MODE_ENDPOINT, data=None).status_code == HTTPStatus.FORBIDDEN |
| 267 | + assert agent_requests.post(ISLAND_RUN_ENDPOINT, data=None).status_code == HTTPStatus.FORBIDDEN |
| 268 | + assert agent_requests.get(GET_MACHINES_ENDPOINT).status_code == HTTPStatus.FORBIDDEN |
| 269 | + assert agent_requests.get(GET_NODES_ENDPOINT).status_code == HTTPStatus.FORBIDDEN |
| 270 | + assert ( |
| 271 | + agent_requests.put(PROPAGATION_CREDENTIALS_ENDPOINT, data=None).status_code |
| 272 | + == HTTPStatus.FORBIDDEN |
| 273 | + ) |
| 274 | + assert agent_requests.get(GET_RANSOMWARE_REPORT_ENDPOINT).status_code == HTTPStatus.FORBIDDEN |
| 275 | + assert agent_requests.get(REMOTE_RUN_ENDPOINT).status_code == HTTPStatus.FORBIDDEN |
| 276 | + assert agent_requests.post(REMOTE_RUN_ENDPOINT, data=None).status_code == HTTPStatus.FORBIDDEN |
| 277 | + assert agent_requests.get(GET_REPORT_STATUS_ENDPOINT).status_code == HTTPStatus.FORBIDDEN |
| 278 | + assert ( |
| 279 | + agent_requests.post(RESET_AGENT_CONFIG_ENDPOINT, data=None).status_code |
| 280 | + == HTTPStatus.FORBIDDEN |
| 281 | + ) |
| 282 | + assert agent_requests.get(GET_SECURITY_REPORT_ENDPOINT).status_code == HTTPStatus.FORBIDDEN |
| 283 | + assert agent_requests.get(GET_ISLAND_VERSION_ENDPOINT).status_code == HTTPStatus.FORBIDDEN |
| 284 | + assert ( |
| 285 | + agent_requests.put(PUT_AGENT_CONFIG_ENDPOINT, data=None).status_code == HTTPStatus.FORBIDDEN |
| 286 | + ) |
| 287 | + |
| 288 | + |
189 | 289 | # NOTE: These test methods are ordered to give time for the slower zoo machines
|
190 | 290 | # to boot up and finish starting services.
|
191 | 291 | # noinspection PyUnresolvedReferences
|
|
0 commit comments