|
| 1 | +<?php |
| 2 | +// script by cyclone to check plaintexts against Umbraco HMACSHA256 hashes |
| 3 | +// while slow, script supports multi-gigabyte wordlists |
| 4 | +// coding this in php was an experiment, so don't cry about how slow it runs |
| 5 | +// $hash_file must be formatted as: "salt==:hash=" (without quotes) |
| 6 | +// requires php & php-mbstring to be installed (sudo apt install php8.2 php8.2-php-mbstring -y) |
| 7 | +// tested with php7.4 & php8.2 |
| 8 | +// version 2022-12-10.1500 |
| 9 | + |
| 10 | +echo "\e[H\e[J"; // clear screen |
| 11 | +$t=time(); // define time |
| 12 | + |
| 13 | +$start_time = microtime(true); |
| 14 | +$count = 0; |
| 15 | +$count_lines = 0; |
| 16 | +$time = 0; |
| 17 | +$wordlist = "wordlist/cyclone_hk_v2.txt"; // point to local wordlist file <---------------------------------------------------- ## EDIT ## |
| 18 | +$hash_file = file('tmp_hash.txt', FILE_SKIP_EMPTY_LINES|FILE_IGNORE_NEW_LINES); // point to 'salt==:hash=' file <-------------- ## EDIT ## |
| 19 | + |
| 20 | +echo "\n#############################################\n"; |
| 21 | +echo "# Cyclone's Umbraco HMACSHA256 Hash Cracker #\n"; |
| 22 | +echo "#############################################\n"; |
| 23 | +echo "\nStarting Search...\n"; |
| 24 | +echo "This may take a while with many hashes and/or large wordlists.\n"; |
| 25 | + |
| 26 | +// optimized getLines wordcount (works with large wordlists) |
| 27 | +function getLines($file) { |
| 28 | + $f = fopen($file, 'rb'); |
| 29 | + $lines = 0; $buffer = ''; |
| 30 | + while (!feof($f)) { |
| 31 | + $buffer = fread($f, 8192); |
| 32 | + $lines += substr_count($buffer, "\n"); |
| 33 | + } |
| 34 | + fclose($f); |
| 35 | + if (strlen($buffer) > 0 && $buffer[-1] != "\n") { |
| 36 | + ++$lines; |
| 37 | + } |
| 38 | + return $lines; |
| 39 | +} |
| 40 | + |
| 41 | +// start main cracking loop |
| 42 | +if ($file = fopen($wordlist, "r")) { |
| 43 | + echo "\nCounting lines in $wordlist...\n"; |
| 44 | + $lines = getLines($wordlist); |
| 45 | + echo "Total lines: $lines\n"; |
| 46 | + while(!feof($file)) { |
| 47 | + $line_raw = fgets($file); |
| 48 | + $line = trim($line_raw); // trim off whitespace from $line_raw |
| 49 | + $line_pass_utf16le = mb_convert_encoding($line, "UTF-16LE"); // convert $line to UTF-16LE |
| 50 | + $count_lines++; // count lines processed |
| 51 | + foreach($hash_file as $hash_line) { |
| 52 | + $hash_array = preg_split("/\:/", $hash_line); // split $hash_file into salt / hash arrays |
| 53 | + $salt_split = trim($hash_array[0]); // salt array |
| 54 | + $hash_split = trim($hash_array[1]); // hash array |
| 55 | + $input = $salt_split . $hash_split; // $input salt/hash for comparison with $output |
| 56 | + $salt_proper = base64_decode($salt_split) . base64_decode($salt_split) . base64_decode($salt_split) . base64_decode($salt_split); // process salt |
| 57 | + $dgst = hash_hmac("sha256", $line_pass_utf16le, $salt_proper, true); // hmac256 |
| 58 | + $output = $salt_split . base64_encode($dgst); // compare $output with $imput to see if we've cracked the hash with $line (password) |
| 59 | + if (time()-$time >= 60) { // show words / percentage searched every 60 seconds |
| 60 | + $percent = ($count_lines / $lines) * 100; |
| 61 | + echo "\nProgress: " . $count_lines . " of " . $lines . ", " . number_format((float)$percent, 2, '.', '') . "%" . ", Hashes found: " . $count; |
| 62 | + $time = time(); |
| 63 | + } |
| 64 | + if ($output == $input){ // display cracked hashes |
| 65 | + echo "\n##################################################################################\n"; |
| 66 | + echo "Password: $line\n"; |
| 67 | + echo "salt==hash: "; |
| 68 | + echo $salt_split . ":" . base64_encode($dgst); |
| 69 | + echo "\n"; |
| 70 | + $count++; // count +1 hashes found |
| 71 | + echo "\nHashes found: " . $count; |
| 72 | + echo "\n##################################################################################\n"; |
| 73 | + } |
| 74 | + } |
| 75 | + } |
| 76 | + fclose($file); // close wordlist |
| 77 | +} |
| 78 | +echo "\nFinished searching.\n"; |
| 79 | +echo "\nHashes found: " . $count . "\n\n"; // show how many hashes were found |
| 80 | +$end_time = microtime(true); // end clock time in seconds |
| 81 | +$execution_time = ($end_time - $start_time); // calculate script execution time |
| 82 | +echo "Script runtime: " . number_format((float)$execution_time, 3, '.', '') . " seconds\n"; // show script execution time |
| 83 | +?> |
0 commit comments