From 64fc9f22690e9af69c6dbfb990f8c338e402c647 Mon Sep 17 00:00:00 2001 From: Ilija Lazoroski Date: Fri, 15 Apr 2022 12:24:04 +0200 Subject: [PATCH 1/6] Island: Rename fileUpload endpoint to file-upload --- monkey/monkey_island/cc/app.py | 6 ++--- .../ui/src/components/pages/ConfigurePage.js | 4 ++-- .../cc/resources/test_pba_file_upload.py | 22 +++++++++---------- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/monkey/monkey_island/cc/app.py b/monkey/monkey_island/cc/app.py index b4413e7a5..b4b884fc7 100644 --- a/monkey/monkey_island/cc/app.py +++ b/monkey/monkey_island/cc/app.py @@ -153,9 +153,9 @@ def init_api_resources(api): api.add_resource(PBAFileDownload, "/api/pba/download/") api.add_resource( FileUpload, - "/api/fileUpload/", - "/api/fileUpload/?load=", - "/api/fileUpload/?restore=", + "/api/file-upload/", + "/api/file-upload/?load=", + "/api/file-upload/?restore=", ) api.add_resource(PropagationCredentials, "/api/propagation-credentials/") api.add_resource(RemoteRun, "/api/remote-monkey") diff --git a/monkey/monkey_island/cc/ui/src/components/pages/ConfigurePage.js b/monkey/monkey_island/cc/ui/src/components/pages/ConfigurePage.js index 4650aec07..5f67c9010 100644 --- a/monkey/monkey_island/cc/ui/src/components/pages/ConfigurePage.js +++ b/monkey/monkey_island/cc/ui/src/components/pages/ConfigurePage.js @@ -20,8 +20,8 @@ import HtmlFieldDescription from '../configuration-components/HtmlFieldDescripti import CONFIGURATION_TABS_PER_MODE from '../configuration-components/ConfigurationTabs.js'; const CONFIG_URL = '/api/configuration/island'; -export const API_PBA_LINUX = '/api/fileUpload/PBAlinux'; -export const API_PBA_WINDOWS = '/api/fileUpload/PBAwindows'; +export const API_PBA_LINUX = '/api/file-upload/PBAlinux'; +export const API_PBA_WINDOWS = '/api/file-upload/PBAwindows'; class ConfigurePageComponent extends AuthComponent { diff --git a/monkey/tests/unit_tests/monkey_island/cc/resources/test_pba_file_upload.py b/monkey/tests/unit_tests/monkey_island/cc/resources/test_pba_file_upload.py index 3dfad70a7..a0b8352e2 100644 --- a/monkey/tests/unit_tests/monkey_island/cc/resources/test_pba_file_upload.py +++ b/monkey/tests/unit_tests/monkey_island/cc/resources/test_pba_file_upload.py @@ -38,7 +38,7 @@ def mock_get_config_value(monkeypatch): @pytest.mark.parametrize("pba_os", [LINUX_PBA_TYPE, WINDOWS_PBA_TYPE]) def test_pba_file_upload_post(flask_client, pba_os, monkeypatch, mock_set_config_value): resp = flask_client.post( - f"/api/fileUpload/{pba_os}", + f"/api/file-upload/{pba_os}", data=TEST_FILE, content_type="multipart/form-data; " "boundary=---------------------------" "1", follow_redirects=True, @@ -48,7 +48,7 @@ def test_pba_file_upload_post(flask_client, pba_os, monkeypatch, mock_set_config def test_pba_file_upload_post__invalid(flask_client, monkeypatch, mock_set_config_value): resp = flask_client.post( - "/api/fileUpload/bogus", + "/api/file-upload/bogus", data=TEST_FILE, content_type="multipart/form-data; " "boundary=---------------------------" "1", follow_redirects=True, @@ -66,7 +66,7 @@ def test_pba_file_upload_post__internal_server_error( ) resp = flask_client.post( - f"/api/fileUpload/{pba_os}", + f"/api/file-upload/{pba_os}", data=TEST_FILE, content_type="multipart/form-data; boundary=---------------------------1", follow_redirects=True, @@ -78,7 +78,7 @@ def test_pba_file_upload_post__internal_server_error( def test_pba_file_upload_get__file_not_found( flask_client, pba_os, monkeypatch, mock_get_config_value ): - resp = flask_client.get(f"/api/fileUpload/{pba_os}?load=bogus_mogus.py") + resp = flask_client.get(f"/api/file-upload/{pba_os}?load=bogus_mogus.py") assert resp.status_code == 404 @@ -87,22 +87,22 @@ def test_pba_file_upload_endpoint( flask_client, pba_os, monkeypatch, mock_get_config_value, mock_set_config_value ): resp_post = flask_client.post( - f"/api/fileUpload/{pba_os}", + f"/api/file-upload/{pba_os}", data=TEST_FILE, content_type="multipart/form-data; " "boundary=---------------------------" "1", follow_redirects=True, ) - resp_get = flask_client.get(f"/api/fileUpload/{pba_os}?load=test.py") + resp_get = flask_client.get(f"/api/file-upload/{pba_os}?load=test.py") assert resp_get.status_code == 200 assert resp_get.data.decode() == "m0nk3y" # Closing the response closes the file handle, else it can't be deleted resp_get.close() resp_delete = flask_client.delete( - f"/api/fileUpload/{pba_os}", data="test.py", content_type="text/plain;" + f"/api/file-upload/{pba_os}", data="test.py", content_type="text/plain;" ) - resp_get_del = flask_client.get(f"/api/fileUpload/{pba_os}?load=test.py") + resp_get_del = flask_client.get(f"/api/file-upload/{pba_os}?load=test.py") assert resp_post.status_code == 200 assert resp_delete.status_code == 200 @@ -114,14 +114,14 @@ def test_pba_file_upload_endpoint__invalid( flask_client, monkeypatch, mock_set_config_value, mock_get_config_value ): resp_post = flask_client.post( - "/api/fileUpload/bogus", + "/api/file-upload/bogus", data=TEST_FILE, content_type="multipart/form-data; " "boundary=---------------------------" "1", follow_redirects=True, ) - resp_get = flask_client.get("/api/fileUpload/bogus?load=test.py") + resp_get = flask_client.get("/api/file-upload/bogus?load=test.py") resp_delete = flask_client.delete( - "/api/fileUpload/bogus", data="test.py", content_type="text/plain;" + "/api/file-upload/bogus", data="test.py", content_type="text/plain;" ) assert resp_post.status_code == 422 assert resp_get.status_code == 422 From 15358322791818e7684b0560ec2c49026d00af1f Mon Sep 17 00:00:00 2001 From: Ilija Lazoroski Date: Fri, 15 Apr 2022 12:36:12 +0200 Subject: [PATCH 2/6] Island, BB: Rename clear_caches endpoint to clear-caches --- envs/monkey_zoo/blackbox/island_client/monkey_island_client.py | 2 +- monkey/monkey_island/cc/app.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/envs/monkey_zoo/blackbox/island_client/monkey_island_client.py b/envs/monkey_zoo/blackbox/island_client/monkey_island_client.py index d203d8f9c..7b5389f44 100644 --- a/envs/monkey_zoo/blackbox/island_client/monkey_island_client.py +++ b/envs/monkey_zoo/blackbox/island_client/monkey_island_client.py @@ -117,6 +117,6 @@ class MonkeyIslandClient(object): :raises: If error (by error code), raises the error :return: The response """ - response = self.requests.get("api/test/clear_caches") + response = self.requests.get("api/test/clear-caches") response.raise_for_status() return response diff --git a/monkey/monkey_island/cc/app.py b/monkey/monkey_island/cc/app.py index b4b884fc7..045d787b1 100644 --- a/monkey/monkey_island/cc/app.py +++ b/monkey/monkey_island/cc/app.py @@ -165,7 +165,7 @@ def init_api_resources(api): # Resources used by black box tests api.add_resource(MonkeyBlackboxEndpoint, "/api/test/monkey") - api.add_resource(ClearCaches, "/api/test/clear_caches") + api.add_resource(ClearCaches, "/api/test/clear-caches") api.add_resource(LogBlackboxEndpoint, "/api/test/log") api.add_resource(TelemetryBlackboxEndpoint, "/api/test/telemetry") From 09c944d52b58b0ea27acffb47d04115d0e428568 Mon Sep 17 00:00:00 2001 From: Ilija Lazoroski Date: Fri, 15 Apr 2022 12:45:47 +0200 Subject: [PATCH 3/6] Island: Rename netmap/nodeStates to netmap/node-states --- monkey/monkey_island/cc/app.py | 2 +- monkey/monkey_island/cc/ui/src/components/pages/MapPage.js | 2 +- .../cc/ui/src/components/report-components/SecurityReport.js | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/monkey/monkey_island/cc/app.py b/monkey/monkey_island/cc/app.py index 045d787b1..cd3538cce 100644 --- a/monkey/monkey_island/cc/app.py +++ b/monkey/monkey_island/cc/app.py @@ -137,7 +137,7 @@ def init_api_resources(api): api.add_resource(NetMap, "/api/netmap") api.add_resource(Edge, "/api/netmap/edge") api.add_resource(Node, "/api/netmap/node") - api.add_resource(NodeStates, "/api/netmap/nodeStates") + api.add_resource(NodeStates, "/api/netmap/node-states") api.add_resource(SecurityReport, "/api/report/security") api.add_resource(ZeroTrustReport, "/api/report/zero-trust/") diff --git a/monkey/monkey_island/cc/ui/src/components/pages/MapPage.js b/monkey/monkey_island/cc/ui/src/components/pages/MapPage.js index 2686cdc19..4d1899360 100644 --- a/monkey/monkey_island/cc/ui/src/components/pages/MapPage.js +++ b/monkey/monkey_island/cc/ui/src/components/pages/MapPage.js @@ -40,7 +40,7 @@ class MapPageComponent extends AuthComponent { } getNodeStateListFromServer = () => { - this.authFetch('/api/netmap/nodeStates') + this.authFetch('/api/netmap/node-states') .then(res => res.json()) .then(res => { this.setState({nodeStateList: res.node_states}); diff --git a/monkey/monkey_island/cc/ui/src/components/report-components/SecurityReport.js b/monkey/monkey_island/cc/ui/src/components/report-components/SecurityReport.js index a23cd6eb8..a57064f2f 100644 --- a/monkey/monkey_island/cc/ui/src/components/report-components/SecurityReport.js +++ b/monkey/monkey_island/cc/ui/src/components/report-components/SecurityReport.js @@ -171,7 +171,7 @@ class ReportPageComponent extends AuthComponent { } getNodeStateListFromServer = () => { - this.authFetch('/api/netmap/nodeStates') + this.authFetch('/api/netmap/node-states') .then(res => res.json()) .then(res => { this.setState({nodeStateList: res.node_states}); From d2cc056a55bb5766096f788036ac6a5052faf526 Mon Sep 17 00:00:00 2001 From: Ilija Lazoroski Date: Fri, 15 Apr 2022 13:16:56 +0200 Subject: [PATCH 4/6] Island, BB: Rename api/monkey_control to api/monkey-control --- .../monkey_zoo/blackbox/island_client/monkey_island_client.py | 2 +- monkey/monkey_island/cc/app.py | 4 ++-- monkey/monkey_island/cc/ui/src/components/pages/MapPage.js | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/envs/monkey_zoo/blackbox/island_client/monkey_island_client.py b/envs/monkey_zoo/blackbox/island_client/monkey_island_client.py index 7b5389f44..cba01a488 100644 --- a/envs/monkey_zoo/blackbox/island_client/monkey_island_client.py +++ b/envs/monkey_zoo/blackbox/island_client/monkey_island_client.py @@ -49,7 +49,7 @@ class MonkeyIslandClient(object): @avoid_race_condition def kill_all_monkeys(self): response = self.requests.post_json( - "api/monkey_control/stop-all-agents", data={"kill_time": time.time()} + "api/monkey-control/stop-all-agents", data={"kill_time": time.time()} ) if response.ok: LOGGER.info("Killing all monkeys after the test.") diff --git a/monkey/monkey_island/cc/app.py b/monkey/monkey_island/cc/app.py index cd3538cce..792888a19 100644 --- a/monkey/monkey_island/cc/app.py +++ b/monkey/monkey_island/cc/app.py @@ -160,8 +160,8 @@ def init_api_resources(api): api.add_resource(PropagationCredentials, "/api/propagation-credentials/") api.add_resource(RemoteRun, "/api/remote-monkey") api.add_resource(VersionUpdate, "/api/version-update") - api.add_resource(StopAgentCheck, "/api/monkey_control/needs-to-stop/") - api.add_resource(StopAllAgents, "/api/monkey_control/stop-all-agents") + api.add_resource(StopAgentCheck, "/api/monkey-control/needs-to-stop/") + api.add_resource(StopAllAgents, "/api/monkey-control/stop-all-agents") # Resources used by black box tests api.add_resource(MonkeyBlackboxEndpoint, "/api/test/monkey") diff --git a/monkey/monkey_island/cc/ui/src/components/pages/MapPage.js b/monkey/monkey_island/cc/ui/src/components/pages/MapPage.js index 4d1899360..13db80e25 100644 --- a/monkey/monkey_island/cc/ui/src/components/pages/MapPage.js +++ b/monkey/monkey_island/cc/ui/src/components/pages/MapPage.js @@ -84,7 +84,7 @@ class MapPageComponent extends AuthComponent { } killAllMonkeys = () => { - this.authFetch('/api/monkey_control/stop-all-agents', + this.authFetch('/api/monkey-control/stop-all-agents', { method: 'POST', headers: {'Content-Type': 'application/json'}, From 52ee31e326ee58a9d46735db95f4bb3a45e4621f Mon Sep 17 00:00:00 2001 From: Ilija Lazoroski Date: Fri, 15 Apr 2022 13:17:26 +0200 Subject: [PATCH 5/6] Agent: Rename api/monkey_control to api/monkey-control --- monkey/infection_monkey/master/control_channel.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/monkey/infection_monkey/master/control_channel.py b/monkey/infection_monkey/master/control_channel.py index 7795a35f7..a74724991 100644 --- a/monkey/infection_monkey/master/control_channel.py +++ b/monkey/infection_monkey/master/control_channel.py @@ -25,7 +25,7 @@ class ControlChannel(IControlChannel): return True try: url = ( - f"https://{self._control_channel_server}/api/monkey_control" + f"https://{self._control_channel_server}/api/monkey-control" f"/needs-to-stop/{self._agent_id}" ) response = requests.get( # noqa: DUO123 From f3d55c423f75e7c23a506746493441b0872061fb Mon Sep 17 00:00:00 2001 From: Mike Salvatore Date: Fri, 15 Apr 2022 09:54:42 -0400 Subject: [PATCH 6/6] CHANGELOG: Add changelog entries for endpoint renaming --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index bec863015..15f7998f3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -26,6 +26,10 @@ Changelog](https://keepachangelog.com/en/1.0.0/). - Log messages to contain human-readable thread names. #1766 - The log file name to `infection-monkey-agent--.log`. #1761 - "Logs" page renamed to "Telemetries". #1640 +- The "/api/fileUpload" endpoint to "/api/file-upload". #1888 +- The "/api/test/clear_caches" endpoint to "/api/test/clear-caches". #1888 +- The "/api/netmap/nodeStates" endpoint to "/api/netmap/node-states". #1888 +- All "/api/monkey_control" endpoints to "/api/monkey-control". #1888 ### Removed - VSFTPD exploiter. #1533