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
|
#!/usr/bin/perl
##########################################################################
# $Id: pam_pwdb,v 1.18 2003/12/15 18:09:23 kirk Exp $
##########################################################################
########################################################
# This was written and is maintained by:
# Kirk Bauer <kirk@kaybee.org>
#
# Please send all comments, suggestions, bug reports,
# etc, to kirk@kaybee.org.
########################################################
# NOTE: This script is for older (6.X era) Red Hat boxes
$Detail = $ENV{'LOGWATCH_DETAIL_LEVEL'} || 0;
while (defined($ThisLine = <STDIN>)) {
if ( ( $ThisLine =~ /(.*) session closed for user .*$/ ) or
( $ThisLine =~ /^Logout user .* host .*$/ ) or
( $ThisLine =~ /^log: Password authentication/ ) or # apparently SSHD messages
( $ThisLine =~ /^log: Closing connection/ ) or # apparently SSHD messages
( $ThisLine =~ /^check pass; user unknown/ ) or
( $ThisLine =~ /^User account has expired/ ) or # This one is caught below (2-line message)
( $ThisLine =~ /^get passwd; pwdb: structure is no longer valid$/) or
( $ThisLine =~ /^fatal: Read error from remote host: Connection reset by peer$/) or
( $ThisLine =~ /^new password not acceptable$/ ) or
( $ThisLine =~ /^FTP session closed$/) or
( $ThisLine =~ /^FTP LOGIN REFUSED/) or
( $ThisLine =~ /^FAILED LOGIN SESSION FROM \S+ FOR , Error in service module/) or
( $ThisLine =~ /^FTP LOGIN FROM/ ) # I will let ftpd handle FTP messages....
) {
# We don't care about these
}
elsif ( $ThisLine =~ /password for \(.*\) changed by \(.*\)$/ ) {
chomp($ThisLine);
push @PWChanges, $ThisLine;
}
elsif ( ($RemoteHost,$User) = ( $ThisLine =~ /^failed login from ([^ ]+) \[.*\], ([^ ]+)$/) or
($RemoteHost,$User) = ( $ThisLine =~ /^Login failure user=(\S+) host=([^ ]+)$/) ) {
chomp ($User);
push @{$FailedLogins{$RemoteHost}}, $User;
}
elsif ( $ThisLine =~ s/auth could not identify password for \[([^ ]+)\]$/$1/ ) {
chomp ($ThisLine);
$CouldNotIDPW{$ThisLine}++;
}
elsif ( $ThisLine =~ s/^expiry check failed for \'([^ ]+)\'/$1/ ) {
# user account expired?
chomp($ThisLine);
push @Expired, $ThisLine;
}
elsif ( $ThisLine =~ s/bad username \[(.*)\]$/$1/ ) {
chomp($ThisLine);
push @BadName, $ThisLine;
}
elsif ( ($StartName,$StartUID,$EndName,$ServiceName) =
( $ThisLine =~ m/authentication failure.*; ([^ ]*)\(uid=(\d+)\) -> ([^ ]+) for ([^ ]+) service$/ ) ) {
$StartName = " " if (!$StartName);
$ThisKey = $StartName . "(uid=" . $StartUID . ") -> " . $EndName;
$AuthFailures{$ThisKey}{$ServiceName}++;
}
elsif ( ($Num,$StartName,$StartUID,$EndName,$ServiceName) =
( $ThisLine =~ m/^(\d+) authentication failure.*; ([^ ]*)\(uid=(\d+)\) -> ([^ ]+) for ([^ ]+) service$/ ) ) {
$StartName = " " if (!$StartName);
$ThisKey = $StartName . "(uid=" . $StartUID . ") -> " . $EndName;
$AuthFailures{$ThisKey}{$ServiceName}+=$Num;
}
elsif ( ($ThisKey,$ServiceName) = ( $ThisLine =~ /([^ ]+) authentication failed for ([^ ]+)$/ ) ) {
chomp($ThisKey); chomp($ServiceName);
$AuthFailures{$ThisKey}{$ServiceName}++;
}
elsif ( ($RemoteHost, $User) = ( $ThisLine =~ m/^FAILED LOGIN .* FROM ([^ ]+) FOR (.+), .*$/ ) ) {
push @{$FailedLogins{$RemoteHost}}, $User;
}
elsif ( $ThisLine =~ s/^ROOT LOGIN ON ([^ ]+)/$1/ ) {
chomp ($ThisLine);
$RootLogins{$ThisLine}++;
}
elsif ( ($User,$From) = ( $ThisLine =~ /^LOGIN ON [^ ]+ BY ([^ ]+) FROM ([^ ]+)$/ ) or
($User,$From) = ( $ThisLine =~ /^Login user=([^ ]+) host=([^ ]+)$/ ) ) {
chomp ($From);
${$RemoteLogins{$User}}{$From}++;
}
elsif ( $ThisLine =~ s/^LOGIN ON [^ ]+ BY ([^ ]+$)/$1/ ) {
chomp ($ThisLine);
$LocalLogins{$ThisLine}++;
}
elsif ( ($ServiceName,$StartName,$StartUID,$EndName) =
( $ThisLine =~ m/([^ ]+)\[[0-9]+\]:\s+authentication\s+failure;\s*logname=([^ ]+)\s+uid=([^ ]+).*user=([^ ]+)/ ) ) {
$StartName = " " if (!$StartName);
$ThisKey = $StartName . "(uid=" . $StartUID . ") -> " . $EndName;
$AuthFailures{$ThisKey}{$ServiceName}++;
}
elsif ( ($Service, $User, $Orig) = ( $ThisLine =~ /^\((.*)\) session opened for user ([^ ]+) by (.*\(uid=.*\))/ ) ) {
if (( $Service eq "su" ) and ($Orig =~ /[^ ]+\(uid=.*\)$/)) {
$Temp = " " . $Orig . " -> " . $User;
$SUList{$Temp}++;
}
else {
${$OpenedSessions{$Service}}{$User}++;
}
}
else {
# Report any unmatched entries...
chomp($ThisLine);
$OtherList{$ThisLine}++;
}
}
if (keys %SUList) {
print "\nSU Sessions:\n";
foreach $SU (keys %SUList) {
print " " . $SU . " - " . $SUList{$SU} . " Time(s)\n";
}
}
if (($Detail >= 10) and (keys %CouldNotIDPW)) {
print "\nCould not identify password for:\n";
foreach $User (keys %CouldNotIDPW) {
print " " . $User . " - " . $CouldNotIDPW{$User} . " Time(s)\n";
}
}
if (@PWChanges) {
print "\nPassword Changes:\n";
foreach $Change (@PWChanges) {
print " " . $Change . "\n";
}
}
if (($Detail >= 5) and (@BadName)) {
print "\nBad Usernames Received:\n";
foreach $User (@BadName) {
print " " . $User . "\n";
}
}
if (@Expired) {
print "\nExpired User Accounts:\n";
foreach $User (@Expired) {
print " " . $User . "\n";
}
}
if (keys %OpenedSessions) {
print "\nOpened Sessions:\n";
foreach $Service (keys %OpenedSessions) {
print " Service: " . $Service . "\n";
foreach $User (keys %{$OpenedSessions{$Service}}) {
print " User " . $User . " - " . ${$OpenedSessions{$Service}}{$User} . " Time(s)\n";
}
}
}
if (keys %RemoteLogins) {
print "\nRemote Logins:\n";
foreach $User (keys %RemoteLogins) {
print " User " . $User . ":\n";
foreach $Remote (keys %{$RemoteLogins{$User}} ) {
print " Remote Host " . $Remote . " - " . ${$RemoteLogins{$User}}{$Remote} . " Time(s)\n";
}
}
}
if (keys %LocalLogins) {
print "\nLocal Logins:\n";
foreach $User (keys %LocalLogins) {
print " " . $User . " - " . $LocalLogins{$User} . " Time(s)\n";
}
}
if (keys %RootLogins) {
print "\nRoot Logins:\n";
foreach $tty (keys %RootLogins) {
print " " . $tty . ": " . $RootLogins{$tty} . " time(s)\n";
}
}
if (($Detail >= 5) and (keys %AuthFailures)) {
print "\nAuthentication Failures:\n";
foreach $Users (keys %AuthFailures) {
print " " . $Users . "\n";
foreach $Service (keys %{$AuthFailures{$Users}}) {
print " Service: " . $Service . ": " . ${$AuthFailures{$Users}}{$Service} . " time(s)\n";
}
}
}
if (($Detail >= 5) and (keys %FailedLogins)) {
print "\nLogin Failures:\n";
foreach $RemoteHost (keys %FailedLogins) {
print " " . $RemoteHost . ": ";
foreach $User ( @{$FailedLogins{$RemoteHost}} ) {
print $User . ", ";
}
print "\n";
}
}
if (keys %OtherList) {
print "\n**Unmatched Entries**\n";
foreach $line (sort {$a cmp $b} keys %OtherList) {
print "$line: $OtherList{$line} Time(s)\n";
}
}
exit(0);
# vi: shiftwidth=3 tabstop=3 et
|