contra

Simple PHP md5 Cracker

Oct 21st, 2012
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.03 KB | None | 0 0
  1. // Simple Hash Cracker From Scratch no dictionary
  2. // run "php -f filename.php <hash here> "
  3. // modify PASSWORD_MAX_LENGTH if more than 8
  4.  
  5. <?php
  6. set_time_limit(0);
  7.  
  8. function getmicrotime() {
  9.    list($usec, $sec) = explode(" ",microtime());
  10.    return ((float)$usec + (float)$sec);
  11. }
  12.  
  13. $time_start = getmicrotime();
  14.  
  15. // algorithm of hash
  16. // see http://php.net/hash_algos for available algorithms
  17. define('HASH_ALGO', 'md5');
  18.  
  19. // max length of password to try
  20. define('PASSWORD_MAX_LENGTH', 8);
  21.  
  22. $charset = 'abcdefghijklmnopqrstuvwxyz';
  23. #$charset .= '0123456789';
  24. #$charset .= 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
  25. #$charset .= '~`!@#$%^&*()-_\/\'";:,.+=<>? ';
  26. $str_length = strlen($charset);
  27.  
  28.  
  29. // If no arguments given present usage info
  30. if ($_SERVER["argc"] < 1) {
  31.   print "Usage: attack.php <hash>\n";
  32.   exit;
  33. }
  34.  
  35. // Get MD5 checksum from command line
  36. $hash_password = $_SERVER["argv"][1];
  37.  
  38. function check($password)
  39. {
  40.         global $hash_password, $time_start;
  41.  
  42.         if (hash(HASH_ALGO, $password) == $hash_password) {
  43.  
  44.                 echo "\n\n" . "FOUND MATCH, password: " . $password . "\n\n";
  45.                 $time_end = getmicrotime();
  46.                 $time = $time_end - $time_start;
  47.                 echo "Found in " . $time . " seconds\n";
  48.                 exit;
  49.         }
  50. }
  51.  
  52.  
  53. function recurse($width, $position, $base_string)
  54. {
  55.         global $charset, $str_length;
  56.  
  57.         for ($i = 0; $i < $str_length; ++$i) {
  58.                 if ($position  < $width - 1) {
  59.                         recurse($width, $position + 1, $base_string . $charset[$i]);
  60.                 }
  61.                 check($base_string . $charset[$i]);
  62.         }
  63. }
  64.  
  65. echo "Target hash: " . $hash_password . "\n";
  66. for ($i = 1; $i < PASSWORD_MAX_LENGTH + 1; ++$i) {
  67.         echo "\n" . "Checking passwords with length:" .$i;
  68.         $time_check = getmicrotime();
  69.         $time = $time_check - $time_start;
  70.         echo "\n" . "Runtime: " . $time . " seconds";
  71.         recurse($i, 0, '');
  72. }
  73.  
  74. echo "Execution complete, no password found\r\n";
  75. ?>
Add Comment
Please, Sign In to add comment