Advertisement
puggan

xlsxhashbf.php

Apr 16th, 2020
468
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.05 KB | None | 0 0
  1. <?php
  2. declare(strict_types=1);
  3.  
  4. $salt = 'OgybOFzbO8htTTop5nuilg==';
  5. $goal = 'X8fKMgIbDaiNDugq1OHuiTClHruTIL/9J48thPAx2kf3VMNWhnWttE3sLH1LKQ/Yg1UUOZd0Bq6ZLtviWDP2dQ==';
  6. $spinCount = 100000;
  7.  
  8. //$charlist = 'aejh';
  9. $charList = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-.,åäöÅÄÖ!$%#=@';
  10.  
  11. echo solve($salt, $goal, $spinCount, $charList, 3);
  12.  
  13. function solve($salt, $goal, $spinCount, $charList, $maxLength)
  14. {
  15.     $arrayCharlist = mb_str_split($charList);
  16.     fwrite(
  17.         STDERR,
  18.         'Bruteforce 1-' . $maxLength . ' of the ' . count($arrayCharlist) . ' characters ' . $charList . PHP_EOL
  19.     );
  20.  
  21.     $c = 0;
  22.     $status = static function ($c) {
  23.         fwrite(STDERR, "\r" . $c . ' @ ' . date('Y-m-d H:i:s') . PHP_EOL);
  24.     };
  25.     $status($c);
  26.  
  27.     foreach (range(1, $maxLength) as $length) {
  28.         foreach (combinations('', $length, $arrayCharlist) as $combination) {
  29.             fwrite(STDERR, '.');
  30.             $c++;
  31.             if ($c % 100 === 0) {
  32.                 $status($c);
  33.             }
  34.             $hash = xlsxhash($combination, $salt, $spinCount);
  35.             if ($hash === $goal) {
  36.                 $status($c);
  37.                 return $combination;
  38.             }
  39.         }
  40.     }
  41. }
  42.  
  43. function combinations($prefix, $length, $charlist)
  44. {
  45.     if ($length < 2) {
  46.         foreach ($charlist as $char) {
  47.             yield $prefix . $char;
  48.         }
  49.         return;
  50.     }
  51.     foreach ($charlist as $char) {
  52.         yield from combinations($prefix . $char, $length - 1, $charlist);
  53.     }
  54. }
  55.  
  56. function xlsxhash($utf8Password, $base64Salt, $intSpinCount)
  57. {
  58.     $utf16BEPassword = mb_convert_encoding($utf8Password, 'UTF-16');
  59.     $utf16LEPassword = pack('n*', ...unpack('v*', $utf16BEPassword));
  60.     $rawSalt = base64_decode($base64Salt);
  61.     $data = $rawSalt . $utf16LEPassword;
  62.     for ($i = 0; $i < $intSpinCount; $i++) {
  63.         $int32LE = pack('V', $i);
  64.         $data = hash('sha512', $data, true) . $int32LE;
  65.     }
  66.     $data = hash('sha512', $data, true);
  67.     return base64_encode($data);
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement