-
Notifications
You must be signed in to change notification settings - Fork 0
/
siem_monitor_redacted.pl
294 lines (264 loc) · 7.76 KB
/
siem_monitor_redacted.pl
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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
#!/usr/bin/perl
use strict;
#use warnings;
#use diagnostics;
use Term::ANSIColor;
#~~ Global Variables ~~#
my $clear_screen = `clear`;
my $server1 = "127.0.0.1";
#~~ End Global Variables ~~#
#~~ Customer Hashes ~~#
my %AAA = (
FW1 => {
IP => '127.0.0.1',
COUNTER => 0,
},
IDS1 => {
IP => 'AAA',
COUNTER => 0,
},
);
my $AAA = \%AAA;
my %BBB = (
IDS1 => {
IP => '127.0.0.1',
COUNTER => 0,
},
);
my $BBB = \%BBB;
my %CCC = (
FW1 => {
IP => '127.0.0.1',
COUNTER => 0,
},
IDS1 => {
IP => 'CCC',
COUNTER => 0,
},
);
my $CCC = \%CCC;
my %DDD = (
FW1 => {
IP => ' 127.0.0.1 ',
COUNTER => 0,
},
FW2 => {
IP => ' 127.0.0.1 ',
COUNTER => 0,
},
IDS1 => {
IP => 'DDD',
COUNTER => 0,
},
);
my $DDD = \%DDD;
my %EEE = (
FW1 => {
IP => ' 127.0.0.1 ',
COUNTER => 0,
},
IDS1 => {
IP => 'EEE',
COUNTER => 0,
},
);
my $EEE = \%EEE;
my %FFFF = (
FW1 => {
IP => '127.0.0.1',
COUNTER => 0,
},
IDS1 => {
IP => 'FFFF',
COUNTER => 0,
},
);
my $FFFF = \%FFFF;
#~~ End Customer Hashes ~~#
#~~ Subroutines ~~#
sub firewall_access_check
{
my @firewall_keywords = ("action=login", "subtype=config", "sys_msgs=installed", "subtype=admin pri=alert", "subtype=admin pri=notice", "system-warning-00519", "Operation=Modify Object", "Operation=Install Policy", "logged in for", "enable_15");
my $exceptions = "Disk log|ntp_daemon";
print color 'bold yellow';
print "\n","="x5," Checking for recent firewall change/login events ","="x5,"\n\n";
print color 'reset';
foreach (@firewall_keywords) {
my $firewall_search_result = `grep -h '$_' server | egrep -v "$exceptions" 2>&1`;
print "$firewall_search_result";
}
}
sub device_check
{
my $customer = shift;
my $customer_ref = shift;
my %customer_deref = %{$customer_ref};
foreach my $device ( sort keys %customer_deref ) {
print color 'bold blue';
print "\n=========== Checking: ", $customer,"-",$device, " : \"", $customer_deref{$device}{IP},"\" ===========\n";
print color 'reset';
my $device_check_result = `grep -h '$customer_deref{$device}{IP}' $ $.1 | grep -v server | tail -n3 2>&1`;
chomp ($device_check_result);
if( length $device_check_result ) {
print "\n$device_check_result\n";
}
else{
print color 'bold red';
print "\nNot receiving events from ", $customer,"-",$device, " : \"", $customer_deref{$device}{IP},"\"\n";
print color 'reset';
}
}
}
sub failed_devices
{
my @failed_devices;
print color 'bold cyan';
print "\n","="x10, " Failed Devices ", "="x10, "\n\n";
print color 'reset';
my @customer_list = ("AAA", "FFFF", "BBB", "CCC", "DDD", "EEE");
foreach my $customer (@customer_list) {
my $customer_ref = eval "\$$customer";
my %customer_deref = %{$customer_ref};
foreach my $device ( sort keys %customer_deref ) {
my $device_check_result = `grep -h '$customer_deref{$device}{IP}' $ $.1 | grep -v server | tail -n3 2>&1`;
chomp ($device_check_result);
if( length $device_check_result ) {
$customer_deref{$device}{COUNTER} = 0;
}
else{
$customer_deref{$device}{COUNTER} += 1;
if ( "$customer_deref{$device}{COUNTER}" > 10)
{
push(@failed_devices, "$customer-$device \($customer_deref{$device}{COUNTER}\) <<== ALERT");
}
else{
push(@failed_devices, "$customer-$device \($customer_deref{$device}{COUNTER}\)");
}
}
}
}
foreach(@failed_devices){
print ":"x10," $_\r\n";
}
}
sub SYSTEM_ALERT_events
{
# SYSTEM Events
my $exceptions = "127.0.0.1";
print color 'bold blue';
print "\n","="x5," Checking for recent SYSTEM events (5 events) ","="x5,"\n\n";
print color 'reset';
my $SYSTEM_search_result = `grep -h 'SYSTEM' $ $.1 | egrep -v "$exceptions" | grep 'from' | tail -n 5 | sort -u 2>&1`;
print "$SYSTEM_search_result";
# ALERT Events
print color 'bold blue';
print "\n","="x5," Checking for recent ALERT events (5 events) ","="x5,"\n\n";
my $ALERT_search_result = `grep -h 'ALERT' $ $.1 | egrep -v "$exceptions" | grep 'from' | tail -n 5 | sort -u 2>&1`;
print color 'bold red';
print "$ALERT_search_result";
print color 'reset';
}
sub known_scanners
{
my %known_scanners = (
M**** => [ '127.0.0.1/27', '127.0.0.1/26', '127.0.0.1/26', '127.0.0.1/28', '127.0.0.1/26', '127.0.0.1/27', '127.0.0.1/26' ],
Q**** => [ '127.0.0.1/20', '127.0.0.1/25', '127.0.0.1/26' ],
T**** => ['127.0.0.1/28'],
H**** => ['127.0.0.1/25'],
S**** => ['127.0.0.1/24'],
R**** => ['127.0.0.1/29'],
G**** => ['127.0.0.1'],
);
print color 'bold magenta';
print "\n","="x5," Checking for recent \"Known Scanners\" events (10 events per CIDR block) ","="x5,"\n\n";
print color 'reset';
foreach my $scanner (sort keys %known_scanners) {
print "Searching for $scanner activity => \n\n";
foreach (@{$known_scanners{$scanner}}) {
my $known_scanner_search_result = `/usr/bin/grep '$_' $ $.1 $.2 | tail -n10 | sort -u`;
if (length $known_scanner_search_result){
print "$known_scanner_search_result\n";
}
}
}
}
sub special_events
{
my $exceptions = "TEST";
my %special_events = (
Web_URL => [ 'nessus', 'passwd', '/etc/passwd', 'SELECT FROM', 'JOIN', 'UNION', 'php.exe', 'win.ini', 'boot.ini' ]
);
print color 'bold magenta';
print "\n","="x5," Checking for recent \ server Special Events\" ","="x5,"\n\n";
print color 'reset';
foreach my $event (sort keys %special_events) {
print "Searching for $event activity => \n\n";
foreach (@{$special_events{$event}}) {
my $special_events_search_result = `grep -h '$_' $ $.1 $.2 | tail -n10 | sort -u | egrep -v "$exceptions"`;
if (length $special_events_search_result){
print "$special_events_search_result\n";
}
}
}
}
sub menu
{
my $menu_option_ref = shift;
my @m = @{$menu_option_ref};
unshift @m, 'Please select:';
chomp(@m);
my $choice;
while (1)
{
print $clear_screen;
print color 'bold green';
print "\n","="x5," Welcome to SIEM Script","="x5,"\n";
print color 'reset';
print "\n$m[0]\n\n";
print map { "\t$_. \t$m[$_]\n" } (1..$#m);
print "\nEnter your number selection: (1-$#m)> ";
chomp ($choice = <STDIN>);
last if ( ($choice > 0) && ($choice <= $#m ));
print "\nYou chose '$choice'. That is not a valid option.\n\n";
sleep 2;
}
return "$m[$choice]";
}
sub auto_run
{
while (1) {
print $clear_screen;
firewall_access_check;
failed_devices;
SYSTEM_ALERT_events;
known_scanners;
special_events;
sleep 5;
}
}
#~~ End Subroutines ~~#
#~~ Subroutine Calls ~~#
while (1) {
my @menu_list = ("AAA", "BBB", "CCC", "DDD", "EEE", "FFFF", "Firewall Change/Logins", "Known Scanners", "Special Events", "Automatic Run");
my $menu_choice = menu(\@menu_list);
print $clear_screen;
if ("$menu_choice" eq "Firewall Change/Logins"){
firewall_access_check;
}
elsif("$menu_choice" eq "Automatic Run"){
auto_run();
}
elsif("$menu_choice" eq "Known Scanners"){
known_scanners();
}
elsif("$menu_choice" eq "Special Events"){
special_events();
}
else{
my $choice_ref = eval "\$$menu_choice";
device_check("$menu_choice", $choice_ref);
}
print "\n\nPress ENTER key to return to main menu..";
my $userinput = <STDIN>;
}
#~~ End Subroutine Calls ~~#