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/fgets


ghost's Avatar
0 0

Hi I'm playing around with fgets so I made a quick md5 dictionary attack:

<h2>Hash:</h2>
<input type="text" name=hash>
<input type="submit" value="Crack Me!">

<?php
$check_file = file_exists('dict.txt');
if (! $check_file)
{
die("Error: No wordlist found!");
} 
$md5hash = $_POST['hash'];
$open = fopen("dict.txt", "r");
  while (! feof($open))
    {
    $dict = fgets($open);
    $hashdict = md5($dict);
    }
if ($md5hash == $hashdict)
  {
  echo "<br /> <br />The Password Is: " . $dict;
  break;
  }
else
  {
  echo "<br /> <br />Password Not Found";
  }
fclose($open);
?>```

and dict.txt is:
```markup
asdfasdf
pass
sdfsdf

The code will work as long as 'pass' is the first word in dict.txt. Otherwise it will not find the password. I'm guessing the problem is with fgets because it is not getting each line of dict.txt? Can you guys help me out? Thanks


Mr_Cheese's Avatar
0 1

your IF statement is outside your while loop.

it needs to be inside. otherwise it will only compare the last line in the dictionary.


spyware's Avatar
Banned
0 0

Wait, like three seconds ago someone replied here with a post full of PHP code, right? Where did that go?


ghost's Avatar
0 0

Thanks :)


ghost's Avatar
0 0

… Welcome.