Projet

Général

Profil

Paste
Télécharger au format
Statistiques
| Branche: | Révision:

root / plugins / ssh / sshd_log @ ff68f641

Historique | Voir | Annoter | Télécharger (4,05 ko)

1
#!/bin/sh
2
#
3
# Plugin to monitor auth.log or journald for sshd server events.
4
#
5
# Require read permitions for $LOG or journald
6
#  (set in /etc/munin/plugin-conf.d/munin-node on debian)
7
#
8
# $Log$
9
# Revision 2.0  2016/11/11 15:42:00  Thomas Riccardi
10
# Revision 1.2  2010/03/19 15:03:00  pmoranga
11
# Revision 1.1  2009/04/26 23:28:00  ckujau
12
# Revision 1.0  2009/04/22 22:00:00  zlati
13
# Initial revision
14
#
15
# Parameters:
16
#
17
#       config   (required)
18
#       autoconf (optional - used by munin-config)
19
#
20
# Magick markers (optional):
21
#%# family=auto
22
#%# capabilities=autoconf
23

    
24
# config example for /etc/munin/plugin-conf.d/munin-node
25
#[sshd_log]
26
#user root
27
#group root
28
#env.logfile /var/log/messages
29
#env.category users
30
#
31
# config example with journald
32
#[sshd_log]
33
#group systemd-journal
34
#env.logfile journald
35
#
36
# config example with journald on the sshd.service unit only
37
#[sshd_log]
38
#group systemd-journal
39
#env.logfile journald
40
#env.journalctlarg --unit=sshd.service
41
#
42

    
43
LOG=${logfile:-/var/log/secure}
44
JOURNALCTL_ARG=${journalctlarg:-_COMM=sshd}
45

    
46

    
47
if [ "$1" = "autoconf" ]; then
48
        if [ "$LOG" = "journald" ]; then
49
                if journalctl --no-pager --quiet --lines=1 "$JOURNALCTL_ARG" | read -r DUMMY; then
50
                        echo "yes"
51
                else
52
                        echo "no (journald empty log for '$JOURNALCTL_ARG' not found)"
53
                fi
54
        else
55
                if [ -r "$LOG" ]; then
56
                        echo "yes"
57
                else
58
                        echo "no (logfile '$LOG' not readable)"
59
                fi
60
        fi
61
        exit 0
62
fi
63

    
64
if [ "$1" = "config" ]; then
65

    
66
        if [ "$LOG" = "journald" ]; then
67
                TYPE=ABSOLUTE
68
        else
69
                TYPE=DERIVE
70
        fi
71

    
72
        echo 'graph_title SSHD login stats from' "$LOG"
73
        echo 'graph_args --base 1000 -l 0'
74
        echo 'graph_vlabel logins'
75
        echo 'graph_category' security
76

    
77
        echo 'LogPass.label Successful password logins'
78
        echo 'LogPass.min 0'
79
        echo 'LogPass.type' "$TYPE"
80

    
81
        echo 'LogPassPAM.label Successful login via PAM'
82
        echo 'LogPassPAM.min 0'
83
        echo 'LogPassPAM.type' "$TYPE"
84

    
85
        echo 'LogKey.label Successful PublicKey logins'
86
        echo 'LogKey.min 0'
87
        echo 'LogKey.type' "$TYPE"
88

    
89
        echo 'NoID.label No identification from user'
90
        echo 'NoID.min 0'
91
        echo 'NoID.type' "$TYPE"
92

    
93
        echo 'rootAttempt.label Root login attempts'
94
        echo 'rootAttempt.min 0'
95
        echo 'rootAttempt.type' "$TYPE"
96

    
97
        echo 'InvUsr.label Invalid user login attepmts'
98
        echo 'InvUsr.min 0'
99
        echo 'InvUsr.type' "$TYPE"
100

    
101
        echo 'NoRDNS.label No reverse DNS for peer'
102
        echo 'NoRDNS.min 0'
103
        echo 'NoRDNS.type' "$TYPE"
104

    
105
        echo 'Breakin.label Potential Breakin Attempts'
106
        echo 'Breakin.min 0'
107
        echo 'Breakin.type' "$TYPE"
108

    
109
        exit 0
110
fi
111

    
112
if [ "$LOG" = "journald" ]; then
113
        CURSOR_FILE="$MUNIN_STATEFILE"
114
        # read cursor
115
        # format: "journald-cursor <cursor>"
116
        CURSOR=
117
        if [ -f "$CURSOR_FILE" ]; then
118
                CURSOR=$(awk '/^journald-cursor / {print $2}' "$CURSOR_FILE")
119
        fi
120
else
121
        CURSOR_FILE=
122
fi
123

    
124
if [ "$LOG" = "journald" ]; then
125
        journalctl --no-pager --quiet --show-cursor ${CURSOR:+"--after-cursor=$CURSOR"} "$JOURNALCTL_ARG"
126
else
127
        cat "$LOG"
128
fi | \
129
    awk -v cursor_file="$CURSOR_FILE" 'BEGIN{c["LogPass"]=0;c["LogKey"]=0;c["NoID"]=0;c["rootAttempt"]=0;c["InvUsr"]=0;c["LogPassPAM"]=0;c["Breakin"]=0;c["NoRDNS"]=0; }
130
     /sshd\[.*Accepted password for/{c["LogPass"]++}
131
     /sshd\[.*Accepted publickey for/{c["LogKey"]++}
132
     /sshd\[.*Did not receive identification string/{c["NoID"]++}
133
     /sshd\[.*Failed password for root/{c["rootAttempt"]++}
134
     /sshd\[.*Invalid user/{c["InvUsr"]++}
135
     /sshd\[.*POSSIBLE BREAK-IN ATTEMPT!/{c["Breakin"]++}
136
     /sshd\[.*keyboard-interactive\/pam/{c["LogPassPAM"]++}
137
     /sshd\[.*reverse mapping checking getaddrinfo/{c["NoRDNS"]++}a
138
     END{if (cursor_file != "") { print "journald-cursor " $3 > cursor_file };for(i in c){print i".value " c[i]} }'