summaryrefslogtreecommitdiffstats
path: root/bin/checklist
blob: d880a288852e5ec71da05925fa69ff37ca443a25 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
#!/usr/bin/perl
# Must run on a machine with dak ls.
# 
# To check for un-updated binary kernel packages, also needs grep-dctrl 
# and a Sources file for the distribution. Set the location of the Sources
# file in SOURCES_FILE in the environment.
use warnings;
use strict;
use URI::Escape;
use Getopt::Long;

my $html=0;
my $debug=0;
my $suite="testing";
my $sta="http://security.debian.org/debian-security/dists/testing/updates/main/source/Sources.gz";
my $output;
if (! GetOptions(
		"html" => \$html,
		"debug" => \$debug,
		"suite=s" => \$suite,
		"sta=s" => \$sta,
		"output=s", \$output)
    || ! @ARGV) {
	die "usage: $0 [--suite suite] [--sta sta-mirror] [--html] [--output=file] [--debug] list ...\n";
}

my $stasources=`tempfile`;
chomp $stasources;
system("wget -q -O $stasources $sta");

if (defined $output) {
	open (OUT, ">$output.tmp.$$") || die "output.tmp.$$: $!"; # Set the output to a file
}
else {
	open (OUT, ">&STDOUT"); # Set the output to stdout
}

if ($html) { # It's HTML, so we need a header
	print OUT "<html><title>$suite security issues</title>\n";
	print OUT <<"EOF";
<p><b>Note:</b>The information in the <a href="http://idssi.enyo.de/tracker">Security
Bug Tracker</a> is more detailed and likely more accurate.
</p>
EOF

	
	# This is being run against something it's not meant to be, so print a warning
	if ($suite ne 'testing' && $suite ne 'unstable') { 
		print OUT <<"EOF";
<p>
<em>Warning:</em> This page is the result of running the testing security
check script against the $suite distribution. As data is only gathered for
the testing distribution, results may be innacurate if a package has
changed its name, if a vulnerability affects $suite and not testing, or if a
vulnerability has been fixed in $suite by the security team.
</p>
EOF
	}
	print OUT "<ul>\n";
}


my %data;
my %advlist;
my %needkernel=qw/2.4.27 0 2.6.11 0/;
my $list_unknown=1; #set to 1 to display kernel images with unknown source version
my $sources=$ENV{SOURCES_FILE};
my $need_rebuild=0;

# Set some colours for the urgency types
my @urgencies=("high", "medium", "low", "unimportant", "unknown", "fixed");
my %colormap=(
	high => "#FF0000",
	medium => "#FF9999",
	low => "#FFFFFF",
	unknown => "#FFFF00",
	fixed => "#00FF00",
);

my $unprop = my $unprop_all = my $unfixed = my $todos = my $fixedsta = 0;

# Add an item into the data array.
sub record {
	my ($package, $condition, $item, $urgency)=@_;

	if (! defined $item) {
		$item='';
	}
		
	if ($html) {
		$condition=~s{bug #(\d+)}{<a href="http://bugs.debian.org/$1">bug #$1</a>}g;
		$condition=~s{unfixed}{<b>unfixed</b>}g;
		$item=~s#(CVE-\d+-\d+)#<a href="http://cve.mitre.org/cgi-bin/cvename.cgi?name=$1">$1</a>#g;
		$item=~s#(DTSA-\d+-\d+)#<a href="http://testing-security.debian.net/DTSA/$1.html">$1</a>#g;
	}

	push @{$data{$package}{$condition}}, {item => $item, urgency => $urgency};
}

foreach my $list (@ARGV) {
	# Each of the @ARGVs we've got passed need parsing. So lets do that
	
	# If it's a directory, set the file to list, cause we need that.
	if (-d $list) {
		$list="$list/list";
	}
	
	my $id;
	open (IN, $list) || die "open $list: $!";
	while (<IN>) {
		print STDERR "line: $_" if $debug;
		chomp;
		if (/\s+TODO/) { # It's a todo item. Add it to the count, and ignore it
			$todos++;
		}
		elsif (/^\[/) { # Checking adv. number for a line starting with [ : Set $id to it
			($id)=m/((?:DSA|DTSA|CVE)-[^\s]+) /;
		}
		elsif (/^((?:DSA|DTSA|CVE)-[^\s]+)/) { # Check for a line with an advisory at the start : Set $id to it
			$id=$1;
		}
		elsif (/^\s+\[\w+\]\s+/) { # line tagged with a debian codename
			next; # don't handle these for now
		}
		elsif (/^\s+(?:\[\w+\]\s+)?[!-]\s+(\S+)\s+(.*?)\s*$/) { # Deal with the rest of the lines
			my $package=$1; # We know which package it is.
			my $rest=$2; 
			my $version;
			my $notes;
			if ($rest=~/([^\(\s]+)\s+\((.*)\)/) {
				$version=$1;
				$notes=$2;
			}
			elsif ($rest=~/\((.*)\)/) {
				$version="";
				$notes=$1;
			}
			else {
				$version=$rest;
				$notes="";
			}

			# by now, we also have the version that's affected by the security problem.
			# This is stored in $version
			next if $version eq '<not-affected>' || $version eq '<removed>' || $version eq '<no-dsa>';
			
			my @notes=split(/\s*;\s+/, $notes);

			# Fetch the urgency, if we can.
			my $urgency="unknown";
			foreach my $u (@urgencies) {
				if (grep { $_ eq $u } @notes) {
					$urgency=$u;
					@notes = grep { $_ ne $u } @notes;
					last;
				}
			}
			next if $urgency eq 'unimportant';
		
			# It's a kernel. Add it to the list of kernels that need to be looked at.
			if ($package=~/kernel-source-([0-9.]+)/ && $version ne '<unfixed>') {
			 	my $kernversion=$1;
				if (exists $needkernel{$kernversion} &&
				    length $version &&
				    system("dpkg --compare-versions $needkernel{$kernversion} lt $version") != 0) {
					$needkernel{$kernversion}=$version;
				}
			}

			# Fire up dak ls.
			my @maddy;
			for (1..5) {
				@maddy=`dak ls -s '$suite' '$package'`;
				if ($? & 127 || ($? >> 8 != 0 && $? >> 8 != 1)) {
					# good old unrelaible newraff,
					# home of our archive..
					next;
				}
				last;
			}
			if ($? & 127) {
				record($package, "<em>[dak ls segfaulted 5 times in a row.. Medic!]</em>", $id);
			}
			elsif ($? >> 8 != 0 && $? >> 8 != 1) {
				record($package, "<em>[dak ls exited with ".($? >> 8)."]</em>", $id);
			}
			if (! @maddy) {
				next;
			}
			
			if ($version eq '<unfixed>' || grep { $_ eq 'pending' } @notes) {
				record($package, '('.join("; ", "unfixed", @notes).')', $id, $urgency);
				$unfixed++;
				# It's not been fixed!
			}
			else {
				foreach my $maddy (@maddy) {
					my @fields = split(/\s*\|\s*/, $maddy);
					my $havver=$fields[1]; # It's this version in the archive I'm checking.
					my $arches=$fields[3];
					$version=~s/\s+//; # strip whitespace
					$arches=~s/\s+$//;
					next if $arches eq 'hurd-i386';
					# Is the version in the archive the same or newer than the fix?
					my $cmp=system("dpkg --compare-versions '$havver' '>=' '$version'"); 
					if ($cmp != 0){ # No, so the archive is vulnerable.
						# Does the version exist in the secure-testing archive?
						my $staversion = `zcat $stasources |grep-dctrl -F Package -e ^$package\$ -s Version -`;
						chomp $staversion;
						$staversion=~s/Version: //;
						$staversion=~s/\s+//;
						if (length ($staversion)) {
							# Yes, but what version is in s-t?
							my $stacmp = system("dpkg --compare-versions '$staversion' '>=' '$version'");
							if ($stacmp == 0){
								# Well, the version in the s-t archive fixes the issue
								# but it's still vulnerable in the main archive
								$urgency='fixed';
								$fixedsta++;
							}
						}
						
						if ($html && $suite eq 'testing') {
							$havver='<a href="http://bjorn.haxx.se/debian/testing.pl?package='.uri_escape($package).'">'.$havver.'</a>';
						}
						record($package, "$version needed, have $havver".(@maddy > 1 ? " [$arches]" : ""), $id, $urgency);
						$unprop++;
						$unprop_all++ unless @maddy > 1;
					}
				}
			}
		}
	}
}


foreach my $package (sort keys %data) {
	foreach my $condition (sort keys %{$data{$package}}) {
		print OUT "<li>" if $html;
		print OUT "$package $condition for ";
		my $items=0;
		foreach my $i (sort @{$data{$package}{$condition}}) {
			print OUT ", " if $items > 0;
			
			if ($html) {
				my $color=$colormap{$i->{urgency}};
				print OUT "<span style=\"background:$color\">";
			}
			print OUT $i->{item};
			if ($html) {
				print OUT "</span>";
			}
			
			$items++;
		}
		print OUT "\n";
	}
}

my %needkern;

foreach my $version (sort keys %needkernel) {
	my %images;
	
	if (defined $needkern{$version} && $needkern{$version} eq "0") {
		next;
	}

	my @dctrl;
	if (defined $sources && length $sources) {
		my $cat=($sources=~/\.gz/) ? "zcat" : "cat";
		@dctrl=`$cat $sources | grep-dctrl -F Binary kernel-image-$version -s Package,Build-Depends -`;
	}

	my $package="";
	my $haveversion;
	
	foreach my $line (@dctrl) {
		chomp $line;
		if ($line=~/Package:\s*(\S+)/) {
			$package=$1;
			$haveversion="0";
		} elsif ($line=~/Build-Depends/) {
			if ($line=~/kernel-tree-$version-([^,\s]+)/) {
				$haveversion="$version-$1";
			} elsif ($line=~/kernel-source-$version\s+\(>?=\s*([^\s\)]+)\)/) {
				$haveversion="$1";
			}
		} else {
			if ($package=~/linux-kernel-di/ || $package eq "") {
				next;
			}
			$images{$package}=$haveversion;
			$package="";
		}
	}

	foreach my $package (sort keys %images) {
		if ($images{$package} eq "0") {
			print OUT "<li>" if ($html && $list_unknown);
			print OUT "$package built from kernel-source-$version $needkernel{$version} needed, current version unknown\n" if $list_unknown;
		} elsif (!system("dpkg --compare-versions $needkernel{$version} gt $images{$package}")) {
			print OUT "<li>" if $html;
			print OUT "$package built from kernel-source-$version $needkernel{$version} needed, have $images{$package}\n";
			$need_rebuild++;
		}
	}


}


if ($html) {
	print OUT "</ul>\n";
	print OUT "<hr>\n";
	print OUT "Key: ";
	foreach my $keyline (@urgencies) {
		next if $keyline eq 'unimportant';
		print OUT "<span style=\"border: 1px dashed; background:".$colormap{$keyline}."\">&nbsp;$keyline&nbsp;</span> ";
	}
	print OUT "<br>";
	print OUT "Total holes unfixed: $unfixed<br>\n";
	print OUT "Total holes fixed in unstable (or experimental) but not $suite: $unprop_all ($fixedsta fixed in secure-testing archive)";
	if ($unprop_all != $unprop) {
		print OUT " (+".($unprop - $unprop_all)." on some arches)";
	}
	print OUT "<br>\n";
	print OUT "Total number of kernel image packages not up to date: $need_rebuild<br>\n";
	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";
	print OUT "Maintained by the <a href=\"http://testing-security.debian.net/\">testing security team</a><br>\n";
	print OUT "Last update: ".`date`."<br>\n";
	print OUT "</html>\n";
}

close OUT;
if (defined $output) {
	rename("$output.tmp.$$", $output) || die "rename: $!";
}
unlink $stasources;

© 2014-2024 Faster IT GmbH | imprint | privacy policy