Skip to content

Commit

Permalink
Add Nimplant info to download gui (Close #12)
Browse files Browse the repository at this point in the history
  • Loading branch information
chvancooten committed Mar 4, 2023
1 parent 8f407f4 commit 39f0944
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 19 deletions.
35 changes: 20 additions & 15 deletions server/api/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -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/<filename>", methods=["GET"])
def get_download(filename):
@app.route("/api/downloads/<nimplant_guid>/<filename>", 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
)
Expand Down
4 changes: 3 additions & 1 deletion server/util/func.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
19 changes: 16 additions & 3 deletions ui/components/DownloadList.tsx
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -30,11 +31,23 @@ function DownloadList() {
}
})}
>
<Link href={`/api/downloads/${file.name}`} passHref style={{ textDecoration: 'none' }}>
<Link href={`/api/downloads/${file.nimplant}/${file.name}`} passHref style={{ textDecoration: 'none' }}>
<Group grow>
<Text size="lg" color="dark">
{file.name}
</Text>
<Stack pl={5} spacing={5}>
<Text size="lg" color="dark">
{file.nimplant}
</Text>
<Text size="md" color="gray">
{
nimplants && nimplants.find((nimplant: any) => nimplant.guid === file.nimplant)?.username
+ '@' +
nimplants.find((nimplant: any) => nimplant.guid === file.nimplant)?.hostname
}
</Text>
</Stack>
<Text pl={10} size="lg" color="gray">
{formatBytes(file.size)}
</Text>
Expand Down
3 changes: 3 additions & 0 deletions ui/pages/downloads.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ const ServerInfo: NextPage = () => {
<Text size="lg">
Filename
</Text>
<Text size="lg">
Nimplant
</Text>
<Text size="lg">
Size
</Text>
Expand Down

0 comments on commit 39f0944

Please sign in to comment.