ResistMonsanto Posted June 21, 2011 Share Posted June 21, 2011 Hello, I've just recently started learning PHP and wanted to make a quick script to compare MD5 hash's, but I've seem to have done something wrong. This is what I've got so far, can someone point out my mistake? The $_GET is used to pass the MD5 hash which is to be tested against the given wordlist. <html> <body> <?php $hashtocrack = $_GET['crackme']; $file = fopen("dictionary.txt","r"); if(isset($file)){ while(!feof($file)){ $hash = fgets($file); $md5check = md5($hash); if($md5check == $hashtocrack){ echo "Hash found! -> ", $hash; exit(1); } } } ?> </body> </html> Any help is greatly appreciated. Link to comment https://forums.phpfreaks.com/topic/239951-what-am-i-doing-wrong-here/ Share on other sites More sharing options...
gizmola Posted June 21, 2011 Share Posted June 21, 2011 The first thing you did wrong "here" ie. phpfreaks, was to post a bunch of code with no php or code tags. Also, where is your indentation? Your 2nd mistake was not describing what the problem is. I don't see anything in the code that jumps out at me as being obviously wrong. Depending on the size of dictionary.txt this could take a long time to run, so it may be timing out. The php.ini has variables that control the amount of time a script can run, how much memory it can use, etc. The default timeout is usually pretty short. Link to comment https://forums.phpfreaks.com/topic/239951-what-am-i-doing-wrong-here/#findComment-1232593 Share on other sites More sharing options...
fugix Posted June 21, 2011 Share Posted June 21, 2011 Try <html> <body> <?php $hashtocrack = $_GET['crackme']; $file = fopen("dictionary.txt","r"); if(isset($file)){ while($hash = fgets($file)){ $md5check = md5($hash); if($md5check == $hashtocrack){ echo "Hash found! -> ", $hash; exit(1); } } } ?> </body> </html> Link to comment https://forums.phpfreaks.com/topic/239951-what-am-i-doing-wrong-here/#findComment-1232594 Share on other sites More sharing options...
ResistMonsanto Posted June 21, 2011 Author Share Posted June 21, 2011 Thanks for the second bit, forgot to specify my issue. When I put a hash in that I know has the plaintext equivalent in the worldlist, I still get no results. So I thought maybe I was making an obvious mistake somewhere. And @fugix, thanks man I tried that but had no luck Link to comment https://forums.phpfreaks.com/topic/239951-what-am-i-doing-wrong-here/#findComment-1232606 Share on other sites More sharing options...
fugix Posted June 21, 2011 Share Posted June 21, 2011 What do your txt file contents look like Link to comment https://forums.phpfreaks.com/topic/239951-what-am-i-doing-wrong-here/#findComment-1232607 Share on other sites More sharing options...
ResistMonsanto Posted June 21, 2011 Author Share Posted June 21, 2011 It's just in a line format because fgets reads line by line right, so the way I have it should be hashing the word on each line and comparing it, then moving on to the next line and discarding the previous right? Or am I effin up somewhere? The list is like this though; This is my awesome wordlist Link to comment https://forums.phpfreaks.com/topic/239951-what-am-i-doing-wrong-here/#findComment-1232611 Share on other sites More sharing options...
Pikachu2000 Posted June 21, 2011 Share Posted June 21, 2011 There's probably whitespace/linefeeds either in the form value, or in the file. Try trim()ming the values before hashing and comparing them. Link to comment https://forums.phpfreaks.com/topic/239951-what-am-i-doing-wrong-here/#findComment-1232612 Share on other sites More sharing options...
ResistMonsanto Posted June 21, 2011 Author Share Posted June 21, 2011 Right on man, that solved the issue. Thanks a ton to everyone who replied. Working code; <html> <body> </h1>Hash Value</h1> <?php $hashtocrack = $_GET['crackme']; $file = fopen("sec.txt","r"); if(isset($file)){ while($hash = trim(fgets($file))){ $md5check = md5($hash); if($md5check == $hashtocrack){ echo "<br />Hash found! -> ", $hash; exit(1); } } } ?> </body> </html> Link to comment https://forums.phpfreaks.com/topic/239951-what-am-i-doing-wrong-here/#findComment-1232626 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.