JavaScript / Cisco IOS – Reverse Cisco Type 7 String

Use this to recover a type 7 string and view it as plain text

JavaScript:

	// Is the character a digit?
	function isDigit(theDigit) 
	{ 
		var digitArray = new Array('0','1','2','3','4','5','6','7','8','9')
	
		for (j = 0; j < digitArray.length; j++)  {
			if (theDigit == digitArray[j]) 
				return true 
		} 
		return false 
	} 
	
    
	function reversePassword(form)
	{
		var crypttext=form.crypttext.value.toUpperCase()
		var plaintext=''
		var xlat="dsfd;kfoA,.iyewrkldJKDHSUBsgvca69834ncxv9873254k;fg87"
		var seed, i, val=0
	
		if(crypttext.length & 1)
			return
	
		seed = (crypttext.charCodeAt(0) - 0x30) * 10 + crypttext.charCodeAt(1) - 0x30
	
		if (seed > 15 || !isDigit(crypttext.charAt(0)) || !isDigit(crypttext.charAt(1)))
			return
	
			for (i = 2 ; i <= crypttext.length; i++) {
					if(i !=2 && !(i & 1)) {
							plaintext+=String.fromCharCode(val ^ xlat.charCodeAt(seed++))
				seed%=xlat.length
							val = 0;
					}
	
					val *= 16
	
			if(isDigit(crypttext.charAt(i))) {
				val += crypttext.charCodeAt(i) - 0x30
				continue
			}
	
	
			if(crypttext.charCodeAt(i) >= 0x41 && crypttext.charCodeAt(i) <= 0x46) {
				val += crypttext.charCodeAt(i) - 0x41 + 0x0a
				continue
			}
	
			if(crypttext.length != i)
				return
			}
	
		form.plaintext.value=plaintext
		
		
	}

HTML:

<form name="form1" id="form1" action="#">
String:<input name="crypttext" type="text" size="40" /><br>
<input type="button" value="Reverse!" onClick="javascript:reversePassword(this.form)" /><br>
Reversed:<input name="plaintext" type="text" size="40" />
</form>

Also do it within a Cisco device:

Switch(config)# key chain TEST_KEYCHAIN
Switch(config-keychain)# key 1
Switch(config-keychain)# key-string 7 {KEY_STRING}
Switch# show key chain
*** Displays plaintext key ***
Switch(config)# no key chain TEST_KEYCHAIN

Leave a Reply

Your email address will not be published. Required fields are marked *