Cisco type 8 and 9 password hashes calculated using Java

In this article I will discuss three types of algorithms used by Cisco to calculate hashes from plain-text passwords, namely: Type 4, Type 5, Type 8 and Type 9.

Back in the year 2013, the Type 4 algorithm was proven insecure because of an implementation error. The algorithm does not use PBKDF2 and does not use a salt as was intended. Instead it performs a single iteration of SHA-256 over the user-provided plain-text password. The poignant case for Cisco here is that ‘Type 4’ was an attempt to create a more secure hash than Type 5, which was a ‘simple’ MD5 hash. But because of the implementation error, the Type 4 passwords/hashes rendered less secure than the Type 5 ones.

It was not possible/desired to fix the Type 4 algorithm because this should cause the current configurations to be invalid. Cisco decided to introduce a new type: Type 8 to do what was expected from Type 4: PBKDF2 (Password-Based Key Derivation Function 2) with 20000 iterations of SHA-256 including salt.

Additionally there are Type 9 passwords/hashes which use the scrypt algorithm, which in turn is doing a lot of PBKDF2 calculations internally. This combination makes Type 9 password/hashes the most difficult to crack for now and the best choice when you are free to select one of the Types discussed in this article. With free is meant that the running IOS must support these Type 9 passwords/hashes and you are not locked because of legacy configurations.

To sum up the security level from low to high:

  1. Type 4 (1x SHA-256 WITHOUT salt) – Don’t use this!
  2. Type 5 (MD5)
  3. Type 8 (PBKDF2 including salt)
  4. Type 9 (scrypt including salt) – Preferred!

I created a proof of concept (POC) to calculate Cisco Type 8 and 9 password hashes using Java including some JUnit tests.

To make this POC, I used a third party library: ‘wg/scrypt
– java implementation of scrypt’ which is also as Maven pre-compiled dependency available: group ID: com.lambdaworks, artifact ID: scrypt

To write the actual Java-source code I used the given examples of plain text password, salts and hashes. Besides of that I ‘translated’ Perl code to Java.

Find the source code at: GitHub – Project: cisco-password-hashes.

You are free to use it, to make the Internet more secure!

Links