Skip to content

Instantly share code, notes, and snippets.

@klustic
Created September 15, 2021 21:37
Show Gist options
  • Save klustic/7ba820eadf7211326b09da68704f1c2b to your computer and use it in GitHub Desktop.
Save klustic/7ba820eadf7211326b09da68704f1c2b to your computer and use it in GitHub Desktop.
Test hostname against hashed entry in SSH known_hosts file
import hashlib, hmac
from base64 import b64decode as b64d, b64decode as b64d
line = input('hashed known_hosts line> ').strip()
host = input('suspected host> ').strip()
_, _, e_hkey, e_hdigest = line.split()[0].encode().split(b'|')
hkey, hdigest = b64d(e_hkey), b64d(e_hdigest)
d = hmac.digest(hkey, host.encode(), hashlib.sha1)
hmac.compare_digest(hdigest, d)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment