• Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Search
  • Register
  • Login
Netgate Discussion Forum
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Search
  • Register
  • Login

Snort Widget v0.3.2, Snort 2.9.2.3 pkg v. 2.5.1 Alerts Tab and Blocked tab fix

Scheduled Pinned Locked Moved pfSense Packages
23 Posts 11 Posters 7.4k Views
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D
    digdug3
    last edited by Jul 26, 2012, 6:46 AM Jul 24, 2012, 7:19 PM

    Here are fixes for the Snort Widget v0.3.2, Snort 2.9.2.3 pkg v. 2.5.1 Alerts Tab and Blocked tab. Please test. If all works it can be committed.
    Snort Widget v0.3.2 fix (update 26-07-2012): Sorts all interfaces by date, displays ip and port, fixes Snort alert descriptions with ",". Uses firewall widget setting as number of entries. Removed bogus line.
    Just install Snort Widget v0.3.2 and replace the /usr/local/www/widgets/snort_alerts.widget.php with this:

     $val){
    		$offset = 0;
    		$found = false;
    		foreach ($temp_array as $tmp_key => $tmp_val) {
    			if (!$found and strtolower($val[$subkey]) > strtolower($tmp_val[$subkey])) {
    				$temp_array = array_merge((array)array_slice($temp_array,0,$offset), array($key => $val), array_slice($temp_array,$offset));
    				$found = true;
    			};
    			$offset++;
    		};
    		if (!$found) $temp_array = array_merge($temp_array, array($key => $val));
    	};
    
    	if ($sort_ascending) {
    		$array = array_reverse($temp_array);
    	} else $array = $temp_array;
    };
    
    /* check if firewall widget variable is set */
    if (!isset($nentries)) $nentries = 5;
    
    /* 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) */
    $counter=0;
    foreach ($a_instance as $instanceid => $instance) {
    	$snort_uuid = $a_instance[$instanceid]['uuid'];
    	$if_real = snort_get_real_interface($a_instance[$instanceid]['interface']);
    
    	/* make sure alert file exists */
    	if (file_exists("/var/log/snort/snort_{$if_real}{$snort_uuid}/alert")) {
    		exec("tail -n{$nentries} /var/log/snort/snort_{$if_real}{$snort_uuid}/alert > /tmp/alert_{$snort_uuid}");
    		if (file_exists("/tmp/alert_{$snort_uuid}")) {
    			$tmpblocked = array_flip(snort_get_blocked_ips());
    
    			/*                 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("/tmp/alert_{$snort_uuid}", "r");
    			while (($fields = fgetcsv($fd, 1000, ',', '"')) !== FALSE) {
    				if(count($fields) < 11)
    					continue;
    
    				$snort_alerts[$counter]['instanceid'] = $a_instance[$instanceid]['interface'];
    				$snort_alerts[$counter]['timestamp'] = $fields[0];
    				$snort_alerts[$counter]['timeonly'] = substr($fields[0], 6, -8);
    				$snort_alerts[$counter]['dateonly'] = substr($fields[0], 0, -17);
    				$snort_alerts[$counter]['src'] = $fields[6];
    				$snort_alerts[$counter]['srcport'] = $fields[7];
    				$snort_alerts[$counter]['dst'] = $fields[8];
    				$snort_alerts[$counter]['dstport'] = $fields[9];
    				$snort_alerts[$counter]['priority'] = $fields[12];
    				$snort_alerts[$counter]['category'] = $fields[11];
    				$counter++;
    			};
    			fclose($fd);
    			@unlink("/tmp/alert_{$snort_uuid}");
    		};
    	};
    };
    
    /* sort the array */
    if (isset($config['syslog']['reverse'])) {
    	sksort($snort_alerts, 'timestamp', false);
    } else {
    	sksort($snort_alerts, 'timestamp', true);
    };
    
    /* display the result */
    ?>
    
    	
    		
    		  IF/Date
    			Src/Dst
    			Details
    		
    
    
    
    				" . $alert['instanceid'] . "
    " . $alert['timeonly'] . " " . $alert['dateonly'] . "		
    				" . $alert['src'] . ":" . $alert['srcport'] . "
    " . $alert['dst'] . ":" . $alert['dstport'] . "
    				Pri : " . $alert['priority'] . "
    Cat : " . $alert['category'] . "
    			");
    		$counter++;
    		if($counter >= $nentries) break;
    	}
    };
    ?>
    	
    

    Snort 2.9.2.3 pkg v. 2.5.1 Alerts Tab fix, fixes Snort alert descriptions with ",".
    Just install Snort 2.9.2.3 pkg v. 2.5.1 package and replace /usr/local/www/snort/snort_alerts.php with this:

    .
     * Copyright (C) 2003-2004 Manuel Kasper ```
    **Snort 2.9.2.3 pkg v. 2.5.1 Blocked Tab fix**, fixes Snort blocked descriptions with ",". (Not just N/A)
    Just install Snort 2.9.2.3 pkg v. 2.5.1 package and replace /usr/local/www/snort/snort\_blocked.php with this:
    
    1. {
      ob_start(); //important or other posts will fail
      $save_date = exec('/bin/date "+%Y-%m-%d-%H-%M-%S"');
      $file_name = "snort_blocked_{$save_date}.tar.gz";
      exec('/bin/mkdir -p /tmp/snort_blocked');
      file_put_contents("/tmp/snort_blocked/snort_block.pf", "");
      foreach($blocked_ips_array_save as $counter => $fileline) {
      if (empty($fileline))
      continue;
      $fileline = trim($fileline, " \n\t");
      file_put_contents("/tmp/snort_blocked/snort_block.pf", "{$fileline}\n", FILE_APPEND);
      }

      exec("/usr/bin/tar cf /tmp/{$file_name} /tmp/snort_blocked");
      
      if(file_exists("/tmp/{$file_name}")) {
      	header("Expires: Mon, 26 Jul 1997 05:00:00 GMT\n");
      	header("Pragma: private"); // needed for IE
      	header("Cache-Control: private, must-revalidate"); // needed for IE
      	header('Content-type: application/force-download');
      	header('Content-Transfer-Encoding: Binary');
      	header("Content-length: " . filesize("/tmp/{$file_name}"));
      	header("Content-disposition: attachment; filename = {$file_name}");
      	readfile("/tmp/{$file_name}");
      	ob_end_clean(); //importanr or other post will fail
      	@unlink("/tmp/{$file_name}");
      	exec("/bin/rm -fr /tmp/snort_blocked");
      } else
      	$savemsg = "An error occurred while createing archive";
      

      } else
      $savemsg = "No content on snort block list";
      }

    if ($_POST['save'])
    {
    /* no errors */
    if (!$input_errors) {
    $config['installedpackages']['snortglobal']['alertsblocks']['brefresh'] = $_POST['brefresh'] ? 'on' : 'off';
    $config['installedpackages']['snortglobal']['alertsblocks']['blertnumber'] = $_POST['blertnumber'];

    	write_config();
    
    	header("Location: /snort/snort_blocked.php");
    	exit;
    }
    

    }

    $pgtitle = "Services: Snort Blocked Hosts";
    include_once("head.inc");

    ?>

    \n";
    ?>

    ' . $pgtitle . '

    ';}?>

    			Last 
    			Blocked.
    			This page lists hosts that have
    			been blocked by Snort.  
    		
    
    
    		
    			Save or Remove Hosts
    			
    				 All
    			blocked hosts will be saved.  **Warning:**
    			all hosts will be removed.
    
    
    			
    		
    		
    			Auto Refresh and Log View
    			
    				 Refresh >
    			**Default** is **ON**.  Enter the
    			number of blocked entries to view. **Default** is **500**.
    			
    		
    
    
    
    	
    		
    			
    				#
    				IP
    				Alert Description
    				Remove
    			
    
    
    	 $blocked_msg) {
    			$blocked_desc = "
    

    " . implode("
    ", $blocked_msg);
    if($counter > $bnentries)
    break;
    else
    $counter++;

    			/* use one echo to do the magic*/
    			echo "
    		 {$counter}
    		 {$blocked_ip}
    		 {$blocked_desc}
    		[
    		![\"Delete\"](\"../themes/{$g['theme']}/images/icons/icon_x.gif\")][0]
    

    \n";

    		}
    
    		echo "\n{$counter} items listed.
    

    ";
    } else
    echo "\n
    There are currently no items being blocked by snort.

    ";

    	?>
    
    
    
    [0]: snort_blocked.php?todelete=" . trim(urlencode($blocked_ip)) . "
    1 Reply Last reply Reply Quote 0
    • E
      eri--
      last edited by Jul 25, 2012, 6:59 AM

      Wy don't you send pull requests on github?

      1 Reply Last reply Reply Quote 0
      • D
        digdug3
        last edited by Jul 25, 2012, 12:09 PM

        I did this morning. Thanks for the reply.

        1 Reply Last reply Reply Quote 0
        • C
          Cino
          last edited by Jul 27, 2012, 6:59 PM

          @digdug3:

          I did this morning. Thanks for the reply.

          they haven't been pulled in yet :-(

          1 Reply Last reply Reply Quote 0
          • D
            digdug3
            last edited by Jul 28, 2012, 9:07 AM Jul 28, 2012, 7:08 AM

            Just checked. Ermal pushed them all 11 hours ago. I did something wrong at Github.
            As an extra it looks like this also fixes the quotes when adding a rule to the suppression list.

            Added another pull request to add back the link to Snort Alerts in the widget.

            1 Reply Last reply Reply Quote 0
            • F
              fillmoreb
              last edited by Aug 2, 2012, 2:31 AM

              Is this supposed to fix the

              Warning: Invalid argument supplied for foreach() in /usr/local/www/widgets/widgets/snort_alerts.widget.php on line 36 
              

              error in the Snort Alerts Widget?  Cuz I still get that. :(

              1 Reply Last reply Reply Quote 0
              • C
                CS
                last edited by Aug 3, 2012, 11:34 AM

                I also get the same error msg.

                1 Reply Last reply Reply Quote 0
                • D
                  digdug3
                  last edited by Aug 3, 2012, 2:27 PM

                  Do you have any alerts in the Snort alerts list?
                  What version of Snort and pfSense are you using?

                  1 Reply Last reply Reply Quote 0
                  • D
                    digdug3
                    last edited by Aug 3, 2012, 2:46 PM

                    This should fix the 'foreach' error:

                    Snort Widget v0.3.2 fix (update 03-08-2012): Sorts all interfaces by date, displays ip and port, fixes Snort alert descriptions with ",". Uses firewall widget setting as number of entries. Removed bogus line. Fixed 'foreach' error when no alerts are found.
                    Just install Snort Widget v0.3.2 and replace the /usr/local/www/widgets/snort_alerts.widget.php with this:

                    /*
                        snort_alerts.widget.php
                        Copyright (C) 2009 Jim Pingle
                        mod 03-08-2012
                    
                        Redistribution and use in source and binary forms, with or without
                        modification, are permitted provided that the following conditions are met:
                    
                        1\. Redistributions of source code must retain the above copyright notice,
                           this list of conditions and the following disclaimer.
                    
                        2\. Redistributions in binary form must reproduce the above copyright
                           notice, this list of conditions and the following disclaimer in the
                           documentation and/or other materials provided with the distribution.
                    
                        THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
                        INClUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
                        AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
                        AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
                        OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
                        SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
                        INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
                        CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
                        ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
                        POSSIBILITY OF SUCH DAMAGE.
                    */
                    global $config, $g;
                    
                    /* array sorting */
                    function sksort(&$array, $subkey="id", $sort_ascending=false) {
                    	if (count($array)) {
                    		$temp_array[key($array)] = array_shift($array);
                    	};
                    
                    	foreach ($array as $key => $val){
                    		$offset = 0;
                    		$found = false;
                    		foreach ($temp_array as $tmp_key => $tmp_val) {
                    			if (!$found and strtolower($val[$subkey]) > strtolower($tmp_val[$subkey])) {
                    				$temp_array = array_merge((array)array_slice($temp_array,0,$offset), array($key => $val), array_slice($temp_array,$offset));
                    				$found = true;
                    			};
                    			$offset++;
                    		};
                    		if (!$found) $temp_array = array_merge($temp_array, array($key => $val));
                    	};
                    
                    	if ($sort_ascending) {
                    		$array = array_reverse($temp_array);
                    	} else $array = $temp_array;
                    };
                    
                    /* check if firewall widget variable is set */
                    if (!isset($nentries)) $nentries = 5;
                    
                    /* 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) */
                    $counter=0;
                    foreach ($a_instance as $instanceid => $instance) {
                    	$snort_uuid = $a_instance[$instanceid]['uuid'];
                    	$if_real = snort_get_real_interface($a_instance[$instanceid]['interface']);
                    
                    	/* make sure alert file exists */
                    	if (file_exists("/var/log/snort/snort_{$if_real}{$snort_uuid}/alert")) {
                    		exec("tail -n{$nentries} /var/log/snort/snort_{$if_real}{$snort_uuid}/alert > /tmp/alert_{$snort_uuid}");
                    		if (file_exists("/tmp/alert_{$snort_uuid}")) {
                    			$tmpblocked = array_flip(snort_get_blocked_ips());
                    
                    			/*                 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("/tmp/alert_{$snort_uuid}", "r");
                    			while (($fields = fgetcsv($fd, 1000, ',', '"')) !== FALSE) {
                    				if(count($fields) < 11)
                    					continue;
                    
                    				$snort_alerts[$counter]['instanceid'] = $a_instance[$instanceid]['interface'];
                    				$snort_alerts[$counter]['timestamp'] = $fields[0];
                    				$snort_alerts[$counter]['timeonly'] = substr($fields[0], 6, -8);
                    				$snort_alerts[$counter]['dateonly'] = substr($fields[0], 0, -17);
                    				$snort_alerts[$counter]['src'] = $fields[6];
                    				$snort_alerts[$counter]['srcport'] = $fields[7];
                    				$snort_alerts[$counter]['dst'] = $fields[8];
                    				$snort_alerts[$counter]['dstport'] = $fields[9];
                    				$snort_alerts[$counter]['priority'] = $fields[12];
                    				$snort_alerts[$counter]['category'] = $fields[11];
                    				$counter++;
                    			};
                    			fclose($fd);
                    			@unlink("/tmp/alert_{$snort_uuid}");
                    		};
                    	};
                    };
                    
                    /* display the result */
                    ?>
                    
                    if (is_array($snort_alerts)) {
                    	/* sort the array */
                    	if (isset($config['syslog']['reverse'])) {
                    		sksort($snort_alerts, 'timestamp', false);
                    	} else {
                    		sksort($snort_alerts, 'timestamp', true);
                    	};
                    
                    	$counter=0;
                    	foreach ($snort_alerts as $alert) {
                    		echo("	
                    
                    ");
                    		$counter++;
                    		if($counter >= $nentries) break;
                    	}
                    };
                    ?>
                    
                    | IF/Date |			 Src/Dst |			 Details |		
                    				 " . $alert['instanceid'] . "
                    " . $alert['timeonly'] . " " . $alert['dateonly'] . " |						 " . $alert['src'] . ":" . $alert['srcport'] . "
                    " . $alert['dst'] . ":" . $alert['dstport'] . " |				 Pri : " . $alert['priority'] . "
                    Cat : " . $alert['category'] . " |				
                    
                    

                    Github pull request made.

                    1 Reply Last reply Reply Quote 0
                    • F
                      fillmoreb
                      last edited by Aug 4, 2012, 12:48 AM

                      I no longer get the error.  Thanx!  I also have no alerts, so I'm waiting to see if they show up. ;)

                      1 Reply Last reply Reply Quote 0
                      • D
                        digdug3
                        last edited by Aug 5, 2012, 10:06 AM

                        @fillmoreb: Thanks for the bugreport and testing.
                        @ermal: could you push this?

                        1 Reply Last reply Reply Quote 0
                        • T
                          Topper727
                          last edited by Aug 8, 2012, 12:55 PM

                          I had the problem and the fix worked for me. Not see a block yet but no more error shows.

                          Dell 2950 g3 server
                          Intel(R) Xeon(R) CPU E5430 @ 2.66GHz
                          Current: 2000 MHz, Max: 2667 MHz
                          8 CPUs: 2 package(s) x 4 core(s)
                          8152 MiB and 600meg 10k drive
                          Pfsense 2.4 .. Hoping to get the phpvirtualbox going again.

                          1 Reply Last reply Reply Quote 0
                          • D
                            digdug3
                            last edited by Aug 11, 2012, 10:08 AM

                            Thanks for the response. The widget will only display alerts if there are any.

                            1 Reply Last reply Reply Quote 0
                            • C
                              CS
                              last edited by Aug 11, 2012, 10:22 AM

                              I am waiting for ermal to pull the changes.  ;)

                              1 Reply Last reply Reply Quote 0
                              • T
                                tester_02
                                last edited by Aug 23, 2012, 1:11 AM

                                Has this been pushed to production?
                                Should we be looking for a version change, or just reinstall the package?

                                1 Reply Last reply Reply Quote 0
                                • D
                                  digdug3
                                  last edited by Aug 27, 2012, 2:08 PM Aug 27, 2012, 2:06 PM

                                  As soon as it has been pulled you just have to reinstall.

                                  1 Reply Last reply Reply Quote 0
                                  • J
                                    java007md
                                    last edited by Aug 27, 2012, 5:01 PM

                                    Looking forward to seeing this fix as well.

                                    1 Reply Last reply Reply Quote 0
                                    • R
                                      ronnieredd Rebel Alliance
                                      last edited by Sep 22, 2012, 6:59 PM

                                      FYI: Widget issue:

                                      Warning: Invalid argument supplied for foreach() in /usr/local/www/widgets/widgets/snort_alerts.widget.php on line 36
                                      

                                      is still there.

                                      Looking over the wall
                                                \ | /
                                                ~   ~
                                         {~(@) (@)~}
                                      –-oOO-(_)-OOo---

                                      1 Reply Last reply Reply Quote 0
                                      • D
                                        digdug3
                                        last edited by Sep 24, 2012, 1:03 PM

                                        The 03-08 fix still not has been pulled…

                                        If you have the error you have to fix it manually with the latest fix I sended 03-08-2012.
                                        The file /usr/local/www/widgets/snort_alerts.widget.php should contain "mod 03-08-2012" at line 5.

                                        1 Reply Last reply Reply Quote 0
                                        • _
                                          _igor_
                                          last edited by Nov 28, 2012, 11:23 PM

                                          Date today: 12-11-29: Fix is not merged into the package. Seems to be like no (or very small) interest to fix it?????

                                          1 Reply Last reply Reply Quote 0
                                          • First post
                                            Last post
                                          Copyright 2025 Rubicon Communications LLC (Netgate). All rights reserved.
                                            This community forum collects and processes your personal information.
                                            consent.not_received