forked from lastchoice/LongTail-Log-Analysis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
LongTail_password_analysis_part_2.pl
executable file
·161 lines (158 loc) · 4.04 KB
/
LongTail_password_analysis_part_2.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
#!/usr/bin/perl
$|=1;
#
# Foreign language days/months from
# http://www.europa-pages.co.uk/lessons/spanish-dates.html
#
$filename=$ARGV[0];
$show_matched_passwords=0;
$column_count=1;
#
# Yes, I read the file twice, once as whatever the file
# contents are, and then I wipe memory and read the file
# a second time and convert it to lower case. It takes
# a little longer, but saves memory
#
$dir[1]="/usr/local/dict-assorted";
$dir[2]="/usr/local/dict-packetstorm";
$directory_counter=1;
while ( $directory_counter <3){
open (LS, "ls $dir[$directory_counter]/*.gz $dir[$directory_counter]/*bz2 $dir[$directory_counter]/*.zip|")||die "can not run ls command on /usr/local/dict/\n";
$directory_counter++;
print "<TABLE>\n";
print "<TR><TH>Dictionary file</TH><TH>\# of words</TH><TH>\# of Matches</TH><TH>% matches</TH><TH>Comments</TH></TR>\n";
while (<LS>){
chomp;
if ( /rockyou/){next;}
$dictionary_name=$_;
$dictionary_word=0;
$dictionary_name_munged = $_;
$dictionary_name_munged =~ s/.usr.local.dict-//;
print "<TR>\n";
print "<TD>$dictionary_name_munged</TD>";
undef (%dict);
undef (%dictlower);
if (/.bz2$/){
open (DICT, "bzcat $_|") || die "can not open /usr/local/dict/$_\n";
}
if (/.gz$/){
open (DICT, "zcat -c $_|") || die "can not open /usr/local/dict/$_\n";
}
if (/.zip$/){
open (DICT, "unzip -c $_|") || die "can not open /usr/local/dict/$_\n";
}
$count=0;
while (<DICT>){
chomp;
$_ =~ s/\cM//g;
if ( $dict{$_} <1){
$dict{$_}=1;
$count++;
}
}
close (DICT);
print "<TD>$count</TD>";
open (FILE, "$filename") || die "Can not open $filename for reading\n";
while (<FILE>){
chomp;
if ($dict{"$_"} >0){
$dict{"$_"} ++;
$dictionary_word++;$flag=1;
if ($show_matched_passwords == 1){
print "<BR>$_ ";
$column_count++;
if ($column_count >8){$column_count=1; print "<BR>\n";}
}
}
#else {print "Miss on $_ "; }
}
close (FILE);
print "<TD> $dictionary_word ";
$percentage=$dictionary_word/$count*100;
$percentage_string=sprintf("%.2f",$percentage);
print "<TD> $percentage_string </TD> ";
if ( $dictionary_word > ($count*.90) ){
if ( $dictionary_word == $count ){
print "<TD>INTERESTING, ALL words in dictionary were used";
}
else {
print "<TD>More than 90%, INTERESTING , missing entries are:";
foreach $value (keys %dict)
{
if ($dict{$value}<2){print "$value "}
}
}
}
print "</TR>\n";
$dictionary_word=0;
#############################################################################
#
# Lower Case now
#
$_ = $dictionary_name;
print "<TR><TD>$dictionary_name_munged in lower case ";
undef (%dict);
undef (%dictlower);
if (/.bz2$/){
#print "DEBUG bz2\n";
open (DICT, "bzcat $_|") || die "can not open /usr/local/dict/$_\n";
}
if (/.gz$/){
#print "DEBUG gz\n";
open (DICT, "zcat -c $_|") || die "can not open /usr/local/dict/$_\n";
}
if (/.zip$/){
#print "DEBUG zip\n";
open (DICT, "unzip -c $_|") || die "can not open /usr/local/dict/$_\n";
}
$count=0;
$tmp_count=0;
while (<DICT>){
chomp;
$_ =~ s/\cM//g;
$_ =~ tr/[A-Z]/[a-z]/;
if ( $dict{$_} <1){
$dict{$_}=1;
$count++;
}
$tmp_count++;
# if ($tmp_count > 10000){$tmp_count=0; print ".";}
}
close (DICT);
print "<TD> $count </TD>";
open (FILE, "$filename") || die "Can not open $filename for reading\n";
while (<FILE>){
chomp;
if ($dict{"$_"} >0){
$dict{"$_"} ++;
$dictionary_word++;$flag=1;
if ($show_matched_passwords == 1){
print "$_ ";
$column_count++;
if ($column_count >8){$column_count=1; print "<BR>\n";}
}
}
}
close (FILE);
print "<TD> $dictionary_word ";
$percentage=$dictionary_word/$count*100;
$percentage_string=sprintf("%.2f",$percentage);
print "<TD>$percentage_string</TD> ";
if ( $dictionary_word > ($count*.90) ){
if ( $dictionary_word == $count ){
print "<TD>INTERESTING, ALL words in dictionary were used";
}
else {
print "<TD>More than 90%, INTERESTING , missing entries are:";
foreach $value (keys %dict)
{
if ($dict{$value}<2){print "$value "}
}
}
}
print "</TR>\n";
$dictionary_word=0;
print "\n";
}
close (LS);
}