2 # -*- mode: perl; perl-indent-level: 8 -*-
4 # Copyright (c) 2003 Kungliga Tekniska Högskolan
5 # (Royal Institute of Technology, Stockholm, Sweden).
8 # Redistribution and use in source and binary forms, with or without
9 # modification, are permitted provided that the following conditions
12 # 1. Redistributions of source code must retain the above copyright
13 # notice, this list of conditions and the following disclaimer.
15 # 2. Redistributions in binary form must reproduce the above copyright
16 # notice, this list of conditions and the following disclaimer in the
17 # documentation and/or other materials provided with the distribution.
19 # 3. Neither the name of the Institute nor the names of its contributors
20 # may be used to endorse or promote products derived from this software
21 # without specific prior written permission.
23 # THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
24 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 # ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
27 # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
37 # kdc-log-analyze - Analyze a KDC log file and give a report on the contents
39 # Note: The parts you want likely want to customize are the variable $notlocal,
40 # the array @local_network_re and the array @local_realms.
42 # Idea and implemetion for MIT Kerberos was done first by
43 # Ken Hornstein <kenh@cmf.nrl.navy.mil>, this program wouldn't exists
50 my $notlocal = 'not SU';
51 my @local_realms = ( "SU.SE" );
52 my @local_networks_re =
62 my %as_req_addr_nonlocal;
69 my %five24_req_addr_nonlocal;
70 my %five24_req_server;
71 my %five24_req_client;
72 my $as_req_successful = 0;
74 my $no_such_princ = 0;
75 my %no_such_princ_princ;
76 my %no_such_princ_addr;
77 my %no_such_princ_addr_nonlocal;
78 my $as_req_etype_odd = 0;
80 my $pa_alt_princ_request = 0;
81 my $pa_alt_princ_verify = 0;
84 my %tgs_req_addr_nonlocal;
87 my $tgs_xrealm_out = 0;
88 my %tgs_xrealm_out_realm;
89 my %tgs_xrealm_out_princ;
90 my $tgs_xrealm_in = 0;
91 my %tgs_xrealm_in_realm;
92 my %tgs_xrealm_in_princ;
96 my $forward_non_forward = 0;
99 my %v4_req_addr_nonlocal;
107 my %strange_tcp_data;
108 my $http_malformed = 0;
109 my %http_malformed_addr;
110 my $http_non_kdc = 0;
111 my %http_non_kdc_addr;
112 my $tcp_conn_timeout = 0;
113 my %tcp_conn_timeout_addr;
114 my $failed_processing = 0;
115 my %failed_processing_addr;
116 my $connection_closed = 0;
117 my %connection_closed_addr;
123 $ip{'4'} = $ip{'6'} = 0;
129 print "Kerberos KDC Log Report for ",
130 hostname
, " on ", scalar localtime, "\n\n";
132 print "General Statistics\n\n";
134 print "\tNumber of IPv4 requests: $ip{'4'}\n";
135 print "\tNumber of IPv6 requests: $ip{'6'}\n\n";
137 print "\tNumber of restarts: $restarts\n";
138 print "\tNumber of V4 requests: $v4_req\n";
140 print "\tTop ten IP addresses performing V4 requests:\n";
141 topten
(\
%v4_req_addr);
143 if (int(keys %v4_req_addr_nonlocal) > 0) {
144 print "\tTop ten $notlocal IP addresses performing V4 requests:\n";
145 topten
(\
%v4_req_addr_nonlocal);
150 print "\tNumber of V4 cross realms (krb4 and 524) requests: $v4_cross\n";
152 print "\tTop ten realms performing V4 cross requests:\n";
153 topten
(\
%v4_cross_realm);
157 print "\tNumber of V45 cross realms requests: $v5_cross\n";
159 print "\tTop ten realms performing V4 cross requests:\n";
160 topten
(\
%v5_cross_realm);
164 print "\tNumber of failed lookups: $no_such_princ\n";
165 if ($no_such_princ > 0) {
166 print "\tTop ten IP addresses failing to find principal:\n";
167 topten
(\
%no_such_princ_addr);
168 print "\tTop ten $notlocal IP addresses failing find principal:\n";
169 topten
(\
%no_such_princ_addr_nonlocal);
170 print "\tTop ten failed to find principals\n";
171 topten
(\
%no_such_princ_princ);
175 print "\tBandwidth pigs:\n";
179 print "\tStrange TCP data clients: ", int(keys %strange_tcp_data),"\n";
180 topten
(\
%strange_tcp_data);
183 print "\tTimeout waiting on TCP requests: ", $tcp_conn_timeout,"\n";
184 if ($tcp_conn_timeout > 0) {
185 print "\tTop ten TCP timeout request clients\n";
186 topten
(\
%tcp_conn_timeout_addr);
190 print "\tFailed processing requests: ", $failed_processing,"\n";
191 if ($failed_processing > 0) {
192 print "\tTop ten failed processing request clients\n";
193 topten
(\
%failed_processing_addr);
197 print "\tConnection closed requests: ", $connection_closed,"\n";
198 if ($connection_closed > 0) {
199 print "\tTop ten connection closed request clients\n";
200 topten
(\
%connection_closed_addr);
204 print "\tMalformed HTTP requests: ", $http_malformed,"\n";
205 if ($http_malformed > 0) {
206 print "\tTop ten malformed HTTP request clients\n";
207 topten
(\
%http_malformed_addr);
211 print "\tHTTP non kdc requests: ", $http_non_kdc,"\n";
212 if ($http_non_kdc > 0) {
213 print "\tTop ten HTTP non KDC request clients\n";
214 topten
(\
%http_non_kdc_addr);
218 print "Report on AS_REQ requests\n\n";
219 print "Overall AS_REQ statistics\n\n";
221 print "\tTotal number: $as_req\n";
223 print "\nAS_REQ client/server statistics\n\n";
225 print "\tDistinct IP Addresses performing requests: ",
226 int(keys %as_req_addr),"\n";
227 print "\tOverall top ten IP addresses\n";
228 topten
(\
%as_req_addr);
230 print "\tDistinct non-local ($notlocal) IP Addresses performing requests: ",
231 int(keys %as_req_addr_nonlocal), "\n";
232 print "\tTop ten non-local ($notlocal) IP address:\n";
233 topten
(\
%as_req_addr_nonlocal);
235 print "\n\tPreauth failed for for: ", $pa_failed, " requests\n";
237 print "\tPreauth failed top ten IP addresses:\n";
238 topten
(\
%pa_failed_addr);
239 print "\tPreauth failed top ten principals:\n";
240 topten
(\
%pa_failed_princ);
243 print "\n\tDistinct clients performing requests: ",
244 int(keys %as_req_client), "\n";
245 print "\tTop ten clients:\n";
246 topten
(\
%as_req_client);
248 print "\tDistinct services requested: ", int(keys %as_req_server), "\n";
249 print "\tTop ten requested services:\n";
250 topten
(\
%as_req_server);
252 print "\n\n\nReport on TGS_REQ requests:\n\n";
253 print "Overall TGS_REQ statistics\n\n";
254 print "\tTotal number: $tgs_req\n";
256 print "\nTGS_REQ client/server statistics\n\n";
257 print "\tDistinct IP addresses performing requests: ",
258 int(keys %tgs_req_addr), "\n";
259 print "\tOverall top ten IP addresses\n";
260 topten
(\
%tgs_req_addr);
262 print "\tDistinct non-local ($notlocal) IP Addresses performing requests: ",
263 int(keys %tgs_req_addr_nonlocal), "\n";
264 print "\tTop ten non-local ($notlocal) IP address:\n";
265 topten
(\
%tgs_req_addr_nonlocal);
267 print "\tDistinct clients performing requests: ",
268 int(keys %tgs_req_client), "\n";
269 print "\tTop ten clients:\n";
270 topten
(\
%tgs_req_client);
272 print "\tDistinct services requested: ", int(keys %tgs_req_server), "\n";
273 print "\tTop ten requested services:\n";
274 topten
(\
%tgs_req_server);
276 print "\n\n\nReport on 524_REQ requests:\n\n";
278 print "\t524_REQ client/server statistics\n\n";
280 print "\tDistinct IP Addresses performing requests: ",
281 int(keys %five24_req_addr),"\n";
282 print "\tOverall top ten IP addresses\n";
283 topten
(\
%five24_req_addr);
285 print "\tDistinct non-local ($notlocal) IP Addresses performing requests: ",
286 int(keys %five24_req_addr_nonlocal), "\n";
287 print "\tTop ten non-local ($notlocal) IP address:\n";
288 topten
(\
%five24_req_addr_nonlocal);
290 print "\tDistinct clients performing requests: ", int(keys %five24_req_client), "\n";
291 print "\tTop ten clients:\n";
292 topten
(\
%five24_req_client);
294 print "\tDistinct services requested: ", int(keys %five24_req_server), "\n";
295 print "\tTop ten requested services:\n";
296 topten
(\
%five24_req_server);
299 print "Cross realm statistics\n\n";
301 print "\tNumber of cross-realm tgs out: $tgs_xrealm_out\n";
302 if ($tgs_xrealm_out > 0) {
303 print "\tTop ten realms used for out cross-realm:\n";
304 topten
(\
%tgs_xrealm_out_realm);
305 print "\tTop ten principals use out cross-realm:\n";
306 topten
(\
%tgs_xrealm_out_princ);
308 print "\tNumber of cross-realm tgs in: $tgs_xrealm_in\n";
309 if ($tgs_xrealm_in > 0) {
310 print "\tTop ten realms used for in cross-realm:\n";
311 topten
(\
%tgs_xrealm_in_realm);
312 print "\tTop ten principals use in cross-realm:\n";
313 topten
(\
%tgs_xrealm_in_princ);
316 print "\n\nReport on referral:\n\n";
318 print "\tNumber of referrals: $referrals\n";
319 if ($referrals > 0) {
320 print "\tTop ten referral-ed principals:\n";
321 topten
(\
%referral_princ);
322 print "\tTop ten to realm referrals:\n";
323 topten
(\
%referral_realm);
326 print "\n\nEnctype Statistics:\n\n";
327 print "\tTop ten session enctypes:\n";
328 topten
(\
%enctype_session);
329 print "\tTop ten ticket enctypes:\n";
330 topten
(\
%enctype_ticket);
332 print "\tDistinct IP addresses using DES: ", int(keys %addr_uses_des), "\n";
333 print "\tTop IP addresses using DES:\n";
334 topten
(\
%addr_uses_des);
335 print "\tDistinct principals using DES: ", int(keys %princ_uses_des), "\n";
336 print "\tTop ten principals using DES:\n";
337 topten
(\
%princ_uses_des);
341 printf("Requests to forward non-forwardable ticket: $forward_non_forward\n");
347 my $last_principal = "";
352 # Eat these lines that are output as a result of startup (but
353 # log the number of restarts)
355 if (/AS-REQ \(krb4\) (.*) from IPv([46]):([0-9\.:a-fA-F]+) for krbtgt.*$/){
358 $v4_req_addr_nonlocal{$3}++ if (!islocaladdr
($3));
360 $last_principal = $1;
362 } elsif (/AS-REQ (.*) from IPv([46]):([0-9\.:a-fA-F]+) for (.*)$/) {
364 $as_req_client{$1}++;
365 $as_req_server{$4}++;
367 $as_req_addr_nonlocal{$3}++ if (!islocaladdr
($3));
369 $last_principal = $1;
371 } elsif (/TGS-REQ \(krb4\)/) {
373 } elsif (/TGS-REQ (.+) from IPv([46]):([0-9\.:a-fA-F]+) for (.*?)( \[.*\]){0,1}$/) {
375 $tgs_req_client{$1}++;
376 $tgs_req_server{$4}++;
378 $tgs_req_addr_nonlocal{$3}++ if (!islocaladdr
($3));
380 $last_principal = $1;
386 if (!islocalrealm
($source)) {
388 $tgs_xrealm_in_princ{$source}++;
389 if ($source =~ /[^@]+@([^@]+)/ ) {
390 $tgs_xrealm_in_realm{$1}++;
393 if ($dest =~ /krbtgt\/([^@
]+)@
[^@
]+/) {
394 if (!islocalrealm
($1)) {
396 $tgs_xrealm_out_realm{$1}++;
397 $tgs_xrealm_out_princ{$source}++;
400 } elsif (/524-REQ (.*) from IPv([46]):([0-9\.:a-fA-F]+) for (.*)$/) {
402 $five24_req_client{$1}++;
403 $five24_req_server{$4}++;
404 $five24_req_addr{$3}++;
405 $five24_req_addr_nonlocal{$3}++ if (!islocaladdr
($3));
407 $last_principal = $1;
409 } elsif (/TCP data of strange type from IPv[46]:([0-9\.:a-fA-F]+)/) {
410 $strange_tcp_data{$1}++;
411 } elsif (/Lookup (.*) failed: No such entry in the database/) {
413 $no_such_princ_addr{$last_addr}++;
414 $no_such_princ_addr_nonlocal{$last_addr}++ if (!islocaladdr
($last_addr));
415 $no_such_princ_princ{$1}++;
416 } elsif (/Lookup .* succeeded$/) {
418 } elsif (/Malformed HTTP request from IPv[46]:([0-9\.:a-fA-F]+)$/) {
420 $http_malformed_addr{$1}++;
421 } elsif (/TCP-connection from IPv[46]:([0-9\.:a-fA-F]+) expired after [0-9]+ bytes/) {
423 $tcp_conn_timeout_addr{$1}++;
424 } elsif (/Failed processing [0-9]+ byte request from IPv[46]:([0-9\.:a-fA-F]+)/) {
425 $failed_processing++;
426 $failed_processing_addr{$1}++;
427 } elsif (/connection closed before end of data after [0-9]+ bytes from IPv[46]:([0-9\.:a-fA-F]+)/) {
428 $connection_closed++;
429 $connection_closed_addr{$1}++;
430 } elsif (/HTTP request from IPv[46]:([0-9\.:a-fA-F]+) is non KDC request/) {
432 $http_non_kdc_addr{$1}++;
433 } elsif (/returning a referral to realm (.*) for server (.*) that was not found/) {
435 $referral_princ{$2}++;
436 $referral_realm{$1}++;
437 } elsif (/krb4 Cross-realm (.*) -> (.*) disabled/) {
439 $v4_cross_realm{$1."->".$2}++;
440 } elsif (/524 cross-realm (.*) -> (.*) disabled/) {
442 $v4_cross_realm{$1."->".$2}++;
443 } elsif (/cross-realm (.*) -> (.*): no transit through realm (.*)/) {
444 } elsif (/cross-realm (.*) -> (.*) via \[([^\]]+)\]/) {
446 $v5_cross_realm{$1."->".$2}++;
447 } elsif (/cross-realm (.*) -> (.*)/) {
449 $v5_cross_realm{$1."->".$2}++;
450 } elsif (/sending ([0-9]+) bytes to IPv[46]:([0-9\.:a-fA-F]+)/) {
452 } elsif (/Using ([-a-z0-9]+)\/([-a
-z0
-9]+)/) {
453 $enctype_ticket{$1}++;
454 $enctype_session{$2}++;
459 if ($ticket =~ /des-cbc-(crc|md4|md5)/) {
460 $addr_uses_des{$last_addr}++;
461 $princ_uses_des{$last_principal}++;
464 } elsif (/Failed to decrypt PA-DATA -- (.+)$/) {
466 $pa_failed_princ{$last_principal}++;
467 $pa_failed_addr{$last_addr}++;
469 } elsif (/Request to forward non-forwardable ticket/) {
470 $forward_non_forward++;
471 } elsif (/HTTP request:/) {
472 } elsif (/krb_rd_req: Incorrect network address/) {
473 } elsif (/krb_rd_req: Ticket expired \(krb_rd_req\)/) {
474 } elsif (/Ticket expired \(.*\)/) {
475 } elsif (/krb_rd_req: Can't decode authenticator \(krb_rd_req\)/) {
476 } elsif (/Request from wrong address/) {
478 } elsif (/UNKNOWN --/) {
480 } elsif (/Too large time skew -- (.*)$/) {
482 } elsif (/No PA-ENC-TIMESTAMP --/) {
484 } elsif (/Looking for pa-data --/) {
486 } elsif (/Pre-authentication succeded -- (.+)$/) {
488 } elsif (/Bad request for ([,a-zA-Z0-9]+) ticket/) {
490 } elsif (/Failed to verify AP-REQ: Ticket expired/) {
492 } elsif (/Client not found in database:/) {
494 } elsif (/Server not found in database \(krb4\)/) {
495 } elsif (/Server not found in database:/) {
497 } elsif (/newsyslog.*logfile turned over/) {
499 } elsif (/Requested flags:/) {
501 } elsif (/shutting down/) {
503 } elsif (/listening on IP/) {
505 } elsif (/commencing operation/) {
509 # Log it if we didn't parse the line
512 print "Unknown log file line: $_";
522 @keys = (sort {$$list{$b} <=> $$list{$a}} (keys %{$list}));
525 foreach $key (@keys) {
526 print "\t\t$key - $$list{$key}\n";
530 sub islocaladdr
(\
$) {
534 foreach $net (@local_networks_re) {
535 return 1 if ($addr =~ /$net/);
540 sub islocalrealm
(\
$) {
544 foreach $realm (@local_realms) {
545 return 1 if ($princ eq $realm);
546 return 1 if ($princ =~ /[^@]+\@${realm}/);