From 175bd2cf66bada3ed7f55cacb44cbc6390b130c3 Mon Sep 17 00:00:00 2001 From: Joe Testa Date: Tue, 20 Oct 2020 21:34:34 -0400 Subject: [PATCH] Fixed recommendation output function from suppressing some algorithms inappropriately. --- README.md | 1 + src/ssh_audit/algorithms.py | 28 ++++++------------- .../dropbear_2019.78_test1.txt | 3 ++ .../expected_results/openssh_4.0p1_test1.txt | 3 ++ .../expected_results/openssh_5.6p1_test1.txt | 3 ++ .../expected_results/openssh_5.6p1_test2.txt | 7 +++-- .../expected_results/openssh_5.6p1_test3.txt | 7 +++-- .../expected_results/openssh_5.6p1_test4.txt | 7 +++-- .../expected_results/openssh_5.6p1_test5.txt | 6 +++- 9 files changed, 38 insertions(+), 27 deletions(-) diff --git a/README.md b/README.md index 579a064..dfc5ff8 100644 --- a/README.md +++ b/README.md @@ -158,6 +158,7 @@ For convenience, a web front-end on top of the command-line tool is available at ## ChangeLog ### v2.3.1-dev (???) + - Fixed bug in recommendation output which suppressed some algorithms inappropriately. - Flag `ssh-rsa-cert-v01@openssh.com` as a failure due to SHA-1 hash. - Now parses public key sizes for `rsa-sha2-256-cert-v01@openssh.com` and `rsa-sha2-512-cert-v01@openssh.com` host key types. - Built-in policies now include CA key requirements (if certificates are in use). diff --git a/src/ssh_audit/algorithms.py b/src/ssh_audit/algorithms.py index 3654991..6b4294b 100644 --- a/src/ssh_audit/algorithms.py +++ b/src/ssh_audit/algorithms.py @@ -189,27 +189,15 @@ class Algorithms: add_count = len(rec[sshv][alg_type]['add']) del_count = len(rec[sshv][alg_type]['del']) chg_count = len(rec[sshv][alg_type]['chg']) - new_alg_count = len(alg_list) + add_count - del_count - if new_alg_count < 1 and del_count > 0: - mf = min(rec[sshv][alg_type]['del'].values()) - new_del = {} - for k, cf in rec[sshv][alg_type]['del'].items(): - if cf != mf: - new_del[k] = cf - if del_count != len(new_del): - rec[sshv][alg_type]['del'] = new_del - new_alg_count += del_count - len(new_del) - if new_alg_count < 1: + + if add_count == 0: + del rec[sshv][alg_type]['add'] + if del_count == 0: + del rec[sshv][alg_type]['del'] + if chg_count == 0: + del rec[sshv][alg_type]['chg'] + if len(rec[sshv][alg_type]) == 0: del rec[sshv][alg_type] - else: - if add_count == 0: - del rec[sshv][alg_type]['add'] - if del_count == 0: - del rec[sshv][alg_type]['del'] - if chg_count == 0: - del rec[sshv][alg_type]['chg'] - if len(rec[sshv][alg_type]) == 0: - del rec[sshv][alg_type] if len(rec[sshv]) == 0: del rec[sshv] return software, rec diff --git a/test/docker/expected_results/dropbear_2019.78_test1.txt b/test/docker/expected_results/dropbear_2019.78_test1.txt index 9679fe4..6f04d61 100644 --- a/test/docker/expected_results/dropbear_2019.78_test1.txt +++ b/test/docker/expected_results/dropbear_2019.78_test1.txt @@ -71,13 +71,16 @@ (rec) -ecdh-sha2-nistp256 -- kex algorithm to remove  (rec) -ecdh-sha2-nistp384 -- kex algorithm to remove  (rec) -ecdh-sha2-nistp521 -- kex algorithm to remove  +(rec) -ecdsa-sha2-nistp256 -- key algorithm to remove  (rec) -hmac-sha1-96 -- mac algorithm to remove  (rec) -ssh-dss -- key algorithm to remove  +(rec) -ssh-rsa -- key algorithm to remove  (rec) +diffie-hellman-group16-sha512 -- kex algorithm to append  (rec) +twofish128-ctr -- enc algorithm to append  (rec) +twofish256-ctr -- enc algorithm to append  (rec) -diffie-hellman-group14-sha1 -- kex algorithm to remove  (rec) -hmac-sha1 -- mac algorithm to remove  +(rec) -hmac-sha2-256 -- mac algorithm to remove  # additional info (nfo) For hardening guides on common OSes, please see:  diff --git a/test/docker/expected_results/openssh_4.0p1_test1.txt b/test/docker/expected_results/openssh_4.0p1_test1.txt index 9e9b4d2..4d3d1a7 100644 --- a/test/docker/expected_results/openssh_4.0p1_test1.txt +++ b/test/docker/expected_results/openssh_4.0p1_test1.txt @@ -133,6 +133,9 @@ (rec) -hmac-sha1-96 -- mac algorithm to remove  (rec) -rijndael-cbc@lysator.liu.se -- enc algorithm to remove  (rec) -ssh-dss -- key algorithm to remove  +(rec) -ssh-rsa -- key algorithm to remove  +(rec) -diffie-hellman-group14-sha1 -- kex algorithm to remove  +(rec) -hmac-sha1 -- mac algorithm to remove  # additional info (nfo) For hardening guides on common OSes, please see:  diff --git a/test/docker/expected_results/openssh_5.6p1_test1.txt b/test/docker/expected_results/openssh_5.6p1_test1.txt index f2361ca..5ac3e37 100644 --- a/test/docker/expected_results/openssh_5.6p1_test1.txt +++ b/test/docker/expected_results/openssh_5.6p1_test1.txt @@ -141,7 +141,10 @@ (rec) -hmac-sha1-96 -- mac algorithm to remove  (rec) -rijndael-cbc@lysator.liu.se -- enc algorithm to remove  (rec) -ssh-dss -- key algorithm to remove  +(rec) -ssh-rsa -- key algorithm to remove  (rec) -diffie-hellman-group14-sha1 -- kex algorithm to remove  +(rec) -hmac-sha1 -- mac algorithm to remove  +(rec) -umac-64@openssh.com -- mac algorithm to remove  # additional info (nfo) For hardening guides on common OSes, please see:  diff --git a/test/docker/expected_results/openssh_5.6p1_test2.txt b/test/docker/expected_results/openssh_5.6p1_test2.txt index 59808a9..a9cd2d9 100644 --- a/test/docker/expected_results/openssh_5.6p1_test2.txt +++ b/test/docker/expected_results/openssh_5.6p1_test2.txt @@ -35,7 +35,8 @@ (key) ssh-rsa (1024-bit) -- [fail] using weak hashing algorithm  `- [warn] using small 1024-bit modulus `- [info] available since OpenSSH 2.5.0, Dropbear SSH 0.28 -(key) ssh-rsa-cert-v01@openssh.com (1024-bit cert/1024-bit CA) -- [fail] using small 1024-bit modulus +(key) ssh-rsa-cert-v01@openssh.com (1024-bit cert/1024-bit CA) -- [fail] using weak hashing algorithm + `- [warn] using small 1024-bit modulus `- [info] available since OpenSSH 5.6 # encryption algorithms (ciphers) @@ -121,7 +122,6 @@ # algorithm recommendations (for OpenSSH 5.6) (rec) !diffie-hellman-group-exchange-sha256 -- kex algorithm to change (increase modulus size to 2048 bits or larger)  -(rec) !ssh-rsa-cert-v01@openssh.com -- key algorithm to change (increase modulus size to 2048 bits or larger)  (rec) -3des-cbc -- enc algorithm to remove  (rec) -aes128-cbc -- enc algorithm to remove  (rec) -aes192-cbc -- enc algorithm to remove  @@ -140,7 +140,10 @@ (rec) -hmac-sha1-96 -- mac algorithm to remove  (rec) -rijndael-cbc@lysator.liu.se -- enc algorithm to remove  (rec) -ssh-rsa -- key algorithm to remove  +(rec) -ssh-rsa-cert-v01@openssh.com -- key algorithm to remove  (rec) -diffie-hellman-group14-sha1 -- kex algorithm to remove  +(rec) -hmac-sha1 -- mac algorithm to remove  +(rec) -umac-64@openssh.com -- mac algorithm to remove  # additional info (nfo) For hardening guides on common OSes, please see:  diff --git a/test/docker/expected_results/openssh_5.6p1_test3.txt b/test/docker/expected_results/openssh_5.6p1_test3.txt index 62a8fa3..1f34924 100644 --- a/test/docker/expected_results/openssh_5.6p1_test3.txt +++ b/test/docker/expected_results/openssh_5.6p1_test3.txt @@ -35,7 +35,8 @@ (key) ssh-rsa (1024-bit) -- [fail] using weak hashing algorithm  `- [warn] using small 1024-bit modulus `- [info] available since OpenSSH 2.5.0, Dropbear SSH 0.28 -(key) ssh-rsa-cert-v01@openssh.com (1024-bit cert/3072-bit CA) -- [fail] using small 1024-bit modulus +(key) ssh-rsa-cert-v01@openssh.com (1024-bit cert/3072-bit CA) -- [fail] using weak hashing algorithm + `- [warn] using small 1024-bit modulus `- [info] available since OpenSSH 5.6 # encryption algorithms (ciphers) @@ -121,7 +122,6 @@ # algorithm recommendations (for OpenSSH 5.6) (rec) !diffie-hellman-group-exchange-sha256 -- kex algorithm to change (increase modulus size to 2048 bits or larger)  -(rec) !ssh-rsa-cert-v01@openssh.com -- key algorithm to change (increase modulus size to 2048 bits or larger)  (rec) -3des-cbc -- enc algorithm to remove  (rec) -aes128-cbc -- enc algorithm to remove  (rec) -aes192-cbc -- enc algorithm to remove  @@ -140,7 +140,10 @@ (rec) -hmac-sha1-96 -- mac algorithm to remove  (rec) -rijndael-cbc@lysator.liu.se -- enc algorithm to remove  (rec) -ssh-rsa -- key algorithm to remove  +(rec) -ssh-rsa-cert-v01@openssh.com -- key algorithm to remove  (rec) -diffie-hellman-group14-sha1 -- kex algorithm to remove  +(rec) -hmac-sha1 -- mac algorithm to remove  +(rec) -umac-64@openssh.com -- mac algorithm to remove  # additional info (nfo) For hardening guides on common OSes, please see:  diff --git a/test/docker/expected_results/openssh_5.6p1_test4.txt b/test/docker/expected_results/openssh_5.6p1_test4.txt index eeb363e..4820129 100644 --- a/test/docker/expected_results/openssh_5.6p1_test4.txt +++ b/test/docker/expected_results/openssh_5.6p1_test4.txt @@ -34,7 +34,8 @@ # host-key algorithms (key) ssh-rsa (3072-bit) -- [fail] using weak hashing algorithm `- [info] available since OpenSSH 2.5.0, Dropbear SSH 0.28 -(key) ssh-rsa-cert-v01@openssh.com (3072-bit cert/1024-bit CA) -- [fail] using small 1024-bit modulus +(key) ssh-rsa-cert-v01@openssh.com (3072-bit cert/1024-bit CA) -- [fail] using weak hashing algorithm + `- [warn] using small 1024-bit modulus `- [info] available since OpenSSH 5.6 # encryption algorithms (ciphers) @@ -120,7 +121,6 @@ # algorithm recommendations (for OpenSSH 5.6) (rec) !diffie-hellman-group-exchange-sha256 -- kex algorithm to change (increase modulus size to 2048 bits or larger)  -(rec) !ssh-rsa-cert-v01@openssh.com -- key algorithm to change (increase modulus size to 2048 bits or larger)  (rec) -3des-cbc -- enc algorithm to remove  (rec) -aes128-cbc -- enc algorithm to remove  (rec) -aes192-cbc -- enc algorithm to remove  @@ -139,7 +139,10 @@ (rec) -hmac-sha1-96 -- mac algorithm to remove  (rec) -rijndael-cbc@lysator.liu.se -- enc algorithm to remove  (rec) -ssh-rsa -- key algorithm to remove  +(rec) -ssh-rsa-cert-v01@openssh.com -- key algorithm to remove  (rec) -diffie-hellman-group14-sha1 -- kex algorithm to remove  +(rec) -hmac-sha1 -- mac algorithm to remove  +(rec) -umac-64@openssh.com -- mac algorithm to remove  # additional info (nfo) For hardening guides on common OSes, please see:  diff --git a/test/docker/expected_results/openssh_5.6p1_test5.txt b/test/docker/expected_results/openssh_5.6p1_test5.txt index 3373e92..ceca269 100644 --- a/test/docker/expected_results/openssh_5.6p1_test5.txt +++ b/test/docker/expected_results/openssh_5.6p1_test5.txt @@ -34,7 +34,8 @@ # host-key algorithms (key) ssh-rsa (3072-bit) -- [fail] using weak hashing algorithm `- [info] available since OpenSSH 2.5.0, Dropbear SSH 0.28 -(key) ssh-rsa-cert-v01@openssh.com (3072-bit cert/3072-bit CA) -- [info] available since OpenSSH 5.6 +(key) ssh-rsa-cert-v01@openssh.com (3072-bit cert/3072-bit CA) -- [fail] using weak hashing algorithm + `- [info] available since OpenSSH 5.6 # encryption algorithms (ciphers) (enc) aes128-ctr -- [info] available since OpenSSH 3.7, Dropbear SSH 0.52 @@ -137,7 +138,10 @@ (rec) -hmac-sha1-96 -- mac algorithm to remove  (rec) -rijndael-cbc@lysator.liu.se -- enc algorithm to remove  (rec) -ssh-rsa -- key algorithm to remove  +(rec) -ssh-rsa-cert-v01@openssh.com -- key algorithm to remove  (rec) -diffie-hellman-group14-sha1 -- kex algorithm to remove  +(rec) -hmac-sha1 -- mac algorithm to remove  +(rec) -umac-64@openssh.com -- mac algorithm to remove  # additional info (nfo) For hardening guides on common OSes, please see: