~ubuntu-security/ubuntu-cve-tracker/master

« back to all changes in this revision

Viewing changes to scripts/monthly-report

  • Committer: Steve Beattie
  • Date: 2019-02-19 06:18:27 UTC
  • Revision ID: sbeattie@ubuntu.com-20190219061827-oh57fzcfc1u9dlfk
The ubuntu-cve-tracker project has been converted to git.

Please use 'git clone https://git.launchpad.net/ubuntu-cve-tracker' to
get the converted tree.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/bin/bash
2
 
# Copyright (C) 2008-2011 Canonical, Ltd.
3
 
# Author: Kees Cook <kees@ubuntu.com>
4
 
# Author: Jamie Strandboge <jamie@ubuntu.com>
5
 
# License: GPLv3
6
 
#
7
 
# This script attempts to build up statistics for a monthly report on
8
 
# security update activity on USNs, triage, and outstanding tasks.
9
 
# It is designed to be run on the month _following_ the month one wants
10
 
# a report for. e.g. run this script in April if you want the March report.
11
 
#
12
 
# By default, report in a more prose-style. E.g.:
13
 
#  The security team had a busy month. We published 29 Ubuntu Security
14
 
#  Notices which fixed 63 security issues (CVEs) across 30 supported
15
 
#  packages. Additionally, we triaged 487 public security vulnerability
16
 
#  reports, retaining only those that applied to Ubuntu.
17
 
#
18
 
#  For all the supported packages in Ubuntu, there are 67 medium-priority
19
 
#  issues and 206 low issues that need to be fixed in 142 packages.
20
 
#
21
 
#  For all partner packages in Ubuntu, there is 1 medium-priority issue
22
 
#  that needs to be fixed in 1 package.
23
 
#
24
 
#  For all community-supported packages in Ubuntu, there are 7 high-priority
25
 
#  issues, 721 medium-priority, and 1005 low-priority issues that need to be
26
 
#  fixed in 686 packages.
27
 
set -e
28
 
export LANG=C
29
 
 
30
 
help() {
31
 
    cat <<EOM
32
 
This script attempts to build up statistics for a monthly report on
33
 
security update activity on USNs, triage, and outstanding tasks.
34
 
It is designed to be run on the month _following_ the month one wants
35
 
a report for. e.g. run this script in April if you want the March report.
36
 
 
37
 
Typical usage:
38
 
$ $UCT/scripts/`basename $0`
39
 
 
40
 
Can also specify different months with:
41
 
$ $UCT/scripts/`basename $0` <first> <second>
42
 
 
43
 
Eg:
44
 
$ $UCT/scripts/`basename $0` March April
45
 
EOM
46
 
}
47
 
 
48
 
use_cached_usndb=
49
 
if [ "$1" = "-h" ] || [ "$1" = "--help" ]; then
50
 
    help
51
 
    exit 0
52
 
elif [ "$1" = "--cache" ]; then
53
 
    use_cached_usndb="yes"
54
 
    shift
55
 
fi
56
 
 
57
 
# Make sure we won't destroy any pending commits
58
 
bzr diff >/dev/null || {
59
 
    echo "Aborting: uncommitted changes. Please use 'bzr commit' before proceeding" >&2
60
 
    exit 1
61
 
}
62
 
 
63
 
REP_MON=$(date +%B -d 'last month')
64
 
REP_MONN=$(date +%m -d 'last month')
65
 
REP_YEAR=$(date +%Y -d 'last month')
66
 
 
67
 
THIS_MONN=$(date +%m)
68
 
THIS_YEAR=$(date +%Y)
69
 
 
70
 
if [ -n "$1" ] && [ -n "$2" ]; then
71
 
    REP_MON=$(date +%B -d "$1 01")
72
 
    REP_MONN=$(date +%m -d "$1 01")
73
 
    REP_YEAR=$(date +%Y -d "$1 01")
74
 
 
75
 
    THIS_MONN=$(date +%m -d "$2 01")
76
 
    THIS_YEAR=$(date +%Y -d "$2 01")
77
 
    if [ "$THIS_MONN" -lt "$REP_MONN" ]; then
78
 
        THIS_YEAR=$(($THIS_YEAR + 1))
79
 
    fi
80
 
fi
81
 
 
82
 
echo "Fetching USN publication list..." >&2
83
 
USNS=$(echo $(curl -s https://lists.ubuntu.com/archives/ubuntu-security-announce/$REP_YEAR-$REP_MON/date.html | fgrep '">[USN-'  | cut -d- -f2,3 | cut -d\] -f1))
84
 
 
85
 
echo "Fetching USN database..." >&2
86
 
if [ "$use_cached_usndb" = "yes" ] && [ -f "./database.pickle" ]; then
87
 
    echo "(skipped-- using cached ./database.pickle)"
88
 
else
89
 
    if grep -q people ~/.ssh/config; then
90
 
        rsync -q -e ssh people.canonical.com:~ubuntu-security/public_html/usn/database.pickle ./database.pickle
91
 
    else
92
 
        ./scripts/fetch-db database.pickle.bz2
93
 
    fi
94
 
fi
95
 
PUBLISHED=$(./scripts/report-usn-numbers.py --prose database.pickle $USNS)
96
 
 
97
 
# We depend on a script to perform output while the tree is reverted, so
98
 
# copy the script out of the tree for later use.
99
 
SCRIPTS=$(mktemp -d -t monthly-report-XXXXXX)
100
 
for i in report-todo-numbers check-cves cache_urllib.py cve_lib.py source_map.py usn_lib.py
101
 
do
102
 
    cp -a scripts/$i "$SCRIPTS"/$i
103
 
done
104
 
 
105
 
TMP1=$(mktemp -t work1-XXXXXX)
106
 
TMP2=$(mktemp -t work2-XXXXXX)
107
 
TMP1_UBUNTU=$(mktemp -t work1u-XXXXXX)
108
 
TMP2_UBUNTU=$(mktemp -t work2u-XXXXXX)
109
 
if [ ! -x "scripts/monthly-report" ]; then
110
 
    echo "Please run this from the top-level directory of Ubuntu CVE Tracker"
111
 
    exit 1
112
 
fi
113
 
 
114
 
bzr_rewind ()
115
 
{
116
 
    local changed count
117
 
 
118
 
    count=0
119
 
    changed="$1"
120
 
    while :; do
121
 
        bzr revert -r date:"$changed" >/dev/null 2>&1 && break
122
 
        changed=$(date +%Y-%m-%d -d "$changed - 1 day")
123
 
        count=$(( count + 1 ))
124
 
        if [ "$count" -gt 32 ]; then
125
 
            echo "Eeek, rewound from $1 past $changed.  Something is wrong."
126
 
            exit 1
127
 
        fi
128
 
    done
129
 
    #echo "rewound to $changed"
130
 
}
131
 
 
132
 
 
133
 
echo "Rewinding bzr tree for stats..." >&2
134
 
# Locate the last day something changed
135
 
bzr_rewind $(date +%Y-%m-%d -d "$REP_YEAR-$REP_MONN-01 - 1 day")
136
 
# Gather stats at the time
137
 
$SCRIPTS/check-cves --known > "$TMP1"
138
 
$SCRIPTS/check-cves --known --skip-nfu > "$TMP1_UBUNTU"
139
 
 
140
 
echo "Fast-forwarding bzr tree for stats..." >&2
141
 
# Fast-forward to end of month
142
 
bzr revert >/dev/null 2>&1
143
 
last_month_end=`date +%Y-%m-%d -d "$THIS_YEAR-$THIS_MONN-01 - 1 day"`
144
 
last_month_fn=`date +%B -d "$THIS_YEAR-$THIS_MONN-01 - 1 day"`
145
 
bzr_rewind "$last_month_end"
146
 
$SCRIPTS/check-cves --known > "$TMP2"
147
 
$SCRIPTS/check-cves --known --skip-nfu > "$TMP2_UBUNTU"
148
 
WORK=$($SCRIPTS/report-todo-numbers --prose --show-unique-sources --skip-low -E -- -S)
149
 
 
150
 
echo "Returning bzr tree to present-day..." >&2
151
 
# Get back to normal
152
 
bzr revert >/dev/null 2>&1
153
 
 
154
 
# Calculate difference
155
 
TRIAGED=$(diff -u "$TMP1" "$TMP2" | grep '^+CVE' | wc -l)
156
 
rm -f "$TMP1" "$TMP2"
157
 
FOR_US=$(diff -u "$TMP1_UBUNTU" "$TMP2_UBUNTU" | grep '^+CVE' | wc -l)
158
 
rm -f "$TMP1_UBUNTU" "$TMP2_UBUNTU"
159
 
rm -rf "$SCRIPTS"
160
 
 
161
 
# Report!
162
 
echo ""
163
 
echo "Add the following template text to https://wiki.canonical.com/UbuntuEngineering/MonthlyReport:"
164
 
echo ""
165
 
echo "=== Development ==="
166
 
echo " * TO BE FILLED IN (eg, look at statuses from team)"
167
 
echo ""
168
 
echo "== Security =="
169
 
echo "=== Reactive ==="
170
 
echo "In the month of $last_month_fn, the Ubuntu Security team:"
171
 
echo " * $PUBLISHED"
172
 
echo " * Triaged $TRIAGED public security vulnerability reports, retaining the $FOR_US that applied to Ubuntu."
173
 
 
174
 
echo ""
175
 
echo "As of the end of $last_month_fn (${last_month_end}):"
176
 
echo "$WORK"
177
 
 
178