<br><div class="gmail_quote">On Tue, Apr 15, 2008 at 3:36 PM, Seth Miller &lt;<a href="mailto:seth@animejunkie.org">seth@animejunkie.org</a>&gt; wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Hello all,<br>
<br>
I&#39;ve having some trouble with a script. &nbsp;I&#39;m trying to grab a complete<br>
list of email accounts on the server and check the password against a<br>
word list to find weak passwords. &nbsp;The hash %data has the email<br>
address in the key and the account password in the value.<br>
<br>
The word list file currently just has the word &#39;password&#39; for testing<br>
but it doesn&#39;t seem to be working. &nbsp;Here&#39;s the portion of the script<br>
that&#39;s not working<br>
<br>
#BEGIN<br>
<br>
open (WORDLIST, &quot;&lt;$wordlist&quot;) or die &quot;Can&#39;t open the wordlist: $!&quot;;<br>
<br>
while (my $pass = &lt;WORDLIST&gt;) {<br>
 &nbsp;while ( my ($user,$password) = each (%data) ) {<br>
 &nbsp; &nbsp;print &quot;$user - $password\n&quot; if ($password =~ /$pass/);<br>
 &nbsp;}<br>
}<br>
<br>
close WORDLIST;<br>
<br>
#END</blockquote><div><br>Other than the chomp, you might want to change your algorithm from O(n^2) to O(n)-ish by using a module like Regexp::Assemble to generate a single regex to apply against your hash.<br><br>It would look something like this:<br>
<br><span style="font-family: courier new,monospace;">#!/usr/bin/perl</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">use warnings; use strict;</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">use Regexp::Assemble;<br><br># ...<br><br>my $regex = Regexp::Assemble-&gt;new( file =&gt; $wordlist);</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">while (my($user,$pass) = each %data) {</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp; print &quot;$user - $pass\n&quot; if $pass =~ $regex;</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">}</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">__END__</span><br style="font-family: courier new,monospace;"><br>I don&#39;t know if it&#39;ll make a difference to what you&#39;re trying to do really, but it&#39;s something you might want to try.<br>
<br>cheers,<br><br>-Scott<br></div></div><br>--<br>Jonathan Scott Duff<br><a href="mailto:perlpilot@gmail.com">perlpilot@gmail.com</a>