File: evtsecurity

package info (click to toggle)
logwatch 7.4.3%2Bgit20161207-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 4,064 kB
  • ctags: 474
  • sloc: perl: 9,204; sh: 231; makefile: 38
file content (352 lines) | stat: -rwxr-xr-x 12,993 bytes parent folder | download
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
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
# Process Windows security events logged to a server, using Snare Agent or
# similar.

########################################################
## Copyright (c) 2008-2014 Orion Poplawski
## Covered under the included MIT/X-Consortium License:
##    http://www.opensource.org/licenses/mit-license.php
## All modifications and contributions by other persons to
## this script are assumed to have been donated to the
## Logwatch project and thus assume the above copyright
## and licensing terms.  If you want to make contributions
## under your own copyright or a different license this
## must be explicitly stated in the contribution an the
## Logwatch project reserves the right to not accept such
## contributions.  If you have made significant
## contributions to this script and want to claim
## copyright please contact logwatch-devel@lists.sourceforge.net.
#########################################################

use strict;
use URI::URL;

my $Detail = $ENV{'LOGWATCH_DETAIL_LEVEL'} || 0;

my $SuccessAudits = 0;
my %SuccessAuditUsers;
my %FailureAudits;
my %SuccessAudits;
my %ClockSkew;
my %UnknownUser;
my %UnknownClient;
my %BadPasswords;
my %TicketExpired;
my %AccountChanged;
my %AccountCreated;
my %AccountDeleted;
my %AccountDisabled;
my %AccountEnabled;
my %AccountLocked;
my %AuditPolicyChanged;
my %ExpiredPassword;
my %PasswordChanged;
my %Logon;
my %PrivilegedLogon;
my %Logoff;
my %WorkstationLocked;
my %WorkstationUnlocked;
my %OtherList;

while (defined(my $ThisLine = <STDIN>)) {
   my ($Hostname,$Criticality,$SourceName,$DateTime,$EventID,$SourceName2,$UserName,$SIDType,$EventLogType,$CategoryString,$DataString,$ExpandedString,$Extra);
   #Determine format
   if ($ThisLine =~ /MSWinEventLog\[/) {  # Snare 4
      #Parse
      ($Criticality,$SourceName,$DateTime,$EventID,$SourceName2,$UserName,$SIDType,$EventLogType,$Hostname,$CategoryString,$DataString,$ExpandedString,$Extra) =
         ($ThisLine =~ /MSWinEventLog\[(\d+)\]:(\w+)\t\d+\t([^\t]+)\t(\d+)\t([^\t]+)\t([^\t]+)\t([^\t]+)\t([^\t]+)\t([^\t]+)\t?([^\t]*)\t?([^\t]*)\t?([^\t]*)\t?([^\t]*)/);
   } elsif ($ThisLine =~ /MSWinEventLog\t/) { # Snare 3
      #Parse
      ($Criticality,$SourceName,$DateTime,$EventID,$SourceName2,$UserName,$SIDType,$EventLogType,$Hostname,$CategoryString,$DataString,$ExpandedString,$Extra) =
         ($ThisLine =~ /MSWinEventLog\t(\d+)\t(\w+)\t\d+\t([^\t]+)\t(\d+)\t([^\t]+)\t([^\t]+)\t([^\t]+)\t([^\t]+)\t([^\t]+)\t?([^\t]*)\t?([^\t]*)\t?([^\t]*)\t?([^\t]*)/);
   }
   if (!defined($Hostname)) {
      print STDERR "Cannot parse $ThisLine";
      next;
   }
   my $url = URI::URL->new("https://www.ultimatewindowssecurity.com/securitylog/encyclopedia/event.aspx?eventID=$EventID");
   if ($EventLogType eq "Success Audit") {
      if ($EventID == 4608    # Windows is starting up. (startups logged by evtsystem)
          or $EventID == 4673 # An operation was attempted on a privileged object.
          or $EventID == 4674 # An operation was attempted on a privileged object.
                              # These are basically noise 
                              # https://www.ultimatewindowssecurity.com/securitylog/encyclopedia/event.aspx?eventID=4674
          or $EventID == 4688 # A new process has been created.
          or $EventID == 4689 # A process has exited.
         ) {
         # Ignore
      } elsif ($EventID == 4624 or $EventID == 4648) {
         $Logon{"$Hostname $UserName"}++;
      } elsif ($EventID == 4634 or $EventID == 4647) {
         $Logoff{"$Hostname $UserName"}++;
      } elsif ($EventID == 4672) {
         $PrivilegedLogon{"$Hostname $UserName"}++;
      } elsif ($EventID == 4719) {
         $AuditPolicyChanged{$Hostname}++;
      } elsif ($EventID == 4720) {
         $AccountCreated{$UserName}++;
      } elsif ($EventID == 4722) {
         $AccountEnabled{$UserName}++;
      } elsif ($EventID == 4723) {
         $PasswordChanged{$UserName}++;
      } elsif ($EventID == 4725) {
         $AccountDisabled{$UserName}++;
      } elsif ($EventID == 4726) {
         $AccountDeleted{$UserName}++;
      } elsif ($EventID == 4738 or $EventID == 4742) {
         $AccountChanged{$UserName}++;
      } elsif ($EventID == 4800) {
         $WorkstationLocked{"$Hostname $UserName"}++;
      } elsif ($EventID == 4801) {
         $WorkstationUnlocked{"$Hostname $UserName"}++;
      } else {
         $SuccessAudits++;
         $SuccessAuditUsers{$UserName}++;
         $SuccessAudits{"$Hostname $ExpandedString\n$url"}++;
      }
   }
   elsif ($EventLogType eq "Failure Audit") {
      if (my ($account,$domain,$reason) = ($ExpandedString =~ /^An account failed to log on\..*Account For Which Logon Failed:.*Account Name:\s+(\S+)\s+Account Domain:\s+(\S+).*Failure Reason:\s+(.+)\s+Status:.*Sub Status:/)) {
         $FailureAudits{"$Hostname Log On Failure for $domain\\$account: $reason"}++;
      } elsif (my ($account,$domain,$process) = ($ExpandedString =~ /^A privileged service was called\..*Account Name:\s+(\S+)\s+Account Domain:\s+(\S+).*Process Name:\s+(.+)\sService/)) {
         $FailureAudits{"$Hostname Privileged service called for $domain\\$account: $process"}++ if $Detail;
      } elsif ($EventID == 4674) {
         # These are basically noise 
         # https://www.ultimatewindowssecurity.com/securitylog/encyclopedia/event.aspx?eventID=4674
         # An operation was attempted on a privileged object.
      } elsif ($EventID == 4768) {
         # A Kerberos authentication ticket (TGT) was requested
         my ($Account,$Realm,$Client,$FailureCode) = $ExpandedString =~ /Account Name:\s+(\S*)\s.*Supplied Realm Name:\s+(\S*)\s.*Client Address:\s+(\S+)\s.*Result Code:\s+(\w+)/;
         if ($FailureCode eq "0x6") {
            # Client not found in Kerberos database
            $UnknownClient{"$Account\\$Realm $Client"}++;
         } elsif ($FailureCode eq "0x17") {
            #   Password has expired
            $ExpiredPassword{"$UserName"}++;
         } else {
            $FailureAudits{"$Hostname $ExpandedString\n$url"}++;
         }
      } elsif ($EventID == 4769) {
         # A Kerberos service ticket was requested
         my ($Client,$FailureCode) = $ExpandedString =~ /Client Address:\s+(\S+)\s.*Failure Code:\s+(\w+)/;
#print STDERR "EventID=$EventID Client=$Client FailureCode=$FailureCode ExpandedString=$ExpandedString\n";
         if ($FailureCode eq "0x20") {
            # Ticket expired
            $TicketExpired{$Client}++;
         } elsif ($FailureCode eq "0x25") {
            # Clock skew too great
            $ClockSkew{$Client}++;
         } else {
            $FailureAudits{"$Hostname $ExpandedString\n$url"}++;
         }
      } elsif ($EventID == 4771) {
         # Kerberos pre-authentication failed
         my ($Account,$Client,$FailureCode) = $ExpandedString =~ /Account Name:\s+(\S+)\s.*Client Address:\s+(\S+)\s.*Failure Code:\s+(\w+)/;
         if ($FailureCode eq "0x12") {
            #Clients credentials have been revoked      Account disabled, expired, locked out, logon hours.
            $AccountLocked{"$Account $Client"}++;
         } elsif ($FailureCode eq "0x18") {
            #Pre-authentication information was invalid - bad password
            $BadPasswords{"$Account $Client"}++;
         } elsif ($FailureCode eq "0x25") {
            # Clock skew too great
            $ClockSkew{$Client}++;
         } else {
            $FailureAudits{"$Hostname $ExpandedString\n$url"}++;
         }
      } elsif ($EventID == 4776) {
         # The domain controller attempted to validate the credentials for an account
         my ($Account,$Client,$FailureCode) = $ExpandedString =~ /Logon Account:\s+(\S+)\s+Source Workstation:\s+(\S*)\s.*Error Code:\s+(\w+)/;
         if (lc($FailureCode) eq "0xc0000064") {
            # user name does not exist
            $UnknownUser{"$Account $Client"}++;
         } elsif (lc($FailureCode) eq "0xc000006a") {
            # user name is correct but the password is wrong
            $BadPasswords{"$Account $Client"}++;
         } elsif (lc($FailureCode) eq "0xc0000071") {
            # expired password
            $ExpiredPassword{"$Account $Client"}++;
         } elsif (lc($FailureCode) eq "0xc0000234") {
            # account locked
            $AccountLocked{"$UserName $Client"}++;
         } else {
            $FailureAudits{"$Hostname $ExpandedString\n$url"}++;
         }
      } else {
         $FailureAudits{"$Hostname $ExpandedString\n$url"}++;
      }
   }
   else {
      # Report any unmatched entries...
      chomp($ThisLine);
      $OtherList{$ThisLine}++;
   }
}

if (keys %ClockSkew) {
   print "\nClock skew too great\n";
   foreach my $Client (sort keys %ClockSkew) {
      print "    $Client : $ClockSkew{$Client} Times\n";
   }
}

if (keys %AccountCreated) {
   print "\nAccount Created\n";
   foreach my $Account (sort keys %AccountCreated) {
      print "    $Account : $AccountCreated{$Account} Times\n";
   }
}

if (keys %AccountDeleted) {
   print "\nAccount Deleted\n";
   foreach my $Account (sort keys %AccountDeleted) {
      print "    $Account : $AccountDeleted{$Account} Times\n";
   }
}

if (keys %AccountDisabled) {
   print "\nAccount Disabled\n";
   foreach my $Account (sort keys %AccountDisabled) {
      print "    $Account : $AccountDisabled{$Account} Times\n";
   }
}

if (keys %AccountEnabled) {
   print "\nAccount Enabled\n";
   foreach my $Account (sort keys %AccountEnabled) {
      print "    $Account : $AccountEnabled{$Account} Times\n";
   }
}

if (keys %AccountChanged) {
   print "\nAccount Changed\n";
   foreach my $Account (sort keys %AccountChanged) {
      print "    $Account : $AccountChanged{$Account} Times\n";
   }
}

if (keys %PasswordChanged) {
   print "\nPassword Changed\n";
   foreach my $Account (sort keys %PasswordChanged) {
      print "    $Account : $PasswordChanged{$Account} Times\n";
   }
}

if (keys %AccountLocked) {
   print "\nAccount Locked\n";
   foreach my $Account (sort keys %AccountLocked) {
      print "    $Account : $AccountLocked{$Account} Times\n";
   }
}

if (keys %ExpiredPassword) {
   print "\nPassword Expired\n";
   foreach my $Account (sort keys %ExpiredPassword) {
      print "    $Account : $ExpiredPassword{$Account} Times\n";
   }
}

if (keys %UnknownUser) {
   print "\nUnknown Users\n";
   foreach my $Account (sort keys %UnknownUser) {
      print "    $Account : $UnknownUser{$Account} Times\n";
   }
}

if (keys %UnknownClient) {
   print "\nUnknown Clients\n";
   foreach my $Account (sort keys %UnknownClient) {
      print "    $Account : $UnknownClient{$Account} Times\n";
   }
}

if (keys %BadPasswords) {
   print "\nBad Passwords\n";
   foreach my $Account (sort keys %BadPasswords) {
      print "    $Account : $BadPasswords{$Account} Times\n";
   }
}

if (keys %TicketExpired) {
   print "\nTicket Expired\n";
   foreach my $Client (sort keys %TicketExpired) {
      print "    $Client : $TicketExpired{$Client} Times\n";
   }
}

if (keys %FailureAudits) {
   print "\nFailure Audits\n";
   foreach my $Error (sort keys %FailureAudits) {
      print "    $Error : $FailureAudits{$Error} Times\n";
   }
}

if (keys %AuditPolicyChanged) {
   print "\nAudit Policy Changed\n";
   foreach my $Hostname (sort keys %AuditPolicyChanged) {
      print "    $Hostname : $AuditPolicyChanged{$Hostname} Times\n";
   }
}

if ((keys %PrivilegedLogon) and ($Detail > 0)) {
   print "\nPrivileged Logons\n";
   foreach my $User (sort keys %PrivilegedLogon) {
      print "    $User : $PrivilegedLogon{$User} Times\n";
   }
}

if (keys %Logon and ($Detail >= 5)) {
   print "\nLogons\n";
   foreach my $User (sort keys %Logon) {
      print "    $User : $Logon{$User} Times\n";
   }
}

if (keys %Logoff and ($Detail >= 5)) {
   print "\nLogoffs\n";
   foreach my $User (sort keys %Logoff) {
      print "    $User : $Logoff{$User} Times\n";
   }
}

if (keys %WorkstationLocked and ($Detail >= 10)) {
   print "\nWorkstaion Locked\n";
   foreach my $User (sort keys %WorkstationLocked) {
      print "    $User : $WorkstationLocked{$User} Times\n";
   }
}

if (keys %WorkstationUnlocked and ($Detail >= 10)) {
   print "\nWorkstaion Unlocked\n";
   foreach my $User (sort keys %WorkstationUnlocked) {
      print "    $User : $WorkstationUnlocked{$User} Times\n";
   }
}

if ($SuccessAudits and ($Detail >= 5) ) {
   print "\nSuccess Audits " . $SuccessAudits . " Time(s)\n";
   foreach my $User (keys %SuccessAuditUsers) {
      print "    $User : $SuccessAuditUsers{$User} Times\n";
   }
   if ($Detail >= 10) {
      print "\nSuccess Audits\n";
      foreach my $Error (sort keys %SuccessAudits) {
         print "    $Error : $SuccessAudits{$Error} Times\n";
      }
   }
}

if (keys %OtherList) {
   print "\n**** Unmatched entries ****\n";
   foreach my $Error (keys %OtherList) {
      print "    $Error : $OtherList{$Error} Times\n";
   }
}

exit(0);

# vi: shiftwidth=3 tabstop=3 syntax=perl et
# Local Variables:
# mode: perl
# perl-indent-level: 3
# indent-tabs-mode: nil
# End: