Advertisement
Guest User

Untitled

a guest
Sep 30th, 2014
215
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.17 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <omp.h>
  5. #include <openssl/md5.h>
  6. #include <time.h>
  7.  
  8. const char LiteralsLower[] = "abcdefghijklmnopqrstuvwxyz";
  9. const int NLiteralsLower = sizeof( LiteralsLower ) - 1;
  10. char HexByteHash[16];
  11. time_t StartTime, EndTime;
  12. /* Prototypes */
  13. static void MD5Hash( const char * );
  14. static void BruteForce( const int * restrict, const int * restrict, const char *, const int *, int );
  15.  
  16. int main()
  17. {
  18. const char HashAsString[] = "172522ec1028ab781d9dfd17eaca4427"; // 'david'
  19. const int *BFOptionSize = &NLiteralsLower;
  20. const char *BFOption = LiteralsLower;
  21. int PasswordLength = 6;
  22. int StrLength = strlen( HashAsString );
  23.  
  24. for( int i = 0; i < StrLength / 2 ; i++ )
  25. {
  26. if( !sscanf( HashAsString + 2 * i, "%02x", ( unsigned int * ) &HexByteHash[i] ) )
  27. {
  28. fprintf( stderr, "FEHLER!!! -> '%s' ist kein Hash-Wert!n", HashAsString );
  29. exit( EXIT_FAILURE );
  30. }
  31. }
  32.  
  33. fprintf( stdout, "Hash: %s mit einer Länge von %li Zeichen.n", HashAsString, strlen( HashAsString ) / 2 );
  34.  
  35. /* Timer starten */
  36. time( &StartTime );
  37.  
  38. #pragma omp parallel shared( PasswordLength, BFOptionSize )
  39. for( int PWLength = 0; PWLength < PasswordLength + 1; ++PWLength )
  40. {
  41. /* Array-Größe für FstEntry und LstEntry festlegen */
  42. int FstEntry[PWLength], LstEntry[PWLength];
  43.  
  44. /* Array-Felder mit 0 initialisieren */
  45. for( int j = 0; j < PWLength; ++j )
  46. FstEntry[j] = LstEntry[j] = 0;
  47.  
  48. #pragma omp for schedule( dynamic )
  49. for( int i = 0; i < *BFOptionSize; ++i )
  50. {
  51. FstEntry[0] = i;
  52. LstEntry[0] = i + 1;
  53. BruteForce( FstEntry, LstEntry, BFOption, BFOptionSize, PWLength );
  54. }
  55. }
  56.  
  57. /* Timer stoppen */
  58. time( &EndTime );
  59.  
  60. puts( "!!! Wort nicht gefunden !!!" );
  61.  
  62. printf( "Elapsed time: %ld minutes %ld secondsnn", ( EndTime - StartTime ) / 60, ( EndTime - StartTime ) % 60 );
  63.  
  64. return EXIT_FAILURE;
  65. }
  66.  
  67. static void BruteForce( const int * restrict FirstEntry, const int * restrict LastEntry, const char *Letters, const int *NLetters, int PSSWDLength )
  68. {
  69. char Password[PSSWDLength];
  70. int Entry[PSSWDLength + 1];
  71. int i, j;
  72.  
  73. /* Null-Byte hinzufügen */
  74. memset( Entry, '', PSSWDLength );
  75. memset( Password, '', PSSWDLength );
  76.  
  77. /* FirstEntry in Entry kopieren */
  78. for( i = 0; i < PSSWDLength; ++i )
  79. Entry[i] = FirstEntry[i];
  80.  
  81. i = 0;
  82.  
  83. while( i < PSSWDLength )
  84. {
  85. /* Generiere Passwort für Hash-Vergleich */
  86. for( i = 0; i < PSSWDLength; ++i )
  87. Password[i] = Letters[Entry[i]];
  88.  
  89. /* generiertes Wort hashen */
  90. MD5Hash( Password );
  91.  
  92. /* Entry inkrementieren */
  93. for( i = 0; i < PSSWDLength && ++Entry[PSSWDLength-i-1] == *NLetters; i++ )
  94. Entry[PSSWDLength-i-1] = 0;
  95.  
  96. /* Return wenn Entry != LastEntry raus aus der Schleife */
  97. for( j = 0; j < PSSWDLength; ++j )
  98. if( Entry[j] != LastEntry[j] )
  99. break;
  100.  
  101. /* wenn Entry == LastEntry Funktion verlassen */
  102. if( j == PSSWDLength )
  103. return;
  104. }
  105. }
  106.  
  107. static void MD5Hash( const char *PasswordStringPointer )
  108. {
  109. unsigned char Digest[16];
  110.  
  111. /* MD5-Hash erzeugen */
  112. MD5_CTX md5;
  113. MD5_Init( &md5 );
  114. MD5_Update( &md5, PasswordStringPointer, strlen( PasswordStringPointer ) );
  115. MD5_Final( Digest, &md5 );
  116.  
  117. if( memcmp( HexByteHash, Digest, 16 ) == 0 )
  118. {
  119. printf( "!!! Wort gefunden: '%s' !!!n", PasswordStringPointer );
  120.  
  121. /* Timer stoppen */
  122. time( &EndTime );
  123.  
  124. printf( "Elapsed time: %ld minutes %ld secondsnn", ( EndTime - StartTime ) / 60, ( EndTime - StartTime ) % 60 );
  125.  
  126. /* Passwortsuche war erfolgreich */
  127. exit( EXIT_SUCCESS);
  128. }
  129. }
  130.  
  131. Hash: 172522ec1028ab781d9dfd17eaca4427 mit einer Länge von 16 Zeichen.
  132. !!! Wort gefunden: 'david' !!!
  133. Elapsed time: 0 minutes 1 seconds
  134.  
  135. Hash: 172522ec1028ab781d9dfd17eaca4427 mit einer Länge von 16 Zeichen.
  136. !!! Wort nicht gefunden !!!
  137. Elapsed time: 0 minutes 14 seconds
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement