Transfusion

4brute.c

Mar 29th, 2019
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 7.46 KB | None | 0 0
  1. /* 4brute -- brute-force the plaintext out of a list of collected
  2.  * crypt'd tripcodes, as used by the futallaby-based image boards
  3.  * (i.e: 4chan.org, wakachan.net)
  4.  * --
  5.  * Compile:
  6.  * gcc -O3 -o 4brute 4brute.c -lssl # Most Linuxen
  7.  * gcc -O3 -o 4brute 4brute.c -ldes # NetBSD
  8.  * gcc -O3 -o 4brute 4brute.c ../mumble/libdes.a # Mine
  9.  * gcc -O3 -fast -mcpu=7450 -o 4tripper 4tripper.c -lcrypto -lssl # OSX on a G4
  10.  * --
  11.  * Usage:
  12.  * ./4brute tripcodelist |tee >cracked.
  13.  * Where "channerlist" looks like:
  14.  *     Lain:dBqnRui06E
  15.  *     Thock:a5sXscBP32
  16.  *     WAHa:WAHa.06x36
  17.  *     [etc..]
  18.  * --
  19.  * Hints:
  20.  * The default searchspace is rather large; however 95% of people will
  21.  * be using a single lowercase word as a tripcode, or some other such
  22.  * shortcut. Try these at first:
  23.  * ./4brute -k 0123456789. -p 10000 <tripcode file>
  24.  * ./4brute -k 0123456789abcdef -p 10000 <tripcode file> - the Lain special!
  25.  * ./4brute -k -r abcdefghijklmnopqrstuvwxyz -p 10000 <tripcode file>
  26.  * Of course, people will now look at the above and immediately try to use
  27.  * letters that would maximise your search time, in which case, you can do
  28.  * things like this:
  29.  * ./4brute -r -k ABCDEFGHIJKLMNOPQRSTUVWXYZ <tripcode file>
  30.  * ./4brute -r -k \?\>\<\/\.\,\"\:\'\;\}\{\]\[ ...etc... <tripcode file>
  31.  * --
  32.  * TODO:
  33.  * Provide something for partitioning up the search across N machines.
  34.  * --
  35.  * COMING SOON (maybe): the quick dictionary cracker. It needs a rewrite
  36.  * though..
  37.  * --
  38.  * Copyright 2004 Chris Baird,, <cjb@brushtail.apana.org.au>
  39.  * Licenced as per the GNU Public Licence Version 2.
  40.  * Released: 2004/12/22. Your CPU heatsink /is/ working, right?
  41.  */
  42.  
  43. #include <stdio.h>
  44. #include <stdlib.h>
  45. #include <string.h>     /* strncpy(3) */
  46. #include <stdlib.h>     /* srandom(3) */
  47. #include <time.h>       /* time(3) */
  48. #include <signal.h>     /* signal(3) */
  49.  
  50. /* not quite the fastest DES library around, but still reasonable, and
  51.  * most free Unixen should have it available. (Works for at least NetBSD
  52.  * and Debian GNU/Linux (after "apt-get install libssl-dev")
  53.  */
  54. #include <openssl/des.h>
  55.  
  56. /* gotta ask for a robust way to tell the difference between the two..
  57.  */
  58. #if !NEW_OPENSSL
  59. #  define our_fcrypt des_fcrypt /* NetBSD, Linux... */
  60. #else
  61. #  define our_fcrypt DES_fcrypt /* Gentoo, OSX... */
  62. #endif
  63.  
  64. extern char *our_fcrypt(const char *buf,const char *salt, char *ret);
  65.  
  66. /*
  67.  * lol internet
  68.  */
  69.  
  70. void usage(void)
  71. {
  72.   fprintf (stderr, "usage: 4brute [-s string] [-e string] [-t string] "
  73.        "[-p num] [-r] tripcodefile\n"
  74.        "\t-s string : initial key for search\n"
  75.        "\t-e string : final key for search\n"
  76.        "\t-k string : characters to use in the keys\n"
  77.        "\t-p num    : show progress every <num> keys checked\n"
  78.        "\t-r    : randomize the order of the keytable\n"
  79.        "    \"tripcodefile\" has the format \"username:tripcode\", "
  80.        "one per line\n");
  81.   exit (1);
  82. }
  83.  
  84. void indexify (int *counts, char *word, char *table)
  85. {
  86.   int i, j;
  87.  
  88.   for (i = 0; (word[i] != 0) && (i < 9); i++)
  89.     {
  90.       for (j = 0; table[j] != 0 && table[j] != word[i]; j++)
  91.     ;
  92.       counts[i] = j;
  93.     }
  94. }
  95.  
  96. void scramble (char *table)
  97. {
  98.   int i, l, r;
  99.   char t;
  100.  
  101.   srandom ((unsigned int)time(NULL));
  102.   l = strlen (table);
  103.   for (i = 0; table[i] != 0; i++)
  104.     {
  105.       r = random () % l;
  106.       t = table[i];
  107.       table[i] = table[r];
  108.       table[r] = t;
  109.     }
  110. }
  111.  
  112. char wordchecked[9] = "4chan";
  113.  
  114. void interrupted (int value)
  115. {
  116.   printf ("\n\"%s\"  \n", wordchecked);
  117.   exit(-1);
  118. }
  119.  
  120. int main(int argc, char *argv[])
  121. {
  122.   FILE *fpass;
  123.   char c, *p, salt0, salt1, salt[3], word[9], result[14], line[96];
  124.   char users[4096][64], crypts[4096][16], salttable[256], table[256];
  125.   int i, j, usercount=0, count=1, quit=0, counts[8], ending[8], counttick=0;
  126.   int opt_e=0, opt_r=0, opt_k=0;
  127.   extern char *optarg;
  128.   extern int optind;
  129.  
  130.   /* setup */
  131.  
  132.   strcpy (table, "etaonrishdlfcmugpywbvkxjqz"
  133.       "ETAONRISHDLFCMUGPYWBVKXJQZ0123456789"
  134.       " .!:#/`()_$[]+*{}-");
  135.  
  136.   salt[2] = 0;
  137.   for (i = 0; i < 8; i++)
  138.     {
  139.       counts[i] = -1;
  140.       word[i] = 0;
  141.     }
  142.  
  143.   for (i = 0; i <= 255; i++)
  144.     salttable[i] = '.';
  145.   for (i = '/'; i <= 'z'; i++)
  146.     salttable[i] = i;
  147.   for (i = ':'; i <= '@'; i++)
  148.     salttable[i] = i + 7;
  149.   for (i = '['; i <= '`'; i++)
  150.     salttable[i] = i + 6;
  151.  
  152.   /* arg parsing */
  153.  
  154.   while ((c = getopt(argc, argv, "p:k:s:e:r")) != -1)
  155.     switch (c)
  156.       {
  157.       case 'p':
  158.     counttick = atoi (optarg);
  159.     break;
  160.  
  161.       case 's':
  162.     strncpy (word, optarg, 8);
  163.     word[8] = 0;
  164.     indexify (counts, word, table);
  165.     printf ("Starting search from \"%s\"\n", word);
  166.     break;
  167.  
  168.       case 'e':
  169.     opt_e = 1;
  170.     indexify (ending, optarg, table);
  171.     printf ("Ending search at \"%s\"\n", optarg);
  172.     break;
  173.  
  174.       case 'k':
  175.     opt_k = 0;
  176.     strncpy (table, optarg, 256);
  177.     printf ("Searching through: %s\n", table);
  178.     break;
  179.  
  180.       case 'r':
  181.     opt_r = 1;
  182.     break;
  183.  
  184.       default: usage();
  185.       }
  186.  
  187.   argc -= optind;
  188.   argv += optind;
  189.  
  190.   if (opt_r)
  191.     {
  192.       scramble (table);
  193.       printf ("Searching through (randomised): %s\n", table);
  194.     }
  195.  
  196.   counts[0] = 0;
  197.   word[0] = table[0];
  198.  
  199.   /* tripcode file reading */
  200.  
  201.   if ((fpass = fopen (argv[0], "r")) == 0)
  202.     usage();
  203.  
  204.   while (fgets (line, 96, fpass) != 0)
  205.     {
  206.       for (i = 0, p = line; *p != ':';)
  207.     users[usercount][i++] = *p++;
  208.       users[usercount][i] = 0;
  209.  
  210.       for (i = 0, p++; *p != '\n';)
  211.     crypts[usercount][i++] = *p++;
  212.       crypts[usercount][i] = 0;
  213.  
  214.       if (i != 10)
  215.     {
  216.       printf ("Bad input at line %d\n", usercount);
  217.       exit(1);
  218.     }
  219.  
  220.       usercount++;
  221.     }
  222.   fclose (fpass);
  223.   printf ("Number of users scanned: %d\n\n", usercount); fflush(stdout);
  224.  
  225.   /* SIGINT catching */
  226.  
  227.   signal (SIGINT, interrupted);
  228.  
  229.   /* mainloop */
  230.  
  231.   while (!quit)
  232.     {
  233.       if (opt_e && (counts[0] == ending[0] && counts[1] == ending[1] &&
  234.             counts[2] == ending[2] && counts[3] == ending[3] &&
  235.             counts[4] == ending[4] && counts[5] == ending[5] &&
  236.             counts[6] == ending[6] && counts[7] == ending[7]))
  237.     quit = 1;
  238.  
  239.       /* find the right salt .. $salt=substr($cap."H.",1,2); */
  240.  
  241.       salt0 = word[1];
  242.       salt1 = word[2];
  243.       if (!salt0)
  244.     {
  245.       salt0 = 'H';
  246.       salt1 = '.';
  247.     }
  248.       else if (!salt1)
  249.     {
  250.       salt1 = 'H';
  251.     }
  252.       salt[0] = salttable[salt0];
  253.       salt[1] = salttable[salt1];
  254.  
  255.       /* blah */
  256.  
  257.       if (counttick && (count++ == counttick))
  258.     {
  259.       printf ("%s\r", word); fflush(stdout);
  260.       count = 1;
  261.     }
  262.  
  263.       /* crunch */
  264.  
  265.       our_fcrypt (word, salt, result);
  266.  
  267.       for (i = 0; i < usercount; i++)
  268.     {
  269.       if (result[3] != crypts[i][0]) continue;
  270.       if (result[4] != crypts[i][1]) continue;
  271.       if (result[5] != crypts[i][2]) continue;
  272.       if (result[6] != crypts[i][3]) continue;
  273.       if (result[7] != crypts[i][4]) continue;
  274.       if (result[8] != crypts[i][5]) continue;
  275.       if (result[9] != crypts[i][6]) continue;
  276.       if (result[10] != crypts[i][7]) continue;
  277.       if (result[11] != crypts[i][8]) continue;
  278.       if (result[12] != crypts[i][9]) continue;
  279.       printf ("Username \"%s\"\r\t\t\t\t\tCrypt \"%s\"\tTripcode \"%s\"\n",
  280.           users[i], crypts[i], word);
  281.       fflush(stdout);
  282.       for (j = 0; j < 10; j++)
  283.         crypts[i][j] = 0;
  284.     }
  285.  
  286.       strcpy (wordchecked, word);
  287.  
  288.       /* bump */
  289.  
  290.       i = 0;
  291.     check:
  292.       counts[i]++;
  293.       c = table[counts[i]];
  294.       word[i] = c;
  295.  
  296.       if (c == 0)
  297.     {
  298.       counts[i] = 0;
  299.       word[i] = table[0];
  300.       i++;
  301.       if (i < 8)
  302.         goto check;
  303.       quit = 1;
  304.     }
  305.     }
  306.  
  307.   return 0;
  308. }
Add Comment
Please, Sign In to add comment