aboutsummaryrefslogtreecommitdiffstats
path: root/config/snort-dev/snort_rulesets.php
diff options
context:
space:
mode:
Diffstat (limited to 'config/snort-dev/snort_rulesets.php')
-rw-r--r--config/snort-dev/snort_rulesets.php532
1 files changed, 249 insertions, 283 deletions
diff --git a/config/snort-dev/snort_rulesets.php b/config/snort-dev/snort_rulesets.php
index a2e4f7f3..313daea2 100644
--- a/config/snort-dev/snort_rulesets.php
+++ b/config/snort-dev/snort_rulesets.php
@@ -1,19 +1,12 @@
<?php
/* $Id$ */
/*
-
- part of pfSense
- All rights reserved.
-
- Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
+ snort_rulesets.php
+ Copyright (C) 2006 Scott Ullrich
+ Copyright (C) 2009 Robert Zelaya
+ Copyright (C) 2011 Ermal Luci
All rights reserved.
- Pfsense Old snort GUI
- Copyright (C) 2006 Scott Ullrich.
-
- Pfsense snort GUI
- Copyright (C) 2008-2012 Robert Zelaya.
-
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
@@ -24,10 +17,6 @@
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
- 3. Neither the name of the pfSense nor the names of its contributors
- may be used to endorse or promote products derived from this software without
- specific prior written permission.
-
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
@@ -38,310 +27,287 @@
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.
-
-*/
+ */
require_once("guiconfig.inc");
-require_once("/usr/local/pkg/snort/snort_new.inc");
require_once("/usr/local/pkg/snort/snort_gui.inc");
+require_once("/usr/local/pkg/snort/snort.inc");
-//Set no caching
-header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
-header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
-header("Cache-Control: no-store, no-cache, must-revalidate");
-header("Cache-Control: post-check=0, pre-check=0", false);
-header("Pragma: no-cache");
+global $g;
-if (isset($_GET['uuid']) && isset($_GET['rdbuuid'])) {
- echo 'Error: more than one uuid';
- exit(0);
+if (!is_array($config['installedpackages']['snortglobal']['rule'])) {
+ $config['installedpackages']['snortglobal']['rule'] = array();
}
-
-// set page vars
-if (isset($_GET['uuid'])) {
- $uuid = $_GET['uuid'];
+$a_nat = &$config['installedpackages']['snortglobal']['rule'];
+
+$id = $_GET['id'];
+if (isset($_POST['id']))
+ $id = $_POST['id'];
+if (is_null($id)) {
+ header("Location: /snort/snort_interfaces.php");
+ exit;
}
-if (isset($_GET['rdbuuid'])) {
- $rdbuuid = $_GET['rdbuuid'];
-}else{
- $ruledbname_pre1 = snortSql_fetchAllSettings('snortDB', 'SnortIfaces', 'uuid', $uuid);
- $rdbuuid = $ruledbname_pre1['ruledbname'];
+if (isset($id) && $a_nat[$id]) {
+ $pconfig['enable'] = $a_nat[$id]['enable'];
+ $pconfig['interface'] = $a_nat[$id]['interface'];
+ $pconfig['rulesets'] = $a_nat[$id]['rulesets'];
+
+ /* convert fake interfaces to real */
+ $if_real = snort_get_real_interface($pconfig['interface']);
+
+ $iface_uuid = $a_nat[$id]['uuid'];
}
-//$a_list = snortSql_fetchAllSettings('snortDBrules', 'SnortIfaces', 'uuid', $uuid);
-
- // list rules in the default dir
- $filterDirList = array();
- $filterDirList = snortScanDirFilter('/usr/local/etc/snort/snortDBrules/DB/' . $rdbuuid . '/rules', '\.rules');
-
- // list rules in db that are on in a array
- $listOnRules = array();
- $listOnRules = snortSql_fetchAllSettings('snortDBrules', 'SnortRuleSets', 'rdbuuid', $rdbuuid);
-
- if (!empty($listOnRules)) {
- foreach ( $listOnRules as $val2 )
- {
- if ($val2['enable'] == 'on') {
- $rulesetOn[] = $val2['rulesetname'];
- }
- }
- unset($listOnRules);
+$pgtitle = "Snort: Interface $id $iface_uuid $if_real Categories";
+
+
+/* Check if the rules dir is empy if so warn the user */
+/* TODO give the user the option to delete the installed rules rules */
+$isrulesfolderempty = exec("ls -A /usr/local/etc/snort/snort_{$iface_uuid}_{$if_real}/rules/*.rules");
+if ($isrulesfolderempty == "") {
+ $isrulesfolderempty = exec("ls -A /usr/local/etc/snort/rules/*.rules");
+ if ($isrulesfolderempty == "") {
+ include_once("head.inc");
+ include("fbegin.inc");
+
+ echo "<p class=\"pgtitle\">";
+ if($pfsense_stable == 'yes'){echo $pgtitle;}
+ echo "</p>\n";
+
+ echo "<body link=\"#000000\" vlink=\"#000000\" alink=\"#000000\">";
+
+ echo "
+ <table width=\"99%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n
+ <tr><td>\n";
+
+ $tab_array = array();
+ $tabid = 0;
+ $tab_array[$tabid] = array(gettext("Snort Interfaces"), false, "/snort/snort_interfaces.php");
+ $tabid++;
+ $tab_array[$tabid] = array(gettext("If Settings"), false, "/snort/snort_interfaces_edit.php?id={$id}");
+ $tabid++;
+ $tab_array[$tabid] = array(gettext("Categories"), true, "/snort/snort_rulesets.php?id={$id}");
+ $tabid++;
+ $tab_array[$tabid] = array(gettext("Rules"), false, "/snort/snort_rules.php?id={$id}");
+ $tabid++;
+ $tab_array[$tabid] = array(gettext("Servers"), false, "/snort/snort_define_servers.php?id={$id}");
+ $tabid++;
+ $tab_array[$tabid] = array(gettext("Preprocessors"), false, "/snort/snort_preprocessors.php?id={$id}");
+ $tabid++;
+ $tab_array[$tabid] = array(gettext("Barnyard2"), false, "/snort/snort_barnyard.php?id={$id}");
+ display_top_tabs($tab_array);
+ echo "
+ </td></tr>
+ <tr>\n
+ <td>\n
+ <div id=\"mainarea\">\n
+ <table id=\"maintable\" class=\"tabcont\" width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n
+ <tr>\n
+ <td>\n
+ # The rules directory is empty. /usr/local/etc/snort/snort_{$iface_uuid}_{$if_real}/rules \n
+ </td>\n
+ </tr>\n
+ </table>\n
+ </div>\n
+ </td>\n
+ </tr>\n
+ </table>\n
+ \n
+ </form>\n
+ \n
+ <p>\n\n";
+
+ echo "Please click on the Update Rules tab to install your selected rule sets. $isrulesfolderempty";
+ include("fend.inc");
+
+ echo "</body>";
+ echo "</html>";
+
+ exit(0);
+ } else {
+ /* Make sure that we have the rules */
+ mwexec("/bin/cp /usr/local/etc/snort/rules/*.rules /usr/local/etc/snort/snort_{$iface_uuid}_{$if_real}/rules", true);
}
-
- $pgtitle = "Snort: Interface Rule Categories";
- include("/usr/local/pkg/snort/snort_head.inc");
+}
+
+/* alert file */
+$d_snortconfdirty_path = "/var/run/snort_conf_{$iface_uuid}_{$if_real}.dirty";
+if ($_POST["Submit"]) {
+ $enabled_items = "";
+ $isfirst = true;
+ if (is_array($_POST['toenable']))
+ $enabled_items = implode("||", $_POST['toenable']);
+ else
+ $enabled_items = $_POST['toenable'];
+ $a_nat[$id]['rulesets'] = $enabled_items;
+
+ write_config();
+ sync_snort_package_config();
+
+ header( 'Expires: Sat, 26 Jul 1997 05:00:00 GMT' );
+ header( 'Last-Modified: ' . gmdate( 'D, d M Y H:i:s' ) . ' GMT' );
+ header( 'Cache-Control: no-store, no-cache, must-revalidate' );
+ header( 'Cache-Control: post-check=0, pre-check=0', false );
+ header( 'Pragma: no-cache' );
+ header("Location: /snort/snort_rulesets.php?id=$id");
+ exit;
+}
+
+$enabled_rulesets = $a_nat[$id]['rulesets'];
+if($enabled_rulesets)
+ $enabled_rulesets_array = split("\|\|", $enabled_rulesets);
+
+include_once("head.inc");
?>
+<body link="#000000" vlink="#000000" alink="#000000">
+<?php include("fbegin.inc"); ?>
+<?if($pfsense_stable == 'yes'){echo '<p class="pgtitle">' . $pgtitle . '</p>';}?>
+<?php
+echo "{$snort_general_css}\n";
+?>
-<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
-
-<script type="text/javascript">
-
-//prepare the form when the DOM is ready
-jQuery(document).ready(function() {
-
- <?php
- /*
- * NOTE: I could have used a php loop to build the table but off loading to client is faster
- * use jQuery jason parse, make sure its in one line
- */
- if (!empty($filterDirList)) {
-
- $countDirList = count($filterDirList);
-
- echo "\n";
-
- echo 'var snortObjlist = jQuery.parseJSON(\' { "ruleSets": [ ';
- $i = 0;
- foreach ($filterDirList as $val3)
- {
-
- $i++;
-
- // if list ruleset is in the db ON mark it checked
- $rulesetOnChecked = 'off';
- if(!empty($rulesetOn))
- {
- if (in_array($val3, $rulesetOn))
- {
- $rulesetOnChecked = 'on';
- }
- }
-
- if ( $i !== $countDirList )
- {
- echo '{"rule": ' . '"' . $val3 . '", ' . '"enable": ' . '"' . $rulesetOnChecked . '"' . '}, ';
- }else{
- echo '{"rule": "' . $val3 . '", ' . '"enable": ' . '"' . $rulesetOnChecked . '"' . '} ';
- }
- }
-
- echo ' ]}\');' . "\n";
-
- }else{
-
- echo 'var snortObjlist = jQuery.parseJSON(\' { "ruleSets": [] } \');' . "\n";
-
- }
-
-
- ?>
-
- // loop through object, dont use .each in jQuery as its slow
- if(snortObjlist.ruleSets.length > 0) {
- for (var i = 0; i < snortObjlist.ruleSets.length; i++) {
-
- if (isEven(i) === true) {
- var rowIsEvenOdd = 'even_ruleset';
- }else{
- var rowIsEvenOdd = 'odd_ruleset';
- }
-
- if (snortObjlist.ruleSets[i].enable === 'on') {
- var rulesetChecked = 'checked';
- }else{
- var rulesetChecked = '';
- }
-
- jQuery('.rulesetloopblock').append(
- "\n" + '<tr>' + "\n" +
- '<td class="' + rowIsEvenOdd + '" align="center" valign="top" width="9%">' + "\n" +
- ' <input class="domecheck" name="filenamcheckbox[]" value="' + snortObjlist.ruleSets[i].rule + '" type="checkbox" ' + rulesetChecked + ' >' + "\n" +
- '</td>' + "\n" +
- '<td class="' + rowIsEvenOdd + '">' + "\n" +
- ' <a href="/snort/snort_rules.php?openruleset=' + snortObjlist.ruleSets[i].rule + '<?php if(isset($uuid)){echo "&uuid=$uuid";}else{echo "&rdbuuid=$rdbuuid";}?>' + '">' + snortObjlist.ruleSets[i].rule + '</a>' + "\n" +
- '</td>' + "\n" +
- '</tr>' + "\n\n"
- );
- };
- }
+<div class="body2">
-
-}); // end of document ready
+<noscript>
+<div class="alert" ALIGN=CENTER><img
+ src="../themes/<?php echo $g['theme']; ?>/images/icons/icon_alert.gif" /><strong>Please
+enable JavaScript to view this content
+</CENTER></div>
+</noscript>
-</script>
+<?php
-<!-- loading msg -->
-<div id="loadingWaiting">
- <div class="snortModal" style="top: 200px; left: 700px;">
- <div class="snortModalTop">
- <!-- <div class="snortModalTopClose"><a href="javascript:hideLoading('#loadingWaiting');"><img src="/snort/images/close_9x9.gif" border="0" height="9" width="9"></a></div> -->
- </div>
- <div class="snortModalTitle">
- <p><img src="./images/loading.gif" /><br><br>Please Wait...</p>
- </div>
- <div>
- <p class="loadingWaitingMessage"></p>
- </div>
- </div>
-</div>
+echo "<form action=\"snort_rulesets.php?id={$id}\" method=\"post\" name=\"iform\" id=\"iform\">";
-<?php include("fbegin.inc"); ?>
+?> <?php
+
+/* Display message */
+
+if ($input_errors) {
+ print_input_errors($input_errors); // TODO: add checks
+}
+
+if ($savemsg) {
+ print_info_box2($savemsg);
+}
-<div class="body2"><!-- hack to fix the hardcoed fbegin link in header -->
-<div id="header-left2"><a href="../index.php" id="status-link2"><img src="./images/transparent.gif" border="0" alt="transgif" ></img></a></div>
-
-<table width="100%" border="0" cellpadding="0" cellspacing="0">
- <?php
- if (!empty($uuid)) {
- echo '
- <tr>
- <td>
- <div class="newtabmenu" style="margin: 1px 0px; width: 775px;"><!-- Tabbed bar code-->
- <ul class="newtabmenu">
- <li><a href="/snort/snort_interfaces.php"><span>Snort Interfaces</span></a></li>
- <li><a href="/snort/snort_interfaces_edit.php?uuid=' . $uuid . '"><span>If Settings</span></a></li>
- <li class="newtabmenu_active"><a href="/snort/snort_rulesets.php?uuid=' . $uuid . '"><span>Categories</span></a></li>
- <li><a href="/snort/snort_rules.php?uuid=' . $uuid . '"><span>Rules</span></a></li>
- <li><a href="/snort/snort_rulesets_ips.php?uuid=' . $uuid . '"><span>Ruleset Ips</span></a></li>
- <li><a href="/snort/snort_define_servers.php?uuid=' . $uuid . '"><span>Servers</span></a></li>
- <li><a href="/snort/snort_preprocessors.php?uuid=' . $uuid . '"><span>Preprocessors</span></a></li>
- <li><a href="/snort/snort_barnyard.php?uuid=' . $uuid . '"><span>Barnyard2</span></a></li>
- </ul>
- </div>
- </td>
- </tr>
- ';
+if (file_exists($d_snortconfdirty_path)) {
+ echo '<p>';
+
+ if($savemsg) {
+ print_info_box_np2("{$savemsg}");
}else{
- echo '
- <tr>
- <td>
- <div class="newtabmenu" style="margin: 1px 0px; width: 775px;"><!-- Tabbed bar code-->
- <ul class="newtabmenu">
- <li><a href="/snort/snort_interfaces.php"><span>Snort Interfaces</span></a></li>
- <li><a href="/snort/snort_interfaces_global.php"><span>Global Settings</span></a></li>
- <li><a href="/snort/snort_download_updates.php"><span>Updates</span></a></li>
- <li class="newtabmenu_active"><a href="/snort/snort_interfaces_rules.php"><span>RulesDB</span></a></li>
- <li><a href="/snort/snort_alerts.php"><span>Alerts</span></a></li>
- <li><a href="/snort/snort_blocked.php"><span>Blocked</span></a></li>
- <li><a href="/snort/snort_interfaces_whitelist.php"><span>Whitelists</span></a></li>
- <li><a href="/snort/snort_interfaces_suppress.php"><span>Suppress</span></a></li>
- <li><a href="/snort/snort_help_info.php"><span>Help</span></a></li>
- </ul>
- </div>
- </td>
- </tr>
- <tr>
- <td>
- <div class="newtabmenu" style="margin: 1px 0px; width: 775px;"><!-- Tabbed bar code-->
- <ul class="newtabmenu">
- <li class="hide_newtabmenu"><a href="/snort/snort_interfaces_rules_edit.php?rdbuuid=' . $rdbuuid . '"><span>Rules DB Edit</span></a></li>
- <li class="hide_newtabmenu newtabmenu_active"><a href="/snort/snort_rulesets.php?rdbuuid=' . $rdbuuid . '"><span>Categories</span></a></li>
- <li class="hide_newtabmenu"><a href="/snort/snort_rules.php?rdbuuid=' . $rdbuuid . '"><span>Rules</span></a></li>
- <li><a href="/snort/snort_rulesets_ips.php?rdbuuid=' . $rdbuuid . '"><span>Ruleset Ips</span></a></li>
- </ul>
- </div>
- </td>
- </tr>
- ';
+ print_info_box_np2('
+ The Snort configuration has changed and snort needs to be restarted on this interface.<br>
+ You must apply the changes in order for them to take effect.<br>
+ ');
}
- ?>
+}
+
+?>
+
+<table width="99%" border="0" cellpadding="0" cellspacing="0">
+<tr><td>
+<?php
+ $tab_array = array();
+ $tabid = 0;
+ $tab_array[$tabid] = array(gettext("Snort Interfaces"), false, "/snort/snort_interfaces.php");
+ $tabid++;
+ $tab_array[$tabid] = array(gettext("If Settings"), false, "/snort/snort_interfaces_edit.php?id={$id}");
+ $tabid++;
+ $tab_array[$tabid] = array(gettext("Categories"), true, "/snort/snort_rulesets.php?id={$id}");
+ $tabid++;
+ $tab_array[$tabid] = array(gettext("Rules"), false, "/snort/snort_rules.php?id={$id}");
+ $tabid++;
+ $tab_array[$tabid] = array(gettext("Servers"), false, "/snort/snort_define_servers.php?id={$id}");
+ $tabid++;
+ $tab_array[$tabid] = array(gettext("Preprocessors"), false, "/snort/snort_preprocessors.php?id={$id}");
+ $tabid++;
+ $tab_array[$tabid] = array(gettext("Barnyard2"), false, "/snort/snort_barnyard.php?id={$id}");
+ display_top_tabs($tab_array);
+?>
+</td></tr>
<tr>
- <td id="tdbggrey">
- <table width="100%" border="0" cellpadding="10px" cellspacing="0">
- <tr>
- <td class="tabnavtbl">
- <table width="100%" border="0" cellpadding="6" cellspacing="0" >
- <!-- START MAIN AREA -->
-
-
-
- <table width="100%" border="0" cellpadding="0" cellspacing="0" >
- <tr>
- <td>
- </td>
- <td>
- <input id="select_all" type="button" class="formbtn" value="Select All" >
- <input id="deselect_all" type="button" class="formbtn" value="Deselect All" >
- </td>
- </tr>
- </table>
-
- <div id="checkboxdo" style="width: 100%; margin-left: auto ; margin-right: auto ; padding-top: 10px; padding-bottom: 0px;">
- <form id="iform" action="" >
- <input type="hidden" name="snortSaveRuleSets" value="1" /> <!-- what to do, save -->
- <input type="hidden" name="dbName" value="snortDBrules" /> <!-- what db-->
- <input type="hidden" name="dbTable" value="SnortruleSets" /> <!-- what db table-->
- <input type="hidden" name="ifaceTab" value="snort_rulesets" /> <!-- what interface tab -->
- <input type="hidden" name="rdbuuid" value="<?=$rdbuuid;?>" /> <!-- what interface to save for -->
- <input type="hidden" name="uuid" value="<?=$uuid;?>" /> <!-- create snort.conf -->
-
- <table width="100%" border="0" cellpadding="0" cellspacing="0">
-
- <tr >
- <td width="5%" class="listtopic">Enabled</td>
- <td class="listtopic">Ruleset: Rules that end with "so.rules" are shared object rules.</td>
- </tr>
- <table class="rulesetbkg" width="100%">
-
- <tbody class="rulesetloopblock" >
- <!-- javscript loop table build here -->
- </tbody>
-
- </table>
- <table class="vncell1" width="100%" border="0" cellpadding="0" cellspacing="0">
- <tr>
- <td class="listtopic" >Check the rulesets that you would like Snort to load at startup.</td>
- </tr>
- </table>
- <tr>
- <td>
- <input name="Submit" type="submit" class="formbtn" value="Save">
- <input id="cancel" type="button" class="formbtn" value="Cancel">
- </td>
- </tr>
+ <td>
+ <div id="mainarea2">
+ <table id="maintable" class="tabcont" width="100%" border="0"
+ cellpadding="0" cellspacing="0">
<tr>
- <td width="78%">
- <span class="vexpl"><span class="red"><strong>Note:</strong></span>
- Please save your settings before you click start.</span>
+ <td>
+ <table id="sortabletable1" class="sortable" width="100%" border="0"
+ cellpadding="0" cellspacing="0">
+ <tr id="frheader">
+ <td width="5%" class="listhdrr">Enabled</td>
+ <td class="listhdrr"><?php if($snort_arch == 'x86'){echo 'Ruleset: Rules that end with "so.rules" are shared object rules.';}else{echo 'Shared object rules are "so.rules" and not available on 64 bit architectures.';}?></td>
+ <!-- <td class="listhdrr">Description</td> -->
+ </tr>
+ <?php
+ $dir = "/usr/local/etc/snort/snort_{$iface_uuid}_{$if_real}/rules/";
+ $dh = opendir($dir);
+ while (false !== ($filename = readdir($dh))) {
+ $files[] = basename($filename);
+ }
+ sort($files);
+ foreach($files as $file) {
+ if(!stristr($file, ".rules"))
+ continue;
+ echo "<tr>\n";
+ echo "<td align=\"center\" valign=\"top\">";
+ if(is_array($enabled_rulesets_array))
+ if(in_array($file, $enabled_rulesets_array)) {
+ $CHECKED = " checked=\"checked\"";
+ } else {
+ $CHECKED = "";
+ }
+ else
+ $CHECKED = "";
+ echo " \n<input type='checkbox' name='toenable[]' value='$file' {$CHECKED} />\n";
+ echo "</td>\n";
+ echo "<td>\n";
+ echo "<a href='snort_rules.php?id={$id}&openruleset=/usr/local/etc/snort/snort_{$iface_uuid}_{$if_real}/rules/" . urlencode($file) . "'>{$file}</a>\n";
+ echo "</td>\n</tr>\n\n";
+ //echo "<td>";
+ //echo "description";
+ //echo "</td>";
+ }
+
+ ?>
+ </table>
</td>
</tr>
-
- </table>
- </form>
- </div>
-
- <!-- STOP MAIN AREA -->
+ <tr>
+ <td>&nbsp;</td>
+ </tr>
+ <tr>
+ <td>Check the rulesets that you would like Snort to load at startup.</td>
+ </tr>
+ <tr>
+ <td>&nbsp;</td>
+ </tr>
+ <tr>
+ <td><input value="Save" type="submit" name="Submit" id="Submit" /></td>
+ </tr>
</table>
+ </div>
</td>
- </tr>
- </table>
- </td>
</tr>
</table>
+
+</form>
+
+<p><b>NOTE:</b> You can click on a ruleset name to edit the ruleset.</p>
+
</div>
-<!-- footer do not touch below -->
-<?php
-include("fend.inc");
+<?php
+include("fend.inc");
echo $snort_custom_rnd_box;
?>
-
</body>
</html>
-