sulfericacid has asked for the wisdom of the Perl Monks concerning the following question:
I'm preparing for a Security+ Comptia exam on the 15th of this month and after going through the resources, brute force password breaking is a fairly big issue. I've never been too interested in playing with it myself but I figured it'd be a good learning experience to see the difference in breaking a 3 character password vs a 5+ character password.
Below is my first attempt. It works fairly well on passwords 1-3 characters long. A 3 character password took about 20 minutes (sometimes as much as 40). And to my shocker I was able to snatch a 4 character password in just over 12 hours (it took 12,000,000 password tries to solve it).
Not happpy yet, I decided to try with a 5 character password. After about 16 hours it locked up saying "OUT OF MEMORY".
Anyway, I have a few questions and please keep in mind it's not perfect (it doesn't read a dictionary as I want this to be a totally random brute force and it doesn't have every character a password can have).
1) I have a hash set up that stores every attempted password which seemed good for short 1-3 character passwords. I know this is why the password solver ran out of memory but would the script work the same without it? My initial assumption is it could ultimately take infinite tries to crack the password unless it's told to find new ones. What are your thoughts on this?
2) I never got into multithreading or anything of that nature but would this be a prime example of something that could be improved by using it?
3) Share your experiences in doing this with Perl. How fast has yours solved your passwords for you? Anything you can share will help me find a base line to improve this script and give me more experience/knowledge for my Security+ exam.
Below is my script in its entirety.
#!/usr/bin/perl use warnings; use strict; my $length = 5; my $password = "passw"; my @chars = ('a' .. 'z', 'A' .. 'Z', 0-9, '!', '@', '#', '$', '%', '^' +, '&', '*', ' '); my %tried; my $tries = 0; my $starttime = time(); while(1) { my @temp_chars; for (1 .. $length) { my @character = shuffle(@chars); my $char = $character[0]; push(@temp_chars, $char); } my $guess = join("", @temp_chars); if (exists $tried{$guess}) { print "\tSkipping $guess - already attempted\n\n"; } $tries++; $tried{$guess} = "1"; if ($guess eq $password) { my $endtime = time(); my $time_took = $endtime - $starttime; print "We found your password. It is $guess!\n"; print "It took $time_took seconds and $tries tries"; exit; } else { print "Guessing: $guess\t\tTry # $tries\n\n"; } } sub shuffle { return @_ if !@_ || ref $_ [0] eq 'ARRAY' && !@{$_ [0]}; my $array = @_ == 1 && ref $_ [0] eq 'ARRAY' ? shift : [@_]; for (my $i = @$array; -- $i;) { my $r = int rand ($i + 1); ($array -> [$i], $array -> [$r]) = ($array -> [$r], $array -> [ +$i]); } wantarray ? @$array : $array; }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Improve password solver
by BrowserUk (Patriarch) on Jul 03, 2009 at 00:54 UTC | |
Re: Improve password solver
by Limbic~Region (Chancellor) on Jul 03, 2009 at 00:39 UTC | |
Re: Improve password solver
by toolic (Bishop) on Jul 03, 2009 at 00:33 UTC | |
by tprocter (Sexton) on Jul 03, 2009 at 01:03 UTC | |
Re: Improve password solver
by jethro (Monsignor) on Jul 03, 2009 at 01:23 UTC | |
Re: Improve password solver
by eyepopslikeamosquito (Archbishop) on Jul 03, 2009 at 01:54 UTC | |
Re: Improve password solver
by AnomalousMonk (Archbishop) on Jul 03, 2009 at 09:40 UTC | |
by tprocter (Sexton) on Jul 03, 2009 at 14:54 UTC | |
Re: Improve password solver
by JavaFan (Canon) on Jul 03, 2009 at 08:11 UTC |