Projet

Général

Profil

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

root / plugins / debian / debsecan_ @ 1eb83ab6

Historique | Voir | Annoter | Télécharger (5,59 ko)

1
#!/bin/sh
2

    
3
: << =cut
4

    
5
=head1 NAME
6

    
7
debsecan - Plugin to monitor the number of CVE vulnerabilities present on a Debian-ish
8
system (using debsecan). This plugin can either report the sum of vulnerabilities present in each packages ('pkg' mode, default), or the number of unique CVEs affecting the system ('cve' mode).
9

    
10
The 'cve' mode is a better indication of the risk level of the system (as
11
multiple packages with the same vulnerable source get counted repeatedly), but
12
the 'pkg' provides valuable information to identify packages with high number
13
of vulnerabilities that should be considered for deletion.
14

    
15
Simply symlink this plugin into your Munin plugins directory as
16
- debsecan_pkg (the extra_info will list the number of CVE affecting each package)
17
- debsecan_cve (the extra_info will list the number of packages affected by each CVE)
18

    
19
For backward compatibility, a symlink without a mode will default to 'pkg'.
20

    
21
=head1 CONFIGURATION
22

    
23
The default configuration is as follows.
24

    
25
    [debsecan]
26
    env.suite jessie
27
    env.fixed_warning 1
28
    env.fixed_critical 1000
29
    env.remote_warning 1
30
    env.remote_critical 10
31

    
32
The name of the group needs to match the name of the symlink to be applied.
33
Shell globbing patterns are allowed.
34

    
35
=head1 AUTHORS
36

    
37
* Nicolas BOUTHORS <nbouthors@nbi.fr> http://nbi.fr/, Inspiration of the moment 10/10/2007
38
* Olivier Mehani <shtrom+munin@ssji.net>, 2016
39

    
40
=head1 LICENSE
41

    
42
Public Domain
43

    
44
=head1 MAGIC MARKERS
45

    
46
%# family=auto
47
%# capabilities=autoconf
48

    
49
=cut
50

    
51
# Auto enable if we have debsecan only
52
if [ "$1" = "autoconf" ] ; then
53
  if [ -x /usr/bin/debsecan ]; then
54
    echo yes
55
  else
56
    echo 'no (/usr/bin/debsecan not found)'
57
  fi
58
  exit 0
59
fi
60

    
61
# Fail if we don't have debsecan
62
if [ ! -x /usr/bin/debsecan ]; then
63
  echo 'error: /usr/bin/debsecan not found' >&2
64
  exit 1
65
fi
66

    
67
SUITE=${suite:-sid}
68
FIXEDWARN=${fixed_warning:-1}
69
FIXEDCRIT=${fixed_critical:-1000}
70
REMOTEWARN=${remote_warning:-1}
71
REMOTECRIT=${remote_critical:-10}
72

    
73
MODE=$(echo "$0" | sed 's/.*_//')
74
case "${MODE}" in
75
	'cve')
76
		TITLE_ADD="unique "
77
		FIELD=1
78
		;;
79
	'pkg' | *)
80
		TITLE_ADD="package "
81
		FIELD=2
82
		;;
83
esac
84

    
85
if [ "$1" = "config" ] ; then
86
  cat <<EOF_
87
graph_title DebSecan: ${TITLE_ADD}vulnerabilities for ${SUITE}
88
graph_args -l 0 --base 1000
89
graph_vlabel number of CVE
90
graph_category system
91
graph_period second
92
graph_info This graph show the number of known ${TITLE_ADD}vulnerabilities present on your system. Use debsecan to see details.
93
remote.label remote
94
remote.colour FF0000
95
remote.type GAUGE
96
remote.draw AREASTACK
97
remote.min 0
98
remote.info The number of ${TITLE_ADD}remotely exploitable CVEs with any priority
99
remote.warning ${REMOTEWARN}
100
remote.critical ${REMOTECRIT}
101
high.label high
102
high.colour DD2200
103
high.type GAUGE
104
high.draw AREASTACK
105
high.min 0
106
high.info The number of ${TITLE_ADD}CVEs marked high priority
107
medium.label medium
108
medium.colour FFAA00
109
medium.type GAUGE
110
medium.draw AREASTACK
111
medium.min 0
112
medium.info The number of ${TITLE_ADD}CVEs marked medium priority
113
low.label low
114
low.colour 0000FF
115
low.type GAUGE
116
low.draw AREASTACK
117
low.min 0
118
low.info The number of ${TITLE_ADD}CVEs marked low priority
119
other.label other
120
other.colour 00AAFF
121
other.type GAUGE
122
other.draw AREASTACK
123
other.min 0
124
other.info The number of ${TITLE_ADD}CVEs with unspecified priority
125
fixed.label fixed
126
fixed.type GAUGE
127
fixed.draw LINE2
128
fixed.min 0
129
fixed.info The number of ${TITLE_ADD}CVEs fixed by available updates
130
fixed.warning ${FIXEDWARN}
131
fixed.critical ${FIXEDCRIT}
132
EOF_
133
  exit 0
134
fi
135

    
136
ALL=$(debsecan --suite "${SUITE}" 2> /dev/null)
137
REMOTE=$(echo "$ALL" | grep -w 'remotely')
138
NONREMOTE=$(echo "$ALL" | grep -wv 'remotely')
139

    
140
HIGH=$(echo "${NONREMOTE}" | grep -w 'high urgency')
141
MEDIUM=$(echo "${NONREMOTE}" | grep -w 'medium urgency')
142
LOW=$(echo "${NONREMOTE}" | grep -w 'low urgency')
143
OTHER=$(echo "${NONREMOTE}" | grep -wv 'urgency')
144
FIXED=$(echo "${ALL}" | grep -w '(fixed')
145

    
146
# Arguments: Field offset to aggregate by
147
count_entries() {
148
	CUT_FIELD="${1}"
149
	cut -f "${CUT_FIELD}" -d " "| sort | uniq -c
150
}
151

    
152
case "${MODE}" in
153
	'cve')
154
		remote_count=$(echo "${REMOTE}" | count_entries "${FIELD}" | wc -l)
155
		high_count=$(echo "${HIGH}" | count_entries "${FIELD}" | wc -l)
156
		medium_count=$(echo "${MEDIUM}" | count_entries "${FIELD}" | wc -l)
157
		low_count=$(echo "${LOW}" | count_entries "${FIELD}" | wc -l)
158
		other_count=$(echo "${OTHER}" | count_entries "${FIELD}" | wc -l)
159
		fixed_count=$(echo "${FIXED}" | count_entries "${FIELD}" | wc -l)
160
		;;
161
	'pkg' | *)
162
		remote_count=$(echo "${REMOTE}" | wc -l)
163
		high_count=$(echo "${HIGH}" | wc -l)
164
		medium_count=$(echo "${MEDIUM}" | wc -l)
165
		low_count=$(echo "${LOW}" | wc -l)
166
		other_count=$(echo "${OTHER}" | wc -l)
167
		fixed_count=$(echo "${FIXED}" | wc -l)
168
		;;
169
esac
170

    
171
# Reformat the output of the cut|sort|uniq... to a more human-friendly "item (count)" format
172
CVECOUNTRE="s/^ *\([0-9]\+\) \+\([^ ]\+\)/\2 (\1)/"
173

    
174
# shellcheck disable=SC2005 disable=SC2046
175
# The nested $(echo ...)s are needed to yet the newlines
176
cat <<EOF
177
remote.value $remote_count
178
remote.extinfo $(echo $(echo "${REMOTE}" | count_entries "${FIELD}" | sort -nr | sed "${CVECOUNTRE}"))
179
high.value $high_count
180
high.extinfo $(echo $(echo "${HIGH}" | count_entries "${FIELD}" | sort -nr | sed "${CVECOUNTRE}"))
181
medium.value $medium_count
182
medium.extinfo $(echo $(echo "${MEDIUM}" | count_entries "${FIELD}" | sort -nr | sed "${CVECOUNTRE}"))
183
low.value $low_count
184
low.extinfo $(echo $(echo "${LOW}" | count_entries "${FIELD}" | sort -nr | sed "${CVECOUNTRE}"))
185
other.value $other_count
186
other.extinfo $(echo $(echo "${OTHER}" | count_entries "${FIELD}" | sort -nr | sed "${CVECOUNTRE}"))
187
fixed.value $fixed_count
188
fixed.extinfo $(echo $(echo "${FIXED}" | count_entries "${FIELD}" | sort -nr | sed "${CVECOUNTRE}"))
189
EOF