forked from nickvourd/CS-Aggressor-Kit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCWD-Beacon-Bar.cna
133 lines (112 loc) · 3.71 KB
/
CWD-Beacon-Bar.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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#Author: @nickvourd
#Inspired by https://github.com/mgeeky/cobalt-arsenal of @mariuszbit
#Original code: https://github.com/mgeeky/cobalt-arsenal/blob/master/cwd-in-beacon-status-bar.cna
global('%OPERATING_BEACONS');
%OPERATING_BEACONS = %();
beacon_command_register(
"cd",
"Change directory on host. Use '-' to get back to previous cwd.",
"Use: cd [directory]\n\nChange directory on host. Use '-' to get back to previous cwd."
);
set BEACON_SBAR_LEFT {
local('$targetHost $targetUser $processId $systemArch $pwd $hostColor $beaconArch');
$targetHost = $2["computer"];
$targetUser = $2["user"];
$processId = $2["pid"];
$systemArch = $2["arch"];
$beaconArch = barch($1);
$pwd = %OPERATING_BEACONS[$1]['cwd'];
# Set hostname color based on admin status
if (-isadmin $1) {
$hostColor = "\c4"; # Red for admin
} else {
$hostColor = "\c3"; # Green for non-admin
}
return "[" . $hostColor . $targetHost . "\o] - $systemArch | $targetUser | $processId - $beaconArch | \c2 $+ $pwd $+ \o";
}
set BEACON_SBAR_RIGHT {
local('$note $last');
$note = $2["note"];
$last = $2["lastf"];
return "\c6 $note \cE(last: $+ $[5]last $+ )\o";
}
on beacon_tasked {
local('$pwd $sep');
# Suppress "Tasked beacon to print working directory" messages
if ($2 ismatch 'pwd.*') {
return;
}
if('cd *' iswm $2) {
$pwd = substr($2, strlen("cd "));
$sep = iff(binfo($1, "os") eq "Windows", "\\", "/");
if($pwd eq "..") {
$pwd = substr(%OPERATING_BEACONS[$1]['cwd'], 0, lindexOf(%OPERATING_BEACONS[$1]['cwd'], $sep));
if($pwd eq "..") {
return;
}
}
else if($pwd eq ".") {
return;
}
else if((strlen($pwd) >= 2) && (charAt($pwd, 1) ne ":")) {
# relative path
$pwd = %OPERATING_BEACONS[$1]['cwd'] . $sep . $pwd;
}
%OPERATING_BEACONS[$1]['prev-cwd'] = %OPERATING_BEACONS[$1]['cwd'];
%OPERATING_BEACONS[$1]['cwd'] = $pwd;
}
}
set BEACON_OUTPUT_ALT {
local('$pwd');
# Handle directory not found errors
if ($2 ismatch '.*The system cannot find the path specified.*') {
return "\cC[!]\o Directory does not exist\n";
}
if($2 ismatch 'Current directory is (.+)') {
$pwd = matched()[0];
%OPERATING_BEACONS[$1]['prev-cwd'] = %OPERATING_BEACONS[$1]['cwd'];
%OPERATING_BEACONS[$1]['cwd'] = $pwd;
return;
}
# Suppress "Tasked beacon to print working directory" messages
if ($2 ismatch 'Tasked beacon to print working directory.*') {
return;
}
return "\cC[*]\o $2\n";
}
on beacon_input {
if (["$3" trim] eq "ls" || ["$3" trim] eq "pwd") {
%OPERATING_BEACONS[$1]['cwd-use-ls'] = 1;
}
}
on beacon_output_ls {
local('$pwd');
if(%OPERATING_BEACONS[$1]['cwd-use-ls'] == 1) {
$pwd = split("\n", ["$2" trim])[0];
if(right($pwd, 2) eq "\\*") {
$pwd = substr($pwd, 0, -2);
}
%OPERATING_BEACONS[$1]['prev-cwd'] = %OPERATING_BEACONS[$1]['cwd'];
%OPERATING_BEACONS[$1]['cwd'] = $pwd;
%OPERATING_BEACONS[$1]['cwd-use-ls'] = 0;
}
}
on beacons {
if(%OPERATING_BEACONS is $null) {
%OPERATING_BEACONS = %();
}
foreach $b ($1) {
if(iff($b in keys(%OPERATING_BEACONS), "true", $null)) {
%OPERATING_BEACONS[$b] = %();
# Initialize working directory
%OPERATING_BEACONS[$b]['cwd'] = bpwd($b);
}
}
}
alias cd {
if(($2 eq "-") && (strlen(%OPERATING_BEACONS[$1]['prev-cwd']) > 0)) {
bcd($1, %OPERATING_BEACONS[$1]['prev-cwd']);
return;
}
bcd($1, $2);
}