Created
September 15, 2021 21:37
-
-
Save klustic/7ba820eadf7211326b09da68704f1c2b to your computer and use it in GitHub Desktop.
Test hostname against hashed entry in SSH known_hosts file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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