<br><div class="gmail_quote">On Tue, Apr 15, 2008 at 3:36 PM, Seth Miller <<a href="mailto:seth@animejunkie.org">seth@animejunkie.org</a>> 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've having some trouble with a script. I'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. 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 'password' for testing<br>
but it doesn't seem to be working. Here's the portion of the script<br>
that's not working<br>
<br>
#BEGIN<br>
<br>
open (WORDLIST, "<$wordlist") or die "Can't open the wordlist: $!";<br>
<br>
while (my $pass = <WORDLIST>) {<br>
while ( my ($user,$password) = each (%data) ) {<br>
print "$user - $password\n" if ($password =~ /$pass/);<br>
}<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->new( file => $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;"> print "$user - $pass\n" 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't know if it'll make a difference to what you're trying to do really, but it'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>