-
Notifications
You must be signed in to change notification settings - Fork 212
/
DA-Watch.cna
119 lines (104 loc) · 2.29 KB
/
DA-Watch.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
# @Bretiz
global('@domain_admins');
global('$listening');
@domain_admins = @("administrator", "jay");
$listening = 1;
sub addDA {
if ($1 !in @domain_admins) {
add(@domain_admins, $1);
println("Added $1 to Domain Admins");
}
else {
println("$1 is already in Domain Admins");
}
}
sub removeDA {
if ($1 in @domain_admins){
@rem = @($1);
@domain_admins = removeAll(@domain_admins, @rem);
println("Removed $1 from Domain Admins");
}
else {
println("$1 is not in Domain Admins");
}
}
sub checkDA {
# strip off " *" if we get a privileged beacon
$n = replace($user, '\Q *\E', '');
if ($n in @domain_admins) {
elog("Beacon with DA $user in PID: $pid");
}
}
sub parseDA {
$out = $1;
@lines = split('\n', $out);
foreach $line (@lines) {
$line = replace($line, '[\r\n]', '');
$line = replace($line, 'received output:', '');
$line = replace($line, 'Group name\p{Space}*Domain Admins', '');
$line = replace($line, 'The command completed successfully.', '');
$line = replace($line, 'Comment\p{Space}.*','');
$line = replace($line, 'Members.*', '');
$line = replace($line, '--------.*', '');
}
remove(@lines, '');
@lines = join('', @lines);
@lines = split('\s+', @lines);
remove(@lines, '');
println(@lines);
foreach $u (@lines) {
addDA($u);
}
}
command uaddDA {
addDA($1);
}
command uremDA {
removeDA($1);
}
command ulistDA {
printAll(@domain_admins);
}
command uhookStatus {
hookStatus();
}
sub hookStatus {
if ($listening) {
println("Beacon output will be parsed for Domain Admins.");
} else {
println("Beacon output will not be parsed.");
}
}
command uhookOn {
$listening = 1;
hookStatus();
}
command uhookOff {
$listening = 0;
hookStatus();
}
on beacon_initial {
$u = beacon_info($1, "user");
$p = beacon_info($1, "pid");
checkDA($user => $u, $pid => $p);
}
on credentials {
@creds = $1;
@unames = @("");
foreach $cred (@creds) {
add(@unames, $cred['user']);
}
foreach $da (@domain_admins) {
if ($da in @unames) {
println("Credentials store has DA $da");
}
}
}
on beacon_output {
if ($listening){
$out = $2;
if (('Domain Admins' isin $out) && ('The command completed successfully.' isin $out)) {
parseDA($out);
}
}
}