Projet

Général

Profil

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

root / plugins / debian / debsecan_ @ f23aa079

Historique | Voir | Annoter | Télécharger (5,78 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
* Wilco de Boer <deboer.wilco@gmail.com>, 2021
40

    
41
=head1 LICENSE
42

    
43
Public Domain
44

    
45
=head1 MAGIC MARKERS
46

    
47
#%# family=auto
48
#%# capabilities=autoconf suggest
49

    
50
=cut
51

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

    
62
# Suggest both modes when asked
63
if [ "$1" = "suggest" ]; then
64
  echo 'pkg'
65
  echo 'cve'
66
  exit 0
67
fi
68

    
69
# Fail if we don't have debsecan
70
if [ ! -x /usr/bin/debsecan ]; then
71
  echo 'error: /usr/bin/debsecan not found' >&2
72
  exit 1
73
fi
74

    
75
SUITE=${suite:-sid}
76
FIXEDWARN=${fixed_warning:-1}
77
FIXEDCRIT=${fixed_critical:-1000}
78
REMOTEWARN=${remote_warning:-1}
79
REMOTECRIT=${remote_critical:-10}
80

    
81
MODE=$(echo "$0" | sed 's/.*_//')
82
case "${MODE}" in
83
	'cve')
84
		TITLE_ADD="unique "
85
		FIELD=1
86
		;;
87
	'pkg' | *)
88
		TITLE_ADD="package "
89
		FIELD=2
90
		;;
91
esac
92

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

    
145
ALL=$(debsecan --suite "${SUITE}" 2> /dev/null)
146
REMOTE=$(echo "$ALL" | grep -w 'remotely')
147
NONREMOTE=$(echo "$ALL" | grep -wv 'remotely')
148

    
149
HIGH=$(echo "${NONREMOTE}" | grep -w 'high urgency')
150
MEDIUM=$(echo "${NONREMOTE}" | grep -w 'medium urgency')
151
LOW=$(echo "${NONREMOTE}" | grep -w 'low urgency')
152
OTHER=$(echo "${NONREMOTE}" | grep -wv 'urgency')
153
FIXED=$(echo "${ALL}" | grep -w '(fixed')
154

    
155
# Arguments: Field offset to aggregate by
156
count_entries() {
157
	CUT_FIELD="${1}"
158
	cut -f "${CUT_FIELD}" -d " "| sort | uniq -c
159
}
160

    
161
case "${MODE}" in
162
	'cve')
163
		remote_count=$(echo "${REMOTE}" | count_entries "${FIELD}" | wc -l)
164
		high_count=$(echo "${HIGH}" | count_entries "${FIELD}" | wc -l)
165
		medium_count=$(echo "${MEDIUM}" | count_entries "${FIELD}" | wc -l)
166
		low_count=$(echo "${LOW}" | count_entries "${FIELD}" | wc -l)
167
		other_count=$(echo "${OTHER}" | count_entries "${FIELD}" | wc -l)
168
		fixed_count=$(echo "${FIXED}" | count_entries "${FIELD}" | wc -l)
169
		;;
170
	'pkg' | *)
171
		remote_count=$(echo "${REMOTE}" | wc -l)
172
		high_count=$(echo "${HIGH}" | wc -l)
173
		medium_count=$(echo "${MEDIUM}" | wc -l)
174
		low_count=$(echo "${LOW}" | wc -l)
175
		other_count=$(echo "${OTHER}" | wc -l)
176
		fixed_count=$(echo "${FIXED}" | wc -l)
177
		;;
178
esac
179

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

    
183
# shellcheck disable=SC2005 disable=SC2046
184
# The nested $(echo ...)s are needed to yet the newlines
185
cat <<EOF
186
remote.value $remote_count
187
remote.extinfo $(echo $(echo "${REMOTE}" | count_entries "${FIELD}" | sort -nr | sed "${CVECOUNTRE}"))
188
high.value $high_count
189
high.extinfo $(echo $(echo "${HIGH}" | count_entries "${FIELD}" | sort -nr | sed "${CVECOUNTRE}"))
190
medium.value $medium_count
191
medium.extinfo $(echo $(echo "${MEDIUM}" | count_entries "${FIELD}" | sort -nr | sed "${CVECOUNTRE}"))
192
low.value $low_count
193
low.extinfo $(echo $(echo "${LOW}" | count_entries "${FIELD}" | sort -nr | sed "${CVECOUNTRE}"))
194
other.value $other_count
195
other.extinfo $(echo $(echo "${OTHER}" | count_entries "${FIELD}" | sort -nr | sed "${CVECOUNTRE}"))
196
fixed.value $fixed_count
197
fixed.extinfo $(echo $(echo "${FIXED}" | count_entries "${FIELD}" | sort -nr | sed "${CVECOUNTRE}"))
198
EOF