-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathBeacon-Name-Tab-Colors.cna
172 lines (144 loc) · 5.27 KB
/
Beacon-Name-Tab-Colors.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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
#Author: @nickvourd
#Inspired by https://github.com/mgeeky/cobalt-arsenal of @mariuszbit
# Format string for beacon tab names - supports placeholders like <user>, <computer>, etc.
$beacon_tab_name_format = "<user>@<computer> (<pid>)";
# Execute once on startup using heartbeat_1s
# This ensures immediate execution when the script is loaded
on heartbeat_1s {
# Check if format string is null or empty
if($beacon_tab_name_format is $null || strlen($beacon_tab_name_format) == 0) {
return;
}
renameBeaconTabs();
makeBoldTabs();
colorBeaconTabs();
# Remove the heartbeat_1s handler after first execution to prevent unnecessary calls
clear("heartbeat_1s");
}
# Execute periodically every 10 seconds to update tab names
# This handles new beacons and any changes to existing ones
on heartbeat_10s {
# Check if format string is null or empty
if($beacon_tab_name_format is $null || strlen($beacon_tab_name_format) == 0) {
return;
}
renameBeaconTabs();
makeBoldTabs();
colorBeaconTabs();
}
# Function to color all beacon tabs
sub colorBeaconTabs {
local('$bid');
foreach $bid (beacon_ids()) {
colorBeaconTab($bid);
}
}
# Function to color a single beacon tab based on admin status
sub colorBeaconTab {
local('$client $apptabs $i $applicationTab');
$bid = $1;
# Import Java Color class
import java.awt.Color;
# Get the Aggressor client object
$client = getAggressorClient();
# Get all application tabs
$apptabs = [[$client tabs] apptabs];
# Find and color the matching beacon tab
for ($i = 0; $i < [$apptabs size]; $i++) {
$applicationTab = [$apptabs get: $i];
if ([$applicationTab A] eq $bid) {
if (-isadmin $bid) {
# Admin user - Red
[[$applicationTab B] setForeground: [Color RED]];
}
else {
# Regular user - Green
[[$applicationTab B] setForeground: [Color GREEN]];
}
}
}
}
# Function to make beacon tabs bold
sub makeBoldTabs {
local('$bid');
foreach $bid (beacon_ids()) {
makeBoldTab($bid);
}
}
# Function to make a single beacon tab bold
sub makeBoldTab {
local('$client $apptabs $i $applicationTab');
$bid = $1;
# Import Java Font class
import java.awt.Font;
# Get the Aggressor client object
$client = getAggressorClient();
# Get all application tabs
$apptabs = [[$client tabs] apptabs];
# Find and bold the matching beacon tab
for ($i = 0; $i < [$apptabs size]; $i++) {
$applicationTab = [$apptabs get: $i];
if ([$applicationTab A] eq $bid) {
# Make font bold
$currentFont = [[$applicationTab B] getFont];
$boldFont = [new Font: [$currentFont getName], [Font BOLD], [$currentFont getSize]];
[[$applicationTab B] setFont: $boldFont];
}
}
}
# Function to iterate through all beacon IDs and rename their tabs
sub renameBeaconTabs {
local('$bid');
foreach $bid (beacon_ids()) {
renameBeaconTab($bid);
}
}
# Function to rename a single beacon tab based on the format string
sub renameBeaconTab {
# Declare local variables to avoid namespace pollution
local('$client $srctabname $i $dsttabname $apptabs $applicationTab');
# Check if format string is null or empty
if($beacon_tab_name_format is $null || strlen($beacon_tab_name_format) == 0) {
return;
}
# Get the beacon ID passed as argument
$bid = $1;
# Get the Aggressor client object
$client = getAggressorClient();
# Get all application tabs
$apptabs = [[$client tabs] apptabs];
# Construct the source (current) tab name using host and PID
$srctabname = "Beacon " . beacon_info($bid, 'host') . "@" . beacon_info($bid, 'pid');
$srctabname = [$srctabname trim];
# Iterate through all tabs
for ( $i = 0; $i < [$apptabs size] ; $i++) {
$applicationTab = [$apptabs get: $i];
# Check if this tab corresponds to our beacon ID
if ([$applicationTab A] eq $bid) {
# Get current tab name
$currtabname = [[[$applicationTab B] getText] trim];
# Only rename if the current name matches our expected source name
if ($currtabname eq $srctabname) {
# Start with the format string
$dsttabname = $beacon_tab_name_format;
# Iterate through all beacons
foreach $beacon (beacons()) {
# Find matching beacon ID
if ($beacon['id'] eq $bid) {
# Replace all placeholders with actual values
foreach $k => $v ($beacon) {
$dsttabname = replace($dsttabname, '<' . $k . '>', $v);
}
}
}
# Set the new tab name (with padding spaces)
# Note: setField() is avoided due to known issues with tab title updates
[[$applicationTab B] setText: $dsttabname . " "];
}
}
}
}
# Initial execution when script is loaded
renameBeaconTabs();
makeBoldTabs();
colorBeaconTabs();