root / plugins / debian / debsecan_ @ 3abb60e3
Historique | Voir | Annoter | Télécharger (5,62 ko)
| 1 | be789bca | Olivier Mehani | #!/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 | 1eb83ab6 | Neraud | env.fixed_warning 1 |
| 28 | be789bca | Olivier Mehani | env.fixed_critical 1000 |
| 29 | 1eb83ab6 | Neraud | env.remote_warning 1 |
| 30 | be789bca | Olivier Mehani | 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 | 75a476c2 | Olivier Mehani | FIELD=1 |
| 78 | be789bca | Olivier Mehani | ;; |
| 79 | 'pkg' | *) |
||
| 80 | TITLE_ADD="package " |
||
| 81 | 75a476c2 | Olivier Mehani | FIELD=2 |
| 82 | be789bca | Olivier Mehani | ;; |
| 83 | esac |
||
| 84 | |||
| 85 | if [ "$1" = "config" ] ; then |
||
| 86 | cat <<EOF_ |
||
| 87 | 3abb60e3 | Olivier Mehani | graph_title DebSecan: ${TITLE_ADD}vulnerabilities
|
| 88 | graph_info ${TITLE_ADD}vulnerabilities for ${SUITE}
|
||
| 89 | be789bca | Olivier Mehani | graph_args -l 0 --base 1000 |
| 90 | graph_vlabel number of CVE |
||
| 91 | graph_category system |
||
| 92 | graph_period second |
||
| 93 | graph_info This graph show the number of known ${TITLE_ADD}vulnerabilities present on your system. Use debsecan to see details.
|
||
| 94 | remote.label remote |
||
| 95 | remote.colour FF0000 |
||
| 96 | remote.type GAUGE |
||
| 97 | remote.draw AREASTACK |
||
| 98 | remote.min 0 |
||
| 99 | remote.info The number of ${TITLE_ADD}remotely exploitable CVEs with any priority
|
||
| 100 | remote.warning ${REMOTEWARN}
|
||
| 101 | remote.critical ${REMOTECRIT}
|
||
| 102 | high.label high |
||
| 103 | high.colour DD2200 |
||
| 104 | high.type GAUGE |
||
| 105 | high.draw AREASTACK |
||
| 106 | high.min 0 |
||
| 107 | high.info The number of ${TITLE_ADD}CVEs marked high priority
|
||
| 108 | medium.label medium |
||
| 109 | medium.colour FFAA00 |
||
| 110 | medium.type GAUGE |
||
| 111 | medium.draw AREASTACK |
||
| 112 | medium.min 0 |
||
| 113 | medium.info The number of ${TITLE_ADD}CVEs marked medium priority
|
||
| 114 | low.label low |
||
| 115 | low.colour 0000FF |
||
| 116 | low.type GAUGE |
||
| 117 | low.draw AREASTACK |
||
| 118 | low.min 0 |
||
| 119 | low.info The number of ${TITLE_ADD}CVEs marked low priority
|
||
| 120 | other.label other |
||
| 121 | other.colour 00AAFF |
||
| 122 | other.type GAUGE |
||
| 123 | other.draw AREASTACK |
||
| 124 | other.min 0 |
||
| 125 | other.info The number of ${TITLE_ADD}CVEs with unspecified priority
|
||
| 126 | fixed.label fixed |
||
| 127 | fixed.type GAUGE |
||
| 128 | fixed.draw LINE2 |
||
| 129 | fixed.min 0 |
||
| 130 | fixed.info The number of ${TITLE_ADD}CVEs fixed by available updates
|
||
| 131 | fixed.warning ${FIXEDWARN}
|
||
| 132 | fixed.critical ${FIXEDCRIT}
|
||
| 133 | EOF_ |
||
| 134 | exit 0 |
||
| 135 | fi |
||
| 136 | |||
| 137 | ALL=$(debsecan --suite "${SUITE}" 2> /dev/null)
|
||
| 138 | 75a476c2 | Olivier Mehani | REMOTE=$(echo "$ALL" | grep -w 'remotely') |
| 139 | NONREMOTE=$(echo "$ALL" | grep -wv 'remotely') |
||
| 140 | be789bca | Olivier Mehani | |
| 141 | 75a476c2 | Olivier Mehani | HIGH=$(echo "${NONREMOTE}" | grep -w 'high urgency')
|
| 142 | MEDIUM=$(echo "${NONREMOTE}" | grep -w 'medium urgency')
|
||
| 143 | LOW=$(echo "${NONREMOTE}" | grep -w 'low urgency')
|
||
| 144 | OTHER=$(echo "${NONREMOTE}" | grep -wv 'urgency')
|
||
| 145 | FIXED=$(echo "${ALL}" | grep -w '(fixed')
|
||
| 146 | |||
| 147 | # Arguments: Field offset to aggregate by |
||
| 148 | count_entries() {
|
||
| 149 | b2d742b2 | Olivier Mehani | CUT_FIELD="${1}"
|
| 150 | 75a476c2 | Olivier Mehani | cut -f "${CUT_FIELD}" -d " "| sort | uniq -c
|
| 151 | } |
||
| 152 | be789bca | Olivier Mehani | |
| 153 | case "${MODE}" in
|
||
| 154 | 'cve') |
||
| 155 | b2d742b2 | Olivier Mehani | remote_count=$(echo "${REMOTE}" | count_entries "${FIELD}" | wc -l)
|
| 156 | high_count=$(echo "${HIGH}" | count_entries "${FIELD}" | wc -l)
|
||
| 157 | medium_count=$(echo "${MEDIUM}" | count_entries "${FIELD}" | wc -l)
|
||
| 158 | low_count=$(echo "${LOW}" | count_entries "${FIELD}" | wc -l)
|
||
| 159 | other_count=$(echo "${OTHER}" | count_entries "${FIELD}" | wc -l)
|
||
| 160 | fixed_count=$(echo "${FIXED}" | count_entries "${FIELD}" | wc -l)
|
||
| 161 | be789bca | Olivier Mehani | ;; |
| 162 | 'pkg' | *) |
||
| 163 | remote_count=$(echo "${REMOTE}" | wc -l)
|
||
| 164 | high_count=$(echo "${HIGH}" | wc -l)
|
||
| 165 | medium_count=$(echo "${MEDIUM}" | wc -l)
|
||
| 166 | low_count=$(echo "${LOW}" | wc -l)
|
||
| 167 | other_count=$(echo "${OTHER}" | wc -l)
|
||
| 168 | fixed_count=$(echo "${FIXED}" | wc -l)
|
||
| 169 | ;; |
||
| 170 | esac |
||
| 171 | |||
| 172 | # Reformat the output of the cut|sort|uniq... to a more human-friendly "item (count)" format |
||
| 173 | 7fed3b97 | Lars Kruse | CVECOUNTRE='s/^ *\([0-9]\+\) \+\([^ ]\+\)/\2 (\1)/' |
| 174 | be789bca | Olivier Mehani | |
| 175 | # shellcheck disable=SC2005 disable=SC2046 |
||
| 176 | # The nested $(echo ...)s are needed to yet the newlines |
||
| 177 | cat <<EOF |
||
| 178 | remote.value $remote_count |
||
| 179 | b2d742b2 | Olivier Mehani | remote.extinfo $(echo $(echo "${REMOTE}" | count_entries "${FIELD}" | sort -nr | sed "${CVECOUNTRE}"))
|
| 180 | be789bca | Olivier Mehani | high.value $high_count |
| 181 | b2d742b2 | Olivier Mehani | high.extinfo $(echo $(echo "${HIGH}" | count_entries "${FIELD}" | sort -nr | sed "${CVECOUNTRE}"))
|
| 182 | be789bca | Olivier Mehani | medium.value $medium_count |
| 183 | b2d742b2 | Olivier Mehani | medium.extinfo $(echo $(echo "${MEDIUM}" | count_entries "${FIELD}" | sort -nr | sed "${CVECOUNTRE}"))
|
| 184 | be789bca | Olivier Mehani | low.value $low_count |
| 185 | b2d742b2 | Olivier Mehani | low.extinfo $(echo $(echo "${LOW}" | count_entries "${FIELD}" | sort -nr | sed "${CVECOUNTRE}"))
|
| 186 | be789bca | Olivier Mehani | other.value $other_count |
| 187 | b2d742b2 | Olivier Mehani | other.extinfo $(echo $(echo "${OTHER}" | count_entries "${FIELD}" | sort -nr | sed "${CVECOUNTRE}"))
|
| 188 | be789bca | Olivier Mehani | fixed.value $fixed_count |
| 189 | b2d742b2 | Olivier Mehani | fixed.extinfo $(echo $(echo "${FIXED}" | count_entries "${FIELD}" | sort -nr | sed "${CVECOUNTRE}"))
|
| 190 | be789bca | Olivier Mehani | EOF |
