Cisco Key & Secret Encryption
Encryption types
Cisco provides two ways of securing secrets inside a Catalyst switch’s running configuration so that they aren’t visible in plaintext:
service password-encryption: When enabled globally, every cleartext key/password configured in the running or startup configuration is obfuscated using an old, weak Cisco “encryption” method, ‘Type 7’, which in reality is more about obfuscating than encrypting.password encryption aes: When this is enabled globally and a master key is configured, existing and new cleartext passwords (0 or WORD) are converted into ‘Type 6’ AES-128-based ciphertext, which cannot be reversed as easily as ‘Type 7’.
C9300LM(config)# key config-key password-encrypt ?
LINE The config-key, minimum 8 characters not beginning with IOS special
character(! # ;)
C9300LM(config)# password encryption aes
With Type 6 encryption, the switch uses the master key you define to encrypt and decrypt the passwords in your configuration using AES-128.
The AES-128 encryption operates in Cipher Block Chaining (CBC) mode with PKCS#5 padding, and it is symmetric-key encryption.
Basically, this means that the exact same master key you configure on the switch is mathematically required both to encrypt the cleartext and to decrypt the ciphertext.
Reversible Encryption (When the switch needs to know the actual password)
When configuring keys on the switch, for example for RADIUS or TACACS, the software allows multiple ways to configure the key:
C9300LM(config-radius-server)#key ?
0 Specifies an UNENCRYPTED key will follow
6 Specifies ENCRYPTED key will follow
7 Specifies HIDDEN key will follow
LINE The UNCRYPTED (cleartext) shared key
0: The password is entered in plaintext during configuration, and if no encryption service is enabled globally, the password will be shown in plaintext in the running-config.
–> If one of the two encryption services is enabled, the password will be stored in either Type 6 or Type 7 format, depending on which service is used.6: The password is entered already encrypted with Cisco’s Type 6 AES-128 encryption. This is useful when copying configuration from one router to another. The router knows that it doesn’t have to re-encrypt the string and accepts it as AES ciphertext.7: The password is entered already encrypted with Cisco’s legacy Type 7 cipher. Like option 6, this is used for pasting existing configurations. Type 7 is widely considered insecure, as it can easily be reversed with online tools.LINE: Exactly the same behaviour as Type0, but without typing the ‘0’.
One-Way Hashing (When the switch doesn’t need to know the cleartext password)
For local account passwords, using AES Type 6 is considered “insecure” because the encrypted password and the master key used to decrypt it are stored on the same device. If attackers gain access to the device and manage to recover a local account’s password in plaintext, it can be a huge problem if that password is reused elsewhere.
Therefore, creating local users with the “password” option is not recommended:
C9300LM(config)#username test privilege 15 password ?
0 Specifies an UNENCRYPTED password will follow
6 Specifies an ENCRYPTED password will follow
7 Specifies a HIDDEN password will follow
LINE The UNENCRYPTED (cleartext) user password
Because the switch only needs to verify the local password against a stored mathematical value when you log in (and never needs to read it in plaintext), we should always use the “secret” method for local users and for enable mode.
Here are the one-way hashing methods available with the “secret” option:
C9300LM(config)#username test privilege 15 secret ?
0 Specifies an UNENCRYPTED secret will follow
5 Specifies a MD5 HASHED secret will follow
8 Specifies a PBKDF2 HASHED secret will follow
9 Specifies a SCRYPT HASHED secret will follow
LINE The UNENCRYPTED (cleartext) user secret
5(MD5): The password is entered as a 30- to 34-character Base64-encoded string that begins with$1$.
–> Takes the cleartext password and a random salt (up to 4 characters) and hashes the two combined, so two identical user passwords don’t produce the same hash.8(PBKDF2-SHA256): The password is entered as a 60-character string that begins with$8$.
–> The password, combined with a 14-character salt, is hashed many times in a row.9(Scrypt): The password is entered as a 60-character string that begins with$9$.
–> The password, combined with a 14-character salt, is hashed using an algorithm that mathematically requires a large amount of RAM to compute, making brute-force attacks with GPUs much slower and more expensive.
Conclusion
When copying configuration from one device to another:
- For reversibly encrypted passwords (RADIUS, TACACS): use password encryption aes with a master key (Type 6).
- For local user hashed passwords: use the secret method with scrypt (Type 9).
When creating a new configuration:
- Enable the password encryption aes service and configure a master key.
- Configure every secret/key by entering the cleartext password/key, and the switch will store them securely as Type 6 and Type 9.
Note: Type 9 is only the default hashing method for cleartext secrets on Cisco IOS XE 16.10.1 and later. On older releases, a cleartext
secretis stored as Type 5 (MD5).