Skip to content

Instantly share code, notes, and snippets.

@dgjustice
Last active March 11, 2022 17:15
Show Gist options
  • Save dgjustice/1102df9738542e2dd2ddaa27935158b9 to your computer and use it in GitHub Desktop.
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.
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