#!/usr/local/bin/perl # A simple cgi-script to generate the X last events # from a snort database on postgresql. I make this script because # I got an old HTTP server where PHP can't run. # # Author : Alexandre Dulaunoy # Date : 3/3/2001 # under the terms of the GNU General Public License. # Version: 0.0.1 # # PS : Don't forget to setup the correct access for uid to postgres use Pg; my $dbname='snort'; my $howmanyevent=200; my $x; my $date = `date`; $conn = Pg::connectdb("dbname=$dbname"); $result = $conn->exec("select * from event ORDER BY event.timestamp DESC LIMIT $howmanyevent"); print "Content-type: text/html\n\n"; print ""; print " Last $howmanyevent events from snort db."; print "

Last $howmanyevent events from snort db. generated on $date

"; print ""; print " \n"; while (@row = $result->fetchrow) { $x++; $result2 = $conn->exec("select ip_src0,ip_src1,ip_src2,ip_src3,ip_dst0,ip_dst1,ip_dst2,ip_dst3 from iphdr where cid=$row[1]"); @ip = $result2->fetchrow; $src_ip = $ip[0].".".$ip[1].".".$ip[2].".".$ip[3]; $dst_ip = $ip[4].".".$ip[5].".".$ip[6].".".$ip[7]; $result3 = $conn->exec("select tcp_sport,tcp_dport from tcphdr where cid=$row[1]"); @tcp = $result3->fetchrow; print " \n"; # print "\n"; # print $row[1]."***".$row[2]."*** SIP:".$src_ip."***DIP:".$dst_ip."\n"; } print "
IDSignatureSource IPTCPSPORTDestination IPTCPDPORT
$row[1] $row[2]$src_ip$tcp[0]$dst_ip$tcp[1]
"; print " by adulau"; print "";