Skip to content

Commit 2a18105

Browse files
authored
Merge pull request #241 from FReeshabh/nextPR
Added a checker for gnutls
2 parents 2b01692 + ff14b13 commit 2a18105

File tree

5 files changed

+85
-4
lines changed

5 files changed

+85
-4
lines changed

cve_bin_tool/checkers/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"curl",
55
"expat",
66
"ffmpeg",
7+
"gnutls",
78
"icu",
89
"kerberos",
910
"libgcrypt",

cve_bin_tool/checkers/gnutls.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/usr/bin/env python3
2+
"""
3+
CVE checker for GnuTLS
4+
References:
5+
https://www.cvedetails.com/vulnerability-list/vendor_id-72/product_id-4433/GNU-Gnutls.html
6+
"""
7+
import os
8+
from ..util import regex_find
9+
10+
11+
def get_version(lines, filename):
12+
"""
13+
returns version information for gnutls found in given file.
14+
Verfies using the tools gnutls-cli
15+
Verifies using the libraries libgnutls.so and libgnutls-dane.so
16+
17+
VPkg: gnu, gnutls
18+
VPkg: gnutls, gnutls
19+
"""
20+
regex = [r"gnutls-cli ([0-9]+\.[0-9]+\.[0-9]+)"]
21+
22+
for modulename, binary_names in (
23+
{
24+
"gnutls-serv": ["gnutls-serv"],
25+
"gnutls-cli": ["gnutls-cli", "libgnutls.so", "libgnutls-dane.so"],
26+
}
27+
).items():
28+
for check in binary_names:
29+
if check in os.path.split(filename)[-1]:
30+
return {
31+
"is_or_contains": "is",
32+
"modulename": modulename,
33+
"version": regex_find(lines, *regex),
34+
}
35+
36+
return {}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#include <stdio.h>
2+
3+
int main() {
4+
printf("This program is designed to test the cve-bin-tool checker.");
5+
printf("It outputs a few strings normally associated with gnutls-cli 2.3.11");
6+
printf("They appear below this line.");
7+
printf("------------------");
8+
printf("gnutls-cli 2.3.11");
9+
10+
return 0;
11+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#include <stdio.h>
2+
3+
int main() {
4+
printf("This program is designed to test the cve-bin-tool checker.");
5+
printf("It outputs a few strings normally associated with gnutls-serv 2.3.11");
6+
printf("They appear below this line.");
7+
printf("------------------");
8+
printf("gnutls-serv 2.3.11");
9+
10+
return 0;
11+
}

test/test_scanner.py

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,14 +91,14 @@ def _binary_test(self, binary, package, version, are_in, not_in):
9191
# Run the scan
9292
cves = self.scan_file(binary)
9393
# Make sure the package and version are in the results
94-
self.assertIn(package, cves)
95-
self.assertIn(version, cves[package])
94+
self.assertIn(package, list(cves.keys()))
95+
self.assertIn(version, list(cves[package].keys()))
9696
# Test for CVEs known in this version
9797
for ensure_in in are_in:
98-
self.assertIn(ensure_in, cves[package][version])
98+
self.assertIn(ensure_in, list(cves[package][version].keys()))
9999
# Test for a CVE that is not in this version
100100
for ensure_out in not_in:
101-
self.assertNotIn(ensure_out, cves[package][version])
101+
self.assertNotIn(ensure_out, list(cves[package][version].keys()))
102102

103103
def _file_test(self, url, filename, package, version):
104104
""" Helper function to get a file (presumed to be a real copy
@@ -245,6 +245,28 @@ def test_ffmpeg_4_1_4(self):
245245
],
246246
)
247247

248+
def test_gnutls_2_3_11(self):
249+
"""Scanning test-gnutls-{binary}-2.3.11.out"""
250+
for binary in ["cli", "serv"]:
251+
with self.subTest(binary=binary):
252+
self._binary_test(
253+
"test-gnutls-{}-2.3.11.out".format(binary),
254+
"gnutls-cli",
255+
"2.3.11",
256+
[
257+
# known cves in 2.3.11
258+
"CVE-2008-1948",
259+
"CVE-2008-1949",
260+
"CVE-2008-1950",
261+
],
262+
[
263+
# an older cve from before 2.3.11
264+
"CVE-2004-2531",
265+
# an newer cve from after 2.3.11
266+
"CVE-2017-7869",
267+
],
268+
)
269+
248270
def test_jpeg_2_0_1(self):
249271
"""Scanning test-libjpeg-turbo-2.0.1"""
250272
self._binary_test(

0 commit comments

Comments
 (0)