Brute Force PHP Script
August 22, 2008
Last weekend I came across this site, Hack This Site!. I've been able to breeze through the Basic missions for the most part, and the Javascript missions, seriously? It's pretty interesting and I know there are many other sites out there that I'm looking forward to trying out once I get far enough with this one.
I came across one mission where I had to crack a hashed password. I was feeling ambitious enough to go ahead and write a brute force script to tackle the task. I messed around an entire day trying to figure out the right combination of nested-loops to solve the problem. I came to the realization that probably the only practical way of solving this algorithm was recursion, which I had very limited experience in doing. So I started searching the web and finally came across a brute force python script written by Robert Green. I ported it over to PHP, and in a matter of seconds I was moving on to the next mission.
<?php
/*
* Thanks to Robert Green for this script he wrote in python
* http://www.rbgrn.net/blog/2007/09/how-to-write-a-brute-force-password-cracker.html
* I took what we wrote and ported this to PHP
*
* This script was written for PHP 5, but should work with
* PHP 4 if the hash() function is replaced with md5() or something else
*/
#########################################################
/* Configuration */
// this is the hash we are trying to crack
define('HASH', '098f6bcd4621d373cade4e832627b4f6');
// algorithm of hash
// see http://php.net/hash_algos for available algorithms
define('HASH_ALGO', 'md5');
// max length of password to try
define('PASSWORD_MAX_LENGTH', 8);
// available characters to try for password
// uncomment additional charsets for more complex passwords
$charset = 'abcdefghijklmnopqrstuvwxyz';
//$charset .= '0123456789';
//$charset .= 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
//$charset .= '~`!@#$%^&*()-_\/\'";:,.+=<>? ';
#########################################################
function check($password)
{
if (hash(HASH_ALGO, $password) == HASH) {
echo 'FOUND MATCH, password: '.$password."\r\n";
exit;
}
}
function recurse($width, $position, $base_string)
{
global $charset;
for ($i = 0; $i < strlen($charset); ++$i) {
if ($position < $width - 1) {
recurse($width, $position + 1, $base_string . $charset[$i]);
}
check($base_string . $charset[$i]);
}
}
echo 'target hash: '.HASH."\r\n";
for ($i = 1; $i < PASSWORD_MAX_LENGTH + 1; ++$i) {
echo 'checking passwords with width: '.$i."\r\n";
recurse($i, 0, '');
}
echo "Execution complete, no password found\r\n";
?>

13 Comments
How could this script be modified to work on a site where there are two intput boxes name: and number, the number filed is 6 characters but can only be from 000000 to 999999? Any suggestions???
12M1WD <a href="http://ldjtdjomygal.com/">ldjtdjomygal</a>, [url=http://wleadoyqacbk.com/]wleadoyqacbk[/url], [link=http://odscfqimmztc.com/]odscfqimmztc[/link], http://znvzmuslklhv.com/
It is not out-of-date information? Because I have other data on this theme. http://video-online-go.ru/map.html
Hi there!
My first post at this great blog!I wanna show u my dayly updated blog: <a href= http://giantblg.cn/whole-ass-amateur.html >Whole Ass Amateur</a>P.S. if you don't want to see this message please write me to no.ads08@gmail.com with subject "NO ADS" and URL of your forumThank you for cooperation!Hi there!
My first post at this great blog!I wanna show u my dayly updated blog: <a href= http://giantblg.cn/whole-ass-amateur.html >Whole Ass Amateur</a>P.S. if you don't want to see this message please write me to no.ads08@gmail.com with subject "NO ADS" and URL of your forumThank you for cooperation!My first post at this great blog!
I wanna show u my dayly updated blog: <a href= http://giantblg.cn/whole-ass-amateur.html >Whole Ass Amateur</a>P.S. if you don't want to see this message please write me to no.ads08@gmail.com with subject "NO ADS" and URL of your forumThank you for cooperation!Great Site, http://bau-free-hosting.co.cc/, 685, rent rent rent north carolina, >:-OOO, fall down by trevor morgan lyrics, whsg, united states marine corps birthday party, 101812, glycogen storage disease type ix, >:)), elvis life size stand ups, :]]], 5hp briggs and stratton troubleshooting, orzq, new ipod touch screen release, 213, interesting facts about delaware first state, lpe, psychological effects of poverty in children, elzf, 24 hour starbucks locations los angeles, xajuyk,
Hi There,
Good Day,
Excellent Site,
Good Job,
Respect Work,
Optimize ur script:
Exp:
<code>$strLenght = strlen($charset);for ($i = 0; $i < $strLenght; ++$i) { [...]}</code>;)posted by Covi @ Sep 16, 2008 09:26 PM EDT