]>
git.ipfire.org Git - people/teissler/ipfire-2.x.git/blob - html/cgi-bin/logs.cgi/ids.dat
5 # This code is distributed under the terms of the GPL
7 # (c) The SmoothWall Team
9 # Copyright (C) 18-03-2002 Mark Wormgoor <mark@wormgoor.com>
10 # - Added links to Snort database and ipinfo.cgi
12 # $Id: ids.dat,v 1.6.2.16 2005/06/14 08:25:30 eoberlander Exp $
17 # enable only the following on debugging purpose
19 #use CGI::Carp 'fatalsToBrowser';
21 require 'CONFIG_ROOT/general-functions.pl';
22 require "${General::swroot}/lang.pl";
23 require "${General::swroot}/header.pl";
27 #workaround to suppress a warning when a variable is used only once
28 my @dummy = ( ${Header
::table1colour
}, ${Header
::table2colour
} );
34 my $errormessage = '';
36 my @shortmonths = ( 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug',
37 'Sep', 'Oct', 'Nov', 'Dec' );
38 my @longmonths = ( $Lang::tr
{'january'}, $Lang::tr
{'february'}, $Lang::tr
{'march'},
39 $Lang::tr
{'april'}, $Lang::tr
{'may'}, $Lang::tr
{'june'}, $Lang::tr
{'july'}, $Lang::tr
{'august'},
40 $Lang::tr
{'september'}, $Lang::tr
{'october'}, $Lang::tr
{'november'},
41 $Lang::tr
{'december'} );
43 my @now = localtime(time);
47 my $year = $now[5]+1900;
49 $cgiparams{'DAY'} = $now[3];
50 $cgiparams{'MONTH'} = $now[4];
51 $cgiparams{'ACTION'} = '';
53 &Header
::getcgihash
(\
%cgiparams);
54 $logsettings{'LOGVIEW_REVERSE'} = 'off';
55 &General
::readhash
("${General::swroot}/logging/settings", \
%logsettings);
56 ${Header
::viewsize
} = defined ($logsettings{'LOGVIEW_VIEWSIZE'}) ?
$logsettings{'LOGVIEW_VIEWSIZE'} : 150;
57 $Header::viewsize
/= 5; # each ids is displayed on 5 lines
59 $now[4] = $cgiparams{'MONTH'}+1;
61 $now[4] = "0$now[4]"; }
64 if ($ENV{'QUERY_STRING'} && $cgiparams{'ACTION'} ne $Lang::tr
{'update'})
66 my @temp = split(',',$ ENV
{'QUERY_STRING'});
68 $cgiparams{'MONTH'} = $temp[1];
69 $cgiparams{'DAY'} = $temp[2];
72 if (!($cgiparams{'MONTH'} =~ /^(0|1|2|3|4|5|6|7|8|9|10|11)$/) ||
73 !($cgiparams{'DAY'} =~ /^(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)$/))
75 $cgiparams{'DAY'} = $now[3];
76 $cgiparams{'MONTH'} = $now[4];
78 elsif($cgiparams{'ACTION'} eq '>>')
81 my @temp_now = localtime(time);
82 $temp_now[4] = $cgiparams{'MONTH'};
83 $temp_now[3] = $cgiparams{'DAY'};
84 @temp_then = localtime(POSIX
::mktime
(@temp_now) + 86400);
85 ## Retrieve the same time on the next day +
86 ## 86400 seconds in a day
87 $cgiparams{'MONTH'} = $temp_then[4];
88 $cgiparams{'DAY'} = $temp_then[3];
90 elsif($cgiparams{'ACTION'} eq '<<')
93 my @temp_now = localtime(time);
94 $temp_now[4] = $cgiparams{'MONTH'};
95 $temp_now[3] = $cgiparams{'DAY'};
96 @temp_then = localtime(POSIX
::mktime
(@temp_now) - 86400);
97 ## Retrieve the same time on the previous day -
98 ## 86400 seconds in a day
99 $cgiparams{'MONTH'} = $temp_then[4];
100 $cgiparams{'DAY'} = $temp_then[3];
104 if (($cgiparams{'DAY'} ne $now[3]) || ($cgiparams{'MONTH'} ne $now[4]))
107 if ( ( $cgiparams{'MONTH'} eq $now[4]) && ($cgiparams{'DAY'} > $now[3]) ||
108 ( $cgiparams{'MONTH'} > $now[4] ) ) {
109 @then = localtime(POSIX
::mktime
( 0, 0, 0, $cgiparams{'DAY'}, $cgiparams{'MONTH'}, $year - 1901 ));
111 @then = localtime(POSIX
::mktime
( 0, 0, 0, $cgiparams{'DAY'}, $cgiparams{'MONTH'}, $year - 1900 ));
114 my $lastleap=($year-1)%4;
116 if ($lastleap == 0 && $tdoy < 60) {
127 $datediff=int(($doy-$tdoy)/7);
128 $dowd=($doy-$tdoy)%7;
129 if (($dow-$dowd)<1) {
130 $datediff=$datediff+1;
132 if (($dow-$dowd)==0) {
137 my $longmonthstr = $longmonths[$cgiparams{'MONTH'}];
138 my $monthnum = $cgiparams{'MONTH'} + 1;
139 my $monthstr = $monthnum <= 9 ?
"0$monthnum" : "$monthnum";
140 my $daystr = $cgiparams{'DAY'} <= 9 ?
"0$cgiparams{'DAY'}" : "$cgiparams{'DAY'}";
143 my ($title,$classification,$priority,$date,$time,$srcip,$srcport,$destip,$destport, $sid, @refs);
148 $datediff=$datediff-1;
152 if ($cgiparams{'ACTION'} eq $Lang::tr
{'export'})
154 print "Content-type: text/plain\n\n";
155 print "IPFire IDS snort log\r\n";
156 print "Date: $cgiparams{'DAY'} $longmonths[$cgiparams{'MONTH'}]\r\n";
159 if ($logsettings{'LOGVIEW_REVERSE'} eq 'on') { @log = reverse @log; }
163 my ($datetime,$title,$priority,$classification,$srcip,$srcport,$destip,$destport,$sid,$refs) = split(/\|/);
165 print "Date: $datetime\n";
166 print "Name: $title\n";
167 print "Priority: $priority\n";
168 print "Type: $classification\n";
171 if ($srcport != "n/a") {
176 if ($destport != "n/a") {
181 print "Refs: $refs\n\n";
187 &Header
::showhttpheaders
();
189 &Header
::openpage
($Lang::tr
{'ids log viewer'}, 1, '');
191 &Header
::openbigbox
('100%', 'left', '', $errormessage);
194 &Header
::openbox
('100%', 'left', $Lang::tr
{'error messages'});
195 print "<font class='base'>$errormessage </font>\n";
199 &Header
::openbox
('100%', 'left', "$Lang::tr{'settings'}:");
202 <form method='post' action="$ENV{'SCRIPT_NAME'}">
205 <td width='10%' class='base'>$Lang::tr{'month'}: </td>
207 <select name='MONTH'>
210 for (my $month = 0; $month < 12; $month++)
213 if ($month == $cgiparams{'MONTH'}) {
214 print 'selected="selected" '; }
215 print "value='$month'>$longmonths[$month]</option>\n";
220 <td width='10%' class='base' align='right'> $Lang::tr{'day'}: </td>
225 for (my $day = 1; $day <= 31; $day++)
228 if ($day == $cgiparams{'DAY'}) {
229 print 'selected="selected" '; }
230 print "value='$day'>$day</option>\n";
235 <td width='5%' align='center'><input type='submit' name='ACTION' title='$Lang::tr{'day before'}' value='<<' /></td>
236 <td width='5%' align='center'><input type='submit' name='ACTION' title='$Lang::tr{'day after'}' value='>>' /></td>
237 <td width='10%' align='center'><input type='submit' name='ACTION' value='$Lang::tr{'update'}' /></td>
238 <td width='10%' align='center'><input type='submit' name='ACTION' value='$Lang::tr{'export'}' /></td>
247 &Header
::openbox
('100%', 'left', $Lang::tr
{'log'});
248 print "<p><b>$Lang::tr{'snort hits'} $longmonthstr $daystr: $lines</b></p>";
251 $start = $lines - ${Header
::viewsize
}; }
252 if ($start >= $lines - ${Header
::viewsize
}) { $start = $lines - ${Header
::viewsize
}; };
253 if ($start < 0) { $start = 0; }
255 my $prev = $start - ${Header
::viewsize
};
256 my $next = $start + ${Header
::viewsize
};
258 if ($prev < 0) { $prev = 0; }
259 if ($next >= $lines) { $next = -1 }
260 if ($start == 0) { $prev = -1; }
261 my @slice = splice(@log, $start, ${Header
::viewsize
});
263 if ($logsettings{'LOGVIEW_REVERSE'} eq 'on') { @slice = reverse @slice; }
279 print "<tr bgcolor='${Header::table1colour}'><td>\n"; }
281 print "<tr bgcolor='${Header::table2colour}'><td>\n"; }
282 my ($datetime,$title,$priority,$classification,$srcip,$srcport,$destip,$destport,$sid,$refs) = split(/\|/);
286 <td width='15%'><b>$Lang::tr{'date'}:</b></td><td width='25%'>$datetime</td>
287 <td width='10%'><b>$Lang::tr{'name'}:</b></td><td width='50%'>$title</td>
289 <tr><td><b>$Lang::tr{'priority'}:</b></td><td>$priority</td>
290 <td><b>$Lang::tr{'type'}:</b></td><td>$classification</td>
292 <tr><td><b>$Lang::tr{'ipinfo'}:</b></td>
296 if ($srcip ne "n/a") {
297 print "<a href='/cgi-bin/ipinfo.cgi?ip=$srcip'>$srcip</a>";
301 print ":$srcport -> ";
302 if ($destip ne "n/a") {
303 print "<a href='/cgi-bin/ipinfo.cgi?ip=$destip'>$destip</a>";
311 <tr><td valign='top'><b>$Lang::tr{'references'}:</b></td><td valign='top'>
314 foreach my $ref (split(/,/,$refs)) {
315 if ($ref =~ m/url (.*)/) {
316 print "<a href='http://$1'>$1</a><br />";
317 } elsif ($ref =~ m/cve (.*)/) {
318 print "<a href='http://cve.mitre.org/cgi-bin/cvename.cgi?name=$1'>$1</a><br />";
319 } elsif ($ref =~ m/nessus (.*)/) {
320 print "<a href='http://cgi.nessus.org/plugins/dump.php3?id=$1'>Nessus $1</a><br />";
321 } elsif ($ref =~ m/bugtraq (.*)/) {
322 print "<a href='http://www.securityfocus.com/bid/$1'>Bugtraq $1</a><br />";
327 print $Lang::tr
{'none found'} unless $refs =~ /,/;
329 <td valign='top'><b>SID:</b></td>
334 print "<a href='http://www.snort.org/pub-bin/sigs.cgi?sid=$sid' ";
335 print "target='_blank'>$sid</a></td>\n";
356 &Header
::closebigbox
();
358 &Header
::closepage
();
362 our ($title,$classification,$priority,$date,$time,$srcip,$srcport,$destip,$destport, $sid, @refs);
366 $filestr="/var/log/snort/alert";
368 $filestr="/var/log/snort/alert.$datediff";
369 $filestr = "$filestr.gz" if -f
"$filestr.gz";
371 if (!(open (LOG
,($filestr =~ /.gz$/ ?
"gzip -dc $filestr |" : $filestr)))) {
372 $errormessage="$errormessage$Lang::tr{'date not in logs'}: $filestr $Lang::tr{'could not be opened'}";
378 if ($_ =~ m/\[\*\*\]/) {
379 unless ($line == 1 || $date ne "$monthstr/$daystr") {
383 ($title,$classification,$priority,$date,$time,$srcip,$srcport,$destip,$destport, $sid) = ("n/a","n/a","n/a","n/a","n/a","n/a","n/a","n/a","n/a", "n/a");
385 $_ =~ m/:([0-9]{1,4})\] (.*) \[\*\*\]/;
386 $title = &Header
::cleanhtml
($2,"y");
388 if ($_ =~ m/Classification: (.*)\] \[Priority: (\d)\]/) {
389 $classification = &Header
::cleanhtml
($1,"y");
392 if ($_ =~ m/([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3}) \-\> ([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})/) {
393 $srcip = $1 . "." . $2 . "." . $3 . "." . $4;
394 $destip = $5 . "." . $6 . "." . $7 . "." . $8;
396 if ($_ =~ m/([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\:([0-9]{1,6}) \-\> ([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\:([0-9]{1,6})/) {
397 $srcip = $1 . "." . $2 . "." . $3 . "." . $4;
399 $destip = $6 . "." . $7 . "." . $8 . "." . $9;
403 if ($_ =~ m/^([0-9\/]{3,5})\
-([0-9\
:]{5,8})\
.([0-9]{1,14})/) {
404 ($date,$time) = ($1,$2);
406 if ($_ =~ m/\[Xref \=\>.*\]/) {
407 $_ =~ s/\]\[Xref \=\> /, /g;
408 $_ =~ m/\[Xref \=\> (.*)\]/;
411 if ($_ =~ m/\[1:([0-9]+):[0-9]+\]/) {
416 unless ($line == 1 || $date ne "$monthstr/$daystr") { &append
; }
423 our ($title,$classification,$priority,$date,$time,$srcip,$srcport,$destip,$destport, $sid, @refs);
425 $log[$lines] = "$date $time|$title|$priority|$classification|$srcip|$srcport|$destip|$destport|$sid|";
427 $log[$lines] = "$log[$lines]$_,"; }
439 print "<td align='center' width='50%'>";
441 print "<a href='/cgi-bin/logs.cgi/ids.dat?$prev,$cgiparams{'MONTH'},$cgiparams{'DAY'}'>$Lang::tr{'older'}</a>"; }
443 print "$Lang::tr{'older'}"; }
446 print "<td align='center' width='50%'>";
448 print "<a href='/cgi-bin/logs.cgi/ids.dat?$next,$cgiparams{'MONTH'},$cgiparams{'DAY'}'>$Lang::tr{'newer'}</a>"; }
450 print "$Lang::tr{'newer'}"; }