forked from wedaa/LongTail-Log-Analysis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
LongTail_import_Kippo_to_LongTail.pl
executable file
·160 lines (151 loc) · 5.36 KB
/
LongTail_import_Kippo_to_LongTail.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
#!/usr/bin/perl
# You must be in the directory with the kippo logs in it.
#
# You must disable all LongTail jobs in crontab before you run this
#
# After you run this, then run /usr/local/etc/LongTail.sh REBUILD
#
#
#LONGTAIL: 2015-05-22T15:33:56-04:00 shepherd sshd-22[19597]: IP: 222.186.21.223 PassLog: Username: root Password: mtcl
#KIPPO: 2015-05-10 18:05:31-0400 [SSHService ssh-userauth on HoneyPotTransport,16534,58.218.204.52] login attempt [root/skata1] failed
sub init{
if ( $ARGV[0] ne ""){
print "$ARGV[0]\n";
$new_hostname=$ARGV[0];
}
else {
print "You forgot to specify a hostname, use LongTail_convert_Kippo_to_LongTail.pl <HOSTNAME>\n";
exit;
}
$date_right_now=`date +%Y.%m.%dT%H:%M`;
chomp $date_right_now;
}
sub pass_1 {
open (FIND, "find . -type f |sort |")||die "Can not run find command\n";
while (<FIND>){
chomp;
if (/kippo.log.1$/){next;}
if (! /kippo.log/){next;}
print "processing file $_ now\n";;
$filename=$_;
open (FILE, $filename) || die "Can not open $filename\n";
while (<FILE>){
if (/Sana/){print ;}
if (/unauthorized login/){next;}
if (/NEW KEYS/){next;}
if (/^\t/){next;}
if (/ \[-\] /){next;}
if (/failed auth password/){next;}
if (/starting service ssh-userauth/){next;}
if (/login attempt/){
#print "DEBUG line is -->$_<--";
($date,$time,$stuff)=split(/ /,$_,3);
$time =~ s/00$/:00/;
# This is a hack for Bob M's condensed Kippo Logs
# Eric Wedaa, 2015-06-18
if (/ \[H,/){
$stuff =~ s/H,/SSHService ssh-userauth on HoneyPotTransport,/;
}
$stuff =~ s/,/ /g;
#print "DEBUG stuff is -->$stuff<--";
($trash,$trash,$trash,$trash,$trash,$ip,$trash,$trash,$attempt,$trash)=split(/ /,$stuff);
$ip =~ s/\]//;
#print "$ip $attempt\n";
$attempt =~ s/\[//;
$attempt =~ s/\]//;
$attempt =~ s/\// Password: /;
($year,$month,$day)=split(/-/,$date,3);
if (! -d "/var/www/html/honey/historical/$year/$month/$day"){
`mkdir -p /var/www/html/honey/historical/$year/$month/$day`;
}
if ( -d "/var/www/html/honey/historical/$year/$month/$day"){
open (OUT, ">>/var/www/html/honey/historical/$year/$month/$day/kippo.data");
print (OUT "$date"."T"."$time $new_hostname sshd-22[KIPPO]: IP: $ip PassLog: Username: $attempt\n");
print ("$date"."T"."$time $new_hostname sshd-22[KIPPO]: IP: $ip PassLog: Username: $attempt\n");
close (OUT);
}
else {
print "X01: This is bad, could not create /var/www/html/honey/historical/$year/$month/$day\n";
print "Exiting now\n\n";
exit;
}
if (! -d "/var/www/html/honey/$new_hostname/historical/$year/$month/$day"){
`mkdir -p /var/www/html/honey/$new_hostname/historical/$year/$month/$day`;
}
if (! -d "/var/www/html/honey/$new_hostname/historical/$year/$month/$day"){
print "X02: This is bad, could not create /var/www/html/honey/$new_hostname/historical/$year/$month/$day\n";
print "Exiting now\n\n";
exit;
}
open (OUT, ">>/var/www/html/honey/$new_hostname/historical/$year/$month/$day/kippo.data");
print (OUT "$date"."T"."$time $new_hostname sshd-22[KIPPO]: IP: $ip PassLog: Username: $attempt\n");
close (OUT);
}
else {
($date,$time,$stuff)=split(/ /,$_,3);
$time =~ s/00$/:00/;
$_ = "$date"."T"."$time $new_hostname $stuff";
($year,$month,$day)=split(/-/,$date,3);
if (! -d "/var/www/html/honey/historical/$year/$month/$day"){
`mkdir -p /var/www/html/honey/historical/$year/$month/$day`;
}
if ( -d "/var/www/html/honey/historical/$year/$month/$day"){
open (OUT, ">>/var/www/html/honey/historical/$year/$month/$day/kippo.data");
print (OUT $_ );
close (OUT);
}
else {
print "x03: This is bad, could not create /var/www/html/honey/historical/$year/$month/$day\n";
print "Exiting now\n\n";
exit;
}
if (! -d "/var/www/html/honey/$new_hostname/historical/$year/$month/$day"){
`mkdir -p /var/www/html/honey/$new_hostname/historical/$year/$month/$day`;
}
if (! -d "/var/www/html/honey/$new_hostname/historical/$year/$month/$day"){
print "X04: This is bad, could not create /var/www/html/honey/$new_hostname/historical/$year/$month/$day\n";
print "Exiting now\n\n";
exit;
}
open (OUT, ">>/var/www/html/honey/$new_hostname/historical/$year/$month/$day/kippo.data");
print (OUT $_ );
close (OUT);
}
}
close (FILE);
# print "sleep 10 now\n";
#sleep(10);
}
close (FIND);
}
sub pass_2 {
open (FIND, "find /var/www/html/honey/historical -type f -name kippo.data| ")||die "Can not run find command\n";
while (<FIND>){
print $_;
chomp;
$filename=$_;
$existing_data=$_;
$existing_data =~ s/kippo.data/current-raw-data.gz/;
if ( ! -e $existing_data ){
`echo "" |gzip -f -c > $existing_data`;
}
$filename_new= $existing_data;
$filename_new=~ s/.gz//;
`zcat $existing_data >$filename_new`;
`mv $existing_data $existing_data.$date_right_now`;
`cat $filename |sort >> $filename_new`;
`gzip $filename_new`;
#`ls -l $filename_new $existing_data.backup`;
`mv $filename $filename.$date_right_now`;
}
close (FIND);
}
&init;
&pass_1;
&pass_2;
print "\n\n";
print "To finish importing your data, please perform the following actions:\n";
print " 1) Disable LongTail in your crontab file\n";
print " 2) run /usr/local/etc/LongTail.sh REBUILD\n";
print " 3) Re-enable LongTail in your crontab file\n";
print "Charts will be updated at midnight.\n";