thc_ssh_crack.c 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /*
  2. * THC/2003
  3. *
  4. * Simple ssh-private key cracker. Tries to brute force (dictionary
  5. * attack) almost any ssh private key file format.
  6. *
  7. * This is just a quick tool from THC. Using OpenSSL is not really
  8. * fast...
  9. *
  10. * COMPILE:
  11. * gcc -Wall -O2 -o thc-ssh-crack thc-ssh-crack.c -lssl
  12. *
  13. * RUN:
  14. * John is a good password generator. We use it for thc-ssh-crack:
  15. *
  16. * $ john -stdout -incremental | nice -19 thc-ssh-crack id_dsa
  17. *
  18. * Normal dictionary (without john's permutation engine):
  19. *
  20. * $ nice -19 thc-ssh-crack id_dsa <dictionary.txt
  21. *
  22. * Enjoy,
  23. *
  24. * http://www.thc.org
  25. */
  26. #include <stdio.h>
  27. #include <openssl/ssl.h>
  28. #include <openssl/err.h>
  29. #include <openssl/evp.h>
  30. #include <openssl/pem.h>
  31. #include <string.h>
  32. int
  33. main(int argc, char *argv[])
  34. {
  35. FILE *fp = fopen(argv[1], "r");
  36. EVP_PKEY *pk;
  37. char *ptr;
  38. char pwd[1024];
  39. SSL_library_init();
  40. pwd[0] = '\0';
  41. while (1)
  42. {
  43. if (!fgets(pwd, sizeof pwd, stdin))
  44. {
  45. printf("Password not found.\n");
  46. exit(0);
  47. }
  48. ptr = strchr(pwd, '\n');
  49. if (ptr)
  50. *ptr = '\0';
  51. pk = PEM_read_PrivateKey(fp, NULL, NULL, (char *)pwd);
  52. if (pk)
  53. {
  54. printf("THC THC THC THC THC THC THC THC THC\n");
  55. printf("----> pwd is '%s' <-----\n", pwd);
  56. printf("THC THC THC THC THC THC THC THC THC\n");
  57. exit(0);
  58. }
  59. }
  60. return 0;
  61. }