home *** CD-ROM | disk | FTP | other *** search
/ Hackers Toolkit v2.0 / Hackers_Toolkit_v2.0.iso / HTML / archive / Passwd-Cracking / unix / b4b0-cr4q.c < prev    next >
C/C++ Source or Header  |  1999-11-04  |  3KB  |  137 lines

  1. /* 
  2.  * by: seegn4l 
  3.  * b4b0-craq.2
  4.  */
  5.  
  6. #include <stdio.h>
  7. #include <pwd.h>
  8. #include <fcntl.h>
  9. #include <stdlib.h>
  10. #include <unistd.h>
  11. #include <string.h>
  12. #include <signal.h>
  13. #include <sys/stat.h>
  14. #include <sys/types.h>
  15.  
  16. #define MAXSIZ          50
  17. #define DEFLOG          "craq.out"
  18.  
  19. void banner (void);
  20. void sigcatch (int);
  21. void usage (char *);
  22. void crack (char *, char *, char *);
  23.  
  24. void
  25. main (int argc, char *argv[])
  26. {
  27.   char logfile[30];
  28.  
  29.   banner ();
  30.   if (argc < 3)
  31.     usage (argv[0]);
  32.   if (!argv[3])
  33.     strncpy (logfile, DEFLOG, sizeof (logfile));
  34.   else
  35.     strncpy (logfile, argv[3], sizeof (logfile));
  36.   crack (argv[1], argv[2], logfile);
  37. }
  38.  
  39. void
  40. banner (void)
  41. {
  42.   fprintf (stdout, "\nb4b0-cr4q.. by: seegn4l, '97.\n\n");
  43. }
  44.  
  45. void
  46. sigcatch (int sig)
  47. {
  48.   fprintf (stdout, "\n[!] caught signal: %d\n", sig);
  49.   exit (0);
  50. }
  51.  
  52. void
  53. usage (char *name)
  54. {
  55.   fprintf (stderr, "us4ge: %s <p455wh0rdF> <d1ctF> [0utputF]\n"
  56.            "\tpasswdf -> password file.\n"
  57.            "\tdictf   -> dictionary file\n"
  58.            "\toutputf -> output of cracking session.\n\n", name);
  59.   exit (1);
  60. }
  61.  
  62. void
  63. crack (char *passwd, char *dict, char *out)
  64. {
  65.   FILE *pw, *dt, *lg, *pipe;
  66.   struct passwd *p;
  67.   char date[20], pwbuf[MAXSIZ], *strip, *try;
  68.  
  69.   signal (SIGINT, sigcatch);
  70.   signal (SIGTERM, sigcatch);
  71.   if ((pw = fopen (passwd, "r")) == NULL)
  72.     {
  73.       perror ("fopen");
  74.       exit (1);
  75.     }
  76.   if ((dt = fopen (dict, "r")) == NULL)
  77.     {
  78.       perror ("fopen");
  79.       exit (1);
  80.     }
  81.   if ((lg = fopen (out, "a+")) == NULL)
  82.     {
  83.       perror ("fopen");
  84.       exit (1);
  85.     }
  86.   if ((pipe = popen ("date", "r")) == NULL)
  87.     {
  88.       perror ("popen");
  89.       exit (1);
  90.     }
  91.   fgets (date, 20, pipe);
  92.   pclose (pipe);
  93.   fprintf (stdout, "[\\] logfile: %s\n[/] passwd: %s\n[\\] dictfile: %s\n\n", out, passwd, dict);
  94.   fprintf (lg, "[\\] b4b0-craq v.121 ...\n");
  95.   fprintf (lg, "[/] Passwd file: %s\n[\\] Date: %s\n\n", passwd, date);
  96.  
  97.   for (;;)
  98.     {
  99.       memset (pwbuf, 0, sizeof (pwbuf));
  100.       rewind (dt);
  101.       if ((p = fgetpwent (pw)) == NULL)
  102.         {
  103.           fprintf (stderr, "*** No more entries in the passwd file.\n\n");
  104.           break;
  105.         }
  106.       if (!strcmp (p->pw_passwd, "*") || (!strcmp (p->pw_passwd, "!")))
  107.         {
  108.           fprintf (lg, "[o] Account: %s is disabled.\n", p->pw_name);
  109.           continue;
  110.         }
  111.       fprintf (stdout, "[o] cracking %s's password.\n", p->pw_name);
  112.       /* ugly (hey it works) continue/breaks have no effects in goto loops */
  113.  
  114.     craq:
  115.       if (!fgets (pwbuf, MAXSIZ, dt))
  116.         continue;
  117.       if (strip = strchr (pwbuf, '\n'))
  118.         *strip = '\0';
  119.       try = crypt (pwbuf, p->pw_passwd);
  120. #ifdef DEBUG
  121.       fprintf (stdout, "DEBUG: dict file word: %s\n", pwbuf);
  122.       fprintf (stdout, "DEBUG: encrypted dict file word: %s\n", try);
  123. #endif
  124.       if (!strcmp (try, p->pw_passwd))
  125.         {
  126.           fprintf (stdout, "\a\a[!] WE GOT ONE.\n");
  127.           fprintf (lg, "[!] user: %s password: %s\n", p->pw_name, pwbuf);
  128.           continue;
  129.         }
  130.       goto craq;
  131.     }
  132.   fclose (dt);
  133.   fclose (pw);
  134.   fclose (lg);
  135.   exit (0);
  136. }
  137.