Entschlüsselung von Cisco Passwörtern

Vermutlich gibt es tausende von Programmen, um Cisco-Passwörter vom Typ “7” in ihre Klartextform zurückzurechnen. Vor kurzem habe ich aber kein passendes für den MAC gefunden. Daher habe ich mich entschieden, kurzerhand selbst eines in Python zu schreiben. Die Funktion der Passwörter habe ich im Beitrag Der Schutz hinter “service password-encryption” im Cisco IOS schon beschrieben.

Das ist dabei herausgekommen:

Download des Scripts “cipade.py”


#! /usr/bin/python
## 
##  Karsten Iwen
##  please send bug-reports, comments or improvements to:
##  ki@security-planet.de
##

import sys

ctable = (0x64, 0x73, 0x66, 0x64, 0x3b, 0x6b, 0x66, 0x6f, 0x41, 0x2c,
0x2e, 0x69, 0x79, 0x65, 0x77, 0x72, 0x6b, 0x6c, 0x64, 0x4a,
0x4b, 0x44, 0x48, 0x53, 0x55, 0x42, 0x73, 0x67, 0x76, 0x63,
0x61, 0x36, 0x39, 0x38, 0x33, 0x34, 0x6e, 0x63, 0x78, 0x76,
0x39, 0x38, 0x37, 0x33, 0x32, 0x35, 0x34, 0x6b, 0x3b, 0x66,
0x67, 0x38, 0x37)

if len(sys.argv) == 2:
	input = sys.argv[1]
	length = len(input)
	if length%2 != 0:
		print ("!!!")
		print ("!!! The encrypted password has an odd number of digits. It should be even!")
		print ("!!! So the decrypted password is not complete!")
		print ("!!!")
		length = length -1
	if length < 4:
		print ("!!!")
		print ("!!! The Input is too short")
		print ("!!!")
	else:
		pos = 2
		tpos = int(input[0:2])
		pw = ""
		while pos < length:
			pw = pw + chr( int("0x"+input[pos:pos+2],16) ^ int(hex(ctable[tpos]),16))
			pos = pos + 2
			tpos = tpos +1
			if tpos == 53: tpos = 0
		print (pw)
else:
	print ("")
	print ("cipade.py v1.0")
	print ("==============")
	print ("cipade (CIsco PAssword DEcoder) 'decrypts' type 7 passwords used in Cisco IOS-configurations")
	print ("")
	print ("Usage")
	print ("=====")
	print ("cipade [the type 7 encrypted password]")
	print ("")
	print ("Written by:")
	print ("===========")
	print ("Karsten Iwen")
	print ("ki@security-planet.de")
	print ("http://security-planet.de")
	print ("")

Ich vermute, daß man mindestens die XOR-Operation noch etwas eleganter programmieren könnte. Verbesserungsvorschläge werden gerne angenommen.
Das Script muss einfach als “cipade.py” im Suchpfad abgespeichert und als ausführbar markiert werden.

4 Replies to “Entschlüsselung von Cisco Passwörtern”

  1. wenn ich grade nix zur Hand habe mache ich einfach:

    Router(config)#enable password rofl
    Router(config)#do sh run | i ena
    enable password 7 1317181407
    Router(config)#key chain test
    Router(config-keychain)#key 1
    Router(config-keychain-key)#key-string 7 1317181407
    Router#sh key chain test
    Key-chain test:
    key 1 — text “rofl”
    accept lifetime (always valid) – (always valid) [valid now]
    send lifetime (always valid) – (always valid) [valid now]

    Setzt natürlich vorraus das man auf irgendeinem IOS Router enabled ist 🙂 GNS tuts zur Not auch, das kann man bei strengen Virenwächtern leichter vorbeibringen als ein pöhses “getpass”

    1. Die Key-Chains versagen leider immer wieder bei sehr langen Passwörtern. Irgendwo bei ca. 25 Stellen ist Schluss. Und mehr Tipparbeit ist es auch … 😉

  2. Hi Karsten,

    ich denke es ist völlig ok sich selber schnell so ein Tool zu baseln, auch wenn die Arbeit schon jemand erledigt hat. Man hat ja auch Spaß dabei, wenn man etwas programmiert und der sollte bei der ganzen Arbeit nicht zu kurz kommen 😉 Ich hatte mir vor ca. 2 Jahren die Perl Version des Tools ebenfalls nach Python portiert. Mittlerweile verwende ich die CiscoPassword Klasse von ciscoconfparse ( http://ciscoconfparse.wiki.sourceforge.net/ ).

    In [11]: from ciscoconfparse import CiscoPassword
    In [12]: p = CiscoPassword()
    In [13]: p.decrypt(“00271A150754”)
    Out[13]: ‘Cisco’

    Gruss

    Jochen

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.