diff --git a/server/api/server.py b/server/api/server.py index e846d89..8c12ba3 100644 --- a/server/api/server.py +++ b/server/api/server.py @@ -38,28 +38,33 @@ def get_downloads(): try: downloadsPath = os.path.abspath(f"server/downloads/server-{np_server.guid}") res = [] - with os.scandir(downloadsPath) as downloads: - for download in downloads: - if download.is_dir(): - continue - - res.append( - { - "name": download.name, - "size": download.stat().st_size, - "lastmodified": download.stat().st_mtime, - } - ) + items = os.scandir(downloadsPath) + for item in items: + if item.is_dir() and item.name.startswith("nimplant-"): + downloads = os.scandir(item.path) + for download in downloads: + if download.is_file(): + res.append( + { + "name": download.name, + "nimplant": item.name.split("-")[1], + "size": download.stat().st_size, + "lastmodified": download.stat().st_mtime, + } + ) + res = sorted(res, key=lambda x: x["lastmodified"], reverse=True) return flask.jsonify(res), 200 except FileNotFoundError: return flask.jsonify([]), 404 # Download a file from the downloads folder - @app.route("/api/downloads/", methods=["GET"]) - def get_download(filename): + @app.route("/api/downloads//", methods=["GET"]) + def get_download(nimplant_guid, filename): try: - downloadsPath = os.path.abspath(f"server/downloads/server-{np_server.guid}") + downloadsPath = os.path.abspath( + f"server/downloads/server-{np_server.guid}/nimplant-{nimplant_guid}" + ) return flask.send_from_directory( downloadsPath, filename, as_attachment=True ) diff --git a/server/util/func.py b/server/util/func.py index 10e05ff..5893a02 100644 --- a/server/util/func.py +++ b/server/util/func.py @@ -479,7 +479,9 @@ def downloadFile(np, args, raw_command): if len(args) == 2: filePath = args[1] fileName = filePath.replace("/", "\\").split("\\")[-1] - localPath = f"server/downloads/server-{np_server.guid}/{fileName}" + localPath = ( + f"server/downloads/server-{np_server.guid}/nimplant-{np.guid}/{fileName}" + ) elif len(args) == 3: filePath = args[1] localPath = args[2] diff --git a/ui/components/DownloadList.tsx b/ui/components/DownloadList.tsx index abcb6d3..8323c64 100644 --- a/ui/components/DownloadList.tsx +++ b/ui/components/DownloadList.tsx @@ -1,10 +1,11 @@ import { FaRegMeh } from 'react-icons/fa' -import { formatBytes, formatTimestamp, getDownloads } from '../modules/nimplant' -import { Text, Group } from '@mantine/core' +import { formatBytes, formatTimestamp, getDownloads, getNimplants } from '../modules/nimplant' +import { Text, Group, Stack } from '@mantine/core' import Link from 'next/link' function DownloadList() { const { downloads, downloadsLoading, downloadsError } = getDownloads() + const {nimplants, nimplantsLoading, nimplantsError} = getNimplants() // Check data length and return placeholder if no downloads are present @@ -30,11 +31,23 @@ function DownloadList() { } })} > - + {file.name} + + + {file.nimplant} + + + { + nimplants && nimplants.find((nimplant: any) => nimplant.guid === file.nimplant)?.username + + '@' + + nimplants.find((nimplant: any) => nimplant.guid === file.nimplant)?.hostname + } + + {formatBytes(file.size)} diff --git a/ui/pages/downloads.tsx b/ui/pages/downloads.tsx index bfdffc9..b029e07 100644 --- a/ui/pages/downloads.tsx +++ b/ui/pages/downloads.tsx @@ -17,6 +17,9 @@ const ServerInfo: NextPage = () => { Filename + + Nimplant + Size