Skip to content

Commit 2b01692

Browse files
authored
Merge pull request #242 from pdxjohnny/openssh_test
Openssh test
2 parents 5ccffc0 + 0da71e4 commit 2b01692

File tree

3 files changed

+56
-25
lines changed

3 files changed

+56
-25
lines changed

cve_bin_tool/checkers/openssh.py

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#!/usr/bin/python3
2+
import os
23

34
"""
45
CVE checker for openssh
@@ -17,7 +18,7 @@ def get_version(lines, filename):
1718
1819
VPkg: openbsd, openssh
1920
"""
20-
regex = re.compile("OpenSSH_([0-9]+\.[0-9]+[0-9a-z\s]*)")
21+
regex = re.compile(r"OpenSSH_([0-9]+\.[0-9]+[0-9a-z\s]*)")
2122
version_info = dict()
2223

2324
# determine version
@@ -27,27 +28,27 @@ def get_version(lines, filename):
2728
break # The binary seems to contain many version strings and the
2829
# first one matches the binary in question
2930

30-
if filename in [
31-
"scp",
32-
"sftp",
33-
"ssh",
34-
"ssh-add",
35-
"ssh-agent",
36-
"ssh-argv0",
37-
"ssh-copy-id",
38-
"ssh-keygen",
39-
"ssh-keyscan",
40-
"slogin",
41-
]:
42-
version_info["is_or_contains"] = "is"
43-
version_info["modulename"] = "openssh-client"
44-
elif filename in ["sshd"]:
45-
version_info["is_or_contains"] = "is"
46-
version_info["modulename"] = "openssh-server"
47-
48-
if "is_or_contains" in version_info:
49-
version_info["modulename"] = "openssl"
50-
else:
51-
return dict()
52-
53-
return version_info
31+
for modulename, binary_names in (
32+
{
33+
"openssh-client": [
34+
"scp",
35+
"sftp",
36+
"ssh",
37+
"ssh-add",
38+
"ssh-agent",
39+
"ssh-argv0",
40+
"ssh-copy-id",
41+
"ssh-keygen",
42+
"ssh-keyscan",
43+
"slogin",
44+
],
45+
"openssh-server": ["sshd"],
46+
}
47+
).items():
48+
for check in binary_names:
49+
if check in os.path.split(filename)[-1]:
50+
version_info["is_or_contains"] = "is"
51+
version_info["modulename"] = modulename
52+
return version_info
53+
54+
return {}

test/binaries/test-openssh-7.9.c

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 OpenSSH 7.9");
6+
printf("They appear below this line.");
7+
printf("------------------");
8+
printf("OpenSSH_7.9");
9+
10+
return 0;
11+
}

test/test_scanner.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,25 @@ def test_nss_rpm_3_26_2(self):
412412
"3.26.2",
413413
)
414414

415+
def test_openssh_7_9(self):
416+
"""Scanning test-openssh-7.9.out"""
417+
self._binary_test(
418+
"test-openssh-7.9.out",
419+
"openssh-client",
420+
"7.9",
421+
[
422+
# known CVEs in this version
423+
"CVE-2019-6111",
424+
"CVE-2019-6110",
425+
"CVE-2019-6109",
426+
"CVE-2018-20685",
427+
],
428+
[
429+
# older CVEs that should not be detected
430+
"CVE-2018-15919",
431+
"CVE-2018-15473",
432+
],
433+
)
415434
def test_openssl_1_0_2g(self):
416435
"""Scanning test-openssl-1.0.2g.out"""
417436
self._binary_test(

0 commit comments

Comments
 (0)