-
Notifications
You must be signed in to change notification settings - Fork 10
/
LongTail_make_historical_dashboard_charts.pl
executable file
·260 lines (224 loc) · 6.87 KB
/
LongTail_make_historical_dashboard_charts.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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
#!/usr/bin/perl
# 2016-05-02 Bug fix so that it only counts SSH attacks, instead
# of ALL attacks (including http and telnet, etc).
#
# Rebuilds dashboard images a day at a time
#
# Called as:
# /usr/local/etc/LongTail_make_historical_dashboard_charts.pl /var/www/html/honey/historical/2015/01/04
$dir=$ARGV[0];
$DATE=$ARGV[0];
$DATE =~ s/historical\///;
$DATE =~ s/\/var\/www\/html\/honey\///;
$DATE =~ s/\//-/g;
print "DATE is -->$DATE<--\n";
if ( ! -d $dir) {
print "$dir is not a directory, exiting now\n";
exit;
}
#current-attack-count.data
#todays_username.count
#todays_password.count
#todays_ips.count
chdir "$dir"; # Change to the date we are looking at rebuilding
chdir ".."; # And then, change up one directory
#
# Yes, I recalculate min, average, max everytime I run the script.
# It's not worth it to optimize this at this point in time.
# This script runs once a month, so I'd rather spend my time
# optimizing other things that run all the time.
# Ericw
open (FIND, "find . -name current-attack-count.data|");
$count=0;
$total=0;
$min_attack=1000000;
$max_attack=0;
while (<FIND>){
chomp;
$file=$_;
open (FILE, $file);
while (<FILE>){
chomp;
$total=$total+$_;
if ($_ < $min_attack){$min_attack=$_;}
if ($_ > $max_attack){$max_attack=$_;}
}
close (FILE);
$count++;
}
$average_attack=$total/$count;
$average_attack=sprintf("%.2f",$average_attack);
#print "min is $min_attack, max is $max_attack, average is $average_attack\n";
open (FIND, "find . -name todays_username.count|");
$count=0;
$total=0;
$min_username=1000000;
$max_username=0;
while (<FIND>){
chomp;
$file=$_;
open (FILE, $file);
while (<FILE>){
chomp;
$total=$total+$_;
if ($_ < $min_username){$min_username=$_;}
if ($_ > $max_username){$max_username=$_;}
}
close (FILE);
$count++;
}
$average_username=$total/$count;
$average_username=sprintf("%.2f",$average_username);
open (FIND, "find . -name todays_password.count|");
$count=0;
$total=0;
$min_password=1000000;
$max_password=0;
while (<FIND>){
chomp;
$file=$_;
open (FILE, $file);
while (<FILE>){
chomp;
$total=$total+$_;
if ($_ < $min_password){$min_password=$_;}
if ($_ > $max_password){$max_password=$_;}
}
close (FILE);
$count++;
}
$average_password=$total/$count;
$average_password=sprintf("%.2f",$average_password);
open (FIND, "find . -name todays_ips.count|");
$count=0;
$total=0;
$min_ip=1000000;
$max_ip=0;
while (<FIND>){
chomp;
$file=$_;
open (FILE, $file);
while (<FILE>){
chomp;
$total=$total+$_;
if ($_ < $min_ip){$min_ip=$_;}
if ($_ > $max_ip){$max_ip=$_;}
}
close (FILE);
$count++;
}
$average_ip=$total/$count;
$average_ip=sprintf("%.2f",$average_ip);
#2015-01-04T23:38:20 shepherd sshd[23322]: IP: 122.225.103.103 PassLog: Username: root Password: 123567
$file="$dir/current-raw-data.gz";
#
# Now we go back to the individual directory
chdir "$dir";
#
# Pass 1, unique IPs
#
$hour=0;
$minute=0;
$minute_count=0;
while ($minute_count < 1441){
$time_attacks[$minute_count]=0;
$time_username_count[$minute_count]=0;
$time_password_count[$minute_count]=0;
$time_ip_count[$minute_count]=0;
$minute_count++;
}
#print "DEBUG ". $time_ip_count[0] . "\n";
open (FILE, "zcat $file|sort|");
while (<FILE>){
if (/IP:/){
if (( /PassLog/)||(/Pass2222Log/)){ # Look at only ssh
chomp;
$time = $_;
$time =~ s/ ..*$//;
$time =~ s/^.*T//;
$time =~ s/:..$//;
($log_hour , $log_minute)=split(/:/,$time);
$minute_number=($log_hour*60)+$log_minute;
$password=$_;
$password=~ s/^..*Password: //;
#print "password is $password\n";
$password_array{$password}=1;
$size=keys (%password_array);
$time_password_count[$minute_number]=$size;
$username=$_;
$username=~ s/^..*Username: //;
$username=~ s/ Password:.*$//;
#print "username is $username\n";
$username_array{$username}=1;
$size=keys (%username_array);
$time_username_count[$minute_number]=$size;
$ip=$_;
$ip =~ s/^..*IP: //;
$ip =~ s/ Pass..*$//;
#print "ip is $ip\n";
$ip_array{$ip}=1;
$size=keys (%ip_array);
$time_ip_count[$minute_number] = $size ;
#print "DEBUG-loading time_ip_count array, minute is $minute_number, ip size is $size\n";
$time_attacks[$minute_number]++;
}
}
}
close (FILE);
open (ATTACK_FILE, ">$dir/dashboard_number_of_attacks.data");
open (IPS_FILE, ">$dir/dashboard_ips.data");
open (USERNAME_FILE, ">$dir/dashboard_usernames.data");
open (PASSWORD_FILE, ">$dir/dashboard_passwords.data");
$minute_count=0;
$last_ip_count_seen=0;
$last_username_count_seen=0;
$last_password_count_seen=0;
$last_attack_count_seen=0;
while ($minute_count < 1440){
$running_total_of_attacks+=$time_attacks[$minute_count];
$minute = $minute_count % 60;
$hour=int $minute_count / 60;
if ($minute < 10){
$time="$hour:0$minute";
}
else {
$time="$hour:$minute";
}
if (( $minute_count % 5) == 0){
if (( $minute_count % 30) != 0){$time = "";}
if ( $time_ip_count[$minute_count] > 0) {
print (IPS_FILE $time_ip_count[$minute_count] . " $time\n");
#print "$minute_count ".$time_ip_count[$minute_count] . " $time\n";
$last_ip_count_seen = $time_ip_count[$minute_count] ;
}
else {
#print "$minute_count ".$time_ip_count[$minute_count] . " $time\n";
print (IPS_FILE "$last_ip_count_seen $time\n");
}
if ($time_username_count[$minute_count] >0 ){
print (USERNAME_FILE $time_username_count[$minute_count] . " $time\n");
$last_username_count_seen = $time_username_count[$minute_count] ;
}
else {
print (USERNAME_FILE "$last_username_count_seen $time\n");
}
if ( $time_password_count[$minute_count] > 0){
print (PASSWORD_FILE $time_password_count[$minute_count] . " $time\n");
$last_password_count_seen = $time_password_count[$minute_count] ;
}
else {
print (PASSWORD_FILE "$last_password_count_seen $time\n");
}
if ($time_attacks[$minute_count] >0){
print (ATTACK_FILE $running_total_of_attacks . " $time\n");
}
else {
print (ATTACK_FILE "$running_total_of_attacks $time\n");
}
}
$minute_count++;
}
`php /usr/local/etc/LongTail_make_dashboard_graph.php $dir/dashboard_passwords.data "Unique Password Count $DATE " "" "" "wide" $min_password $max_password $average_password $max_password > /var/www/html/honey/dashboard/dashboard_passwords-$DATE.png`;
`php /usr/local/etc/LongTail_make_dashboard_graph.php $dir/dashboard_usernames.data "Unique Username Count $DATE " "" "" "wide" $min_username $max_username $average_username $max_username > /var/www/html/honey/dashboard/dashboard_usernames-$DATE.png`;
`php /usr/local/etc/LongTail_make_dashboard_graph.php $dir/dashboard_ips.data "Unique IP Count $DATE " "" "" "wide" $min_ip $max_ip $average_ip $max_ip > /var/www/html/honey/dashboard/dashboard_ips-$DATE.png`;
`php /usr/local/etc/LongTail_make_dashboard_graph.php $dir/dashboard_number_of_attacks.data "Number Of Attacks $DATE " "" "" "wide" $min_attack $max_attack $average_attack $max_attack > /var/www/html/honey/dashboard/dashboard_number_of_attacks-$DATE.png`;