function show_form() { global $sensor_list; global $net_group_list; global $host_group_list; global $hosts_list; global $nets_list; global $conn; global $sensor_index; global $net_group_index; global $host_group_index; global $hosts_index; global $nets_index; $global_i = 0; $num = count($sensor_list); if ($num > 20) { $cols = 5; } else { $cols = 3; } $rows = intval($num / $cols) + 1; $num_ng = count($net_group_list); if ($num_ng > 20) { $cols = 5; } else { $cols = 3; } $rows_ng = intval($num_ng / $cols) + 1; $num_hg = count($host_group_list); if ($num_hg > 20) { $cols = 5; } else { $cols = 3; } $rows_hg = intval($num_hg / $cols) + 1; $num_hs = count($hosts_list); if ($num_hs > 20) { $cols = 5; } else { $cols = 3; } $rows_hs = intval($num_hs / $cols) + 1; $num_ns = count($nets_list); if ($num_ns > 20) { $cols = 5; } else { $cols = 3; } $rows_ns = intval($num_ns / $cols) + 1; if ($num_ns + $num_hs + $num_hg + $num_ng > 20) { $cols_full = 5; } else { $cols_full = 3; } ?> <h3><center> <?php echo _("Select sensors for this scan"); ?> </center></h3> <ul> <?php $group_scan_list = Net_group_scan::get_list($conn, "WHERE plugin_id = " . NESSUS); foreach ($group_scan_list as $group_scan) { $net_group_sensors = Net_group::get_sensors($conn, $group_scan->get_net_group_name()); echo "\n<script>\n"; echo "var " . $group_scan->get_net_group_name() . " = true;\n"; echo "</script>\n"; $sensor_string = ""; foreach ($net_group_sensors as $ng_sensor => $name) { if ($sensor_string == "") { $sensor_string .= $sensor_index[$name]; } else { $sensor_string .= "," . $sensor_index[$name]; } } $nets_string = ""; $nets = Net_group::get_networks($conn, $group_scan->get_net_group_name(), NESSUS); foreach ($nets as $net) { $name = $net->get_net_name(); if ($nets_string == "") { $nets_string .= $nets_index[$name]; } else { $nets_string .= "," . $nets_index[$name]; } } print "<li><a href=\"#\" onClick=\"return selectSomeNets('" . $group_scan->get_net_group_name() . "','" . $sensor_string . "','" . $nets_string . "');\">" . $group_scan->get_net_group_name() . "</a>"; } $group_scan_list = Host_group_scan::get_list($conn, "WHERE plugin_id = " . NESSUS); foreach ($group_scan_list as $group_scan) { $host_group_sensors = Host_group::get_sensors($conn, $group_scan->get_host_group_name()); echo "\n<script>\n"; echo "var " . $group_scan->get_host_group_name() . " = true;\n"; echo "</script>\n"; $sensor_string = ""; foreach ($host_group_sensors as $hg_sensor) { $name = $hg_sensor->get_sensor_name(); if ($sensor_string == "") { $sensor_string .= $sensor_index[$name]; } else { $sensor_string .= "," . $sensor_index[$name]; } } $hosts_string = ""; $hosts = Host_group::get_hosts($conn, $group_scan->get_host_group_name(), NESSUS); foreach ($hosts as $host) { $name = $host->get_host_name($conn); if ($hosts_string == "") { $hosts_string .= $hosts_index[$name]; } else { $hosts_string .= "," . $hosts_index[$name]; } } print "<li><a href=\"#\" onClick=\"return selectSomeHosts('" . $group_scan->get_host_group_name() . "','" . $sensor_string . "','" . $hosts_string . "');\">" . $group_scan->get_host_group_name() . "</a>"; } ?> </ul> <form action="<?php echo $_SERVER["SCRIPT_NAME"]; ?> " method="POST"> <p> <?php echo _("Please adjust incident creation threshold, incidents will only be created for vulnerabilities whose risk level exceeds the threshold."); ?> <br/> <?php echo _("It is recommended to set a high level at the beginning in order to concentrate on more critical vulnerabilities first, lowering it after having solved/tagged them as false positivies."); ?> <br/> <?php echo _("Threshold configuration can be found at Configuration->Main, \"vulnerability_incident_threshold\"."); ?> <?php echo _("Current risk threshold is:"); ?> <b> <?php require_once 'ossim_conf.inc'; $conf = $GLOBALS["CONF"]; print $conf->get_conf("vulnerability_incident_threshold"); ?> </b> </p> <h4><center> (<?php echo _("Empty means all"); ?> ) </center></h4> <center><a href="#" onClick="return selectAll();"><?php echo _("Select / Unselect all"); ?> </a></center> <br/> <table width="100%" border="0" align="center"><tr><td> <input type="radio" name="groupType" value="sensor" checked onClick="selectGroup('sensor');"> Sensor <input type="radio" name="groupType" value="host" onClick="selectGroup('host');"> NetGroup / Nets / HostGroup / Hosts </td></tr> <tr><td> <div id="rowSensor"> <table width="100%" align="left" border="0"><tr> <?php for ($i = 1; $i <= $rows; $i++) { ?> <?php for ($a = 0; $a < $cols && $global_i < $num; $a++) { $sensor = $sensor_list[$global_i]; echo "<td width=\"" . intval(100 / $cols) . "%\">"; $all['sensors'][] = "sensor" . $global_i; ?> <div align="left"> <input align="left" type="checkbox" id="<?php echo "sensor" . $global_i; ?> " name="<?php echo "sensor" . $global_i; ?> " value="<?php echo $sensor->get_ip(); ?> " /><?php echo $sensor->get_name(); ?> </div></td> <?php $global_i++; } echo "</tr>\n"; ?> <?php } echo "</table>\n"; ?> </div> <div id="rowHost" style="display: none"> <table width="100%" align="left" border="0"> <tr> <th colspan="3">NetGroups</th></tr><tr> <?php $global_ng = 0; for ($i = 1; $i <= $rows_ng; $i++) { ?> <?php for ($a = 0; $a < $cols_full && $global_ng < $num_ng; $a++) { $netgroup = $net_group_list[$global_ng]; echo "<td width=\"" . intval(100 / $cols_full) . "%\">"; $all['netgroups'][] = "netgroup" . $global_ng; ?> <div align="left"> <input align="left" type="checkbox" id="<?php echo "netgroup" . $global_ng; ?> " name="netgroupList[]" value="<?php echo $netgroup->get_name(); ?> " /><?php echo $netgroup->get_name($conn); ?> </div></td> <?php $global_ng++; } echo "</tr>\n"; ?> <tr> <?php } ?> <th colspan="3">HostGroups</th></tr><tr> <?php $global_hg = 0; for ($i = 1; $i <= $rows_hg; $i++) { for ($a = 0; $a < $cols_full && $global_hg < $num_hg; $a++) { $hostgroup = $host_group_list[$global_hg]; echo "<td width=\"" . intval(100 / $cols_full) . "%\">"; $all['hostgroups'][] = "hostgroup" . $global_hg; ?> <div align="left"> <input align="left" type="checkbox" id="<?php echo "hostgroup" . $global_hg; ?> " name="hostgroupList[]" value="<?php echo $hostgroup->get_name(); ?> " /><?php echo $hostgroup->get_name($conn); ?> </div></td> <?php $global_hg++; } echo "</tr>\n"; ?> <tr> <?php } ?> <th colspan="3">Nets</th></tr><tr> <?php $global_ns = 0; for ($i = 1; $i <= $rows_ns; $i++) { ?> <?php for ($a = 0; $a < $cols_full && $global_ns < $num_ns; $a++) { $nets = $nets_list[$global_ns]; echo "<td width=\"" . intval(100 / $cols_full) . "%\">"; $all['nets'][] = "net" . $global_ns; ?> <div align="left"> <input align="left" type="checkbox" id="<?php echo "net" . $global_ns; ?> " name="netList[]" value="<?php echo $nets->get_name(); ?> " /><?php echo $nets->get_name($conn); ?> </div></td> <?php $global_ns++; } echo "</tr>\n"; ?> <tr> <?php } ?> <th colspan="3">Hosts</th></tr><tr> <?php $global_hs = 0; for ($i = 1; $i <= $rows_hs; $i++) { ?> <?php for ($a = 0; $a < $cols_full && $global_hs < $num_hs; $a++) { $hosts = $hosts_list[$global_hs]; echo "<td width=\"" . intval(100 / $cols_full) . "%\">"; $all['hosts'][] = "host" . $global_hs; ?> <div align="left"> <input align="left" type="checkbox" id="<?php echo "host" . $global_hs; ?> " name="hostList[]" value="<?php echo $hosts->get_host_ip(); ?> " /><?php echo $hosts->get_name($conn); ?> </div></td> <?php $global_hs++; } echo "</tr>\n"; ?> <?php } echo "</table>\n"; ?> </div> </td></tr></table> <br> <center> <input type="hidden" name="nsensors" value="<?php echo $global_i; ?> " /> <input type="Submit" class="button" value="<?php echo _("Submit"); ?> "> </center> </form> <center><a href="index.php"> <?php echo gettext("Back"); ?> </a></center> <script> var check_sensors = true; var check_nethost = true; var scanType = 'sensor'; function selectAll() { if (scanType == 'sensor') { <?php if (count($all['sensors']) != 0) { foreach ($all['sensors'] as $id) { ?> document.getElementById('<?php echo $id; ?> ').checked = check_sensors; <?php } } ?> check_sensors = check_sensors == false ? true : false; } else { <?php if (count($all['netgroups']) != 0) { foreach ($all['netgroups'] as $id) { ?> document.getElementById('<?php echo $id; ?> ').checked = check_nethost; <?php } } ?> <?php if (count($all['hostgroups']) != 0) { foreach ($all['hostgroups'] as $id) { ?> document.getElementById('<?php echo $id; ?> ').checked = check_nethost; <?php } } ?> <?php if (count($all['nets']) != 0) { foreach ($all['nets'] as $id) { ?> document.getElementById('<?php echo $id; ?> ').checked = check_nethost; <?php } } ?> <?php if (count($all['hosts']) != 0) { foreach ($all['hosts'] as $id) { ?> document.getElementById('<?php echo $id; ?> ').checked = check_nethost; <?php } } ?> check_nethost = check_nethost == false ? true : false; } return false; } function selectSomeNets(name, identifiersSensors, identifiersNets) { if (identifiersSensors.length != 0) { arrayOfStringsSensor = identifiersSensors.split(","); for (var i=0; i < arrayOfStringsSensor.length; i++) { document.getElementById("sensor" + arrayOfStringsSensor[i]).checked = window[name]; } } if (identifiersNets.length != 0) { arrayOfStringsNets = identifiersNets.split(","); for (var i=0; i < arrayOfStringsNets.length; i++) { document.getElementById("net" + arrayOfStringsNets[i]).checked = window[name]; } } window[name] = window[name] == false ? true : false; return false; } function selectSomeHosts(name, identifiersSensors, identifiersHosts) { if (identifiersSensors.length != 0) { arrayOfStringsSensor = identifiersSensors.split(","); for (var i=0; i < arrayOfStringsSensor.length; i++) { document.getElementById("sensor" + arrayOfStringsSensor[i]).checked = window[name]; } } if (identifiersHosts.length != 0) { arrayOfStringsHosts = identifiersHosts.split(","); for (var i=0; i < arrayOfStringsHosts.length; i++) { document.getElementById("host" + arrayOfStringsHosts[i]).checked = window[name]; } } window[name] = window[name] == false ? true : false; return false; } function selectGroup(category) { if (category == 'sensor') { document.getElementById("rowHost").style.display = 'none'; document.getElementById("rowSensor").style.display = 'block'; } else { document.getElementById("rowHost").style.display = 'block'; document.getElementById("rowSensor").style.display = 'none'; } scanType = category; } </script> </body> </html> <?php }
$q->close(); } } } } if ($nagios) { if (Host_group_scan::in_host_group_scan($conn, $hgname, 2007)) { Host_group_scan::delete($conn, $hgname, 2007); } Host_group_scan::insert($conn, $hgname, 2007); $q = new NagiosAdm(); $q->addNagiosHostGroup(new NagiosHostGroup($hgname, $hosts, $sensors), $conn); $q->close(); } else { if (Host_group_scan::in_host_group_scan($conn, $hgname, 2007)) { Host_group_scan::delete($conn, $hgname, 2007); } } Host_group::update($conn, $hgname, $threshold_c, $threshold_a, $rrd_profile, $sensors, $hosts, $descr); $db->close($conn); Util::clean_json_cache_files("(policy|vulnmeter|hostgroup)"); } if (isset($_SESSION['_hostgroup'])) { unset($_SESSION['_hostgroup']); } if ($_SESSION["menu_sopc"] == "Host groups" && POST('withoutmenu') != "1") { ?> <p><?php echo gettext("Host group succesfully updated"); ?> </p>
$sensor_string .= "," . $sensor_index[$name]; } } $nets_string = ""; $nets = Net_group::get_networks($conn, $group_scan->get_net_group_name(), NESSUS); foreach ($nets as $net) { $name = $net->get_net_name(); if ($nets_string == "") { $nets_string .= $nets_index[$name]; } else { $nets_string .= "," . $nets_index[$name]; } } print "<li><a href=\"#\" onClick=\"return selectSomeNets('" . $group_scan->get_net_group_name() . "','" . $sensor_string . "','" . $nets_string . "');\">" . $group_scan->get_net_group_name() . "</a>"; } $group_scan_list = Host_group_scan::get_list($conn, "WHERE plugin_id = " . NESSUS); foreach ($group_scan_list as $group_scan) { $host_group_sensors = Host_group::get_sensors($conn, $group_scan->get_host_group_name()); echo "\n<script>\n"; echo "var " . $group_scan->get_host_group_name() . " = true;\n"; echo "</script>\n"; $sensor_string = ""; foreach ($host_group_sensors as $hg_sensor) { $name = $hg_sensor->get_sensor_name(); if ($sensor_string == "") { $sensor_string .= $sensor_index[$name]; } else { $sensor_string .= "," . $sensor_index[$name]; } } $hosts_string = "";
if ($type == 'groupAndHosts') { require_once 'classes/Host_scan.inc'; $host_list = Host_group::get_hosts($conn, $name); foreach ($host_list as $host) { $ip = $host->get_host_ip(); if (Host::can_delete($conn, $ip)) { if (Host_scan::in_host_scan($conn, $ip, 2007)) { Host_scan::delete($conn, $ip, 2007); } Host_scan::delete($conn, $ip, 3001); Host::delete($conn, $ip); } } } // Host_group_scan::delete($conn, $name, 3001); Host_group::delete($conn, $name); } else { echo "ERROR_CANNOT"; } $db->close($conn); ?> <p> <?php echo gettext("Host group deleted"); ?> </p> <p><a href="hostgroup.php"><?php echo gettext("Back"); ?> </a></p>
function update_db($global_info, $scan) { $db = new ossim_db(); $conn = $db->connect(); $array_os = array("win" => "1", "linux" => "2", "cisco" => "3", "freebsd" => "5", "netbsd" => "6", "openbsd" => "7", "hp-ux" => "8", "solaris" => "9", "macos" => "10", "plan9" => "11", "sco" => "12", "aix" => "13", "unix" => "14"); $ips = $global_info["ips"]; $sensors = $global_info["sboxs"]; $nagios = $global_info['nagios']; // load protocol ids $protocol_ids = array(); if ($protocol_list = Protocol::get_list($conn)) { foreach ($protocol_list as $protocol_data) { $protocol_ids[$protocol_data->get_name()] = $protocol_data->get_id(); } } for ($i = 0; $i < $ips; $i++) { $ip = $global_info["ip_{$i}"]; if (!empty($ip)) { $hosts[] = $ip; //gethostbyaddr($ip); $os = $scan[$ip]["os"]; $os_id = 0; foreach ($array_os as $k => $v) { if (preg_match("/{$k}/i", $os)) { $os_id = $v; break; } } if (Host::in_host($conn, $ip)) { echo "* " . gettext("Updating") . " {$ip}..<br/>"; Host::update($conn, $ip, gethostbyaddr($ip), $global_info["asset"], $global_info["threshold_c"], $global_info["threshold_a"], $global_info["rrd_profile"], 0, 0, $global_info["nat"], $sensors, $global_info["descr"], $scan["{$ip}"]["os"], $scan["{$ip}"]["mac"], $scan["{$ip}"]["mac_vendor"]); Host_scan::delete($conn, $ip, 3001); //if (isset($global_info["nessus"])) { Host_scan::insert($conn, $ip, 3001, 0); } } else { echo "<span style='color='blue'>\n"; echo "* " . gettext("Inserting") . " {$ip}..<br/>\n"; echo "</span>\n"; Host::insert($conn, $ip, gethostbyaddr($ip), $global_info["asset"], $global_info["threshold_c"], $global_info["threshold_a"], $global_info["rrd_profile"], 0, 0, $global_info["nat"], $sensors, $global_info["descr"], $scan[$ip]["os"], $scan[$ip]["mac"], $scan[$ip]["mac_vendor"]); // if (isset($global_info["nessus"])) { Host_scan::insert($conn, $ip, 3001, 0); } } if ($os_id != 0) { Host_plugin_sid::delete($conn, $ip, 5001); Host_plugin_sid::insert($conn, $ip, 5001, $os_id); } if (!empty($nagios)) { if (!Host_scan::in_host_scan($conn, $ip, 2007)) { Host_scan::insert($conn, $ip, 2007, "", $ip, $sensors, ""); } } else { if (Host_scan::in_host_scan($conn, $ip, 2007)) { Host_scan::delete($conn, $ip, 2007); } } /* Services */ Host_plugin_sid::delete($conn, $ip, 5002); foreach ($scan[$ip]["services"] as $port_proto => $service) { $service["proto"] = $protocol_ids[strtolower(trim($service["proto"]))]; Host_services::insert($conn, $ip, $service["port"], strftime("%Y-%m-%d %H:%M:%S"), $_SERVER["SERVER_ADDR"], $service["proto"], $service["service"], $service["service"], $service["version"], 1); Host_plugin_sid::insert($conn, $ip, 5002, $service["port"]); } flush(); } } // Insert group name $groupname = $global_info["groupname"]; if (!empty($groupname) && !empty($hosts)) { $exists_hosts = count(Host_group::get_list($conn, " AND g.name='{$groupname}'")) > 0; if ($exists_hosts) { echo "<br/>" . _("The group name already exists") . "<br/>"; } else { Host_group::insert($conn, $groupname, $global_info["threshold_c"], $global_info["threshold_a"], $global_info["rrd_profile"], $sensors, $hosts, $global_info["descr"]); } //if (isset($global_info["nessus"])) { Host_group_scan::insert($conn, $groupname, 3001, 0); } if (!empty($nagios)) { Host_group_scan::insert($conn, $groupname, 2007, 0); } } $db->close($conn); }
$hosts = $sensors = array(); if ($hgname != '') { ossim_valid($hgname, OSS_ALPHA, OSS_SPACE, OSS_PUNC, OSS_NULLABLE, OSS_SQL, 'illegal:' . _("Host Group Name")); if (ossim_error()) { die(ossim_error()); } if ($host_group_list = Host_group::get_list($conn, " AND g.name = '{$hgname}'")) { $host_group = $host_group_list[0]; $descr = $host_group->get_descr(); $threshold_c = $host_group->get_threshold_c(); $threshold_a = $host_group->get_threshold_a(); $obj_hosts = $host_group->get_hosts($conn); foreach ($obj_hosts as $host) { $hosts[] = $host->get_host_ip($conn); } $nagios = Host_group_scan::in_host_group_scan($conn, $hgname, 2007) ? "1" : ''; $rrd_profile = $host_group->get_rrd_profile(); if (!$rrd_profile) { $rrd_profile = "None"; } $tmp_sensors = $host_group->get_sensors($conn); foreach ($tmp_sensors as $sensor) { $sensors[] = $sensor->get_sensor_name(); } } } } if (GET('withoutmenu') != "1") { include "../hmenu.php"; } ?>
$xml .= "<cell><![CDATA[" . $host_group->get_threshold_c() . "]]></cell>"; $xml .= "<cell><![CDATA[" . $host_group->get_threshold_a() . "]]></cell>"; /* Nessus if ($scan_list = Host_group_scan::get_list($conn, "WHERE host_group_name = '$name' AND plugin_id = 3001")) { $scan_types = "<img src='../pixmaps/tables/tick.png'>"; } else { $scan_types = "<img src='../pixmaps/tables/cross.png'>"; } $xml.= "<cell><![CDATA[" . $scan_types . "]]></cell>"; */ // Nagios $rep = ""; if ($linkedocs = Repository::have_linked_documents($conn, $host_group->get_name(), 'host_group')) { $rep .= "<a href=\"javascript:;\" onclick=\"GB_edit('../repository/repository_list.php?keyname=" . urlencode($name) . "&type=host_group')\" class=\"blue\">[" . $linkedocs . "]</a> "; } $rep .= "<a href=\"../repository/index.php?hmenu=Repository&smenu=Repository\" target='main'><img src=\"../pixmaps/tables/table_edit.png\" title=\"Edit KDB\" alt=\"Edit KDB\" border=0 align=\"absmiddle\"></a>"; $xml .= "<cell><![CDATA[" . $rep . "]]></cell>"; if ($scan_list = Host_group_scan::get_list($conn, "WHERE host_group_name = '{$name}' AND plugin_id = 2007")) { $scan_types = "<img src='../pixmaps/tables/tick.png'>"; } else { $scan_types = "<img src='../pixmaps/tables/cross.png'>"; } $xml .= "<cell><![CDATA[" . $scan_types . "]]></cell>"; $xml .= "</row>\n"; } $xml .= "</rows>\n"; echo $xml; $db->close($conn); ?>