Welcome to HBH! If you have tried to register and didn't get a verification email, please using the following link to resend the verification email.

Improving code


ghost's Avatar
0 0

I have patched together this code which is currently generating a md5 rainbow table for people to use on my website.

So far it works well but I want to make it fill the db quicker.

What there are two main tables which this part of the code accesses.

  1. md5 This contains plaintext and md5s of all the characters the code goes through. (Mainly a modded out version of the code avaliable on securiteam

  2. md5_key This is a table which contains one record with one column called key. This basically gets updated each time a new record is added to the main database.

In essence I think I need to create a way of having many sessions generating many areas of my table.

Any suggestions will be appriciated

if ($action == 'brute') {

set_time_limit(0);
$yes=1111111111111111111111111000000000000000000000000;
$key2 = mysql_query("SELECT `key` FROM md5_key WHERE key2 = '1'");
$key3 = mysql_fetch_array($key2);
$key = $key3['key'];
$SIZ = strlen($key);
echo $SIZ;
for ($SIZE=$SIZ;$SIZE<$yes;$SIZE++) {
$memid = $_COOKIE[$cookie_pfx.'member_id'];
$HASH = "";
$keyspace = pow(95,$SIZE);
$start = strtotime ("now");
$start2 = strtotime ("now");
********** GEN first KEY ******************
$key2 = mysql_query("SELECT `key` FROM md5_key WHERE key2 = '1'");
$key3 = mysql_fetch_array($key2);
$key = $key3['key'];
if (!$key || (strlen($key) < $SIZE)) {
$key = "";
for ($y=0;$y<$SIZE;$y++)
{
$key = $key . " ";
}
}
*******************************************

for ($x=0;$x<$keyspace;$x++)
{
********** GEN NEW KEY ******************
for ($y=0;$y<$SIZE;$y++)
{
if ($key[$y] != "~")
  {
    $key[$y] = chr(ord($key[$y])+1);
    if ($y > 0)
    {
    for ($z = 0; $z < $y; $z++) $key[$z] = "0";
      
    }
    
    break;  

  }
}
$key2 = md5($key); 
*$key2 = crypt($key); 
$changekey = mysql_query("UPDATE `md5_key` SET `key` = '".$key."' WHERE `key2`='1'");
if( mysql_num_rows(mysql_query("SELECT * FROM `md5` WHERE hash='".md5($key)."'")) )
echo '<font color="*FF0000">Already in database ('.strip_tags($key).')</font><br/>';
else {
	$name = mysql_query("SELECT members_display_name FROM ibf_members WHERE id = '".mysql_real_escape_string($memid)."'");
	if (!$name) {
	$name2 =  "Unknown";
	}
	else {
$name2 =  mysql_fetch_array($name);
	}
$insert = "INSERT INTO md5 (plaintext, hash, hash2, hash3, user)".' VALUES ("'.mysql_real_escape_string($key).'", "'.md5($key).'", "'.md5(md5($key)).'", "'.md5(md5(md5($key))).'", "'.$name2["members_display_name"].'")';

if( mysql_query($insert) )
echo '<font color="*00FF00">Added <b>('.strip_tags(mysql_real_escape_string($key)).')</b></font><br/>';
}

if ($x % 24000 == 0)
{
  $x2++;
if ($x2 == 4)
{
  $x2 =0;
$time = strtotime ("now") - $start;
$start = strtotime("now");
if ($time==0) $time=1;
$rate = (24000 *4) / $time;
  print "... $x/$keyspace ($key) [$rate Keys/sec]&*92;r&*92;n";
}
}
}
}
}


ghost's Avatar
0 0

Okay, had to edit my last comment; I obviously don't know much about encrypting MD5 programmatically. My question would be, though… if the key is changed every time a record is added to the database, then why not let each process have their own self-contained key? What is the reasoning behind having one unified key if it's going to change with each new record? I'm probably missing something important, but that's my two cents.