Code Sample |
#!/usr/bin/perl # curagacrack2.pl # Demonstration brute force password cracker #2 using use Algorithm::Combinatorics use strict; use warnings; use Algorithm::Combinatorics qw(variations_with_repetition); #==========================// SETTINGS // ========================= my @set = ( 'a'..'z', 'A'..'Z', '0'..'9' ); my $skip = 1; # filter: set to 1 to skip any perm containing 3 adjacent identical chars my $printall = 0; # set to 1 to print every perm my $startlen; my $endlen; # Leave the following commented out to do all length perms within @set #~ $startlen = 3; # begin processing with strings of length $startlen #~ $endlen = 5; # end processing with strings of length $endlen #================================================================ my $perm = ""; my $k; my $i; sub print_perm { print "Perm no. $k = $perm\n"; } #================================// MAIN // ======================= $SIG{'HUP'} = 'print_perm'; # print current perm on receipt of sighup $k = 0; my $setlen = $#set + 1; # defaults unless (defined($startlen)) { $startlen = 1 } unless (defined($endlen)) { $endlen = $setlen } unless ($startlen >= 1) { die "Error: startlen must be >= 1" } unless ($endlen >= $startlen) { die "Error: startlen must be <= endlen" } unless ($endlen <= $setlen) { die "Error: endlen must be <= $setlen" } foreach $i ($startlen..$endlen) { my $p = variations_with_repetition(\@set, $i); my $c; while ( $c = $p->next) { $k++; $perm = join("", @$c); if ($printall == 1) { print "$k $perm\n"; } if (($skip == 1) && ($perm =~ /(.)\1\1/)){ next } system("echo $perm | 2>/dev/null openssl bf -pass stdin -d -in encryptedfile -out out.txt && file -b out.txt | grep -qE '^ASCII.+text'") == 0 && die "Found passphrase \"$perm\""; } } |
Code Sample |
time combina -a -A -n -p 1 -k 5 | ( while read PW; do if 2>/dev/null openssl bf -pass pass:$PW -d -in encryptedfile -out out.txt; then if file -b out.txt | grep -qE '^ASCII.+text'; then echo "Found passphrase $PW"; exit; else continue; fi; fi; done ) |