07 February 2005

If anyone's interested, here's the perl script I wrote to check through a .pwf file and print the names of any users who are also using their username as a password. It's not documented, but I guess that'll be a feature of version 2.0.

while(<STDIN>){
        chop;
        next unless /^(.+):(.+)/;
        my $name = $1; 
        my $pwd = $2;
        my $salt = substr($pwd, 0, 2);

        if (crypt($name, $salt) eq $pwd) {
                print "$name\n";
        }
}

This iterates through whatever's coming in on stdin (so call this like perl foo.pl < bar.pwf) one line at a time. It chops the newline char off the end then skips the line unless it matches the pattern of one or more characters then a colon then one or more other characters. It then checks if the username encrypts to the encrypted password. If it does, the name gets printed to stdout. ta da!

No comments: