From 752201c08a1731641a09304f74aa66fdb91b937f Mon Sep 17 00:00:00 2001 From: Russ Allbery Date: Mon, 4 Nov 2013 10:59:19 -0800 Subject: [PATCH] Support a maximum word length in cdbmake-wordlist Add a new -L (--max-length) option that filters out words longer than a particular length. --- tests/tools/cdbmake-wordlist-t | 10 +++++++++- tools/cdbmake-wordlist | 18 ++++++++++++++++-- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/tests/tools/cdbmake-wordlist-t b/tests/tools/cdbmake-wordlist-t index f2c63ac..e22587d 100755 --- a/tests/tools/cdbmake-wordlist-t +++ b/tests/tools/cdbmake-wordlist-t @@ -17,7 +17,7 @@ if ! command -v cdb >/dev/null 2>&1 ; then fi # Output the test plan. -plan 11 +plan 14 # Create a temporary directory and wordlist and ensure it's writable. tmpdir=`test_tmpdir` @@ -61,6 +61,14 @@ ok_program 'Database still contains password' 0 '1' \ ok_program 'Database does not contain non-ASCII password' 100 '' \ cdb -q "$tmpdir/wordlist.cdb" 'عربى' +# Regenerate the database, filtering out long passwords. +ok_program 'Database generation with no long passwords' 0 '' \ + "$cdbmake" -L 10 "$tmpdir/wordlist" +ok_program 'Database still contains bitterbane' 0 '1' \ + cdb -q "$tmpdir/wordlist.cdb" bitterbane +ok_program 'Database does not contain happenstance' 100 '' \ + cdb -q "$tmpdir/wordlist.cdb" happenstance + # Clean up. rm -f "$tmpdir/wordlist.cdb" rm -f "$tmpdir/wordlist" diff --git a/tools/cdbmake-wordlist b/tools/cdbmake-wordlist index 557ca60..c0ca0c4 100755 --- a/tools/cdbmake-wordlist +++ b/tools/cdbmake-wordlist @@ -42,10 +42,11 @@ my $fullpath = $0; local $0 = basename($0); # Parse the argument list. -my ($ascii, $min_length, $manual); +my ($ascii, $max_length, $min_length, $manual); Getopt::Long::config('bundling', 'no_ignore_case'); GetOptions( 'ascii|a' => \$ascii, + 'max-length|L=i' => \$max_length, 'min-length|l=i' => \$min_length, 'manual|man|m' => \$manual ); @@ -75,6 +76,7 @@ while (defined(my $word = <$in>)) { chomp($word); my $length = length($word); next if (defined($min_length) && $length < $min_length); + next if (defined($max_length) && $length > $max_length); if ($ascii) { next if $word =~ m{ [^[:ascii:]] }xms; next if $word =~ m{ [[:cntrl:]] }xms; @@ -106,7 +108,8 @@ cdbmake-wordlist - Create a cdb database from a wordlist =head1 SYNOPSIS -B [B<-am>] [B<-l> I] I +B [B<-am>] [B<-l> I] [B<-L> I] + I =head1 DESCRIPTION @@ -133,6 +136,17 @@ Filter all words that contain non-ASCII characters or control characters from the resulting cdb file, leaving only words that consist solely of ASCII non-control characters. +=item B<-L> I, B<--max-length>=I + +Filter all words of length greater than I from the resulting cdb +database. The length of each line (minus the separating newline) in the +input wordlist will be checked against I and will be filtered out +of the resulting database if it is shorter. Useful for generating +password dictionaries from word lists that contain random noise that's +highly unlikely to be used as a password. + +The default is to not filter out any words for maximum length. + =item B<-l> I, B<--min-length>=I Filter all words of length less than I from the resulting cdb -- 2.39.2