Skip to content

Instantly share code, notes, and snippets.

@yashodhank
Forked from Wruczek/WHMCSDecryptor.php
Created April 27, 2020 03:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save yashodhank/ab83f0dcf1d2e0d52aa7c33800c1cd0d to your computer and use it in GitHub Desktop.
Save yashodhank/ab83f0dcf1d2e0d52aa7c33800c1cd0d to your computer and use it in GitHub Desktop.
Simple PHP script to decrypt WHMCS hashed strings
<?php
$encoded_string = "JATa2iUqVdzCkBP5RiyitlQlUiACl8UrpJOeGUJO";
$cc_encryption_hash = "SOmECRAZYLONGHASHROFLCOPTERBBQKTHX";
echo decrypt_whmcs($encoded_string, $cc_encryption_hash);
function decrypt_whmcs($encoded_string, $cc_encryption_hash) {
$key = md5(md5($cc_encryption_hash)) . md5($cc_encryption_hash);
$hash_key = _hash($key);
$hash_length = strlen($hash_key);
$string = base64_decode($encoded_string);
$tmp_iv = substr($string, 0, $hash_length);
$string = substr($string, $hash_length);
$iv = $out = "";
for($c = 0; $c < $hash_length; $c++) {
$iv .= chr(ord($tmp_iv[$c]) ^ ord($hash_key[$c]));
}
$key = $iv;
for($c = 0; $c < strlen($string); $c++) {
if ($c != 0 && $c % $hash_length == 0) {
$key = _hash($key . substr($out, $c - $hash_length, $hash_length));
}
$out .= chr(ord($key[$c % $hash_length]) ^ ord($string[$c]));
}
return $out;
}
function _hash($string) {
if (function_exists("sha1")) {
$hash = sha1($string);
} else {
$hash = md5($string);
}
$out = "";
for($c = 0; $c < strlen($hash); $c += 2) {
$out .= chr(hexdec($hash[$c] . $hash[$c + 1]));
}
return $out;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment