Last active
March 11, 2022 17:15
-
-
Save dgjustice/1102df9738542e2dd2ddaa27935158b9 to your computer and use it in GitHub Desktop.
Check if configured password on Cisco device is what you expect it to be.
This file contains hidden or 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 crypt | |
from hmac import compare_digest | |
cisco = "username REDACTED password 5 $5$SALT$SOME-HASH role network-admin" | |
def check_pw_hashes_are_eq(username_cmd: str, cleartext: str) -> bool: | |
parts = username_cmd.split(' ') | |
pw_hash = parts[4] | |
pw_parts = pw_hash.split('$') | |
meth, salt, pw = pw_parts[1:] | |
return compare_digest( | |
pw_hash, | |
crypt.crypt(cleartext, '${m}${s}'.format(m=meth, s=salt)), | |
) | |
print(check_pw_hashes_are_eq(cisco, 'REDACTED')) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment