# /usr/bin/perl #----------------------------------------------------------------------- # Purpose: convert hashcat found plains to masks, account for $HEX # Created: 2016-06-18 # $Id: pot2masks.pl,v 1.1 2016/06/19 05:02:19 root Exp root $ #----------------------------------------------------------------------- my %masks; $SIG{'INT'} = 'INT_handler'; sub print_masks { print "# ?2 = @!.*#_-\n"; print "# ?3 = all other specials\n"; print "# ?4 = [^luds] (all others - non-printable, or utf-8\n"; # Sort masks in frequency descending order. my @keylist = sort { $masks{$b} <=> $masks{$a} } keys(%masks); foreach my $key (@keylist) { # Option 1: blah,$count #print ($key . ',' . $masks{$key} . "\n"); # Option 2: $count blah print ($masks{$key} . ' ' . $key . "\n"); } } sub INT_handler { print STDERR "\n- Aborting. Writing masks ...\n"; print_masks(); exit(0); } #----------------------------------------------------------------------- my $record_count = 0; print STDERR "# ?2 = @!.*#_-\n"; print STDERR "# ?3 = all other specials\n"; print STDERR "# ?4 = [^luds] (all others - non-printable, or utf-8\n"; while (<>) { # Accumulate record counts for progress indicator. $record_count++; # Convert $HEX[] plains. # Credit: undeath, https://hashcat.net/forum/thread-3522.html if ($_ =~ m/\$HEX\[([A-Fa-f0-9]+)\]/) { $output = pack("H*", $1) . "\n"; } else { $output = $_; } # Replace elements with their mask equivalents. # TODO - consider an option to leave literal 8-bit intact instead of replacing with ?a # Replace simple alphanumerics. $output =~ tr/[a-z]/l/; $output =~ tr/[A-Z]/u/; $output =~ tr/[0-9]/d/; # Replace common specials - as custom set 2. $output =~ tr/[@!\.\*#_\-/2/; # Replace uncommon specials - as custom set 3. $output =~ tr/[\ \"$%\&\'()\+,\/:;<=>?\[\\\]^\`{|}~]/3/; # Replace everything not already categorized - as custom set 4. $output =~ s/[^luds23\n]/4/g; # Turn simple substitution into ?x syntax. $output =~ s/([luds234])/?$1/g; chomp($output); # Accumulate mask frequency counts. $masks{$output}++; if ($record_count % 1000000 == 0) { print STDERR 'M'; } elsif ($record_count % 100000 == 0) { print STDERR '.'; } } print STDERR "\n- Writing masks ...\n"; print_masks(); #-----------------------------------------------------------------------