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
|
#!/usr/bin/perl
##########################################################################
# $Id: pluto,v 1.8 2003/12/15 18:09:23 kirk Exp $
##########################################################################
# This is a scanner for logwatch (see www.logwatch.org) that processes
# FreeSWAN's <http://www.freeswan.org/> Pluto log files and attempts to
# make some sense out of them.
#
# Please CC suggestions to mcr@freeswan.org and/or design@lists.freeswan.org
# as well as to kirk@kaybee.org.
# the vendorID hash maps vendor IDs to products. VendorIDs are hashs of
# internal stuff from each vendor. Grow this table as you encouter new
# products.
$vendorID{"p....}..&..i...5..............................."}="KAME/Racoon";
$debug=0;
while(<>) {
# May 4 04:04:33 abigail Pluto[24170]: "abigail-istari" #1479: ISAKMP SA expired (LATEST!)
chop;
($month,$day,$time,$host,$process,$conn,$msg)=split(/ +/,$_,7);
$today="$month $day";
next unless ($process =~ /pluto/i);
$loglines{$today}++;
print STDERR "Msg: $msg\n" if $debug>1;
if($msg =~ /([^\#]*)\#(\d*)\:(.*)/) {
$ipaddr = $1;
$stateinfo = $2;
$rest = $3;
} elsif($msg =~ /no Phase 1 state for Delete/) {
$baddelete++;
next;
} elsif($msg =~ /from ([^:]*)\:([^:]*)\: Main Mode message is part of an unknown exchange/) {
$ipaddr = $1;
$ipport = $2;
$badexch{"[$ipaddr]:$ipport"}++;
next;
} else {
print STDERR "Failed to decode: $msg (of $_)\n" if $debug;
next;
}
# print STDERR "conn: $conn IP: $ipaddr STATE: $stateinfo\n" if $debug;
$conn =~ s/\"(.*)\"/$1/;
$conns{$conn}++;
if(!defined($peerIP{"$conn|$ipaddr"})) {
#print STDERR "Adding $ipaddr to $conn\n" if $debug;
$peerIP{$conn}=$peerIP{$conn}.$ipaddr." ";
}
$peerIP{"$conn|$ipaddr"}++;
$stateobjects{$stateinfo}++;
if(!defined($peer{$stateinfo}) && length($ipaddr)>0) {
$peer{$stateinfo}=$ipaddr;
}
# ignore following
next if($rest =~ /ISAKMP SA expired/);
next if($rest =~ /responding to Main Mode/);
next if($rest =~ /responding to Quick Mode/);
next if($rest =~ /IPsec SA expired/);
next if($rest =~ /ignoring informational payload, type IPSEC_INITIAL_CONTACT/);
next if($rest =~ /regenerating DH private secret to avoid Pluto 1.0 bug handling public value with leading zero/);
next if($rest =~ /regenerating DH private secret to avoid Pluto 1.0 bug handling shared secret with leading zero/);
next if($rest =~ /shared DH secret has leading zero -- triggers Pluto 1.0 bug/);
next if($rest =~ /ignoring Delete SA payload/);
next if($rest =~ /received and ignored informational message/);
next if($rest =~ /discarding duplicate packet; already STATE_MAIN_../);
next if($rest =~ /discarding duplicate packet; already STATE_QUICK_../);
next if($rest =~ /deleting state \(STATE_MAIN_..\)/);
next if($rest =~ /deleting state \(STATE_QUICK_..\)/);
next if($rest =~ /Quick Mode .. message is unacceptable because it uses a previously used Message ID/);
next if($rest =~ /deleting connection .* instance with peer .*/);
next if($rest =~ /dropping and reinitiating exchange to avoid Pluto 1.0 bug handling DH shared secret with leading zero byte/);
next if($rest =~ /KE has 191 byte DH public value; 192 required/);
next if($rest =~ /retransmitting in response to duplicate packet; already STATE_MAIN_../);
#Manuel Mitnyan <logo@videotron.ca> Thu Jul 31 2003 -To handle somes non important messages
next if($rest =~ /Peer ID is ID_IPV4_ADDR/);
next if($rest =~ /Peer ID is ID_FQDN/);
$relevantlog{"$today"}++;
print STDERR "Rest is $rest\n" if $debug>1;
# but process these.
if($rest =~ /initiating Main Mode to replace \#(.*)/) {
$oldinfo = $1;
$statechain{$conn.$stateinfo}="$conn|$oldinfo";
next;
} elsif($rest =~ /initiating Main Mode/) {
$statechain{$conn.$stateinfo}="$conn";
next;
} elsif($rest =~ /initiating Quick Mode (.*) to replace \#(.*)/) {
$oldinfo = $2;
$phase2 = $1;
$statechain{"$conn|$stateinfo"}="$conn|$oldinfo";
$quickmode{"$conn"}=$quickmode{"$conn"}." ".$phase2;
next;
} elsif($rest =~ /initiating Quick Mode (.*)/) {
$phase2 = $1;
$statechain{"$conn|$stateinfo"}="$conn";
$quickmode{"$conn"}=$quickmode{"$conn"}." ".$phase2;
next;
} elsif($rest =~ /ISAKMP SA established/) {
$rekeysuccess{$conn}++;
next;
} elsif($rest =~ /cannot respond to IPsec SA request because no connection is known for (.*)/) {
$rekeyfail{$conn}++;
$rekeyfail_notknown{$1}++;
} elsif($rest =~ /max number of retransmissions \((.*)\) reached STATE_QUICK_I./) {
$rekeyfail{$conn}++;
$rekeyfailQI1{$conn}++;
next;
} elsif($rest =~ /max number of retransmissions \((.*)\) reached STATE_QUICK_R./) {
$rekeyfail{$conn}++;
$rekeyfailQR1{$conn}++;
next;
} elsif($rest =~ /max number of retransmissions \((.*)\) reached STATE_MAIN_I./) {
$rekeyfail{$conn}++;
$rekeyfailI1{$conn}++;
next;
} elsif($rest =~ /max number of retransmissions \((.*)\) reached STATE_MAIN_R./) {
$rekeyfail{$conn}++;
$rekeyfailR1{$conn}++;
next;
} elsif($rest =~ /ERROR: asynchronous network error report on .* for message to .* port 500, complainant .*:.*errno (.*), origin ICMP type (.*) code (.*)/) {
$rekeyfail{$conn}++;
$rekeyfail_ICMPunreachable{$conn}++;
} elsif($rest =~ /ERROR: asynchronous network error report on .* for message to .* port 500, complainant .*:.*errno (.*), origin ICMP type (.*) code (.*)/) {
$rekeyfail{$conn}++;
$rekeyfail_ICMPunreachable{$conn}++;
} elsif($rest =~ /starting keying attempt (.*) of an unlimited number/) {
$lastattempt=$1;
if($maxattempts{$conn} < $lastattempt) {
$maxattempts{$conn} = $lastattempt;
}
next;
} elsif($rest =~ /Vendor ID: (.*)/) {
$vid=$1;
if(defined($vendorID{$vid})) {
$peerID{$conn}=$vendorID{$vid};
} else {
$peerID{$conn}="unknown $vid";
$vendorID{$vid}="unknown $vid at $stateinfo/$ipaddr\n";
}
next;
} elsif($rest =~ /prepare-client output.*/) {
$setupfail{$conn}++;
} elsif(($rest =~ /sent QI2, IPsec SA established/) ||
($rest =~ /IPsec SA established/)) {
$ipsecSAs{$conn}++;
next;
} else {
print STDERR "UNKNOWN: $_"."\n";
}
}
if (keys %loglines) {
print "Overview summary of log files:\n";
foreach $day (keys %loglines) {
print "\t $day had ".$loglines{$day}." entries of which ".$relevantlog{$day}." were relevant\n";
}
}
if (keys %conns) {
print "Summary by peer:\n";
foreach $conn (keys %conns) {
print " Peer $conn caused $conns{$conn} lines of output.\n";
print "\tconnected from:".$peerIP{$conn}."\n";
if(defined($peerID{$conn})) {
print "\tVID: ".$peerID{$conn}."\n";
}
print "\tKeyed: ".($rekeysuccess{$conn}+0)." successes ",($rekeyfail{$conn}+0)." failures (max retries: ".($maxattempts{$conn}+0).")\n";
print "\tIPsec SAs: ".($ipsecSAs{$conn}+0)."\n";
if($setupfail{$conn} > 0) {
print "\tSetup failures: ".$setupfail{$conn}."\n";
}
}
}
if (keys %badexch) {
print "Summary of bad peers\n";
foreach $badpeer (keys %badexch) {
print "\t".$badpeer." caused ".$badexch{$badpeer}." bad exchanges\n";
}
}
# vi: shiftwidth=3 tabstop=3 et
|