ciscocrack.c 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /*
  2. * descambles cisco IOS type-7 passwords
  3. * found somewhere on the internet, slightly modified, anonymous@segfault.net
  4. *
  5. * gcc -Wall -o ciscocrack ciscocrack.c
  6. * ./ciscocrack 01178E05590909022A
  7. *
  8. */
  9. #include <stdio.h>
  10. #include <ctype.h>
  11. char xlat[] = {
  12. 0x64, 0x73, 0x66, 0x64, 0x3b, 0x6b, 0x66, 0x6f,
  13. 0x41, 0x2c, 0x2e, 0x69, 0x79, 0x65, 0x77, 0x72,
  14. 0x6b, 0x6c, 0x64, 0x4a, 0x4b, 0x44, 0x48, 0x53,
  15. 0x55, 0x42
  16. };
  17. int
  18. cdecrypt(char *enc_pw, char *dec_pw)
  19. {
  20. unsigned int seed, i, val = 0;
  21. if(strlen(enc_pw) & 1)
  22. return(-1);
  23. seed = (enc_pw[0] - '0') * 10 + enc_pw[1] - '0';
  24. if (seed > 15 || !isdigit(enc_pw[0]) || !isdigit(enc_pw[1]))
  25. return(-1);
  26. for (i = 2 ; i <= strlen(enc_pw); i++) {
  27. if(i !=2 && !(i & 1)) {
  28. dec_pw[i / 2 - 2] = val ^ xlat[seed++];
  29. val = 0;
  30. }
  31. val *= 16;
  32. if(isdigit(enc_pw[i] = toupper(enc_pw[i]))) {
  33. val += enc_pw[i] - '0';
  34. continue;
  35. }
  36. if(enc_pw[i] >= 'A' && enc_pw[i] <= 'F') {
  37. val += enc_pw[i] - 'A' + 10;
  38. continue;
  39. }
  40. if(strlen(enc_pw) != i)
  41. return(-1);
  42. }
  43. dec_pw[++i / 2] = 0;
  44. return(0);
  45. }
  46. void
  47. usage()
  48. {
  49. fprintf(stdout, "Usage: ciscocrack <encrypted password>\n");
  50. }
  51. int
  52. main(int argc, char *argv[])
  53. {
  54. char passwd[65];
  55. memset(passwd, 0, sizeof(passwd));
  56. if(argc != 2)
  57. {
  58. usage();
  59. exit(1);
  60. }
  61. if(cdecrypt(argv[1], passwd)) {
  62. fprintf(stderr, "Error.\n");
  63. exit(1);
  64. }
  65. printf("Passwd: %s\n", passwd);
  66. return 0;
  67. }