From 662fc6b50e74bc9cd306bd956c8be2001d76cc0a Mon Sep 17 00:00:00 2001
From: Shreya Malviya <shreya.malviya@gmail.com>
Date: Thu, 2 Jun 2022 17:32:40 +0530
Subject: [PATCH] Island: Change agent binary download endpoint

---
 monkey/monkey_island/cc/resources/agent_binaries.py           | 4 +---
 monkey/monkey_island/cc/services/aws/aws_command_runner.py    | 4 ++--
 .../pages/RunMonkeyPage/commands/local_linux_curl.js          | 2 +-
 .../pages/RunMonkeyPage/commands/local_linux_wget.js          | 2 +-
 .../pages/RunMonkeyPage/commands/local_windows_powershell.js  | 2 +-
 5 files changed, 6 insertions(+), 8 deletions(-)

diff --git a/monkey/monkey_island/cc/resources/agent_binaries.py b/monkey/monkey_island/cc/resources/agent_binaries.py
index 2f70bdb70..5b1609356 100644
--- a/monkey/monkey_island/cc/resources/agent_binaries.py
+++ b/monkey/monkey_island/cc/resources/agent_binaries.py
@@ -20,9 +20,7 @@ class UnsupportedOSError(Exception):
 
 
 class AgentBinaries(AbstractResource):
-    # API Spec: Rename to /api/agent-binaries, because information about agent runs
-    # and binary files are different resources
-    urls = ["/api/agent/download/<string:host_os>"]
+    urls = ["/api/agent-binaries/<string:host_os>"]
 
     # Used by monkey. can't secure.
     def get(self, host_os):
diff --git a/monkey/monkey_island/cc/services/aws/aws_command_runner.py b/monkey/monkey_island/cc/services/aws/aws_command_runner.py
index e896e2cfb..fffacb4dc 100644
--- a/monkey/monkey_island/cc/services/aws/aws_command_runner.py
+++ b/monkey/monkey_island/cc/services/aws/aws_command_runner.py
@@ -60,7 +60,7 @@ def _get_run_agent_command(target_os: str, island_ip: str):
 def _get_run_monkey_cmd_linux_line(island_ip):
     binary_name = "monkey-linux-64"
 
-    download_url = f"https://{island_ip}:5000/api/agent/download/linux"
+    download_url = f"https://{island_ip}:5000/api/agent-binaries/linux"
     download_cmd = f"wget --no-check-certificate {download_url} -O {binary_name}"
 
     chmod_cmd = f"chmod +x {binary_name}"
@@ -76,7 +76,7 @@ def _get_run_monkey_cmd_windows_line(island_ip):
         "[System.Net.ServicePointManager]::ServerCertificateValidationCallback = {$true}"
     )
 
-    download_url = f"https://{island_ip}:5000/api/agent/download/windows"
+    download_url = f"https://{island_ip}:5000/api/agent-binaries/windows"
     download_cmd = (
         f"(New-Object System.Net.WebClient).DownloadFile('{download_url}', '{agent_exe_path}')"
     )
diff --git a/monkey/monkey_island/cc/ui/src/components/pages/RunMonkeyPage/commands/local_linux_curl.js b/monkey/monkey_island/cc/ui/src/components/pages/RunMonkeyPage/commands/local_linux_curl.js
index 2f45ce457..b417d742f 100644
--- a/monkey/monkey_island/cc/ui/src/components/pages/RunMonkeyPage/commands/local_linux_curl.js
+++ b/monkey/monkey_island/cc/ui/src/components/pages/RunMonkeyPage/commands/local_linux_curl.js
@@ -1,5 +1,5 @@
 export default function generateLocalLinuxCurl(ip, username) {
-  let command = `curl https://${ip}:5000/api/agent/download/linux -k `
+  let command = `curl https://${ip}:5000/api/agent-binaries/linux -k `
     + `-o monkey-linux-64; `
     + `chmod +x monkey-linux-64; `
     + `./monkey-linux-64 m0nk3y -s ${ip}:5000;`;
diff --git a/monkey/monkey_island/cc/ui/src/components/pages/RunMonkeyPage/commands/local_linux_wget.js b/monkey/monkey_island/cc/ui/src/components/pages/RunMonkeyPage/commands/local_linux_wget.js
index d03b9a4f7..beb1aaa01 100644
--- a/monkey/monkey_island/cc/ui/src/components/pages/RunMonkeyPage/commands/local_linux_wget.js
+++ b/monkey/monkey_island/cc/ui/src/components/pages/RunMonkeyPage/commands/local_linux_wget.js
@@ -1,5 +1,5 @@
 export default function generateLocalLinuxWget(ip, username) {
-  let command = `wget --no-check-certificate https://${ip}:5000/api/agent/download/`
+  let command = `wget --no-check-certificate https://${ip}:5000/api/agent-binaries/`
     + `linux -O ./monkey-linux-64; `
     + `chmod +x monkey-linux-64; `
     + `./monkey-linux-64 m0nk3y -s ${ip}:5000`;
diff --git a/monkey/monkey_island/cc/ui/src/components/pages/RunMonkeyPage/commands/local_windows_powershell.js b/monkey/monkey_island/cc/ui/src/components/pages/RunMonkeyPage/commands/local_windows_powershell.js
index 8c194c252..39825f692 100644
--- a/monkey/monkey_island/cc/ui/src/components/pages/RunMonkeyPage/commands/local_windows_powershell.js
+++ b/monkey/monkey_island/cc/ui/src/components/pages/RunMonkeyPage/commands/local_windows_powershell.js
@@ -1,7 +1,7 @@
 function getAgentDownloadCommand(ip) {
   return `$execCmd = @"\r\n`
     + `[System.Net.ServicePointManager]::ServerCertificateValidationCallback = {\`$true};`
-    + `(New-Object System.Net.WebClient).DownloadFile('https://${ip}:5000/api/agent/download/windows',`
+    + `(New-Object System.Net.WebClient).DownloadFile('https://${ip}:5000/api/agent-binaries/windows',`
     + `"""$env:TEMP\\monkey.exe""");Start-Process -FilePath '$env:TEMP\\monkey.exe' -ArgumentList 'm0nk3y -s ${ip}:5000';`
     + `\r\n"@; \r\n`
     + `Start-Process -FilePath powershell.exe -ArgumentList $execCmd`;