From f904c9d7c4fd59ede1e69acd7295d4f522845eda Mon Sep 17 00:00:00 2001 From: Ermal Date: Fri, 20 Jul 2012 07:39:32 +0000 Subject: Commit code from http://forum.pfsense.org/index.php/topic,51569.0.html with some fixes --- config/widget-snort/snort_alerts.widget.php | 90 +++++++++++++++++++---------- 1 file changed, 60 insertions(+), 30 deletions(-) (limited to 'config/widget-snort/snort_alerts.widget.php') diff --git a/config/widget-snort/snort_alerts.widget.php b/config/widget-snort/snort_alerts.widget.php index c2622dc7..ad7827b7 100644 --- a/config/widget-snort/snort_alerts.widget.php +++ b/config/widget-snort/snort_alerts.widget.php @@ -2,6 +2,7 @@ /* snort_alerts.widget.php Copyright (C) 2009 Jim Pingle + mod 19-07-2012 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: @@ -26,43 +27,72 @@ */ global $config, $g; +/* retrieve snort variables */ +require_once("/usr/local/pkg/snort/snort.inc"); + +if (!is_array($config['installedpackages']['snortglobal']['rule'])) + $config['installedpackages']['snortglobal']['rule'] = array(); +$a_instance = &$config['installedpackages']['snortglobal']['rule']; + +/* read log file(s) */ +$snort_alerts = array(); +$tmpblocked = array_flip(snort_get_blocked_ips()); +foreach ($a_instance as $instanceid => $instance) { + $snort_uuid = $a_instance[$instanceid]['uuid']; + $if_real = snort_get_real_interface($a_instance[$instanceid]['interface']); + $tmpfile = "{$g['tmp_path']}/.widget_alert_{$snort_uuid}"; + + /* make sure alert file exists */ + if (file_exists("/var/log/snort/snort_{$if_real}{$snort_uuid}/alert")) { + if (isset($config['syslog']['reverse'])) + exec("tail -10 /var/log/snort/snort_{$if_real}{$snort_uuid}/alert | sort -r > {$tmpfile}"); + else + exec("tail -10 /var/log/snort/snort_{$if_real}{$snort_uuid}/alert > {$tmpfile}"); + if (file_exists($tmpfile)) { + /* 0 1 2 3 4 5 6 7 8 9 10 11 12 */ + /* File format timestamp,sig_generator,sig_id,sig_rev,msg,proto,src,srcport,dst,dstport,id,classification,priority */ + $fd = fopen($tmpfile, "r"); + while (($fileline = @fgets($fd))) { + if (empty($fileline)) + continue; + $fields = explode(",", $fileline); + + $snort_alert = array(); + $snort_alert[]['instanceid'] = snort_get_friendly_interface($a_instance[$instanceid]['interface']); + $snort_alert[]['timestamp'] = $fields[0]; + $snort_alert[]['timeonly'] = substr($fields[0], 6, -8); + $snort_alert[]['dateonly'] = substr($fields[0], 0, -17); + $snort_alert[]['src'] = $fields[6]; + $snort_alert[]['srcport'] = $fields[7]; + $snort_alert[]['dst'] = $fields[8]; + $snort_alert[]['dstport'] = $fields[9]; + $snort_alert[]['priority'] = $fields[12]; + $snort_alert[]['category'] = $fields[11]; + $snort_alerts[] = $snort_alert; + }; + fclose($fd); + @unlink($tmpfile); + }; + }; +}; + +/* display the result */ ?> - + - - - - > - - - - - +foreach ($snort_alerts as $counter => $alert) { + echo(" + + + + "); +} +?>
DateIF/Date Src/Dst Details
' . $alert['dateonly'] ?>' . $alert["dst"] ?>' . 'Cat : ' . $alert['category'] ?>
{$alert['instanceid']}
{$alert['timeonly']} {$alert['dateonly']}
{$alert['src']}:{$alert['srcport']}
{$alert['dst']}:{$alert['dstport']}
Pri : {$alert['priority']}
Cat : {$alert['category']}
-- cgit v1.2.3