From b16ef4d040d74dd7ed7bdb77f8c1d37fda876a0e Mon Sep 17 00:00:00 2001 From: Andris Raugulis Date: Sat, 17 Sep 2016 20:15:47 +0300 Subject: [PATCH] Add fingerprint support. --- ssh-audit.py | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/ssh-audit.py b/ssh-audit.py index 358b655..6b59eb9 100755 --- a/ssh-audit.py +++ b/ssh-audit.py @@ -24,7 +24,7 @@ THE SOFTWARE. """ from __future__ import print_function -import os, io, sys, socket, struct, random, errno, getopt, re +import os, io, sys, socket, struct, random, errno, getopt, re, hashlib, base64 VERSION = 'v1.0.20160915' @@ -278,6 +278,12 @@ class SSH1(object): def host_key_public_modulus(self): return self.__host_key[2] + @property + def host_key_fingerprint_data(self): + mod = WriteBuf._create_mpint(self.host_key_public_modulus, False) + e = WriteBuf._create_mpint(self.host_key_public_exponent, False) + return mod + e + @property def protocol_flags(self): return self.__protocol_flags @@ -686,6 +692,22 @@ class SSH(object): comments = (mx.group(4) or '').strip() or None return cls(protocol, software, comments) + class Fingerprint(object): + def __init__(self, fpd): + self.__fpd = fpd + + @property + def md5(self): + h = hashlib.md5(self.__fpd).hexdigest() + h = u':'.join(h[i:i + 2] for i in range(0, len(h), 2)) + return u'MD5:{0}'.format(h) + + @property + def sha256(self): + h = base64.b64encode(hashlib.sha256(self.__fpd).digest()) + h = h.decode().rstrip('=') + return u'SHA256:{0}'.format(h) + class Security(object): CVE = { 'Dropbear SSH': [