Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

For Snort sfPortScan, add ignore_scanned option to ignore destination… #122

Merged
merged 7 commits into from
May 20, 2016
Next Next commit
For Snort sfPortScan, add ignore_scanned option to ignore destination…
…s CIDR/ports.
  • Loading branch information
zxvv committed Apr 27, 2016
commit 95a152deee306acab5eeedc8940e035b06b0d4a6
Original file line number Diff line number Diff line change
Expand Up @@ -640,6 +640,11 @@
$sf_pscan_ignore_scanners = trim(filter_expand_alias($snortcfg['pscan_ignore_scanners']));
$sf_pscan_ignore_scanners = preg_replace('/\s+/', ',', trim($sf_pscan_ignore_scanners));
}
$sf_pscan_ignore_scanned = "";
if (!empty($snortcfg['pscan_ignore_scanned']) && is_alias($snortcfg['pscan_ignore_scanned'])) {
$sf_pscan_ignore_scanned = trim(filter_expand_alias($snortcfg['pscan_ignore_scanned']));
$sf_pscan_ignore_scanned = preg_replace('/\s+/', ',', trim($sf_pscan_ignore_scanned));
}

$sf_portscan = <<<EOD
# sf Portscan #
Expand All @@ -648,7 +653,8 @@
proto { {$sf_pscan_protocol} } \
memcap { {$sf_pscan_memcap} } \
sense_level { {$sf_pscan_sense_level} } \
ignore_scanners { {$sf_pscan_ignore_scanners} }
ignore_scanners { {$sf_pscan_ignore_scanners} } \
ignore_scanned { {$sf_pscan_ignore_scanned} }

EOD;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@
// Retrieve previously typed values we passed to SELECT ALIAS page
$pconfig['sf_portscan'] = htmlspecialchars($_GET['sf_portscan'])? 'on' : 'off';
$pconfig['pscan_ignore_scanners'] = htmlspecialchars($_GET['pscan_ignore_scanners']);
$pconfig['pscan_ignore_scanned'] = htmlspecialchars($_GET['pscan_ignore_scanned']);
$pconfig['pscan_protocol'] = htmlspecialchars($_GET['pscan_protocol']);
$pconfig['pscan_type'] = htmlspecialchars($_GET['pscan_type']);
$pconfig['pscan_memcap'] = htmlspecialchars($_GET['pscan_memcap']);
Expand Down Expand Up @@ -368,6 +369,7 @@
$pconfig['pscan_type'] = "all";
$pconfig['pscan_sense_level'] = "medium";
$pconfig['pscan_ignore_scanners'] = "";
$pconfig['pscan_ignore_scanned'] = "";
$pconfig['pscan_memcap'] = '10000000';
$pconfig['dce_rpc_2'] = "on";
$pconfig['dns_preprocessor'] = "on";
Expand Down Expand Up @@ -475,6 +477,12 @@
$input_errors[] = gettext("FQDN aliases are not supported in Snort for the PORTSCAN IGNORE_SCANNERS parameter.");
}

// Validate Portscan Ignore_Scanned parameter
if ($_POST['sf_portscan'] == 'on' && is_alias($_POST['pscan_ignore_scanned'])) {
if (trim(filter_expand_alias($_POST["def_{$key}"])) == "")
$input_errors[] = gettext("FQDN aliases are not supported in Snort for the PORTSCAN IGNORE_SCANNED parameter.");
}

/* if no errors write to conf */
if (!$input_errors) {
/* post new options */
Expand All @@ -495,6 +503,7 @@
if ($_POST['pscan_memcap'] != "") { $natent['pscan_memcap'] = $_POST['pscan_memcap']; }else{ $natent['pscan_memcap'] = "10000000"; }
if ($_POST['pscan_sense_level'] != "") { $natent['pscan_sense_level'] = $_POST['pscan_sense_level']; }else{ $natent['pscan_sense_level'] = "medium"; }
if ($_POST['pscan_ignore_scanners'] != "") { $natent['pscan_ignore_scanners'] = $_POST['pscan_ignore_scanners']; }else{ $natent['pscan_ignore_scanners'] = ""; }
if ($_POST['pscan_ignore_scanned'] != "") { $natent['pscan_ignore_scanned'] = $_POST['pscan_ignore_scanned']; }else{ $natent['pscan_ignore_scanned'] = ""; }
if ($_POST['frag3_max_frags'] != "") { $natent['frag3_max_frags'] = $_POST['frag3_max_frags']; }else{ $natent['frag3_max_frags'] = "8192"; }
if ($_POST['frag3_memcap'] != "") { $natent['frag3_memcap'] = $_POST['frag3_memcap']; }else{ $natent['frag3_memcap'] = "4194304"; }
if ($_POST['ftp_telnet_inspection_type'] != "") { $natent['ftp_telnet_inspection_type'] = $_POST['ftp_telnet_inspection_type']; }else{ $natent['ftp_telnet_inspection_type'] = "stateful"; }
Expand Down Expand Up @@ -1316,12 +1325,34 @@
);
$btnaliases->removeClass('btn-primary')->addClass('btn-default')->addClass('btn-success')->addClass('btn-sm');
$btnaliases->setAttribute('title', gettext("Select an existing IP alias"));
$btnaliases->setAttribute('onclick', 'selectAlias();');
$btnaliases->setAttribute('onclick', 'selectAlias(\'pscan_ignore_scanners\');');
$group = new Form_Group('Ignore Scanners');
$group->add($bind_to);
$group->add($btnaliases);
$group->setHelp('Ignores the specified entity as a source of scan alerts. Entity must be a defined alias.');
$section->add($group);
$bind_to = new Form_Input(
'pscan_ignore_scanned',
'',
'text',
$pconfig['pscan_ignore_scanned']
);
$bind_to->setAttribute('title', trim(filter_expand_alias($pconfig['pscan_ignore_scanned'])));
$bind_to->setHelp('Leave blank for default. Default value is <em>blank</em>, which means ignore none.');
$btnaliases = new Form_Button(
'btnSelectAlias',
' ' . 'Aliases',
'#',
'fa-search-plus'
);
$btnaliases->removeClass('btn-primary')->addClass('btn-default')->addClass('btn-success')->addClass('btn-sm');
$btnaliases->setAttribute('title', gettext("Select an existing IP alias"));
$btnaliases->setAttribute('onclick', 'selectAlias(\'pscan_ignore_scanned\');');
$group = new Form_Group('Ignore Scanned');
$group->add($bind_to);
$group->add($btnaliases);
$group->setHelp('Ignores the specified entity as a destination of scan alerts. Entity must be a defined alias.');
$section->add($group);
print($section);
//----- END Portscan settings -----

Expand Down Expand Up @@ -2045,15 +2076,15 @@ function enable_change_all() {
ftp_telnet_enable_change();
}

function selectAlias() {
function selectAlias(targetVar) {

var loc;
var fields = [ "#sf_portscan", "#pscan_protocol", "#pscan_type", "#pscan_sense_level", "#pscan_memcap", "#pscan_ignore_scanners" ];
var fields = [ "#sf_portscan", "#pscan_protocol", "#pscan_type", "#pscan_sense_level", "#pscan_memcap", "#pscan_ignore_scanners", "#pscan_ignore_scanned" ];

// Scrape current form field values and add to
// the select alias URL as a query string.
var loc = 'snort_select_alias.php?id=<?=$id;?>&act=import&type=host|network';
loc = loc + '&varname=pscan_ignore_scanners&multi_ip=yes';
loc = loc + '&varname=' + targetVar + '&multi_ip=yes';
loc = loc + '&returl=<?=urlencode($_SERVER['PHP_SELF']);?>';

// Iterate over just the specific form fields we want to pass to
Expand Down Expand Up @@ -2104,6 +2135,10 @@ function getFileContents() {
source: addressarray
});

$('#pscan_ignore_scanned').autocomplete({
source: addressarray
});

// ---------- Click handlers -------------------------------------------------------

$('#host_attribute_table').click(function() {
Expand Down