fork download
  1. /*
  2. * This is a high-speed brute-force password cracker for MySQL hashed
  3. * passwords. It can break an 8-character password containing any
  4. * printable ascii characters in a matter of hours on an ordinary PC.
  5. *
  6. * This program is public domain. Share and enjoy.
  7. *
  8. * Example:
  9. * $ gcc -O2 -fomit-frame-pointer mysqlfast.c -o mysqlfast
  10. * $ mysqlfast 6294b50f67eda209
  11. * Hash: 6294b50f67eda209
  12. * Trying length 3
  13. * Trying length 4
  14. * Found pass: barf
  15. *
  16. * The MySQL password hash function could be strengthened considerably
  17. * by:
  18. * - making two passes over the password
  19. * - using a bitwise rotate instead of a left shift
  20. * - causing more arithmetic overflows
  21. */
  22.  
  23. #include <stdio.h>
  24.  
  25. typedef unsigned long u32;
  26.  
  27. /* Allowable characters in password; 33-126 is printable ascii */
  28. #define MIN_CHAR 33
  29. #define MAX_CHAR 126
  30.  
  31. /* Maximum length of password */
  32. #define MAX_LEN 12
  33.  
  34. #define MASK 0x7fffffffL
  35.  
  36. int crack0(int stop, u32 targ1, u32 targ2, int *pass_ary)
  37. {
  38. int i, c;
  39. u32 d, e, sum, step, diff, div, xor1, xor2, state1, state2;
  40. u32 newstate1, newstate2, newstate3;
  41. u32 state1_ary[MAX_LEN-2], state2_ary[MAX_LEN-2];
  42. u32 xor_ary[MAX_LEN-3], step_ary[MAX_LEN-3];
  43. i = -1;
  44. sum = 7;
  45. state1_ary[0] = 1345345333L;
  46. state2_ary[0] = 0x12345671L;
  47.  
  48. while (1) {
  49. while (i < stop) {
  50. i++;
  51. pass_ary[i] = MIN_CHAR;
  52. step_ary[i] = (state1_ary[i] & 0x3f) + sum;
  53. xor_ary[i] = step_ary[i]*MIN_CHAR + (state1_ary[i] << 8);
  54. sum += MIN_CHAR;
  55. state1_ary[i+1] = state1_ary[i] ^ xor_ary[i];
  56. state2_ary[i+1] = state2_ary[i]
  57. + ((state2_ary[i] << 8) ^ state1_ary[i+1]);
  58. }
  59.  
  60. state1 = state1_ary[i+1];
  61. state2 = state2_ary[i+1];
  62. step = (state1 & 0x3f) + sum;
  63. xor1 = step*MIN_CHAR + (state1 << 8);
  64. xor2 = (state2 << 8) ^ state1;
  65.  
  66. for (c = MIN_CHAR; c <= MAX_CHAR; c++, xor1 += step) {
  67. newstate2 = state2 + (xor1 ^ xor2);
  68. newstate1 = state1 ^ xor1;
  69.  
  70. newstate3 = (targ2 - newstate2) ^ (newstate2 << 8);
  71. div = (newstate1 & 0x3f) + sum + c;
  72. diff = ((newstate3 ^ newstate1) - (newstate1 << 8)) & MASK;
  73. if (diff % div != 0) continue;
  74. d = diff / div;
  75. if (d < MIN_CHAR || d > MAX_CHAR) continue;
  76.  
  77. div = (newstate3 & 0x3f) + sum + c + d;
  78. diff = ((targ1 ^ newstate3) - (newstate3 << 8)) & MASK;
  79. if (diff % div != 0) continue;
  80. e = diff / div;
  81. if (e < MIN_CHAR || e > MAX_CHAR) continue;
  82.  
  83. pass_ary[i+1] = c;
  84. pass_ary[i+2] = d;
  85. pass_ary[i+3] = e;
  86. return 1;
  87. }
  88.  
  89. while (i >= 0 && pass_ary[i] >= MAX_CHAR) {
  90. sum -= MAX_CHAR;
  91. i--;
  92. }
  93. if (i < 0) break;
  94. pass_ary[i]++;
  95. xor_ary[i] += step_ary[i];
  96. sum++;
  97. state1_ary[i+1] = state1_ary[i] ^ xor_ary[i];
  98. state2_ary[i+1] = state2_ary[i]
  99. + ((state2_ary[i] << 8) ^ state1_ary[i+1]);
  100. }
  101.  
  102. return 0;
  103. }
  104.  
  105. void crack(char *hash)
  106. {
  107. int i, len;
  108. u32 targ1, targ2, targ3;
  109. int pass[MAX_LEN];
  110.  
  111. if ( sscanf(hash, "%8lx%lx", &targ1, &targ2) != 2 ) {
  112. printf("Invalid password hash: %s\n", hash);
  113. return;
  114. }
  115. printf("Hash: %08lx%08lx\n", targ1, targ2);
  116. targ3 = targ2 - targ1;
  117. targ3 = targ2 - ((targ3 << 8) ^ targ1);
  118. targ3 = targ2 - ((targ3 << 8) ^ targ1);
  119. targ3 = targ2 - ((targ3 << 8) ^ targ1);
  120.  
  121. for (len = 3; len <= MAX_LEN; len++) {
  122. printf("Trying length %d\n", len);
  123. if ( crack0(len-4, targ1, targ3, pass) ) {
  124. printf("Found pass: ");
  125. for (i = 0; i < len; i++)
  126. putchar(pass[i]);
  127. putchar('\n');
  128. break;
  129. }
  130. }
  131. if (len > MAX_LEN)
  132. printf("Pass not found\n");
  133. }
  134.  
  135. int main(int argc, char *argv[])
  136. {
  137. int i;
  138. if (argc <= 1)
  139. printf("usage: %s hash\n", argv[0]);
  140. for (i = 1; i < argc; i++)
  141. crack(argv[i]);
  142. return 0;
  143. }
Success #stdin #stdout 0s 5280KB
stdin
/*  Berechnung des Hamming-Abstandes zwischen zwei 128-Bit Werten in 	*/
/*	einer Textdatei. 													*/
/*  Die Werte müssen auf einer separaten Zeile gespeichert sein			*/
/* 																		*/
/*	Erstellt: 17.5.2010													*/
/*  Autor: Thomas Scheffler												*/

#include <stdio.h>
#include <stdlib.h>

#define ARRAY_SIZE 32

unsigned Hamdist(unsigned x, unsigned y)
{
  unsigned dist = 0, val = x ^ y;
 
  // Count the number of set bits
  while(val)
  {
    ++dist; 
    val &= val - 1;
  }
 
  return dist;
}



int main (void)
{
	char hex;
	int i;
	int a[ARRAY_SIZE];
	int b[ARRAY_SIZE];
	int hamDist = 0;
	FILE* fp;
	
	//Arrays mit 0 initialisieren
	for (i = 0; i < ARRAY_SIZE; ++i)
	{
  		a[i] = 0;
  		b[i] = 0;
	}

	
	fp = fopen("hex.txt","r");
	if (fp == NULL) 
	{
		printf("Die Datei hex.txt wurde nicht gefunden!");
		exit(EXIT_FAILURE);
	}

	i=0;
	printf("1.Zeile einlesen.\n");

 	while((hex=fgetc(fp))!='\n' && hex != EOF)
    {
        a[i]=strtol(&hex,0,16);
		i++;
    }
	i=0;
	printf("2.Zeile einlesen.\n");

 	while((hex=fgetc(fp))!='\n' && hex != EOF)
    {
    	b[i]=strtol(&hex,0,16);
        i++;
    }
	fclose(fp);

	printf("Hamming-Abweichung pro Nibble:\n");
	for (i = 0; i < ARRAY_SIZE; ++i)
	{
		printf ("%i\t%i\t%i\n",a[i],b[i],Hamdist(a[i],b[i]));
		hamDist += Hamdist(a[i],b[i]);
	}
	printf ("\nHamming-Abweichung der Hash-Werte:%d\n",hamDist);
}

stdout
usage: ./prog hash