} ?> </div> </td> </tr> </table> <?php } $commands = array("play_task", "pause_task", "stop_task", "resume_task", "delete_task"); // OMP commands if (in_array($disp, $commands)) { // get server info to manage tasks $uuid = Util::get_system_uuid(); $result_server = $dbconn->Execute("SELECT meth_Wcheck FROM vuln_jobs WHERE id=" . $job_id); preg_match("/.*\\s(\\d+\\.\\d+\\.\\d+\\.\\d+)<.*/", $result_server->fields['meth_Wcheck'], $found); $sensor_id = Av_sensor::get_id_by_ip($dbconn, $found[1]); $sensor_object = new Av_sensor($sensor_id); $sensor_object->load_from_db($dbconn); $ov_credentials = $sensor_object->get_vs_credentials($dbconn); $port = $ov_credentials['port']; $user = $ov_credentials['user']; $password = $ov_credentials['password']; $omp = new Omp($sensor_object->get_ip(), $port, $user, $password); } switch ($disp) { case "kill": $schedid = intval($schedid); if ($schedid > 0) { system("sudo /usr/share/ossim/scripts/vulnmeter/cancel_scan.pl {$schedid}"); } break;
ossim_valid($id, OSS_HEX, OSS_NULLABLE, 'illegal:' . _('Sensor ID')); ossim_valid($ip, OSS_IP_ADDR, OSS_NULLABLE, 'illegal:' . _('IP')); if (ossim_error()) { die(ossim_error()); } // From 'Insert' link detected by server if ($ip != '' && $id == '') { $unregistered_sensors = Av_sensor::get_unregistered($conn); foreach ($unregistered_sensors as $s_data) { if ($s_data['ip'] == $ip) { $id = $s_data['id']; break; } } if ($id == '') { $id = Av_sensor::get_id_by_ip($conn, $ip); } if ($id != '') { $disable_inputs = TRUE; $sname = 'sensor-' . str_replace('.', '-', $ip); } } $can_i_modify_elem = TRUE; $external_ctx = ''; $is_ossim_sensor = FALSE; if ($id != '') { $sensor = Av_sensor::get_object($conn, $id); if (is_object($sensor) && !empty($sensor)) { $sname = $sname != '' ? $sname : $sensor->get_name(); $ip = $sensor->get_ip(); $priority = $sensor->get_priority();
function insert_host($conn, $data) { $ips = preg_replace('/\\s*/', '', $data['ip']); $name = utf8_decode($data['name']); list($os, $dtype) = explode("_", $data['type']); // Type ossim_valid($ips, OSS_IP_ADDR, 'illegal:' . _("IP")); ossim_valid($name, OSS_HOST_NAME, 'illegal:' . _("Name")); ossim_valid($os, OSS_NULLABLE, OSS_ALPHA, 'illegal:' . _("OS")); ossim_valid($dtype, OSS_NULLABLE, OSS_ALPHA, 'illegal:' . _("Device Type")); check_ossim_error(); $ips = explode(',', $ips); foreach ($ips as $ip) { $h_ip[$ip] = array('ip' => $ip, 'mac' => NULL); } //Insert the New Host $uuid = Util::uuid(); $sensor_ip = Util::get_default_admin_ip(); $sensor = Av_sensor::get_id_by_ip($conn, $sensor_ip); $host = new Asset_host($conn, $uuid); $host->set_ips($h_ip); $host->set_name($name); $host->set_sensors(array($sensor)); $host->save_in_db($conn); // Device Type if ($dtype == 'networkdevice') { Asset_host_devices::save_device_in_db($conn, $uuid, 4); } // OS if ($os == 'windows' || $os == 'linux') { Asset_host_properties::save_property_in_db($conn, $uuid, 3, ucfirst($os), 1, TRUE); } $response['error'] = FALSE; $response['data'] = array(); return $response; }
function get_assets($conn, $id, $type, $host_types) { $filters = array('where' => 'sensor_properties.has_nagios = 1', 'order_by' => 'priority desc'); list($nagios_list, $nagios_total) = Av_sensor::get_list($conn, $filters); $sensor = NULL; $sensors = array(); $type = strtolower($type); $id = strtoupper($id); // in_assets first $in_assets = is_in_assets($conn, $id, $type); //Host, sensor or server if (in_array($type, $host_types)) { $table = $type; if ($type == 'host') { $what = 'host_id'; $table = 'host_ip'; } else { $what = 'id'; } $query = "SELECT INET6_NTOA(ip) AS ip FROM {$table} WHERE {$what} = UNHEX(?) LIMIT 1"; $params = array($id); $rs = $conn->Execute($query, $params); if ($rs) { $ips = $rs->fields['ip']; } // Related sensors if ($type == 'host') { $sensors = Asset_host_sensors::get_sensors_by_id($conn, $id); } elseif ($type == 'sensor') { $sensors[$id] = $ips; } else { $s_id = Av_sensor::get_id_by_ip($conn, Util::get_default_admin_ip()); $sensors[$s_id] = Util::get_default_admin_ip(); } } elseif ($type == 'net') { $query = "SELECT ips FROM net WHERE id = UNHEX(?)"; $params = array($id); $rs = $conn->Execute($query, $params); if ($rs) { $ips = $rs->fields['ips']; } // Related sensors $sensors = Asset_net_sensors::get_sensors_by_id($conn, $id); } elseif ($type == 'net_group' || $type == 'netgroup') { $query = "SELECT hex(ngr.net_id) as net_id, n.ips FROM net_group_reference AS ngr, net AS n\n WHERE ngr.net_group_id = UNHEX(?) AND ngr.net_id = n.id"; $net_ids = array($id); $params = $net_ids; $rs = $conn->Execute($query, $params); if ($rs) { $ipng = array(); if (!$rs->EOF) { $net_ids = array(); } while (!$rs->EOF) { $ipng[] = $rs->fields['ips']; $net_ids[] = $rs->fields['net_id']; $rs->MoveNext(); } $ips = count($ipng) > 0 ? implode(",", $ipng) : "'0.0.0.0/0'"; if (count($ipng) == 0) { $in_assets = 0; } } // Related sensors foreach ($net_ids as $net_id) { $_sensors_aux = Asset_net_sensors::get_sensors_by_id($conn, $net_id); foreach ($_sensors_aux as $sensor_id => $sensor_data) { $sensors[$sensor_id] = $sensor_data['ip']; } } } elseif ($type == 'host_group' || $type == 'hostgroup') { $query = "SELECT hex(hg.host_id) as host_id, INET6_NTOA(hi.ip) AS ip FROM host_group_reference hg, host_ip hi\n WHERE hi.host_id=hg.host_id AND hg.host_group_id = UNHEX(?)"; $host_ids = array($id); $params = $host_ids; $rs = $conn->Execute($query, $params); if ($rs) { $iphg = array(); if (!$rs->EOF) { $host_ids = array(); } while (!$rs->EOF) { $iphg[] = "'" . $rs->fields['ip'] . "'"; $host_ids[] = $rs->fields['host_id']; $rs->MoveNext(); } $ips = count($iphg) > 0 ? implode(',', $iphg) : "'0.0.0.0'"; if (count($iphg) == 0) { $in_assets = 0; } } // Related sensors foreach ($host_ids as $host_id) { $_sensors_aux = Asset_host_sensors::get_sensors_by_id($conn, $host_id); foreach ($_sensors_aux as $sensor_id => $sensor_data) { $sensors[$sensor_id] = $sensor_data['ip']; } } } //Getting first Nagios sensor (By priority) if ($nagios_total > 0) { foreach ($nagios_list as $n_sensor_id => $n_sensor_data) { if (array_key_exists($n_sensor_id, $sensors)) { $sensor = $n_sensor_data['ip']; break; } } } return array($id, $sensor, $type, $ips, $in_assets); }
function schedule_scan($conn, $wizard, $data) { $step = intval($wizard->get_step_data('scan_step')); $nets = $wizard->get_step_data('scan_nets'); if ($step != 3 || count($nets) < 1) { $response['error'] = TRUE; $response['msg'] = _('NMAP Scan not valid to schedule'); return $response; } $sched = $data['sch_opt']; ossim_valid($sched, OSS_DIGIT, 'illegal:' . _("Schedule Option")); if (ossim_error()) { $response['error'] = TRUE; $response['msg'] = ossim_get_error(); ossim_clean_error(); $wizard->set_step_data('scan_nets', -1); return $response; } if ($sched == 1) { $period = 86400; } elseif ($sched == 2) { $period = 604800; } else { $period = 2419200; } $sensor_ip = Util::get_default_admin_ip(); $sensor_id = Av_sensor::get_id_by_ip($conn, $sensor_ip); $name = _('Default_wizard_scan'); $type = 5; $enable = 1; $targets = array(); foreach ($nets as $cidrs) { $cidrs = explode(' ', $cidrs); foreach ($cidrs as $cidr) { $targets[$cidr] = $cidr; } } $targets = implode(' ', $targets); $params = $targets . '#-T5 -A -sS -F'; Inventory::insert($conn, $sensor_id, $name, $type, $period, $params, $enable, $targets); $response['error'] = FALSE; $response['data'] = array(); return $response; }