-
-
Notifications
You must be signed in to change notification settings - Fork 153
/
better-upload.cna
104 lines (90 loc) · 3.24 KB
/
better-upload.cna
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#
# Handy alternative for built-in 'upload' command: lets you upload file to the specified
# remote location. By default, the built-in upload command puts uploaded file to the CWD.
# This script lets us override that behavior.
#
# In addition - the upload command will print uploaded file's MD5 hash value, for traceability.
#
# -------------------------------------------
# beacon> upload implant.exe \\DC1\c$\windows\temp\implant.exe
# [*] Tasked Beacon to upload file (size: 929.25KB) from: (implant.exe) to: (\\DC1\c$\windows\temp\implant.exe)
# [+] host called home, sent: 951655 bytes
#
# -------------------------------------------
#
# Author:
# Mariusz Banach / mgeeky, '20
# <mb [at] binary-offensive.com>
# (https://github.com/mgeeky)
#
#
beacon_command_register(
"upload",
"Upload a file to specified remote location.",
"Use: upload </local/path/to/file> [/remote/path/to/file]\n\nUpload a file from local path (first argument) to remote path (second argument, optional).");
sub interpretSize {
local('$s $size');
$s = $1;
if($s == 0) {
$size = "";
}
else if($s < 1024) {
$size .= $s . "B";
}
else if($s < 1024 * 1024) {
$size = round($s / 1024.0, 1);
$size .= "KB";
}
else if($s < 1024 * 1024 * 1024) {
$size = round(($s / 1024.0) / 1024, 1);
$size .= "MB";
}
else if($s < 1024 * 1024 * 1024 * 1024) {
$size = round((($s / 1024.0) / 1024) / 1024, 1);
$size .= "GB";
}
return $size;
}
alias upload {
local('$bid $f $localpath $remotepath $content');
($bid, $localpath, $remotepath) = @_;
if($localpath is $null || strlen($localpath) == 0) {
prompt_file_open("Choose a file", $null, false, lambda({
fireAlias($bid, "upload", $1);
}, $bid => $bid));
return;
}
if($localpath is $null || strlen($localpath) == 0) {
berror($1, "Source file path (local path) must be specified.");
return;
}
if(!-exists $localpath) {
berror($1, "Specified input file does not exist: ( $+ $localpath $+ )");
return;
}
try {
$f = openf($localpath);
$content = readb($f, -1);
if($content is $null) {
throw "Read empty file";
}
closef($f);
}
catch $message {
berror($1, "Could not read contents of file to upload. Error: $message");
return;
}
$algo = "MD5";
$md = [java.security.MessageDigest getInstance: $algo];
$digest = [$md digest: $content];
$hash = transform($digest, "hex");
$hash = lc($hash);
if($remotepath is $null || strlen($remotepath) == 0) {
$remotepath = getFileName($localpath);
btask($1, "Tasked Beacon to upload file (size: " . interpretSize(strlen($content)) . ", md5: " . $hash . ") from: ( $+ $localpath $+ ) to: ( $+ $remotepath $+ )");
bupload!($bid, $localpath);
return;
}
btask($1, "Tasked Beacon to upload file (size: " . interpretSize(strlen($content)) . ", md5: " . $hash . ") from: ( $+ $localpath $+ ) to: ( $+ $remotepath $+ )");
bupload_raw!($1, $remotepath, $content, $localpath);
}