| 1 |
#!/usr/bin/perl
|
| 2 |
# Must run on a machine with madison.
|
| 3 |
#
|
| 4 |
# To check for un-updated binary kernel packages, also needs grep-dctrl
|
| 5 |
# and a Sources file for the distribution. Set the location of the Sources
|
| 6 |
# file in SOURCES_FILE in the environment.
|
| 7 |
use warnings;
|
| 8 |
use strict;
|
| 9 |
use URI::Escape;
|
| 10 |
use Getopt::Long;
|
| 11 |
|
| 12 |
my $html=0;
|
| 13 |
my $debug=0;
|
| 14 |
my $suite="testing";
|
| 15 |
my $sta="http://secure-testing.debian.net/debian-secure-testing/dists/testing/security-updates/main/source/Sources.gz";
|
| 16 |
my $output;
|
| 17 |
if (! GetOptions(
|
| 18 |
"html" => \$html,
|
| 19 |
"debug" => \$debug,
|
| 20 |
"suite=s" => \$suite,
|
| 21 |
"sta=s" => \$sta,
|
| 22 |
"output=s", \$output)
|
| 23 |
|| ! @ARGV) {
|
| 24 |
die "usage: $0 [--suite suite] [--sta sta-mirror] [--html] [--output=file] [--debug] list ...\n";
|
| 25 |
}
|
| 26 |
|
| 27 |
my $stasources=`tempfile`;
|
| 28 |
chomp $stasources;
|
| 29 |
system("wget -q -O $stasources $sta");
|
| 30 |
|
| 31 |
if (defined $output) {
|
| 32 |
open (OUT, ">$output.tmp.$$") || die "output.tmp.$$: $!"; # Set the output to a file
|
| 33 |
}
|
| 34 |
else {
|
| 35 |
open (OUT, ">&STDOUT"); # Set the output to stdout
|
| 36 |
}
|
| 37 |
|
| 38 |
if ($html) { # It's HTML, so we need a header
|
| 39 |
print OUT "<html><title>$suite security issues</title>\n";
|
| 40 |
|
| 41 |
# This is being run against something it's not meant to be, so print a warning
|
| 42 |
if ($suite ne 'testing' && $suite ne 'unstable') {
|
| 43 |
print OUT <<"EOF";
|
| 44 |
<p>
|
| 45 |
<em>Warning:</em> This page is the result of running the testing security
|
| 46 |
check script against the $suite distribution. As data is only gathered for
|
| 47 |
the testing distribution, results may be innacurate if a package has
|
| 48 |
changed its name, if a vulnerability affects $suite and not testing, or if a
|
| 49 |
vulnerability has been fixed in $suite by the security team.
|
| 50 |
</p>
|
| 51 |
EOF
|
| 52 |
}
|
| 53 |
print OUT "<ul>\n";
|
| 54 |
}
|
| 55 |
|
| 56 |
|
| 57 |
my %data;
|
| 58 |
my %advlist;
|
| 59 |
my %needkernel=qw/2.4.27 0 2.6.11 0/;
|
| 60 |
my $list_unknown=1; #set to 1 to display kernel images with unknown source version
|
| 61 |
my $sources=$ENV{SOURCES_FILE};
|
| 62 |
my $need_rebuild=0;
|
| 63 |
|
| 64 |
# Set some colours for the urgency types
|
| 65 |
my @urgencies=("high", "medium", "low", "unknown");
|
| 66 |
my %colormap=(
|
| 67 |
high => "#FF0000",
|
| 68 |
medium => "#FF9999",
|
| 69 |
low => "#FFFFFF",
|
| 70 |
unknown => "#FFFF00"
|
| 71 |
);
|
| 72 |
|
| 73 |
my $unprop = my $unprop_all = my $unfixed = my $todos = my $fixedsta = 0;
|
| 74 |
|
| 75 |
# Add an item into the data array.
|
| 76 |
sub record {
|
| 77 |
my ($package, $condition, $item, $urgency)=@_;
|
| 78 |
|
| 79 |
if (! defined $item) {
|
| 80 |
$item='';
|
| 81 |
}
|
| 82 |
|
| 83 |
if ($html) {
|
| 84 |
$condition=~s{bug #(\d+)}{<a href="http://bugs.debian.org/$1">bug #$1</a>}g;
|
| 85 |
$condition=~s{unfixed}{<b>unfixed</b>}g;
|
| 86 |
$item=~s#((?:CAN|CVE)-\d+-\d+)#<a href="http://www.cve.mitre.org/cgi-bin/cvename.cgi?name=$1">$1</a>#g;
|
| 87 |
$item=~s#(DTSA-\d+-\d+)#<a href="http://secure-testing-master.debian.net/DTSA/$1.html">$1</a>#g;
|
| 88 |
}
|
| 89 |
|
| 90 |
push @{$data{$package}{$condition}}, {item => $item, urgency => $urgency};
|
| 91 |
}
|
| 92 |
|
| 93 |
foreach my $list (@ARGV) {
|
| 94 |
# Each of the @ARGVs we've got passed need parsing. So lets do that
|
| 95 |
|
| 96 |
# If it's a directory, set the file to list, cause we need that.
|
| 97 |
if (-d $list) {
|
| 98 |
$list="$list/list";
|
| 99 |
}
|
| 100 |
|
| 101 |
my $id;
|
| 102 |
open (IN, $list) || die "open $list: $!";
|
| 103 |
while (<IN>) {
|
| 104 |
print STDERR "line: $_" if $debug;
|
| 105 |
chomp;
|
| 106 |
if (/\s+TODO/) { # It's a todo item. Add it to the count, and ignore it
|
| 107 |
$todos++;
|
| 108 |
}
|
| 109 |
elsif (/^\[/) { # Checking adv. number for a line starting with [ : Set $id to it
|
| 110 |
($id)=m/((?:DSA|DTSA|CAN|CVE)-[^\s]+) /;
|
| 111 |
}
|
| 112 |
elsif (/^((?:DSA|DTSA|CAN|CVE)-[^\s]+)/) { # Check for a line with an advisory at the start : Set $id to it
|
| 113 |
$id=$1;
|
| 114 |
}
|
| 115 |
elsif (/^\s+[!-]\s+(\S+)\s+(.*?)\s*$/) { # Deal with the rest of the lines
|
| 116 |
my $package=$1; # We know which package it is.
|
| 117 |
my $rest=$2;
|
| 118 |
my $version;
|
| 119 |
my $notes;
|
| 120 |
if ($rest=~/([^\(\s]+)\s+\((.*)\)/) {
|
| 121 |
$version=$1;
|
| 122 |
$notes=$2;
|
| 123 |
}
|
| 124 |
elsif ($rest=~/\((.*)\)/) {
|
| 125 |
$version="";
|
| 126 |
$notes=$1;
|
| 127 |
}
|
| 128 |
else {
|
| 129 |
$version=$rest;
|
| 130 |
$notes="";
|
| 131 |
}
|
| 132 |
|
| 133 |
# by now, we also have the version that's affected by the security problem.
|
| 134 |
# This is stored in $version
|
| 135 |
|
| 136 |
my @notes=split(/\s*;\s+/, $notes);
|
| 137 |
|
| 138 |
# Fetch the urgency, if we can.
|
| 139 |
my $urgency="unknown";
|
| 140 |
foreach my $u (@urgencies) {
|
| 141 |
if (grep { $_ eq $u } @notes) {
|
| 142 |
$urgency=$u;
|
| 143 |
@notes = grep { $_ ne $u } @notes;
|
| 144 |
last;
|
| 145 |
}
|
| 146 |
}
|
| 147 |
|
| 148 |
# It's a kernel. Add it to the list of kernels that need to be looked at.
|
| 149 |
if ($package=~/kernel-source-([0-9.]+)/) {
|
| 150 |
my $kernversion=$1;
|
| 151 |
if (exists $needkernel{$kernversion} &&
|
| 152 |
length $version &&
|
| 153 |
system("dpkg --compare-versions $needkernel{$kernversion} lt $version") != 0) {
|
| 154 |
$needkernel{$kernversion}=$version;
|
| 155 |
}
|
| 156 |
}
|
| 157 |
|
| 158 |
# Fire up madison.
|
| 159 |
my @maddy;
|
| 160 |
for (1..5) {
|
| 161 |
@maddy=`madison -s '$suite' '$package'`;
|
| 162 |
if ($? & 127 || ($? >> 8 != 0 && $? >> 8 != 1)) {
|
| 163 |
# good old unrelaible newraff,
|
| 164 |
# home of our archive..
|
| 165 |
next;
|
| 166 |
}
|
| 167 |
last;
|
| 168 |
}
|
| 169 |
if ($? & 127) {
|
| 170 |
record($package, "<em>[madison segfaulted 5 times in a row.. Medic!]</em>", $id);
|
| 171 |
}
|
| 172 |
elsif ($? >> 8 != 0 && $? >> 8 != 1) {
|
| 173 |
record($package, "<em>[madison exited with ".($? >> 8)."]</em>", $id);
|
| 174 |
}
|
| 175 |
if (! @maddy) {
|
| 176 |
next;
|
| 177 |
}
|
| 178 |
|
| 179 |
if (grep { $_ eq 'unfixed' || $_ eq 'pending' } @notes) {
|
| 180 |
record($package, '('.join("; ", @notes).')', $id, $urgency);
|
| 181 |
$unfixed++;
|
| 182 |
# It's not been fixed!
|
| 183 |
}
|
| 184 |
else {
|
| 185 |
foreach my $maddy (@maddy) {
|
| 186 |
my @fields = split(/\s*\|\s*/, $maddy);
|
| 187 |
my $havver=$fields[1]; # It's this version in the archive I'm checking.
|
| 188 |
my $arches=$fields[3];
|
| 189 |
$version=~s/\s+//; # strip whitespace
|
| 190 |
$arches=~s/\s+$//;
|
| 191 |
# Is the version in the archive the same or newer than the fix?
|
| 192 |
my $cmp=system("dpkg --compare-versions '$havver' '>=' '$version'");
|
| 193 |
if ($cmp != 0){ # No, so the archive is vulnerable.
|
| 194 |
my $starchive = "";
|
| 195 |
|
| 196 |
# Does the version exist in the secure-testing archive?
|
| 197 |
my $staversion = `zcat $stasources |grep-dctrl -F Package -e ^$package\$ -s Version -`;
|
| 198 |
chomp $staversion;
|
| 199 |
$staversion=~s/Version: //;
|
| 200 |
$staversion=~s/\s+//;
|
| 201 |
if (length ($staversion)) {
|
| 202 |
# Yes, but what version is in s-t?
|
| 203 |
my $stacmp = system("dpkg --compare-versions '$staversion' '>=' '$version'");
|
| 204 |
if ($stacmp == 0){
|
| 205 |
# Well, the version in the s-t archive fixes the issue
|
| 206 |
# but it's still vulnerable in the main archive
|
| 207 |
$starchive = " (fixed in $staversion in the secure-testing archive)";
|
| 208 |
$fixedsta++;
|
| 209 |
}
|
| 210 |
}
|
| 211 |
|
| 212 |
if ($html && $suite eq 'testing') {
|
| 213 |
$havver='<a href="http://bjorn.haxx.se/debian/testing.pl?package='.uri_escape($package).'">'.$havver.'</a>';
|
| 214 |
}
|
| 215 |
record($package, "$version needed, have $havver".(@maddy > 1 ? " [$arches]" : "").$starchive, $id, $urgency);
|
| 216 |
$unprop++;
|
| 217 |
$unprop_all++ unless @maddy > 1;
|
| 218 |
}
|
| 219 |
}
|
| 220 |
}
|
| 221 |
}
|
| 222 |
}
|
| 223 |
}
|
| 224 |
|
| 225 |
|
| 226 |
foreach my $package (sort keys %data) {
|
| 227 |
foreach my $condition (sort keys %{$data{$package}}) {
|
| 228 |
print OUT "<li>" if $html;
|
| 229 |
print OUT "$package $condition for ";
|
| 230 |
my $items=0;
|
| 231 |
foreach my $i (sort @{$data{$package}{$condition}}) {
|
| 232 |
print OUT ", " if $items > 0;
|
| 233 |
|
| 234 |
if ($html) {
|
| 235 |
my $color=$colormap{$i->{urgency}};
|
| 236 |
print OUT "<span style=\"background:$color\">";
|
| 237 |
}
|
| 238 |
print OUT $i->{item};
|
| 239 |
if ($html) {
|
| 240 |
print OUT "</span>";
|
| 241 |
}
|
| 242 |
|
| 243 |
$items++;
|
| 244 |
}
|
| 245 |
print OUT "\n";
|
| 246 |
}
|
| 247 |
}
|
| 248 |
|
| 249 |
my %needkern;
|
| 250 |
|
| 251 |
foreach my $version (sort keys %needkernel) {
|
| 252 |
my %images;
|
| 253 |
|
| 254 |
if (defined $needkern{$version} && $needkern{$version} eq "0") {
|
| 255 |
next;
|
| 256 |
}
|
| 257 |
|
| 258 |
my @dctrl;
|
| 259 |
if (defined $sources && length $sources) {
|
| 260 |
my $cat=($sources=~/\.gz/) ? "zcat" : "cat";
|
| 261 |
@dctrl=`$cat $sources | grep-dctrl -F Binary kernel-image-$version -s Package,Build-Depends -`;
|
| 262 |
}
|
| 263 |
|
| 264 |
my $package="";
|
| 265 |
my $haveversion;
|
| 266 |
|
| 267 |
foreach my $line (@dctrl) {
|
| 268 |
chomp $line;
|
| 269 |
if ($line=~/Package:\s*(\S+)/) {
|
| 270 |
$package=$1;
|
| 271 |
$haveversion="0";
|
| 272 |
} elsif ($line=~/Build-Depends/) {
|
| 273 |
if ($line=~/kernel-tree-$version-([^,\s]+)/) {
|
| 274 |
$haveversion="$version-$1";
|
| 275 |
} elsif ($line=~/kernel-source-$version\s+\(>?=\s*([^\s\)]+)\)/) {
|
| 276 |
$haveversion="$1";
|
| 277 |
}
|
| 278 |
} else {
|
| 279 |
if ($package=~/linux-kernel-di/ || $package eq "") {
|
| 280 |
next;
|
| 281 |
}
|
| 282 |
$images{$package}=$haveversion;
|
| 283 |
$package="";
|
| 284 |
}
|
| 285 |
}
|
| 286 |
|
| 287 |
foreach my $package (sort keys %images) {
|
| 288 |
if ($images{$package} eq "0") {
|
| 289 |
print OUT "<li>" if ($html && $list_unknown);
|
| 290 |
print OUT "$package built from kernel-source-$version $needkernel{$version} needed, current version unknown\n" if $list_unknown;
|
| 291 |
} elsif (!system("dpkg --compare-versions $needkernel{$version} gt $images{$package}")) {
|
| 292 |
print OUT "<li>" if $html;
|
| 293 |
print OUT "$package built from kernel-source-$version $needkernel{$version} needed, have $images{$package}\n";
|
| 294 |
$need_rebuild++;
|
| 295 |
}
|
| 296 |
}
|
| 297 |
|
| 298 |
|
| 299 |
}
|
| 300 |
|
| 301 |
|
| 302 |
if ($html) {
|
| 303 |
print OUT "</ul>\n";
|
| 304 |
print OUT "<hr>\n";
|
| 305 |
print OUT "Key: ";
|
| 306 |
foreach my $keyline (@urgencies) {
|
| 307 |
print OUT "<span style=\"border: 1px dashed; background:".$colormap{$keyline}."\"> $keyline </span> ";
|
| 308 |
}
|
| 309 |
print OUT "<br>";
|
| 310 |
print OUT "Total holes unfixed: $unfixed<br>\n";
|
| 311 |
print OUT "Total holes fixed in unstable but not $suite: $unprop_all ($fixedsta fixed in secure-testing archive)";
|
| 312 |
if ($unprop_all != $unprop) {
|
| 313 |
print OUT " (+".($unprop - $unprop_all)." on some arches)";
|
| 314 |
}
|
| 315 |
print OUT "<br>\n";
|
| 316 |
print OUT "Total number of kernel image packages not up to date: $need_rebuild<br>\n";
|
| 317 |
print OUT "Number of TODO lines in <a href=\"http://svn.debian.org/wsvn/secure-testing/data/?rev=0&sc=0\">records</a>: $todos<br>\n";
|
| 318 |
print OUT "Maintained by the <a href=\"http://secure-testing-master.debian.net/\">testing security team</a><br>\n";
|
| 319 |
print OUT "Last update: ".`date`."<br>\n";
|
| 320 |
print OUT "</html>\n";
|
| 321 |
}
|
| 322 |
|
| 323 |
close OUT;
|
| 324 |
if (defined $output) {
|
| 325 |
rename("$output.tmp.$$", $output) || die "rename: $!";
|
| 326 |
}
|