-
Notifications
You must be signed in to change notification settings - Fork 300
/
ProcessMonitor.cna
178 lines (170 loc) · 5.72 KB
/
ProcessMonitor.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
173
174
175
176
177
178
#Process Monitor
#Author: @r3dQu1nn
#Queries the processes at a set interval to see what processes have been started since that interval time
#Thanks to @Alyssa (ramen0x3f) for the code snippets! Big thanks to @i_am_excite for the powershell code!
#Big thanks to raffi for the on heartbeat help!
#Global Variables
$timer = "";
$interval = "5m";
include(script_resource("ProcessMonitor.ps1"));
#Register Alias for Process Monitor
beacon_command_register("ProcessMonitor",
"Start/Stop and Change the Interval Time for Process Monitor",
"Synopsis: ProcessMonitor [Start/Stop] [Time]\n" .
"Options: 1m, 5m (default), 10m, 20m, 30m. If no time supplied, default of 5m is used.");
#Process Monitor alias
alias ProcessMonitor {
if ( $2 eq 'Start' && $3 eq '1m' ) {
if (-exists script_resource("ProcessMonitor.ps1")) {
$bid = $1;
$timer = "Start";
$interval = "1m";
blog($1, "\c9Process Monitor Started! Time Interval is set to " . $interval);
blog($1, "\c4Run ProcessMonitor [Stop] to stop ProcessMonitor from running continuously.");
blog($1, "\cBDepending on your sleep time, results might come before or after checkin.");
bpowershell_import!($1, script_resource("ProcessMonitor.ps1"));
bpowerpick!($1, 'Get-Proc 1');
}
else {
$timer = "";
$interval = "5m";
berror($1, "\c4ProcessMonitor.ps1 does not exist!");
show_message("ProcessMonitor.ps1 does not exist!");
}
}
else if ( $2 eq 'Start' && $3 eq '5m' ) {
if (-exists script_resource("ProcessMonitor.ps1")) {
$bid = $1;
$timer = "Start";
$interval = "5m";
blog($1, "\c9Process Monitor Started! Time Interval is set to " . $interval);
blog($1, "\c4Run ProcessMonitor [Stop] to stop ProcessMonitor from running continuously.");
blog($1, "\cBDepending on your sleep time, results might come before or after checkin.");
bpowershell_import!($1, script_resource("ProcessMonitor.ps1"));
bpowerpick!($1, 'Get-Proc 5');
}
else {
$timer = "";
$interval = "5m";
berror($1, "\c4ProcessMonitor.ps1 does not exist!");
show_message("ProcessMonitor.ps1 does not exist!");
}
}
else if ( $2 eq 'Start' && $3 eq '10m' ) {
if (-exists script_resource("ProcessMonitor.ps1")) {
$bid = $1;
$timer = "Start";
$interval = "10m";
blog($1, "\c9Process Monitor Started! Time Interval is set to " . $interval);
blog($1, "\c4Run ProcessMonitor [Stop] to stop ProcessMonitor from running continuously.");
blog($1, "\cBDepending on your sleep time, results might come before or after checkin.");
bpowershell_import!($1, script_resource("ProcessMonitor.ps1"));
bpowerpick!($1, 'Get-Proc 10');
}
else {
$timer = "";
$interval = "5m";
berror($1, "\c4ProcessMonitor.ps1 does not exist!");
show_message("ProcessMonitor.ps1 does not exist!");
}
}
else if ( $2 eq 'Start' && $3 eq '20m' ) {
if (-exists script_resource("ProcessMonitor.ps1")) {
$bid = $1;
$timer = "Start";
$interval = "20m";
blog($1, "\c9Process Monitor Started! Time Interval is set to " . $interval);
blog($1, "\c4Run ProcessMonitor [Stop] to stop ProcessMonitor from running continuously.");
blog($1, "\cBDepending on your sleep time, results might come before or after checkin.");
bpowershell_import!($1, script_resource("ProcessMonitor.ps1"));
bpowerpick!($1, 'Get-Proc 20');
}
else {
$timer = "";
$interval = "5m";
berror($1, "\c4ProcessMonitor.ps1 does not exist!");
show_message("ProcessMonitor.ps1 does not exist!");
}
}
else if ( $2 eq 'Start' && $3 eq '30m' ) {
if (-exists script_resource("ProcessMonitor.ps1")) {
$bid = $1;
$timer = "Start";
$interval = "30m";
blog($1, "\c9Process Monitor Started! Time Interval is set to " . $interval);
blog($1, "\c4Run ProcessMonitor [Stop] to stop ProcessMonitor from running continuously.");
blog($1, "\cBDepending on your sleep time, results might come before or after checkin.");
bpowershell_import!($1, script_resource("ProcessMonitor.ps1"));
bpowerpick!($1, 'Get-Proc 30');
}
else {
$timer = "";
$interval = "5m";
berror($1, "\c4ProcessMonitor.ps1 does not exist!");
show_message("ProcessMonitor.ps1 does not exist!");
}
}
else if ( $2 eq 'Stop' ) {
$timer = "Stop";
$interval = "5m";
blog($1, "\cBProcess Monitor has Stopped.");
}
else if ( $2 is $null ) {
blog($1, "\c4Please provide 'Start' then a correct time interval to Start Process Monitor.");
show_message("Please provide 'Start' then a correct time interval to Start Process Monitor.");
}
else if ( $3 != '1m' || $3 != '5m' || $3 != '10m' || $3 != '20m' || $3 != '30m' ) {
blog($1, "\c4Please provide a correct time interval to Start Process Monitor.");
show_message("Please provide a correct time interval to Start Process Monitor.");
}
else {
$timer = "";
$interval = "5m";
}
}
#Process Monitor heartbeat checks
on heartbeat_1m {
if ( $timer eq 'Start' && $interval eq '1m' ) {
bpowerpick!($bid, 'Get-Proc 1');
}
else if ( $timer eq 'Stop' ) {
}
else {
}
}
on heartbeat_5m {
if ( $timer eq 'Start' && $interval eq '5m' ) {
bpowerpick!($bid, 'Get-Proc 5');
}
else if ( $timer eq 'Stop' ) {
}
else {
}
}
on heartbeat_10m {
if ( $timer eq 'Start' && $interval eq '10m' ) {
bpowerpick!($bid, 'Get-Proc 10');
}
else if ( $timer eq 'Stop' ) {
}
else {
}
}
on heartbeat_20m {
if ( $timer eq 'Start' && $interval eq '20m' ) {
bpowerpick!($bid, 'Get-Proc 20');
}
else if ( $timer eq 'Stop' ) {
}
else {
}
}
on heartbeat_30m {
if ( $timer eq 'Start' && $interval eq '30m' ) {
bpowerpick!($bid, 'Get-Proc 30');
}
else if ( $timer eq 'Stop' ) {
}
else {
}
}