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.

PHP md5 MySQL Db


ghost's Avatar
0 0

<?php $dbh=mysql_connect ("localhost", "siliconb_md5", "<PASSWORD is normally here but hidden atm") or die ("I cannot connect to the database because I'm a faggot but more importantly" . mysql_error()); mysql_select_db ("siliconb_md5");

if ($_GET['action'] == 'search'){ $result = mysql_query("SELECT * FROM md5 WHERE hash = ".$hash." ORhash2 = ".$hash." OR hash3 = ".$hash." LIMIT 1"); if (mysql_num_rows($result) > 0 ) { $ech = mysql_fetch_array($result); echo $ech['plaintext']."<br>Added to the database by: ".$ech['user']; } else { echo 'Sorry, not found. If you find it out please add it.'; } }

if ($_GET['action'] == 'add') { $hash = $_GET['word']; $i = 0; $hashs = explode(";", $hash); while ($hashs[$i]) { $result = mysql_query("SELECT * FROM md5 WHERE plaintext = ".$hashs[$i]." LIMIT 1"); $num = mysql_num_rows($result); if ($num > 1) { echo "Already in database (".$hashs[$i].")</br>"; $i ++; } else { $memid = $_COOKIE[$cookie_pfx ."member_id"]; require_once "../includes/newfunctions.php"; $user = getUserfromID($memid); while ($hashs = explode(";", $hash)) { $insert = mysql_query("INSERT INTO md5 (plaintext, hash, hash2, hash3, user) VALUES (".$hash.", ".md5($hashs[$i]).", ".md5(md5($hashs[$i])).", ".md5(md5(md5($hashs[$i]))).", ".$user.")"); if ($insert) { echo "Added to database! (".$hashs[$i].")</br>"; } $i ++; } } } }

?>

<form name="form1" method="get" action=""/ <table width="200" border="0"> <tr> <td> Word: </td> <td>

&lt;input type=&quot;text&quot; name=&quot;word&quot; /&gt;    &lt;/td&gt;

</tr> <tr> <td>Hash:</td> <td><input type="text" name="hash" /></td> </tr> <tr> <td>Action</td> <td> <select name="action"> <option value="search">Search</option> <option value="add">Add</option> </select> </td> </tr> <tr> <td colspan="2"><center><input type="submit" name="Submit" value="Go!!!"></center></td> </tr> </table> </form>

I keep getting errors with the mysql_num_rows everywhere. Any ideas?

Thanx

mozzer

[edit by SM]Disabled smileys[/edit]


ghost's Avatar
0 0

I thought it wasy mysql_numrows(), but I might be wrong.


ghost's Avatar
0 0

No, its definately mysql_num_rows


ghost's Avatar
0 0

In PHP 5.1.2 (Dajoob.com) mysql_numrows() works, so maybe you have a different version?


SySTeM's Avatar
-=[TheOutlaw]=-
20 0

Yes, it is mysql_num_rows(), what are the exact errors you are getting?


ghost's Avatar
0 0

Warning: mysql_numrows(): supplied argument is not a valid MySQL result resource in /home/siliconb/public_html/cracker/index.php on line 21 mozzer

is the exact ouput. Though I know why the "mozzer" is there!


ghost's Avatar
0 0

mozzer wrote: Warning: mysql_numrows(): supplied argument is not a valid MySQL result resource in /home/siliconb/public_html/cracker/index.php on line 21 mozzer

is the exact ouput. Though I know why the "mozzer" is there!

perhaps it is because you used mysql_numrows() where you should have used mysql_num_rows(). I don't know for sure, though, since I haven't ever tried using an SQL database.


ghost's Avatar
0 0

I have looked at that but I think it is because there is something wrong with what I am getting from the db


ghost's Avatar
0 0

?word=a&action=add

Unknown column 'a' in 'where clause'


ghost's Avatar
0 0

Sorry about the double post but it now works but adds it in and then adds the wrong plaintext with blank encrpyted.

This is the new code

<?php <MySQL Connection Stuff>

if ($_GET['action'] == 'search'){ $result = mysql_query("SELECT * FROM md5 WHERE hash = '".$hash."' OR hash2 = '".$hash."' OR hash3 = '".$hash."'") or die(mysql_error()); ; if (mysql_num_rows($result) > 0 ) { $ech = mysql_fetch_array($result); echo $ech['plaintext']."<br>Added to the database by: ".$ech['user']; } else { echo 'Sorry, not found. If you find it out please add it.'; } }

if ($_GET['action'] == 'add') { $hash = $_GET['word']; $i = 0; $hashs = explode(";", $hash); while ($hashs[$i]) { $result = mysql_query("SELECT * FROM md5 WHERE plaintext = '".$hashs[$i]."'") or die(mysql_error()); $num = mysql_num_rows($result); if ($num > 1) { echo "Already in database (".$hashs[$i].")</br>"; $i ++; } else { $memid = $_COOKIE[$cookie_pfx ."member_id"]; require_once "../includes/newfunctions.php"; while ($hashs = explode(";", $hash)) { $insert = mysql_query("INSERT INTO md5 (plaintext, hash, hash2, hash3, user) VALUES ('".$hash."', '".md5($hashs[$i])."', '".md5(md5($hashs[$i]))."', '".md5(md5(md5($hashs[$i])))."', '".getUserfromID($memid)."')") or die(mysql_error()); ; if ($insert) { echo "Added to database! (".$hashs[$i].")</br>"; } $i ++; } } } }

?>

<form name="form1" method="get" action=""/ <table width="200" border="0"> <tr> <td> Word: </td> <td>

&lt;input type=&quot;text&quot; name=&quot;word&quot; /&gt;    &lt;/td&gt;

</tr> <tr> <td>Hash:</td> <td><input type="text" name="hash" /></td> </tr> <tr> <td>Action</td> <td> <select name="action"> <option value="search">Search</option> <option value="add">Add</option> </select> </td> </tr> <tr> <td colspan="2"><center><input type="submit" name="Submit" value="Go!!!"></center></td> </tr> </table> </form>


ghost's Avatar
0 0

I didn't test it out or anything, but this should work (Click 'quote' if you want some formatting):

 error_reporting( E_ALL ^ E_NOTICE );
 @mysql_connect(&#39;localhost&#39;, &#39;root&#39;, &#39;rootpass&#39;) or die(&#39;Failed to connect to the database.&#39;);

 require_once(&#39;../includes/newfunctions.php&#39;);
 $memid = $_COOKIE[$cookie_pfx.&#39;member_id&#39;];

 $action = isset($_GET[&#39;action&#39;]) ? $_GET[&#39;action&#39;] : &#39;&#39;;
 $hash   = isset($_GET[&#39;hash&#39;]) ? $_GET[&#39;hash&#39;] : &#39;&#39;;

 if( $action == &#39;search&#39; ) {
     if( !preg_match(&#39;/^[a-f0-9]{32}$/&#39;, $hash) )
         echo &#39;Sorry, but that is a invalid MD5 hash.&#39;;

     elseif( !mysql_num_rows($result = mysql_query(&quot;SELECT plaintext, user FROM `md5` WHERE hash=&#39;$hash&#39; or hash2=&#39;$hash&#39; or hash3=&#39;$hash&#39;&quot;)) )
         echo &#39;We apologize, but that hash was not found in the database.&lt;br/&gt;&#39;.
              &#39;If you find out the plaintext, please add it.&#39;;

     else {
         $r = mysql_fetch_assoc($result);
         echo &quot;{$r[&#39;plaintext&#39;]}&lt;br/&gt;&*92;nAdded to the database by &lt;b&gt;{$r[&#39;user&#39;]}&lt;/b&gt;&quot;;
     }
 } elseif( $action == &#39;add&#39; ) {
     $hash = addslashes(urldecode(stripslashes($hash)));
     foreach( explode(&#39;;&#39;, $hash) as $word ) {
         if( mysql_num_rows(mysql_query(&quot;SELECT * FROM `md5` WHERE plaintext=&#39;$word&#39;&quot;)) )
             echo &quot;Already in database ($word)&lt;br/&gt;&*92;n&quot;;
         else {

             $insert = &quot;INSERT INTO md5 (plaintext, hash, hash2, hash3, user)&quot;.
                       &#39;  VALUES (&quot;$hash&quot;, &quot;&#39;.md5($hash).&#39;&quot;, &quot;&#39;.md5(md5($hash)).&#39;&quot;, &quot;&#39;.md5(md5(md5($hash))).&#39;&quot;, &quot;&#39;.getUserfromID($memid).&#39;&quot;)&#39;;

             if( mysql_query($insert) )
                 echo &quot;Added ($word)&lt;br/&gt;&*92;n&quot;;
         }
     }
 }

?&gt;
&lt;form name=&quot;form1&quot;&gt;
    &lt;table width=&quot;400&quot; border=&quot;0&quot; align=&quot;center&quot;&gt;
        &lt;tr&gt;
            &lt;td&gt;Hash/Word to add:&lt;/td&gt;
            &lt;td&gt;&lt;input type=&quot;text&quot; name=&quot;hash&quot;/&gt;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;td&gt;Action:&lt;/td&gt;
            &lt;td&gt;
                &lt;select name=&quot;action&quot;&gt;
                    &lt;option value=&quot;search&quot;&gt;Search&lt;/option&gt;
                    &lt;option value=&quot;add&quot;&gt;Add&lt;/option&gt;
                &lt;/select&gt;
            &lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr align=&quot;center&quot;&gt;
            &lt;td colspan=&quot;2&quot;&gt;&lt;input type=&quot;submit&quot; value=&quot;Go!&quot;/&gt;&lt;/td&gt;
        &lt;/tr&gt;
    &lt;/table&gt;
&lt;/form&gt;```

ghost's Avatar
0 0

I had to edit that slightly to get it to work with my servers settings but now it works. Thanx

Out of interest how long have you been learning PHP for?

EDIT: Now I need to see how I can quickly use word lists


ghost's Avatar
0 0

I've been programming in PHP for about 6 years now.

To add wordlists, all you have to do is:

&lt;?php

set_time_limit(0);

foreach( file(&#39;wordlist.txt&#39;) as $line ) {
    $word = str_replace(array(&quot;*r&quot;, &quot;*n&quot;), &#39;&#39;, $line);

    mysql_query(&quot;INSERT query here&quot;);
}
?&gt;

Change * to a backslash, for some reason the HBH filters try changing it


ghost's Avatar
0 0

Wow, I've only been at it 3 months. Nice to talk to a true Guru.

Thanx for the help with the code

mozzer

EDIT: When I get something out of a remote db each new line gets encypted from some reason. Why?

set_time_limit(0);
$list = file($_GET[&#39;hash&#39;]);
foreach($list as $line ) {
$word = str_replace(array(&quot;*r&quot;, &quot;*n&quot;, &quot; &quot;), &#39;&#39;, $line);
if( mysql_num_rows(mysql_query(&quot;SELECT * FROM `md5` WHERE plaintext=&#39;&quot;.mysql_real_escape_string($word).&quot;&#39;&quot;)) )
echo &quot;Already in database ($word)&lt;br/&gt;&quot;;
else {
	$user = meh()
	}
	else {
$name2 =  mysql_fetch_array($name);
	}
$insert = &quot;INSERT INTO md5 (plaintext, hash, hash2, hash3, user)&quot;.
&#39; VALUES (&quot;&#39;.mysql_real_escape_string($word).&#39;&quot;, &quot;&#39;.md5($word).&#39;&quot;, &quot;&#39;.md5(md5($word)).&#39;&quot;, &quot;&#39;.md5(md5(md5($word))).&#39;&quot;, &quot;&#39;.$user.&#39;&quot;)&#39;;

if( mysql_query($insert) )
echo &quot;Added (&quot;.$word.&quot;)&lt;br/&gt;&quot;;
}
}
}```

ghost's Avatar
0 0

Sorry if people are against double posting or anything but I thought 4 edits was a bit excessive. The answer was to use trim() if anyone has a similar problem