Advertisement
puggan

xlsxbf.c

Apr 24th, 2020
496
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.74 KB | None | 0 0
  1. #include <openssl/sha.h>
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <string.h>
  5. #include <time.h>
  6.  
  7. #include "Base64Encode.h"
  8. #include "Base64Decode.h"
  9.  
  10. int nextPassword(int charlistLength, const char* charlist, int passwordLength, int* passwordIndex, char* password)
  11. {
  12.     if(passwordLength > 1) {
  13.         if(nextPassword(charlistLength, charlist, passwordLength - 1, passwordIndex + 1, password + 1) > 0) {
  14.             return 1;
  15.         }
  16.     }
  17.  
  18.     (*passwordIndex)++;
  19.     if(*passwordIndex >= charlistLength) {
  20.         *passwordIndex = 0;
  21.         *password = *charlist;
  22.         return 0;
  23.     }
  24.     *password = charlist[*passwordIndex];
  25.     return 1;
  26. }
  27.  
  28. void status(int c, char* password)
  29. {
  30.     time_t t;
  31.     time(&t);
  32.     struct tm *d = localtime(&t);
  33.     printf("\r%d @ %04d-%02d-%02d %02d:%02d:%02d with ", c, d->tm_year+1900, d->tm_mon+1, d->tm_mday, d->tm_hour, d->tm_min, d->tm_sec);
  34.     putchar('"');
  35.     while(*password) {
  36.         // Simple UTF-16 part -> UTF-8
  37.         if(*password > 0x80 || *password < 0) {
  38.             putchar(0xc3);
  39.             putchar(*password - 0x40);
  40.         } else {
  41.             putchar(*password);
  42.         }
  43.         password++;
  44.     }
  45.     putchar('"');
  46.     putchar('\n');
  47. }
  48.  
  49. int main()
  50. {
  51.     // start of config
  52.  
  53.     const int charlistLength = 77;
  54.     char charlist[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-.,______!$%#=@";
  55.     charlist[65] = 0xe5; // å in UTF-16 is [0x00, 0xe5], but we only use the lower part.
  56.     charlist[66] = 0xe4; // ä
  57.     charlist[67] = 0xf6; // ö
  58.     charlist[68] = 0xc5; // Å
  59.     charlist[69] = 0xc4; // Ä
  60.     charlist[70] = 0xd6; // Ö
  61.  
  62.     const int saltLength = 16;
  63.     const char* saltB64 = "PBEN2sa8NDIpdtvhjLYtjQ==";
  64.  
  65.     const char* goal = "lbU0e7K9mQ54tlh+rZVF8YkCrOX0/d2frkuhBJUUmgtvJG0HEyPQXC+Q/X74HYwNF32gHCUbZmdXNmFwX+Y2yA==";
  66.  
  67.     int passwordLength = 1;
  68.     int maxPasswordLength = 30;
  69.     int skip = 62900-1;
  70.  
  71.     // end of config
  72.  
  73.     setvbuf(stdout, NULL, _IONBF, 0);
  74.  
  75.     int passwordIndex[maxPasswordLength];
  76.     char password[maxPasswordLength + 1];
  77.  
  78.     int c = 0;
  79.  
  80.     for(;passwordLength <= maxPasswordLength; passwordLength++) {
  81.         for(int i = 0; i < passwordLength; i++) {
  82.             passwordIndex[i] = 0;
  83.             password[i] = charlist[0];
  84.         }
  85.         passwordIndex[passwordLength - 1] = -1;
  86.         password[passwordLength] = 0;
  87.  
  88.         char* salt;
  89.         Base64Decode(saltB64, &salt);
  90.  
  91.         unsigned char initData[saltLength + passwordLength*2 + 1];
  92.         unsigned char* data = initData;
  93.         unsigned char* passwordStart = initData + saltLength;
  94.         memcpy(initData, salt, saltLength);
  95.  
  96.         while(nextPassword(charlistLength, charlist, passwordLength, passwordIndex, password))
  97.         {
  98.             if(skip >= 0) {
  99.                 if(skip-- > 0) {
  100.                     c++;
  101.                     continue;
  102.                 }
  103.                 status(c + 1, password);
  104.             }
  105.  
  106.             for(int i = 0; i < passwordLength; i++) {
  107.                 passwordStart[i*2] = password[i];
  108.                 passwordStart[i*2 + 1] = 0;
  109.             }
  110.  
  111.             data = initData;
  112.             unsigned char hashData1[SHA512_DIGEST_LENGTH + 4];
  113.             unsigned char hashData2[SHA512_DIGEST_LENGTH + 4];
  114.  
  115.             unsigned char* hash = hashData1;
  116.             unsigned char* loopIndex;// = data + SHA512_DIGEST_LENGTH;
  117.             SHA512(data, saltLength + passwordLength*2, hash);
  118.  
  119.             for(int i = 0; i < 100000; i++) {
  120.                 if(i & 1) {
  121.                     hash = hashData1;
  122.                     data = hashData2;
  123.                 } else {
  124.                     hash = hashData2;
  125.                     data = hashData1;
  126.                 }
  127.                 loopIndex = data + SHA512_DIGEST_LENGTH;
  128.                 loopIndex[0] = (i >> 0) & 0xff;
  129.                 loopIndex[1] = (i >> 8) & 0xff;
  130.                 loopIndex[2] = (i >> 16) & 0xff;
  131.                 loopIndex[3] = (i >> 24) & 0xff;
  132.                 SHA512(data, SHA512_DIGEST_LENGTH + 4, hash);
  133.             }
  134.  
  135.             const char* hash2 = (const char*) hash;
  136.             char* b64;
  137.             Base64Encode(hash2, &b64, SHA512_DIGEST_LENGTH);
  138.  
  139.             putchar('.');
  140.             if(++c % 100 == 0) {
  141.                 status(c, password);
  142.             }
  143.             if(strcmp(b64, goal) == 0) {
  144.                 printf("\n%d @ '%s' => '%s'\n", c, password, b64);
  145.                 return 0;
  146.             }
  147.         }
  148.     }
  149.     return 1;
  150. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement