home *** CD-ROM | disk | FTP | other *** search
/ Hacks & Cracks / Hacks_and_Cracks.iso / hackersclub / km / library / hack / ciscopw.txt < prev    next >
Text File  |  1998-03-25  |  3KB  |  56 lines

  1. #! /bin/sh
  2. ## Decrypts cisco "encrypted" passwords.  Feed this confg files as stdin.
  3. ## Anything that looks like a "type 7 encrypted" string gets decrypted.
  4. ## This should really be a C program, but is presented as a script just to
  5. ## piss off a certain group of people.  One beer, please...
  6.  
  7. while read xx ; do
  8.   case "$xx" in
  9.     *d\ 7\ [01]??* ) ;;
  10.     *) continue ;;
  11.   esac
  12.   DEC=`echo "$xx" | sed -e 's/.* //' -e 's/\(^..\).*/\1/'`
  13.   DP1=`expr $DEC + 1`
  14.   HEX=`echo "$xx" | sed -e 's/.* //' -e 's/^..\(..*\)/\1/'`
  15.   echo 'dsfd;kfoA,.iyewrkldJKDHSUB' | cut -c "${DP1}-30" > /tmp/cis$$.pad
  16.   echo '#' > /tmp/cis$$.in
  17.   for xx in 1-2 3-4 5-6 7-8 9-10 11-12 13-14 15-16 17-18 19-20 21-22 ; do
  18.     echo "${HEX}" | cut -c $xx | sed -e '/^$/q' -e 's/^/0x/' >> /tmp/cis$$.in
  19.   done
  20.   echo -n "${DEC}${HEX}: "
  21.   data -g < /tmp/cis$$.in | xor /tmp/cis$$.pad
  22.   echo ''
  23. done
  24. rm -f /tmp/cis$$.pad /tmp/cis$$.in
  25. exit 0
  26.  
  27. # Discussion:
  28.  
  29. # When "service password-encryption" is configured into a cisco router and
  30. # the configuration subsequently viewed, the passwords are no longer printed
  31. # as plaintext but as strings of randomish-looking garbage.  Analysis of
  32. # several samples reveals the scrambling algorithm to be trivially weak.
  33.  
  34. # Dr. Delete derived and published an analysis and decryption program some
  35. # time ago, but since that didn't seem to be generally available at the time
  36. # I went looking for it, here is an independent explanation.  This was worked
  37. # out on PAPER over a plate of nachos in a hotel bar in downtown LA, but
  38. # still illustrates where a general-purpose "xor" handler can be useful for
  39. # quickly cracking lame "proprietary" algorithms of this genre.
  40.  
  41. # Passwords can be up to eleven mixed-case characters.  In the "encrypted"
  42. # representation, the first two bytes of the long string are a random decimal
  43. # offset between 0 and 15 into a magic block of characters, and the remaining
  44. # bytes are ascii-hex representations of the password bytes xored against
  45. # the character-block bytes from the given offset on down.  The character
  46. # block is "dsfd;kfoA,.iyewrkldJKDHSUB", which is enough for a maximum-length
  47. # password at the maximum offset.
  48.  
  49. # Another character block consisting of "sgvca69834ncxv9873254k;fg87" is
  50. # located after the first one in the IOS image, which may be relevant to
  51. # something else and is simply mentioned here for posterity.  It is also
  52. # interesting to note that the strings "%02d" and "%02x" occur immediately
  53. # afterward, which in light of the above is another clue.
  54.  
  55. # _H* 960315
  56.