function get_targets($conn, $ip_list) { $result = array(); if (!empty($ip_list)) { if (is_array($ip_list) == FALSE) { $ip_list = explode("\n", trim($ip_list)); } foreach ($ip_list as $asset) { $asset = trim($asset); if (preg_match('/^([a-f\\d]{32})#(\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\/\\d{1,2})$/i', $asset, $found)) { $_asset_name = Asset_net::is_in_db($conn, $found[1]) ? Asset_net::get_name_by_id($conn, $found[1]) : $found[2]; $result[$asset] = $_asset_name; } else { if (preg_match('/^([a-f\\d]{32})#(\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3})$/i', $asset, $found)) { $_asset_name = Asset_host::is_in_db($conn, $found[1]) ? Asset_host::get_name_by_id($conn, $found[1]) : $found[2]; $result[$asset] = $_asset_name; } else { if (preg_match('/^([a-f\\d]{32})#hostgroup$/i', $asset, $found)) { $result[$asset] = Asset_group::get_name_by_id($conn, $found[1]); } else { if (preg_match('/^([a-f\\d]{32})#netgroup$/i', $asset, $found)) { $result[$asset] = Net_group::get_name_by_id($conn, $found[1]); } else { $result[$asset] = $asset; } } } } } } return $result; }
$arrResults[$hostIP . "#" . $hostctx][] = array('service' => $service, 'port' => $service_num, 'protocol' => $service_proto, 'application' => $app, 'risk' => $risk, 'scriptid' => $scriptid, 'exception' => $eid, 'msg' => preg_replace('/(<br\\s*?\\/??>)+/i', "\n", $msg), 'pname' => $pname); $result->MoveNext(); } //Vulnerability table configs $vcols = array(_("Risk"), _("Details")); //widths for columns $vwidth_array = array(20, 170); // 196 total $count = 0; $oldip = ""; // iterate through the IP is the results foreach ($arrResults as $hostIP_ctx => $scanData) { list($hostIP, $hostctx) = explode("#", $hostIP_ctx); $host_id = key(Asset_host::get_id_by_ips($dbconn, $hostIP, $hostctx)); if (valid_hex32($host_id)) { $hostname = Asset_host::get_name_by_id($dbconn, $host_id); } else { $hostname = _('unknown'); } $hostIP = htmlspecialchars_decode($hostIP); $hostname = htmlspecialchars_decode($hostname); $pdf->SetLink(${"IP_" . $hostIP_ctx}, $pdf->GetY()); //print out the host cell $pdf->SetFillColor(229, 229, 229); $pdf->SetFont('', 'B', 10); $pdf->Cell(95, 6, $hostIP, 1, 0, 'C', 1); $pdf->Cell(95, 6, $hostname, 1, 0, 'C', 1); //$pdf->Cell(105, 6, "",1,0,'C'); $pdf->SetFont('', ''); $pdf->Ln(); // now iterate through the scan results for this IP
function main_page($viewall, $sortby, $sortdir) { global $uroles, $username, $dbconn, $hosts; global $arruser, $user; $dbconn->SetFetchMode(ADODB_FETCH_BOTH); $tz = Util::get_timezone(); if ($sortby == "") { $sortby = "id"; } if ($sortdir == "") { $sortdir = "DESC"; } $sql_order = "order by {$sortby} {$sortdir}"; if (Session::menu_perms("environment-menu", "EventsVulnerabilitiesScan")) { ?> <div style="width:50%; position: relative; height: 5px; float:left"> <div style="width:100%; position: absolute; top: -41px;left:0px;"> <div style="float:left; height:28px; margin:5px 5px 0px 0px;"> <a class="button" href="<?php echo Menu::get_menu_url(AV_MAIN_PATH . '/vulnmeter/sched.php?smethod=schedule&hosts_alive=1&scan_locally=1', 'environment', 'vulnerabilities', 'scan_jobs'); ?> "> <?php echo _("New Scan Job"); ?> </a> </div> <div style="float:left;height:28px;margin:5px 5px 0px -2px;"> <a class="greybox button av_b_secondary" href="import_nbe.php" title="<?php echo _("Import nbe file"); ?> "> <?php echo _("Import nbe file"); ?> </a> </div> </div> </div> <?php } if (intval($_GET['page']) != 0) { $page = intval($_GET['page']); } else { $page = 1; } $pagesize = 10; if ($username == "admin") { $query = "SELECT count(id) as num FROM vuln_jobs"; } else { $query = "SELECT count(id) as num FROM vuln_jobs where username='******'"; } $result = $dbconn->Execute($query); $jobCount = $result->fields["num"]; $num_pages = ceil($jobCount / $pagesize); //echo "num_pages:[".$num_pages."]"; //echo "jobCount:[".$jobCount."]"; //echo "page:[".$page."]"; if (Vulnerabilities::scanner_type() == "omp") { // We can display scan status with OMP protocol echo Vulnerabilities::get_omp_running_scans($dbconn); } else { // Nessus all_jobs(0, 10, "R"); } ?> <?php $schedulejobs = _("Scheduled Jobs"); echo <<<EOT <table style='margin-top:20px;' class='w100 transparent'><tr><td class='sec_title'>{$schedulejobs}</td></tr></table> <table summary="Job Schedules" class='w100 table_list'> EOT; if ($sortdir == "ASC") { $sortdir = "DESC"; } else { $sortdir = "ASC"; } $arr = array("name" => "Name", "schedule_type" => "Schedule Type", "time" => "Time", "next_CHECK" => "Next Scan", "enabled" => "Status"); // modified by hsh to return all scan schedules if (empty($arruser)) { $query = "SELECT t2.name as profile, t1.meth_TARGET, t1.id, t1.name, t1.schedule_type, t1.meth_VSET, t1.meth_TIMEOUT, t1.username, t1.enabled, t1.next_CHECK, t1.email\n FROM vuln_job_schedule t1 LEFT JOIN vuln_nessus_settings t2 ON t1.meth_VSET=t2.id "; } else { $query = "SELECT t2.name as profile, t1.meth_TARGET, t1.id, t1.name, t1.schedule_type, t1.meth_VSET, t1.meth_TIMEOUT, t1.username, t1.enabled, t1.next_CHECK, t1.email\n FROM vuln_job_schedule t1 LEFT JOIN vuln_nessus_settings t2 ON t1.meth_VSET=t2.id WHERE username in ({$user}) "; } $query .= $sql_order; $result = $dbconn->execute($query); if ($result->EOF) { echo "<tr><td class='empty_results' height='20' style='text-align:center;'>" . _("No Scheduled Jobs") . "</td></tr>"; } if (!$result->EOF) { echo "<tr>"; foreach ($arr as $order_by => $value) { echo "<th><a href=\"manage_jobs.php?sortby={$order_by}&sortdir={$sortdir}\">" . _($value) . "</a></th>"; } if (Session::menu_perms("environment-menu", "EventsVulnerabilitiesScan")) { echo "<th>" . _("Action") . "</th></tr>"; } } $colors = array("#FFFFFF", "#EEEEEE"); $color = 0; while (!$result->EOF) { list($profile, $targets, $schedid, $schedname, $schedtype, $sid, $timeout, $user, $schedstatus, $nextscan, $servers) = $result->fields; $name = Av_sensor::get_name_by_id($dbconn, $servers); $servers = $name != '' ? $name : "unknown"; $targets_to_resolve = explode("\n", $targets); $ttargets = array(); foreach ($targets_to_resolve as $id_ip) { if (preg_match("/^([a-f\\d]{32})#\\d+\\.\\d+\\.\\d+\\.\\d+\\/\\d{1,2}/i", $id_ip, $found) && Asset_net::is_in_db($dbconn, $found[1])) { $ttargets[] = preg_replace("/^([a-f\\d]{32})#/i", "", $id_ip) . " (" . Asset_net::get_name_by_id($dbconn, $found[1]) . ")"; } else { if (preg_match("/^([a-f\\d]{32})#\\d+\\.\\d+\\.\\d+\\.\\d+/i", $id_ip, $found) && Asset_host::is_in_db($dbconn, $found[1])) { $ttargets[] = preg_replace("/^([a-f\\d]{32})#/i", "", $id_ip) . " (" . Asset_host::get_name_by_id($dbconn, $found[1]) . ")"; } else { $ttargets[] = preg_replace("/[a-f\\d]{32}/i", "", $id_ip); } } } $targets = implode("<BR/>", $ttargets); $tz = intval($tz); $nextscan = gmdate("Y-m-d H:i:s", Util::get_utc_unixtime($nextscan) + 3600 * $tz); preg_match("/\\d+\\-\\d+\\-\\d+\\s(\\d+:\\d+:\\d+)/", $nextscan, $found); $time = $found[1]; switch ($schedtype) { case "N": $stt = _("Once (Now)"); break; case "O": $stt = _("Once"); break; case "D": $stt = _("Daily"); break; case "W": $stt = _("Weekly"); break; case "M": $stt = _("Monthly"); break; case "Q": $stt = _("Quarterly"); break; case "H": $stt = _("On Hold"); break; case "NW": $stt = _("N<sup>th</sup> weekday of the month"); break; default: $stt = " "; break; } switch ($schedstatus) { case "1": $itext = _("Disable Scheduled Job"); $isrc = "images/stop_task.png"; $ilink = "manage_jobs.php?disp=setstatus&schedid={$schedid}&enabled=0"; break; default: $itext = _("Enable Scheduled Job"); $isrc = "images/play_task.png"; $ilink = "manage_jobs.php?disp=setstatus&schedid={$schedid}&enabled=1"; break; } if (!Session::menu_perms("environment-menu", "EventsVulnerabilitiesScan")) { $ilink = "javascript:return false;"; } if ($schedstatus) { $txt_enabled = "<td><a href=\"{$ilink}\"><font color=\"green\">" . _("Enabled") . "</font></a></td>"; } else { $txt_enabled = "<td><a href=\"{$ilink}\"><font color=\"red\">" . _("Disabled") . "</font></a></td>"; } require_once 'classes/Security.inc'; if (valid_hex32($user)) { $user = Session::get_entity_name($dbconn, $user); } echo "<tr bgcolor=\"" . $colors[$color % 2] . "\">"; if ($profile == "") { $profile = _("Default"); } echo "<td><span class=\"tip\" title=\"<b>" . _("Owner") . ":</b> {$user}<br><b>" . _("Server") . ":</b> {$servers}<br /><b>" . _("Scheduled Job ID") . ":</b> {$schedid}<br><b>" . _("Profile") . ":</b> {$profile}<br><b>" . _("Targets") . ":</b><br>" . $targets . "\">{$schedname}</span></td>"; ?> <td><?php echo $stt; ?> </td> <td><?php echo $time; ?> </td> <td><?php echo $nextscan; ?> </td> <?php echo <<<EOT {$txt_enabled} <td style="padding-top:2px;"><a href="{$ilink}"><img alt="{$itext}" src="{$isrc}" border=0 title="{$itext}"></a> EOT; if (Session::menu_perms("environment-menu", "EventsVulnerabilitiesScan")) { echo "<a href='" . Menu::get_menu_url(AV_MAIN_PATH . '/vulnmeter/sched.php?disp=edit_sched&sched_id=' . $schedid, 'environment', 'vulnerabilities', 'scan_jobs') . "'><img src='images/pencil.png' title='" . _("Edit Scheduled") . "'></a> "; echo "<a href='manage_jobs.php?disp=delete&schedid={$schedid}' onclick='return confirmDelete();'><img src='images/delete.gif' title='" . gettext("Delete Scheduled") . "'></a>"; } echo "</td>"; echo <<<EOT </tr> EOT; $result->MoveNext(); $color++; } echo <<<EOT </table> EOT; ?> <br /> <?php $out = all_jobs(($page - 1) * $pagesize, $pagesize); ?> <table width="100%" align="center" class="transparent" cellspacing="0" cellpadding="0"> <tr> <td class="nobborder" valign="top" style="padding-top:5px;"> <div class="fright"> <?php if ($out != 0 && $num_pages != 1) { $page_url = "manage_jobs.php"; if ($page == 1 && $page == $num_pages) { echo '<a href="" class="link_paginate_disabled" onclick="return false">< ' . _("PREVIOUS") . '</a>'; echo '<a class="lmargin link_paginate_disabled" href="" onclick="return false">' . _("NEXT") . ' ></a>'; } elseif ($page == 1) { echo '<a href="" class="link_paginate_disabled" onclick="return false">< ' . _("PREVIOUS") . '</a>'; echo '<a class="lmargin" href="' . $page_url . '?page=' . ($page + 1) . '">' . _("NEXT") . ' ></a> '; } elseif ($page == $num_pages) { echo '<a href="' . $page_url . '?page=' . ($page - 1) . '">< ' . _("PREVIOUS") . '</a>'; echo '<a class="lmargin link_paginate_disabled" href="" onclick="return false">' . _("NEXT") . ' ></a>'; } else { echo '<a href="' . $page_url . '?page=' . ($page - 1) . '">< ' . _("PREVIOUS") . '</a><a class="lmargin" href="' . $page_url . '?page=' . ($page + 1) . '">' . _("NEXT") . ' ></a>'; } } ?> </div> </td> </tr> </table> <?php }
function list_results($type, $value, $ctx_filter, $sortby, $sortdir) { global $allres, $offset, $pageSize, $dbconn; global $user, $arruser; $dbconn->SetFetchMode(ADODB_FETCH_BOTH); $filteredView = FALSE; $selRadio = array("", "", "", ""); $query_onlyuser = ""; $url_filter = ""; // Deprecated filter //if(!empty($arruser)) {$query_onlyuser = "******";} $sortby = "t1.results_sent DESC, t1.hostIP DESC"; $sortdir = ""; $queryw = ""; $queryl = ""; $querys = "SELECT distinct t1.hostIP, HEX(t1.ctx) as ctx, t1.scantime, t1.username, t1.scantype, t1.report_key, t1.report_type as report_type, t1.sid, t3.name as profile\n FROM vuln_nessus_latest_reports AS t1 LEFT JOIN vuln_nessus_settings AS t3 ON t1.sid = t3.id, vuln_nessus_latest_results AS t5\n WHERE\n t1.hostIP = t5.hostIP\n AND t1.ctx = t5.ctx\n AND t1.deleted = '0' "; // set up the SQL query based on the search form input (if any) if ($type == "scantime" && $value != "") { $selRadio[0] = "CHECKED"; $q = $value; $queryw = " AND t1.scantime LIKE '%{$q}%' {$query_onlyuser} order by {$sortby} {$sortdir}"; $queryl = " limit {$offset},{$pageSize}"; $stext = "<b>" . _("Search for Date/Time") . "</b> = '*{$q}*'"; $url_filter = "&type={$type}&value={$value}"; } else { if ($type == "service" && $value != "") { $selRadio[5] = "CHECKED"; $q = $value; $queryw = " AND t5.service LIKE '%{$q}%' {$query_onlyuser} order by {$sortby} {$sortdir}"; $queryl = " limit {$offset},{$pageSize}"; $stext = "<b>" . _("Search for Service") . "</b> = '*" . html_entity_decode($q) . "*'"; $url_filter = "&type={$type}&value={$value}"; } else { if ($type == "freetext" && $value != "") { $selRadio[6] = "CHECKED"; $q = $value; $queryw = " AND t5.msg LIKE '%{$q}%' {$query_onlyuser} order by {$sortby} {$sortdir}"; $queryl = " limit {$offset},{$pageSize}"; $stext = "<b>" . _("Search for Free Text") . "</b> = '*" . html_entity_decode($q) . "*'"; $url_filter = "&type={$type}&value={$value}"; } else { if ($type == "hostip" && $value != "") { $selRadio[1] = "CHECKED"; $q = strtolower($value); $queryw = " t1.hostIP LIKE '%{$q}%' {$query_onlyuser} order by {$sortby} {$sortdir}"; $queryl = " limit {$offset},{$pageSize}"; $stext = "<b>" . _("Search for Host-IP") . "</b> = '*{$q}*'"; $url_filter = "&type={$type}&value={$value}"; } else { if ($type == "fk_name" && $value != "") { $selRadio[2] = "CHECKED"; $q = strtolower($value); $queryw = " AND t1.fk_name LIKE '%{$q}%' {$query_onlyuser} order by {$sortby} {$sortdir}"; $queryl = " limit {$offset},{$pageSize}"; $stext = _("Search for Subnet/CIDR") . " = '*{$q}*'"; $url_filter = "&type={$type}&value={$value}"; } else { if ($type == "username" && $value != "") { $selRadio[3] = "CHECKED"; $q = strtolower($value); $queryw = " AND t1.username LIKE '%{$q}%' {$query_onlyuser} order by {$sortby} {$sortdir}"; $queryl = " limit {$offset},{$pageSize}"; $stext = "<b>" . _("Search for user") . "</b> = '*{$q}*'"; $url_filter = "&type={$type}&value={$value}"; } else { if ($type == "hn" && $value != "") { if (!empty($ctx_filter)) { $queryw = " AND t1.ctx=UNHEX('{$ctx_filter}')"; } $selRadio[4] = "CHECKED"; if (preg_match("/\\//", $value)) { $ip_range = array(); $ip_range = Cidr::expand_CIDR($value, "SHORT"); $queryw .= " AND (inet_aton(t1.hostIP) >= '" . $ip_range[0] . "' AND inet_aton(t1.hostIP) <='" . $ip_range[1] . "') {$query_onlyuser} order by {$sortby} {$sortdir}"; } elseif (preg_match("/\\,/", $value)) { $q = implode("','", explode(",", $value)); $queryw .= " AND t1.hostIP in ('{$q}') {$query_onlyuser} order by {$sortby} {$sortdir}"; $q = "Others"; } else { $q = $value; $queryw .= " AND t1.hostIP LIKE '{$q}' {$query_onlyuser} order by {$sortby} {$sortdir}"; } $queryl = " limit {$offset},{$pageSize}"; if (!preg_match("/\\//", $value)) { $stext = "<b>" . _("Search for Host") . "</b> = '" . html_entity_decode($q) . "'"; } else { $stext = "<b>" . _("Search for Subnet/CIDR") . "</b> = '{$value}'"; } $url_filter = "&type={$type}&value={$value}"; } else { $selRadio[4] = "CHECKED"; $viewAll = FALSE; $queryw = "{$query_onlyuser} order by {$sortby} {$sortdir}"; $queryl = " limit {$offset},{$pageSize}"; $stext = ""; } } } } } } } // set up the pager and search fields if viewing all hosts $reportCount = 0; if (!$filteredView) { $dbconn->Execute(str_replace("SELECT distinct", "SELECT SQL_CALC_FOUND_ROWS distinct", $querys) . $queryw); $reportCount = $dbconn->GetOne("SELECT FOUND_ROWS() as total"); $previous = $offset - $pageSize; if ($previous < 0) { $previous = 0; } $last = intval($reportCount / $pageSize) * $pageSize; if ($last < 0) { $last = 0; } $next = $offset + $pageSize; $pageEnd = $offset + $pageSize; $value = html_entity_decode($value); //echo "<center><table cellspacing='0' cellpadding='0' border='0' width='100%'><tr><td class='headerpr' style='border:0;'>"._("Current Vulnerablities")."</td></tr></table>"; // output the search form echo "<table class='w100 transparent'>"; echo "<tr><td class='sec_title'>" . _("Asset Vulnerability Details") . "</td></tr>"; echo "<tr><td style='padding:12px 0px 0px 0px;' class='transparent'>"; ?> <div id='cvleftdiv'> <a id="new_scan_button" class="button" href="<?php echo Menu::get_menu_url(AV_MAIN_PATH . '/vulnmeter/sched.php?action=create_scan&hosts_alive=1&scan_locally=1', 'environment', 'vulnerabilities', 'scan_jobs'); ?> " style="text-decoration:none;"> <?php echo _("New Scan Job"); ?> </a> </div> <div id='cvrightdiv'> <?php echo '<form name="hostSearch" id="hostSearch" action="index.php" method="GET"> <input type="text" length="25" name="value" id="assets" class="assets" style="margin:0px !important;" value="' . Util::htmlentities($value) . '">'; // cvfiltertype -> current vulnerabilities filter type echo "\n<input type=\"radio\" name=\"type\" value=\"service\" {$selRadio['5']}>" . _("Service") . "\n<input type=\"radio\" name=\"type\" value=\"freetext\" {$selRadio['6']}>" . _("Free text") . "\n<input type=\"radio\" name=\"type\" value=\"hn\" {$selRadio['4']}>" . _("Host/Net") . "\n"; echo "<input type=\"submit\" name=\"submit\" value=\"" . _("Find") . "\" id=\"current_vulns_find_button\" class=\"av_b_secondary small\" style=\"margin-left:15px;\">"; echo <<<EOT </form> </p> EOT; } else { // get the search result count $queryc = "SELECT count( report_id ) FROM vuln_nessus_latest_reports WHERE t1.deleted = '0' "; $scount = $dbconn->GetOne($queryc . $queryw); echo "<p>{$scount} report"; if ($scount != 1) { echo "s"; } else { } echo " " . _("found matching search criteria") . " | "; echo " <a href='index.php' alt='" . _("View All Reports") . "'>" . _("View All Reports") . "</a></p>"; } echo "<p>"; echo $stext; echo "</p>"; echo "</div></td></tr></table>"; $result = array(); // get the hosts to display $result = $dbconn->GetArray($querys . $queryw . $queryl); // main query //echo $querys.$queryw.$queryl; $delete_ids = array(); if (count($result) > 0) { foreach ($result as $rpt) { $delete_ids[] = $dreport_id = $rpt["report_id"]; } } $_SESSION["_dreport_ids"] = implode(",", $delete_ids); //echo "$querys$queryw$queryl"; if ($result === false) { $errMsg[] = _("Error getting results") . ": " . $dbconn->ErrorMsg(); $error++; dispSQLError($errMsg, $error); } else { $data['vInfo'] = 0; $data['vLow'] = 0; $data['vMed'] = 0; $data['vHigh'] = 0; $data['vSerious'] = 0; $perms_where = Asset_host::get_perms_where('host.', TRUE); if (!empty($perms_where)) { $queryt = "SELECT count(lr.result_id) AS total, lr.risk, lr.hostIP, HEX(lr.ctx) AS ctx\n FROM vuln_nessus_latest_results lr, host, host_ip hi\n WHERE host.id=hi.host_id AND inet6_ntoa(hi.ip)=lr.hostIP {$perms_where} AND falsepositive='N'\n GROUP BY risk, hostIP, ctx"; } else { $queryt = "SELECT count(lr.result_id) AS total, risk, lr.hostIP, HEX(lr.ctx) AS ctx\n FROM vuln_nessus_latest_results lr\n WHERE falsepositive='N'\n GROUP BY risk, hostIP, ctx"; } //echo "$queryt<br>"; $resultt = $dbconn->Execute($queryt); while (!$resultt->EOF) { $riskcount = $resultt->fields['total']; $risk = $resultt->fields['risk']; if ($risk == 7) { $data['vInfo'] += $riskcount; } else { if ($risk == 6) { $data['vLow'] += $riskcount; } else { if ($risk == 3) { $data['vMed'] += $riskcount; } else { if ($risk == 2) { $data['vHigh'] += $riskcount; } else { if ($risk == 1) { $data['vSerious'] += $riskcount; } } } } } $resultt->MoveNext(); } if ($data['vInfo'] == 0 && $data['vLow'] == 0 && $data['vMed'] == 0 && $data['vHigh'] == 0 && $data['vSerious'] == 0) { $tdata[] = array("report_id" => "All", "host_name" => "", "scantime" => "", "username" => "", "scantype" => "", "report_key" => "", "report_type" => "", "sid" => "", "profile" => "", "hlink" => "", "plink" => "", "xlink" => "", "vSerious" => $data['vSerious'], "vHigh" => $data['vHigh'], "vMed" => $data['vMed'], "vLow" => $data['vLow'], "vInfo" => $data['vInfo']); } else { $tdata[] = array("report_id" => "All", "host_name" => "", "scantime" => "", "username" => "", "scantype" => "", "report_key" => "", "report_type" => "", "sid" => "", "profile" => "", "hlink" => "lr_reshtml.php?ipl=all&disp=html&output=full&scantype=M", "plink" => "lr_respdf.php?ipl=all&scantype=M", "xlink" => "lr_rescsv.php?ipl=all&scantype=M", "dlink" => "", "vSerious" => $data['vSerious'], "vHigh" => $data['vHigh'], "vMed" => $data['vMed'], "vLow" => $data['vLow'], "vInfo" => $data['vInfo']); } foreach ($result as $data) { if (!Session::hostAllowed_by_ip_ctx($dbconn, $data["hostIP"], $data["ctx"])) { continue; } $host_id = key(Asset_host::get_id_by_ips($dbconn, $data["hostIP"], $data["ctx"])); if (valid_hex32($host_id)) { $data['host_name'] = Asset_host::get_name_by_id($dbconn, $host_id); } $data['vSerious'] = 0; $data['vHigh'] = 0; $data['vMed'] = 0; $data['vLow'] = 0; $data['vInfo'] = 0; // query for reports for each IP $query_risk = "SELECT distinct risk, port, protocol, app, scriptid, msg, hostIP FROM vuln_nessus_latest_results WHERE hostIP = '" . $data['hostIP']; $query_risk .= "' AND username = '******'username'] . "' AND sid =" . $data['sid'] . " AND ctx = UNHEX('" . $data['ctx'] . "') AND falsepositive='N'"; $result_risk = $dbconn->Execute($query_risk); while (!$result_risk->EOF) { if ($result_risk->fields["risk"] == 7) { $data['vInfo']++; } else { if ($result_risk->fields["risk"] == 6) { $data['vLow']++; } else { if ($result_risk->fields["risk"] == 3) { $data['vMed']++; } else { if ($result_risk->fields["risk"] == 2) { $data['vHigh']++; } else { if ($result_risk->fields["risk"] == 1) { $data['vSerious']++; } } } } } $result_risk->MoveNext(); } $data['plink'] = "lr_respdf.php?treport=latest&ipl=" . urlencode($data['hostIP']) . "&ctx=" . $data['ctx'] . "&scantype=" . $data['scantype']; $data['hlink'] = "lr_reshtml.php?treport=latest&ipl=" . urlencode($data['hostIP']) . "&ctx=" . $data['ctx'] . "&scantype=" . $data['scantype']; $data['xlink'] = "lr_rescsv.php?treport=latest&ipl=" . urlencode($data['hostIP']) . "&ctx=" . $data['ctx'] . "&scantype=" . $data['scantype']; if (Session::am_i_admin()) { $data['dlink'] = "index.php?delete=" . $data['report_key'] . "&scantime=" . $data['scantime']; } $list = explode("\n", trim($data['meth_target'])); if (count($list) == 1) { $list[0] = trim($list[0]); $data['target'] = resolve_asset($dbconn, $list[0]); } elseif (count($list) == 2) { $list[0] = trim($list[0]); $list[0] = resolve_asset($dbconn, $list[0]); $list[1] = trim($list[1]); $list[1] = resolve_asset($dbconn, $list[1]); $data['target'] = $list[0] . ' ' . $list[1]; } else { $list[0] = trim($list[0]); $list[0] = resolve_asset($dbconn, $list[0]); $list[count($list) - 1] = trim($list[count($list) - 1]); $list[count($list) - 1] = resolve_asset($dbconn, $list[count($list) - 1]); $data['target'] = $list[0] . " ... " . $list[count($list) - 1]; } $tdata[] = $data; } if ($sortdir == "ASC") { $sortdir = "DESC"; } else { $sortdir = "ASC"; } $url = $_SERVER['SCRIPT_NAME'] . "?offset={$offset}&sortby=%var%&sortdir={$sortdir}" . $url_filter; $fieldMapLinks = array(); $fieldMapLinks = array(gettext("HTML Results") => array('url' => '%param%', 'param' => 'hlink', 'target' => 'main', 'icon' => 'images/html.png'), gettext("PDF Results") => array('url' => '%param%', 'param' => 'plink', 'target' => '_blank', 'icon' => 'images/pdf.png'), gettext("EXCEL Results") => array('url' => '%param%', 'param' => 'xlink', 'target' => '_blank', 'icon' => 'images/page_white_excel.png')); if (Session::am_i_admin()) { $fieldMapLinks["DELETE Results"] = array('url' => '%param%', 'param' => 'dlink', 'target' => 'main', 'icon' => 'images/delete.gif'); } $fieldMap = array("Host - IP" => array('var' => 'hostip'), "Date/Time" => array('var' => 'scantime'), "Profile" => array('var' => 'profile'), "Serious" => array('var' => 'vSerious'), "High" => array('var' => 'vHigh'), "Medium" => array('var' => 'vMed'), "Low" => array('var' => 'vLow'), "Info" => array('var' => 'vInfo'), "Links" => $fieldMapLinks); // echo "<pre>"; // var_dump($tdata); // echo "</pre>"; if (count($tdata) > 1) { drawTableLatest($fieldMap, $tdata, "Hosts"); } elseif (Session::menu_perms("environment-menu", "EventsVulnerabilitiesScan")) { echo "<br><span class='gray'>" . _("No results found: ") . "</span><a href='" . Menu::get_menu_url(AV_MAIN_PATH . '/vulnmeter/sched.php?action=create_scan&hosts_alive=1&scan_locally=1', 'environment', 'vulnerabilities', 'scan_jobs') . "'>" . _("Click here to run a Vulnerability Scan now") . "</a><br><br>"; } } // draw the pager again, if viewing all hosts if (!$filteredView && $reportCount > 10) { ?> <div class="fright tmargin"> <?php if ($next > $pageSize) { ?> <a href="index.php?<?php echo "offset={$previous}{$url_filter}"; ?> " class="pager">< <?php echo _("PREVIOUS"); ?> </a> <?php } else { ?> <a class='link_paginate_disabled' href="" onclick='return false'>< <?php echo _("PREVIOUS"); ?> </a> <?php } if ($next <= $last) { ?> <a class='lmargin' href="index.php?<?php echo "offset={$next}{$url_filter}"; ?> "> <?php echo _("NEXT"); ?> ></a> <?php } else { ?> <a class='link_paginate_disabled lmargin' href="" onclick='return false'><?php echo _("NEXT"); ?> ></a> <?php } ?> </div> <?php } else { echo "<p> </p>"; } }
} } else { $e_msg = ossim_get_error_clean(); Av_exception::throw_error(Av_exception::USER_ERROR, $e_msg); } $agents = Ossec_agent::get_list($sensor_id); $data = array(); if (is_array($agents) && !empty($agents)) { foreach ($agents as $agent_id => $a_data) { if (empty($a_data)) { continue; } $a_unique_id = md5($agent_id); $agent_actions = Ossec_agent::get_actions($agent_id, $a_data); if (!empty($a_data['host_id'])) { $asset_name = Asset_host::get_name_by_id($conn, $a_data['host_id']); } else { $asset_name = '-'; } //Normalize status description (See asset list filters) if ($a_data['status']['id'] == 1) { $a_data['status']['descr'] = 'Disconnected'; } $t_data = array("DT_RowId" => 'cont_agent_' . $agent_id, "DT_RowData" => array('agent_key' => $a_unique_id, 'asset_id' => $a_data['host_id'], 'agent_status' => $a_data['status']), '', $agent_id, $a_data['name'], $asset_name, $a_data['ip_cidr'], "-", "-", $a_data['status']['descr'], $agent_actions); $data[] = $t_data; } } } catch (Exception $e) { $db->close(); Util::response_bad_request($e->getMessage()); }
foreach ($source_net_list as $source_net_group) { if (!check_any($source_net_group->get_net_group_id())) { $source .= ($source == "" ? "" : "<br/>") . "<img src='../pixmaps/theme/net_group.png' align=absbottom /> " . Net_group::get_name_by_id($conn, $source_net_group->get_net_group_id()); } } } if (empty($source)) { $source = "<img src='../pixmaps/theme/host.png' align=absbottom />" . _('ANY'); } $xml .= "<cell><![CDATA[" . $source . "]]></cell>"; // $dest = ""; if ($dest_host_list = $policy->get_hosts($conn, 'dest')) { foreach ($dest_host_list as $dest_host) { if (!check_any($dest_host->get_host_id())) { $dest .= ($dest == "" ? "" : "<br/>") . "<img src='../pixmaps/theme/host.png' align=absbottom /> " . Asset_host::get_name_by_id($conn, $dest_host->get_host_id()); } } } if ($dest_net_list = $policy->get_nets($conn, 'dest')) { foreach ($dest_net_list as $dest_net) { if (!check_any($dest_net->get_net_id())) { $dest .= ($dest == "" ? "" : "<br/>") . "<img src='../pixmaps/theme/net.png' align=absbottom /> " . Asset_net::get_name_by_id($conn, $dest_net->get_net_id()); } } } if ($dest_host_list = $policy->get_host_groups($conn, 'dest')) { foreach ($dest_host_list as $dest_host_group) { if (!check_any($dest_host_group->get_host_group_id())) { $dest .= ($dest == "" ? "" : "<br/>") . "<img src='../pixmaps/theme/host_group.png' align=absbottom /> " . Asset_group::get_name_by_id($conn, $dest_host_group->get_host_group_id()); }
} else { $list = $security_report->AttackHost($target, $limit, $type, $date_from, $date_to); } $datax = $datay = array(); $gorientation = "h"; foreach ($list as $key => $l) { if ($key >= 10) { // ponemos un límite de resultados para la gráfica //break; $gorientation = "v"; } $ip = $l[0]; $occurrences = number_format($l[1], 0, ",", "."); $id = $l[2]; $ctx = $l[3]; $hostname = valid_hex32($id) ? Asset_host::get_name_by_id($security_report->ossim_conn, $id) : $ip; $datax[] = $hostname ? $hostname : $ip; $datay[] = $l[1]; } require_once 'ossim_conf.inc'; $conf = $GLOBALS["CONF"]; $jpgraph = $conf->get_conf("jpgraph_path"); require_once "{$jpgraph}/jpgraph.php"; require_once "{$jpgraph}/jpgraph_bar.php"; // Setup the graph. if ($gorientation == "v") { $y = 30 + count($list) * 21; } else { $y = 250; } $graph = new Graph(400, $y, "auto");
function origdetails() { global $uroles, $user, $sid, $query_risk, $border, $report_id, $scantime, $scantype, $fp, $nfp, $filterip, $enableFP, $enableNotes, $output, $sortby, $dbconn, $arruser; global $treport, $ipl, $query_byuser, $ips_inrange, $ctx, $key; $colors = array("Serious" => "#FFCDFF", "High" => "#FFDBDB", "Medium" => "#FFF283", "Low" => "#FFFFC0", "Info" => "#FFFFE3"); $images = array("Serious" => "./images/risk1.gif", "High" => "./images/risk2.gif", "Medium" => "./images/risk3.gif", "Low" => "./images/risk6.gif", "Info" => "./images/risk7.gif"); $levels = array("Serious" => "1", "High" => "2", "Medium" => "3", "Low" => "6", "Info" => "7"); $query_host = ''; if ($filterip) { $query_host = " AND hostip='{$filterip}'"; } echo "<center>"; echo "<form>"; echo "<table width=\"900\" class=\"noborder\" style=\"background:transparent;\">"; echo "<tr><td style=\"text-align:left;\" class=\"nobborder\">"; echo "<input id=\"checkboxFP\" type=\"checkbox\" onclick=\"showFalsePositives()\"> <span style=\"color:black\">" . _("View false positives") . "</span>"; echo "</td><td class=\"nobborder\" style=\"text-align:center;\">"; // print the icon legend if ($enableFP) { echo "<img alt='True' src='images/true.gif' border=0 align='absmiddle'> - " . _("True result") . " "; echo "<img alt='False' src='images/false.png' border=0 align='absmiddle'> - " . _("False positive result") . " "; } $feed = exists_feed_tables($dbconn); echo "<img alt='Info' src='images/info.png' border=0 align='absmiddle'> - " . _("Additional information is available"); echo "</td></tr></table>"; echo "</form>"; echo "<br>"; $perms_where = Session::get_ctx_where() != "" ? " AND res.ctx in (" . Session::get_ctx_where() . ")" : ""; if ($ipl == "all") { $query = "select distinct res.hostIP, HEX(res.ctx) as ctx\n from vuln_nessus_latest_results res\n where falsepositive='N' \n {$perms_where}\n {$query_byuser}"; } else { if (!empty($ipl) && !empty($ctx)) { $query = "select distinct res.hostIP, HEX(res.ctx) as ctx\n from vuln_nessus_latest_results res\n where falsepositive='N' \n and res.hostIP='{$ipl}'\n and res.ctx=UNHEX('{$ctx}')\n {$perms_where}\n {$query_byuser}"; } else { if (!empty($scantime) && !empty($key)) { $query = "select distinct res.hostIP, HEX(res.ctx) as ctx\n from vuln_nessus_latest_results res, vuln_nessus_latest_reports rep\n where res.falsepositive='N'\n and res.scantime='{$scantime}' \n and res.hostIP=rep.hostIP\n and res.ctx=rep.ctx\n and res.username=rep.username\n and res.sid=rep.sid\n {$perms_where}\n and rep.report_key='{$key}' {$query_byuser}"; } } } $resultp = $dbconn->execute($query); $host_range = array_keys($ips_inrange); while (list($hostip, $hostctx) = $resultp->fields) { $host_id = key(Asset_host::get_id_by_ips($dbconn, $hostip, $hostctx)); if (valid_hex32($host_id)) { $hostname = Asset_host::get_name_by_id($dbconn, $host_id); } else { $hostname = _('unknown'); } if (in_array($hostip . ";" . $hostctx, $host_range)) { echo "<div class='hostip'>"; echo "<br><font color='red'><b><a name='{$hostip};{$hostctx}' href='javascript:;' ctx='{$hostctx}' id='{$hostip};{$hostname}' class='HostReportMenu'>{$hostip} - {$hostname}</a></b></font>"; echo "<br><br><table summary=\"{$hostip} - " . _("Reported Ports") . "\">"; echo "<tr><th colspan=2>" . _("Reported Ports") . "</th></tr>"; if (!empty($scantime) && !empty($key)) { $query = "select distinct res.port, res.protocol\n from vuln_nessus_latest_results res, vuln_nessus_latest_reports rep\n where res.falsepositive='N'\n and res.scantime='{$scantime}' \n and res.hostIP=rep.hostIP\n and res.ctx=rep.ctx\n and res.username=rep.username\n and res.sid=rep.sid\n and res.hostIP='{$hostip}'\n and res.ctx='{$hostctx}'\n and rep.report_key='{$key}' {$query_byuser}) as t group by risk"; } else { $query = "select distinct res.port, res.protocol\n from vuln_nessus_latest_results res \n where hostip='{$hostip}' and ctx=UNHEX('{$hostctx}') {$query_byuser} AND port > '0' ORDER BY port ASC"; } $result1 = $dbconn->execute($query); $k = 1; $pos = ''; if (!$result1->fields) { print "<tr><td>" . _("No reported ports found") . "</td></tr>"; } else { while (list($port, $proto) = $result1->fields) { if ($k % 2) { echo "<tr><td>{$port}/{$proto}</td>"; $pos = "open"; } else { echo "<td>{$port}/{$proto}</td></tr>"; $pos = "closed"; } $k++; $result1->MoveNext(); } // end while // close up the table if ($pos != "closed") { echo "<td> </td></tr>"; } } echo "</table><br/>"; echo "<table width='900' summary='{$hostip} - risks'><tr>"; echo "<th>" . _("Vuln Name") . "</th>"; echo "<th>" . _("VulnID") . "</th>"; echo "<th>" . _("Service") . "</th>"; echo "<th>" . _("Severity") . "</th>"; echo "</tr>"; if (!empty($scantime) && !empty($key)) { if ($feed) { $query = "select res.result_id, res.service, res.risk, res.falsepositive, res.scriptid, v.name, res.msg, rep.sid\n from vuln_nessus_latest_results AS res LEFT JOIN vuln_nessus_plugins AS v ON v.id=res.scriptid, vuln_nessus_latest_reports rep\n where res.msg<>''\n and res.scantime='{$scantime}' \n and res.hostIP=rep.hostIP\n and res.ctx=rep.ctx\n and res.hostIP='{$hostip}'\n and res.ctx=UNHEX('{$hostctx}')\n and res.username=rep.username\n and res.sid=rep.sid\n and rep.report_key='{$key}' and rep.sid>=0 {$query_byuser}\n UNION DISTINCT\n select res.result_id, res.service, res.risk, res.falsepositive, res.scriptid, v.name, res.msg, rep.sid\n from vuln_nessus_latest_results AS res LEFT JOIN vuln_nessus_plugins_feed AS v ON v.id=res.scriptid, vuln_nessus_latest_reports rep\n where res.msg<>''\n and res.scantime='{$scantime}' \n and res.hostIP=rep.hostIP\n and res.ctx=rep.ctx\n and res.hostIP='{$hostip}'\n and res.ctx=UNHEX('{$hostctx}')\n and res.username=rep.username\n and res.sid=rep.sid\n and rep.report_key='{$key}' and rep.sid<0 {$query_byuser}\n "; } else { $query = "select res.result_id, res.service, res.risk, res.falsepositive, res.scriptid, v.name, res.msg, rep.sid\n from vuln_nessus_latest_results AS res LEFT JOIN vuln_nessus_plugins AS v ON v.id=res.scriptid, vuln_nessus_latest_reports rep\n where res.msg<>''\n and res.scantime='{$scantime}' \n and res.hostIP=rep.hostIP\n and res.ctx=rep.ctx\n and res.hostIP='{$hostip}'\n and res.ctx=UNHEX('{$hostctx}')\n and res.username=rep.username\n and res.sid=rep.sid\n and rep.report_key='{$key}' {$query_byuser}"; } } else { if ($feed) { $query = "select res.result_id, res.service, res.risk, res.falsepositive, res.scriptid, v.name, res.msg, rep.sid\n FROM vuln_nessus_latest_results res LEFT JOIN vuln_nessus_plugins AS v ON v.id=res.scriptid, vuln_nessus_latest_reports rep\n WHERE\n res.hostIP=rep.hostIP\n and res.ctx=rep.ctx\n and res.username=rep.username\n and res.sid=rep.sid\n and res.hostIP='{$hostip}'\n and res.ctx=UNHEX('{$hostctx}')\n {$query_byuser} and msg<>'' and rep.sid>=0\n UNION DISTINCT\n select res.result_id, res.service, res.risk, res.falsepositive, res.scriptid, v.name, res.msg, rep.sid\n FROM vuln_nessus_latest_results res LEFT JOIN vuln_nessus_plugins_feed AS v ON v.id=res.scriptid, vuln_nessus_latest_reports rep\n WHERE\n res.hostIP=rep.hostIP\n and res.ctx=rep.ctx\n and res.username=rep.username\n and res.sid=rep.sid\n and res.hostIP='{$hostip}'\n and res.ctx=UNHEX('{$hostctx}')\n {$query_byuser} and msg<>'' and rep.sid<0"; } else { $query = "select res.result_id, res.service, res.risk, res.falsepositive, res.scriptid, v.name, res.msg, rep.sid\n FROM vuln_nessus_latest_results res LEFT JOIN vuln_nessus_plugins AS v ON v.id=res.scriptid, vuln_nessus_latest_reports rep\n WHERE\n res.hostIP=rep.hostIP\n and res.ctx=rep.ctx\n and res.username=rep.username\n and res.sid=rep.sid\n and res.hostIP='{$hostip}'\n and res.ctx=UNHEX('{$hostctx}')\n {$query_byuser} and msg<>''"; } } $query .= " group by risk, port, protocol, app, scriptid, msg order by risk"; $result1 = $dbconn->execute($query); $arrResults = array(); while (list($result_id, $service, $risk, $falsepositive, $scriptid, $pname, $msg, $sid) = $result1->fields) { $tmpport1 = preg_split("/\\(|\\)/", $service); if (sizeof($tmpport1) == 1) { $tmpport1[1] = $tmpport1[0]; } $tmpport2 = preg_split("/\\//", $tmpport1[1]); $service_num = $tmpport2[0]; $service_proto = $tmpport2[1]; $arrResults[] = array($service_num, $service_proto, $service, $risk, $falsepositive, $result_id, $msg, $scriptid, $pname, $sid); $result1->MoveNext(); } if (empty($arrResults)) { // empty, print out message echo "<tr><td colspan='4'>" . _("No vulnerability results matching this reports filtering criteria were found") . ".</td></tr>"; } foreach ($arrResults as $arrkey => $value) { list($service_num, $service_proto, $service, $risk, $falsepositive, $resid, $msg, $scriptid, $pname, $sid) = $value; $msg = preg_replace("/^[ \t]*/", "", $msg); $cves_found = ""; if (preg_match_all("/CVE\\-\\d+\\-\\d+/i", $msg, $found)) { $cves_found = implode(" ", $found[0]); } $msg = preg_replace("/[\n\r]/", "<br>", $msg); $msg = wordwrap($msg, 100, "<br>", 1); $tmprisk = getrisk($risk); $msg = preg_replace("/^\\<br\\>/i", "", str_replace("\\r", "", $msg)); $msg = preg_replace("/(Solution|Summary|Details|Overview|Synopsis|Description|See also|Plugin output|References|Vulnerability Insight|Vulnerability Detection|Impact|Impact Level|Affected Software\\/OS|Fix|Information about this scan)\\s*:/", "<b>\\1:</b>", $msg); // output the table cells $ancla = $hostip . "_" . $hostctx . "_" . $levels[$tmprisk]; $pname = $pname != "" ? $pname : _("No name"); echo "<tr " . ($falsepositive == 'Y' ? "class=\"trsk risk{$risk} fp\"" : "class=\"trsk risk{$risk}\"") . "style=\"background-color:" . $colors[$tmprisk] . ($falsepositive == 'Y' ? ";display:none;" : "") . "\">"; //echo "<tr>"; echo "<td width=\"50%\" style=\"padding:3px 0px 3px 0px;\"><b>" . $pname . "</b></td>"; echo "<td style=\"padding:3px 0px 3px 0px;\">{$scriptid}</td>"; ?> <td style="padding:3px;" width="180"><?php echo $service; ?> </td> <td style="text-align:center;"> <?php echo $tmprisk; ?> <img align="absmiddle" src="<?php echo $images[$tmprisk]; ?> " style="border: 1px solid ; width: 25px; height: 10px;"> </td> </tr> <?php echo "<tr " . ($falsepositive == 'Y' ? "class=\"trsk risk{$risk} fp\"" : "class=\"trsk risk{$risk}\"") . "style=\"background-color:" . $colors[$tmprisk] . ($falsepositive == 'Y' ? ";display:none;" : "") . "\">"; ?> <td style="padding:3px 0px 3px 6px;text-align:left;"> <a class="msg" name="<?php echo $resid; ?> "></a> <a name="<?php echo $ancla; ?> "></a> <?php echo $msg; ?> <font size="1"> <br><br> </font> <?php if ($cves_found != '') { ?> <a title="<?php echo _("Info from cve.mitre.org"); ?> " target="cve_mitre_org" href="http://cve.mitre.org/cgi-bin/cvekey.cgi?keyword=<?php echo urlencode($cves_found); ?> "><img src="images/cve_mitre.png" border='0'></a> <!--Add link to popup with Script Info--> <?php } if ($scriptid != "0") { ?> <!--Add link to popup with Script Info--> <div lid="<?php echo $scriptid; ?> " style="text-decoration:none;display:inline" class="scriptinfo"><img alt="Info" src="images/info.png" border=0></div> <?php } $tmpu = array(); $url = ""; foreach ($_GET as $kget => $vget) { if ($kget != "pluginid" && $kget != "nfp" && $kget != "fp") { $tmpu[] = Util::htmlentities($kget) . "=" . urlencode($vget); } } $url = implode("&", $tmpu); if ($falsepositive == "Y") { ?> <a href="<?php echo $_SERVER['SCRIPT_NAME'] . '?' . $url; ?> &nfp=<?php echo $resid; ?> "> <img alt="<?php echo _("Clear false positive"); ?> " src='images/false.png' title='<?php echo _("Clear false positive"); ?> ' border='0' /> </a> <?php } else { ?> <a href="<?php echo $_SERVER['SCRIPT_NAME'] . '?' . $url; ?> &fp=<?php echo $resid; ?> "> <img alt="<?php echo _("Mark as false positive"); ?> " src='images/true.gif' title='<?php echo _("Mark as false positive"); ?> ' border='0' /> </a> <?php } $pticket = "ref=Vulnerability&title=" . urlencode($pname) . "&priority=1&ip=" . urlencode($hostip) . "&port=" . urlencode($service_num) . "&nessus_id=" . urlencode($scriptid) . "&risk=" . urlencode($tmprisk) . "&type=" . urlencode("Nessus Vulnerability"); echo "<a title=\"" . _("New ticket") . "\" class=\"greybox\" href=\"../incidents/newincident.php?{$pticket}\"><img style=\"padding-bottom:2px;\" src=\"../pixmaps/script--pencil.png\" border=\"0\" alt=\"i\" width=\"12\"></a> "; ?> </td> <?php if ($sid < 0) { $plugin_info = $dbconn->execute("SELECT t2.name, t3.name, t1.copyright, t1.summary, t1.version \n FROM vuln_nessus_plugins_feed t1\n LEFT JOIN vuln_nessus_family_feed t2 on t1.family=t2.id\n LEFT JOIN vuln_nessus_category_feed t3 on t1.category=t3.id\n WHERE t1.id='{$scriptid}'"); } else { $plugin_info = $dbconn->execute("SELECT t2.name, t3.name, t1.copyright, t1.summary, t1.version \n FROM vuln_nessus_plugins t1\n LEFT JOIN vuln_nessus_family t2 on t1.family=t2.id\n LEFT JOIN vuln_nessus_category t3 on t1.category=t3.id\n WHERE t1.id='{$scriptid}'"); } list($pfamily, $pcategory, $pcopyright, $psummary, $pversion) = $plugin_info->fields; ?> <td colspan="3" valign="top" style="text-align:left;padding:3px;"> <?php $plugindetails = ''; if ($pfamily != '') { $plugindetails .= '<b>Family name:</b> ' . $pfamily . '<br><br>'; } if ($pcategory != '') { $plugindetails .= '<b>Category:</b> ' . $pcategory . '<br><br>'; } if ($pcopyright != '') { $plugindetails .= '<b>Copyright:</b> ' . $pcopyright . '<br><br>'; } if ($psummary != '') { $plugindetails .= '<b>Summary:</b> ' . $psummary . '<br><br>'; } if ($pversion != '') { $plugindetails .= '<b>Version:</b> ' . $pversion . '<br><br>'; } echo $plugindetails; ?> </td> </tr> <?php $result1->MoveNext(); } echo "</table>"; echo "</div>"; } $resultp->MoveNext(); } echo "</center>"; }
foreach ($source_host_list as $source_host_group) { $sources['hostgroup_' . $source_host_group->get_host_group_id()] = check_any($source_host_group->get_host_group_id()) ? _("ANY") : _("HOST_GROUP") . ": " . Asset_group::get_name_by_id($conn, $source_host_group->get_host_group_id()); } } if ($source_net_list = $policy->get_net_groups($conn, 'source')) { foreach ($source_net_list as $source_net_group) { $sources['netgroup_' . $source_net_group->get_net_group_id()] = check_any($source_net_group->get_net_group_id()) ? _("ANY") : _("NETWORK_GROUP") . ": " . Net_group::get_name_by_id($conn, $source_net_group->get_net_group_id()); } } //DESTINY if ($dest_host_list = $policy->get_hosts($conn, 'dest')) { foreach ($dest_host_list as $dest_host) { if (check_any($dest_host->get_host_id())) { $dests[$dest_host->get_host_id()] = _("ANY"); } else { $dests['host_' . $dest_host->get_host_id()] = _("HOST") . ": " . Asset_host::get_name_by_id($conn, $dest_host->get_host_id()); } } } if ($dest_net_list = $policy->get_nets($conn, 'dest')) { foreach ($dest_net_list as $dest_net) { $dests['net_' . $dest_net->get_net_id()] = check_any($dest_net->get_net_id()) ? _("ANY") : _("NETWORK") . ": " . Asset_net::get_name_by_id($conn, $dest_net->get_net_id()); } } if ($dest_host_list = $policy->get_host_groups($conn, 'dest')) { foreach ($dest_host_list as $dest_host_group) { $dests['hostgroup_' . $dest_host_group->get_host_group_id()] = check_any($dest_host_group->get_host_group_id()) ? _("ANY") : _("HOST_GROUP") . ": " . Asset_group::get_name_by_id($conn, $dest_host_group->get_host_group_id()); } } if ($dest_net_list = $policy->get_net_groups($conn, 'dest')) { foreach ($dest_net_list as $dest_net_group) {
function deploy_agents($conn, $wizard) { //Aux variable that is returned $data = array(); //If we have already initialized the deploy, we return true to check the status $started = $wizard->get_step_data('deploy_initialized'); if ($started === TRUE) { $response['error'] = FALSE; $response['data'] = $data; return $response; } //Retrieving the params $os = $wizard->get_step_data('deploy_os'); $username = $wizard->get_step_data('deploy_username'); $domain = $wizard->get_step_data('deploy_domain'); //Getting the array of hosts $hosts = $wizard->get_step_data('deploy_hosts'); $hosts = is_array($hosts) ? $hosts : array(); //Getting the password and decrypting $password = $wizard->get_step_data('deploy_password'); $password = Util::decrypt($password, Util::get_system_uuid()); $total_ip = 0; //Performing linux deployment --> Agentless if ($os == 'linux') { $sensor_id = get_sensor_id(); $deploy = 0; //Num of successful deployments --> Initially 0 //Arguments for the agentless entries $arguments = '/etc /usr/bin /usr/sbin /bin /sbin'; foreach ($hosts as $h) { $ips = Asset_host_ips::get_ips_to_string($conn, $h); $ips = explode(',', $ips); $hostname = Asset_host::get_name_by_id($conn, $h); foreach ($ips as $ip) { try { //Adding Aggentless Ossec_agentless::save_in_db($conn, $ip, $sensor_id, $hostname, $username, $password, '', FALSE, ''); //Adding Aggentless Entries Ossec_agentless::add_monitoring_entry($conn, $ip, $sensor_id, 'ssh_integrity_check_bsd', 3600, 'periodic', $arguments); Ossec_agentless::add_monitoring_entry($conn, $ip, $sensor_id, 'ssh_integrity_check_linux', 3600, 'periodic', $arguments); $deploy++; } catch (Exception $e) { Av_exception::write_log(Av_exception::USER_ERROR, $e->getMessage()); } $total_ip++; } } //Saving the number of the successful deployments $wizard->set_step_data('deploy_success', $deploy); } elseif ($os == 'windows') { $jobs = array(); foreach ($hosts as $h) { $ips = Asset_host_ips::get_ips_to_string($conn, $h); $ips = explode(',', $ips); foreach ($ips as $ip) { try { //Adding job to deploy ossec. $name = 'Windows-' . str_replace('.', '-', $ip); $job = Welcome_wizard::launch_ossec_deploy($name, $ip, $username, $domain, $password); $jid = md5($h . $ip); $jobs[$jid] = array('job_id' => $job['job_id'], 'agent' => $name . '(' . $ip . ')'); } catch (Exception $e) { Av_exception::write_log(Av_exception::USER_ERROR, $e->getMessage()); } $total_ip++; } } //Saving the jobs IDs in the wizard object $wizard->set_step_data('deploy_jobs', $jobs); } $total_ip = $total_ip > count($hosts) ? $total_ip : count($hosts); $data['total_ips'] = $total_ip; //Setting the total of ips. $wizard->set_step_data('deploy_total_ips', $total_ip); //Setting to true the flag that warns that the deploy has been already initialized. $wizard->set_step_data('deploy_initialized', TRUE); //Saving the wizard status $wizard->save_status(); $response['error'] = FALSE; $response['data'] = $data; return $response; }
<th> <?php echo _("Info"); ?> </th> </tr> </thead> <tbody> <?php foreach ($data['ip'] as $ip => $dip) { $hostname = ''; $location = $dip['country']; $flag = strtolower($location); $uuid = strtoupper(preg_replace('/^0x|NULL/i', '', $dip['uuid'])); if (!isset($hosts_ids[$uuid])) { $_hname = Asset_host::get_name_by_id($conn, $uuid); $hosts_ids[$uuid] = $_hname == _('Unknown') ? '' : $_hname; } $hostname = $hosts_ids[$uuid]; $hostname = $hostname == '' && $hostname != $ip ? $ip : $hostname . " ({$ip})"; if (strlen($location) == 2 && $location != $geoloc->get_country_name($location)) { $location = $geoloc->get_country_name($location); } if (file_exists("/usr/share/ossim/www/pixmaps/flags/{$flag}.png")) { $flag = "/ossim/pixmaps/flags/{$flag}.png"; } else { // Try to geoloc $record = $geoloc->get_location_from_file($ip); $flag = strtolower($record->country_code); if (!file_exists("/usr/share/ossim/www/pixmaps/flags/{$flag}.png")) { $flag = "/ossim/alarm/style/img/unknown.png";
function get_indicator_asset_name($conn, $type, $asset_id) { $name = ''; switch ($type) { case 'host': $name = Asset_host::get_name_by_id($conn, $asset_id); break; case 'net': $name = Asset_net::get_name_by_id($conn, $asset_id); break; case 'hostgroup': case 'host_group': $name = Asset_group::get_name_by_id($conn, $asset_id); break; case 'net_group': case 'netgroup': $name = Net_group::get_name_by_id($conn, $asset_id); break; case 'sensor': $name = Av_sensor::get_name_by_id($conn, $asset_id); break; } $name = empty($name) ? _('Unknown') : $name; return $name; }
$_aux_agents = Asset_host::get_related_hids_agents($conn, $asset_id, $sensor_id); $agent_key = md5(strtoupper($sensor_id) . '#' . $agent_id); unset($_aux_agents[$agent_key]); if (!empty($_aux_agents)) { $validation_errors['asset_id'] = sprintf(_("Unable to connect HIDS agent to '%s'. This asset already has an agent deployed. If you want to deploy a new agent, please review <a class=\"bold_red\" href=\"https://www.alienvault.com/help/redirect/usm/connect_agent\" target=\"_blank\">how to manage agent connections</a> and try again"), Asset_host::get_name_by_id($conn, $asset_id)); } $db->close(); } if (is_array($validation_errors) && !empty($validation_errors)) { $validation_errors['html_errors'] = "<div style='text-align: left;'>" . _('The following errors occurred') . ":</div>\n <div style='padding-left:15px; text-align: left;'>" . implode('<br/>', $validation_errors) . "</div>"; $data['status'] = 'error'; $data['data'] = $validation_errors; } else { $data['status'] = 'success'; $data['data'] = _('Your changes have been saved'); try { Ossec_agent::link_to_asset($sensor_id, $agent_id, $asset_id); $db = new ossim_db(); $conn = $db->connect(); $agents = Asset_host::get_related_hids_agents($conn, $asset_id, $sensor_id); $agent_key = md5(strtoupper($sensor_id) . '#' . $agent_id); $agent_info = array('ip_cidr' => $agents[$agent_key]['ip_cidr'], 'host_id' => $asset_id); $data['asset'] = array('id' => $asset_id, 'name' => Asset_host::get_name_by_id($conn, $asset_id), 'actions' => Ossec_agent::get_actions($agent_id, $agent_info)); $db->close(); } catch (Exception $e) { $data['status'] = 'error'; $data['data'] = _('An unexpected error occurred. Unable to connect asset to HIDS agent. Please try again') . '.<br/><br/>' . sprintf(_('Reason: %s'), $e->getMessage()); } } echo json_encode($data); exit;
$new_agent = Ossec_agent::create($sensor_id, $agent_name, $ip_cidr, $asset_id); //If ossec-remoted is not running, we have to restart Ossec Server $ossec_status = Ossec_control::execute_action($sensor_id, 'status'); if ('UP' !== $ossec_status['general_status']['ossec-remoted']) { Ossec_control::execute_action($sensor_id, 'restart'); } if (is_array($new_agent) && !empty($new_agent)) { $agent_id = $new_agent['id']; $agent_info = array('name' => $new_agent['name'], 'ip_cidr' => $new_agent['ip_cidr'], 'status' => $new_agent['status']); $agent_actions = Ossec_agent::get_actions($agent_id, $new_agent); $data['data'] = _("HIDS agent has been created. To deploy the agent, please choose one of the options under the 'Actions' column") . "###" . $agent_id . "###"; $a_unique_id = md5($agent_id); if (valid_hex32($new_agent['host_id'])) { $db = new Ossim_db(); $conn = $db->connect(); $asset_name = Asset_host::get_name_by_id($conn, $new_agent['host_id']); $db->close(); } else { $asset_name = '-'; } //Normalize status description (See asset list filters) if ($new_agent['status']['id'] == 1) { $new_agent['status']['descr'] = 'Disconnected'; } $agent_elem = array("DT_RowId" => 'cont_agent_' . $agent_id, "DT_RowData" => array('agent_key' => $a_unique_id, 'asset_id' => $new_agent['host_id'], 'agent_status' => $new_agent['status']), '', $agent_id, $new_agent['name'], $asset_name, $new_agent['ip_cidr'], "-", "-", $new_agent['status']['descr'], $agent_actions); $data['data'] .= json_encode(array($agent_elem)); } } catch (Exception $e) { $data['status'] = 'error'; $data['data'] = _('An unexpected error occurred. Unable to create HIDS agent. Please try again') . '.<br/><br/>' . $e->getMessage(); }
$host_info = $scan_results['scanned_ips']; foreach ($data['by_host'] as $host_key => $host_data) { ?> <tr> <td class='td_ip'> <?php echo $host_info[$host_key]['ip']; ?> </td> <td class='td_hostname'> <?php $hostname = ''; $id = $data['general']['hosts_in_group'][$host_key]; if (!empty($id)) { $hostname = Asset_host::get_name_by_id($conn, $id); } if (empty($hostname)) { $hostname = $host_info[$host_key]['hostname']; } echo $hostname; ?> </td> <td class='td_status'> <span class="<?php echo $host_data['status']; ?> "><?php echo ucfirst($host_data['status']); ?> </span>
function tab_discovery() { global $component, $uroles, $editdata, $scheduler, $username, $useremail, $dbconn, $disp, $enScanRequestImmediate, $enScanRequestRecur, $timeout, $smethod, $SVRid, $sid, $ip_list, $ip_exceptions_list, $schedule_type, $ROYEAR, $ROday, $ROMONTH, $time_hour, $time_min, $dayofweek, $dayofmonth, $sname, $user, $entity, $hosts_alive, $scan_locally, $version, $nthweekday, $semail, $not_resolve, $time_interval, $ssh_credential, $smb_credential, $net_id; global $pluginOptions, $enComplianceChecks, $profileid; $conf = $GLOBALS["CONF"]; $users = Session::get_users_to_assign($dbconn); $entities_to_assign = Session::get_entities_to_assign($dbconn); $pre_scan_locally_status = $conf->get_conf("nessus_pre_scan_locally"); $user_selected = $user; $entity_selected = $entity; $SVRid_selected = $SVRid; $sid_selected = $sid != "" ? $sid : $editdata['meth_VSET']; $timeout_selected = $editdata["meth_TIMEOUT"]; $ip_list_selected = str_replace("\\r\\n", "\n", str_replace(";;", "\n", $ip_list)); if (count($ip_exceptions_list) > 0) { $ip_list_selected .= "\n" . implode("\n", $ip_exceptions_list); } $ROYEAR_selected = $ROYEAR; $ROday_selected = $ROday; $ROMONTH_selected = $ROMONTH; $time_hour_selected = $time_hour; $time_min_selected = $time_min; $dayofweek_selected = $dayofweek; $dayofmonth_selected = $dayofmonth; $sname_selected = $sname; if (preg_match("/^[a-f\\d]{32}\$/i", $net_id)) { // Autofill new scan job from deployment if (Asset_net::is_in_db($dbconn, $net_id)) { $sname_selected = Asset_net::get_name_by_id($dbconn, $net_id); $schedule_type = "M"; $ip_list = array(); $nips = explode(",", Asset_net::get_ips_by_id($dbconn, $net_id)); foreach ($nips as $nip) { $ip_list[] = $net_id . "#" . trim($nip); } } } if ($schedule_type != "") { $editdata['schedule_type'] = $schedule_type; } $cquery_like = ""; if ($component != "") { $cquery_like = " AND component='{$component}'"; } $today = date("Ymd"); $tyear = substr($today, 0, 4); $nyear = $tyear + 1; $tmonth = substr($today, 4, 2); $tday = substr($today, 6, 2); #SET VALUES UP IF EDIT SCHEDULER if (isset($editdata['notify'])) { $enotify = $editdata['notify']; } else { $enotify = "{$useremail}"; } if (isset($editdata['time'])) { list($time_hour, $time_min, $time_sec) = split(':', $editdata['time']); $tz = Util::get_timezone(); $time_hour = $time_hour + $tz; } $arrTypes = array("N", "O", "D", "W", "M", "NW"); foreach ($arrTypes as $type) { $sTYPE[$type] = ""; } $arrJobTypes = array("C", "M", "R", "S"); foreach ($arrJobTypes as $type) { $sjTYPE[$type] = ""; } if (isset($editdata['schedule_type'])) { $sTYPE[$editdata['schedule_type']] = "selected='selected'"; if ($editdata['schedule_type'] == 'D') { $ni = 2; } elseif ($editdata['schedule_type'] == 'O') { $ni = 3; } elseif ($editdata['schedule_type'] == 'W') { $ni = 4; } elseif ($editdata['schedule_type'] == 'NW') { $ni = 6; } else { $ni = 5; } $show = "<br><script language=javascript>showLayer('idSched', {$ni});</script>"; } else { if ($enScanRequestImmediate) { $sTYPE['N'] = "selected='selected'"; $show = "<br><script language=javascript>showLayer('idSched', 1);</script>"; } else { $sTYPE['O'] = "selected='selected'"; $show = "<br><script language=javascript>showLayer('idSched', 3);</script>"; } } if ($schedule_type != "") { if ($schedule_type == "N") { $show .= "<br><script language=javascript>showLayer('idSched', 1);</script>"; } if ($schedule_type == "O") { $show .= "<br><script language=javascript>showLayer('idSched', 3);</script>"; } if ($schedule_type == "D") { $show .= "<br><script language=javascript>showLayer('idSched', 2);</script>"; } if ($schedule_type == "W") { $show .= "<br><script language=javascript>showLayer('idSched', 4);</script>"; } if ($schedule_type == "M") { $show .= "<br><script language=javascript>showLayer('idSched', 5);</script>"; } if ($schedule_type == "NW") { $show .= "<br><script language=javascript>showLayer('idSched', 6);</script>"; } } if (isset($editdata['job_TYPE'])) { $sjTYPE[$editdata['job_TYPE']] = "SELECTED"; } else { $sjTYPE['M'] = "SELECTED"; } if (isset($editdata['day_of_month'])) { $dayofmonth = $editdata['day_of_month']; } if (isset($editdata['day_of_week'])) { $day[$editdata['day_of_week']] = "SELECTED"; } if ($dayofweek_selected != "") { $day[$dayofweek_selected] = "SELECTED"; } if (!$uroles['nessus']) { $name = "sr-" . substr($username, 0, 6) . "-" . time(); $name = $editdata['name'] == "" ? $name : $editdata['name']; $nameout = $name . "<input type=hidden style='width:210px' name='sname' value='{$name}'>"; } else { $nameout = "<input type=text style='width:210px' name='sname' value='" . ($sname_selected != "" ? "{$sname_selected}" : "{$editdata['name']}") . "'>"; } $discovery = "<input type=\"hidden\" name=\"save_scan\" value=\"1\">"; $discovery .= "<input type=\"hidden\" name=\"cred_type\" value=\"N\">"; $discovery .= "<table width=\"80%\" cellspacing=\"4\">"; $discovery .= "<tr>"; $discovery .= "<input type=\"hidden\" name=\"smethod\" value=\"{$smethod}\">"; $discovery .= "<td width=\"25%\" class='job_option'>" . Util::strong(_("Job Name") . ":") . "</td>"; $discovery .= "<td style=\"text-align:left;\">{$nameout}</td>"; $discovery .= "</tr>"; list($sensor_list, $total) = Av_sensor::get_list($dbconn); $discovery .= "<tr>"; $discovery .= "<td class='job_option'>" . Util::strong(_("Select Server") . ":") . "</td>"; $discovery .= "<td style='text-align:left;'><select id='SVRid' style='width:212px' name='SVRid'>"; $discovery .= "<option value='Null'>" . _("First Available Server-Distributed") . "</option>"; foreach ($sensor_list as $_sensor_id => $sensor_data) { if (intval($sensor_data['properties']['has_vuln_scanner']) == 1) { $discovery .= "<option value=\"{$_sensor_id}\" "; if ($editdata['email'] == $_sensor_id || $editdata['scan_ASSIGNED'] == $_sensor_id) { $discovery .= " SELECTED"; } if ($SVRid_selected == $_sensor_id) { $discovery .= " SELECTED"; } $discovery .= ">" . strtoupper($sensor_data['name']) . " [" . $sensor_data['ip'] . "] </option>"; } } $discovery .= <<<EOT </select> </td> </tr> <tr> EOT; $discovery .= "<td class='job_option'>" . Util::strong(_("Profile") . ":") . "</td>"; $discovery .= "<td style='text-align:left;'><select name='sid'>"; $query = ""; if ($username == "admin" || Session::am_i_admin()) { $query = "SELECT distinct(t1.id), t1.name, t1.description \n FROM vuln_nessus_settings t1 WHERE deleted='0'\n ORDER BY t1.name"; } else { if (Session::is_pro()) { $users_and_entities = Acl::get_entities_to_assign($dbconn); if (Acl::am_i_proadmin()) { $users = Acl::get_my_users($dbconn, Session::get_session_user()); foreach ($users as $us) { $users_and_entities[$us->get_login()] = $us->get_login(); } $owner_list['0'] = '0'; $owner_list = array_keys($users_and_entities); $owner_list = implode("','", $owner_list); $query = "SELECT distinct(t1.id), t1.name, t1.description FROM vuln_nessus_settings t1\n WHERE deleted = '0' and (name='Default' or owner in ('" . $owner_list . "')) ORDER BY t1.name"; } else { $owner_list['0'] = '0'; $owner_list[$username] = $username; $owner_list = array_keys($users_and_entities); $owner_list[] = Session::get_session_user(); $owner_list = implode("','", $owner_list); $user_where = "owner in ('" . $owner_list . "')"; $query = "SELECT distinct(t1.id), t1.name, t1.description FROM vuln_nessus_settings t1\n WHERE deleted = '0' and (name='Default' or {$user_where}) ORDER BY t1.name"; } } else { $query = "SELECT distinct(t1.id), t1.name, t1.description FROM vuln_nessus_settings t1\n WHERE deleted = '0' and (name='Default' or owner in ('0','{$username}')) ORDER BY t1.name"; } } $dbconn->SetFetchMode(ADODB_FETCH_BOTH); $result = $dbconn->execute($query); $job_profiles = array(); $id_found = false; $ipr = 0; while (!$result->EOF) { list($sid, $sname, $sdescription) = $result->fields; if ($sid_selected == $sid) { $id_found = true; } $job_profiles[$ipr]["sid"] = $sid; $job_profiles[$ipr]["sname"] = $sname; $job_profiles[$ipr]["sdescription"] = $sdescription; $ipr++; $result->MoveNext(); } foreach ($job_profiles as $profile_data) { $sid = $profile_data["sid"]; $sname = $profile_data["sname"]; $sdescription = $profile_data["sdescription"]; $discovery .= "<option value=\"{$sid}\" "; if ($sid_selected == $sid) { if ($sdescription != "") { $discovery .= "selected>{$sname} - {$sdescription}</option>"; } else { $discovery .= "selected>{$sname}</option>"; } } else { if ($sdescription != "") { $discovery .= (preg_match("/default/i", $sname) && !$id_found ? 'selected="selected"' : "") . ">{$sname} - {$sdescription}</option>"; } else { $discovery .= (preg_match("/default/i", $sname) && !$id_found ? 'selected="selected"' : "") . ">{$sname}</option>"; } } } $discovery .= "</select>  <a href=\"" . Menu::get_menu_url('settings.php', 'environment', 'vulnerabilities', 'scan_jobs') . "\">[" . _("EDIT PROFILES") . "]</a></td>"; $discovery .= "</tr>"; $discovery .= "<tr>"; $discovery .= "<td class='job_option' style='vertical-align: top;'><div>" . Util::strong(_("Schedule Method") . ":") . "</div></td>"; $discovery .= "<td style='text-align:left'><div><select name='schedule_type' id='scheduleM'>"; $discovery .= "<option value='N' {$sTYPE['N']}>" . _("Immediately") . "</option>"; $discovery .= "<option value='O' {$sTYPE['O']}>" . _("Run Once") . "</option>"; $discovery .= "<option value='D' {$sTYPE['D']}>" . _("Daily") . "</option>"; $discovery .= "<option value='W' {$sTYPE['W']}>" . _("Day of the Week") . "</option>"; $discovery .= "<option value='M' {$sTYPE['M']}>" . _("Day of the Month") . "</option>"; $discovery .= "<option value='NW' {$sTYPE['NW']}>" . _("N<sup>th</sup> weekday of the month") . "</option>"; $discovery .= "</select></div></tr>"; $smethods = array("O", "D", "W", "M", "NW"); $smethodtr_display = in_array($editdata['schedule_type'], $smethods) ? "" : "style='display:none'"; $discovery .= "<tr {$smethodtr_display} id='smethodtr'><td> </td>"; $discovery .= <<<EOT </td> <td><div> <div id="idSched1" class="forminput"> </div> EOT; // div to select start day $discovery .= "<div id=\"idSched8\" class=\"forminput\">"; $discovery .= "<table cellspacing=\"2\" cellpadding=\"0\" width=\"100%\">"; $discovery .= "<tr><th width='35%'>" . _("Begin in") . "</th><td class='noborder' nowrap='nowrap'>" . gettext("Year") . " <select name='biyear'>"; $discovery .= "<option value=\"{$tyear}\" selected>{$tyear}</option>"; $discovery .= "<option value=\"{$nyear}\" >{$nyear}</option>"; $discovery .= "</select> " . gettext("Month") . " <select name='bimonth'>"; for ($i = 1; $i <= 12; $i++) { $discovery .= "<option value=\"{$i}\" "; if ($i == $tmonth) { $discovery .= "selected"; } $discovery .= ">{$i}</option>"; } $discovery .= "</select> " . gettext("Day") . " <select name=\"biday\">"; for ($i = 1; $i <= 31; $i++) { $discovery .= "<option value=\"{$i}\" "; if ($i == $tday) { $discovery .= "selected"; } $discovery .= ">{$i}</option>"; } $discovery .= "</select></td>"; $discovery .= "</tr>"; $discovery .= "</table>"; $discovery .= "</div>"; $discovery .= <<<EOT <div id="idSched3" class="forminput"> <table cellspacing="2" cellpadding="0" width="100%"> EOT; $discovery .= "<tr><th width='35%'>" . _("Day") . "</th><td colspan='6' class='noborder' nowrap='nowrap'>" . gettext("Year") . " <select name='ROYEAR'>"; $discovery .= "<option value=\"{$tyear}\" " . ($ROYEAR_selected == "" || $ROYEAR_selected == $tyear ? "selected" : "") . ">{$tyear}</option>"; $discovery .= "<option value=\"{$nyear}\" " . ($ROYEAR_selected == $nyear ? "selected" : "") . ">{$nyear}</option>"; $discovery .= "</select> " . gettext("Month") . " <select name='ROMONTH'>"; for ($i = 1; $i <= 12; $i++) { $discovery .= "<option value=\"{$i}\" "; if ($i == $tmonth && $ROMONTH_selected == "" || $ROMONTH_selected == $i) { $discovery .= "selected"; } $discovery .= ">{$i}</option>"; } $discovery .= "</select> " . gettext("Day") . " <select name=\"ROday\">"; for ($i = 1; $i <= 31; $i++) { $discovery .= "<option value=\"{$i}\" "; if ($i == $tday && $ROday_selected == "" || $ROday_selected == $i) { $discovery .= "selected"; } $discovery .= ">{$i}</option>"; } $discovery .= <<<EOT </select></td> </tr> </table> </div> <div id="idSched4" class="forminput" > <table width="100%"> <tr> EOT; $discovery .= "<th align=\"right\" width=\"35%\">" . _("Weekly") . "</th><td colspan=\"2\" class=\"noborder\">"; $discovery .= "<select name=\"dayofweek\">"; $discovery .= "<option value=\"Su\" SELECTED >" . gettext("Select week day to run") . "</option>"; $discovery .= "<option value=\"Su\" {$day['Su']} >" . gettext("Sunday") . "</option>"; $discovery .= "<option value=\"Mo\" {$day['Mo']} >" . gettext("Monday") . "</option>"; $discovery .= "<option value=\"Tu\" {$day['Tu']} >" . gettext("Tuesday") . "</option>"; $discovery .= "<option value=\"We\" {$day['We']} >" . gettext("Wednesday") . "</option>"; $discovery .= "<option value=\"Th\" {$day['Th']} >" . gettext("Thursday") . "</option>"; $discovery .= "<option value=\"Fr\" {$day['Fr']} >" . gettext("Friday") . "</option>"; $discovery .= "<option value=\"Sa\" {$day['Sa']} >" . gettext("Saturday") . "</option>"; $discovery .= "</select>"; $discovery .= "</td>"; $discovery .= <<<EOT </tr> </table> </div> <div id="idSched5" class="forminput"> <table width="100%"> <tr> EOT; $discovery .= "<th width='35%'>" . gettext("Select Day") . "</td>"; $discovery .= <<<EOT <td colspan="2" class="noborder"><select name="dayofmonth">" EOT; for ($i = 1; $i <= 31; $i++) { $discovery .= "<option value=\"{$i}\""; if ($dayofmonth == $i && $dayofmonth_selected == "" || $dayofmonth_selected == $i) { $discovery .= " selected"; } $discovery .= ">{$i}</option>"; } $discovery .= <<<EOT </select></td> </tr> </table> </div> <div id="idSched6" class="forminput"> <table width="100%"> <tr> EOT; $discovery .= "<th width=\"35%\">" . gettext("Day of week") . "</th><td colspan=\"2\" class=\"noborder\">"; $discovery .= "<select name=\"nthdayofweek\">"; $discovery .= "<option value=\"Su\" SELECTED >" . gettext("Select week day to run") . "</option>"; $discovery .= "<option value=\"Su\" {$day['Su']} >" . gettext("Sunday") . "</option>"; $discovery .= "<option value=\"Mo\" {$day['Mo']} >" . gettext("Monday") . "</option>"; $discovery .= "<option value=\"Tu\" {$day['Tu']} >" . gettext("Tuesday") . "</option>"; $discovery .= "<option value=\"We\" {$day['We']} >" . gettext("Wednesday") . "</option>"; $discovery .= "<option value=\"Th\" {$day['Th']} >" . gettext("Thursday") . "</option>"; $discovery .= "<option value=\"Fr\" {$day['Fr']} >" . gettext("Friday") . "</option>"; $discovery .= "<option value=\"Sa\" {$day['Sa']} >" . gettext("Saturday") . "</option>"; $discovery .= "</select>"; $discovery .= "</td>"; $discovery .= <<<EOT </tr> </table> <br> <table width="100%"> <tr> EOT; $discovery .= "<th align='right'>" . gettext("N<sup>th</sup> weekday") . "</th><td colspan='2' class='noborder'>"; $discovery .= "<select name='nthweekday'>"; $discovery .= "<option value='1'>" . gettext("Select nth weekday to run") . "</option>"; $discovery .= "<option value='1'" . ($dayofmonth == 1 ? " selected" : "") . ">" . gettext("First") . "</option>"; $discovery .= "<option value='2'" . ($dayofmonth == 2 ? " selected" : "") . ">" . gettext("Second") . "</option>"; $discovery .= "<option value='3'" . ($dayofmonth == 3 ? " selected" : "") . ">" . gettext("Third") . "</option>"; $discovery .= "<option value='4'" . ($dayofmonth == 4 ? " selected" : "") . ">" . gettext("Fourth") . "</option>"; $discovery .= "<option value='5'" . ($dayofmonth == 5 ? " selected" : "") . ">" . gettext("Fifth") . "</option>"; $discovery .= "<option value='6'" . ($dayofmonth == 6 ? " selected" : "") . ">" . gettext("Sixth") . "</option>"; $discovery .= "<option value='7'" . ($dayofmonth == 7 ? " selected" : "") . ">" . gettext("Seventh") . "</option>"; $discovery .= "<option value='8'" . ($dayofmonth == 8 ? " selected" : "") . ">" . gettext("Eighth") . "</option>"; $discovery .= "<option value='9'" . ($dayofmonth == 9 ? " selected" : "") . ">" . gettext("Ninth") . "</option>"; $discovery .= "<option value='10'" . ($dayofmonth == 10 ? " selected" : "") . ">" . gettext("Tenth") . "</option>"; $discovery .= <<<EOT </select> </td> </tr> </table> </div> EOT; $discovery .= "<div id='idSched7' class='forminput' style=margin-bottom:3px;>"; $discovery .= "<table width='100%'>"; $discovery .= "<tr>"; $discovery .= "<th width='35%'>" . _("Frequency") . "</th>"; $discovery .= "<td width='100%' style='text-align:center;' class='nobborder'>"; $discovery .= "<span style='margin-right:5px;'>" . _("Every") . "</span>"; $discovery .= "<select name='time_interval'>"; for ($itime = 1; $itime <= 30; $itime++) { $discovery .= "<option value='" . $itime . "'" . ($editdata['time_interval'] == $itime ? " selected" : "") . ">" . $itime . "</option>"; } $discovery .= "</select>"; $discovery .= "<span id='days' style='margin-left:5px'>" . _("day(s)") . "</span><span id='weeks' style='margin-left:5px'>" . _("week(s)") . "</span>"; $discovery .= "</td>"; $discovery .= "</tr>"; $discovery .= "</table>"; $discovery .= "</div>"; $discovery .= <<<EOT <div id="idSched2" class="forminput"> <table width="100%"> EOT; $discovery .= "<tr>"; $discovery .= "<th rowspan='2' align='right' width='35%'>" . gettext("Time") . "</td>"; $discovery .= "<td align='right'>" . gettext("Hour") . "</td>"; $discovery .= <<<EOT <td align="left" class="noborder"><select name="time_hour"> EOT; for ($i = 0; $i <= 23; $i++) { $discovery .= "<option value=\"{$i}\""; if ($time_hour == $i && $time_hour_selected == "" || $time_hour_selected == $i) { $discovery .= " selected"; } $discovery .= ">{$i}</option>"; } $discovery .= "</select></td><td align='right'>" . gettext("Minutes") . "</td>\n <td class='noborder' align='left'><select name='time_min'>"; for ($i = 0; $i < 60; $i = $i + 15) { $discovery .= "<option value=\"{$i}\""; if ($time_min == $i && $time_min_selected == "" || $time_min_selected == $i) { $discovery .= " selected"; } $discovery .= ">{$i}</option>"; } $discovery .= <<<EOT </select></td> </tr> </table> </div> </tr> EOT; $discovery .= "<tr>"; $discovery .= "\t\t<td class='madvanced'><a class='section'><img id='advanced_arrow' border='0' align='absmiddle' src='../pixmaps/arrow_green.gif'>" . _("ADVANCED") . "</a></td>"; $discovery .= "\t\t<td> </td>"; $discovery .= "</tr>"; if ($_SESSION["scanner"] == "omp") { $credentials = Vulnerabilities::get_credentials($dbconn, 'ssh'); preg_match("/(.*)\\|(.*)/", $editdata["credentials"], $found); $discovery .= "<tr class='advanced'>"; $discovery .= "<td class='job_option'>" . Util::strong(_("SSH Credential:")) . "</td>"; $discovery .= "<td style='text-align:left'><select id='ssh_credential' name='ssh_credential'>"; $discovery .= "<option value=''>--</option>"; foreach ($credentials as $cred) { $login_text = $cred["login"]; if ($cred["login"] == '0') { $login_text = _("All"); } elseif (valid_hex32($cred["login"])) { $login_text = Session::get_entity_name($dbconn, $cred["login"]); } $selected = $found[1] == $cred["name"] . "#" . $cred["login"] || $cred["name"] . "#" . $cred["login"] == $ssh_credential ? " selected='selected'" : ""; $discovery .= "<option value='" . $cred["name"] . "#" . $cred["login"] . "' {$selected}>" . $cred["name"] . " (" . $login_text . ")</option>"; } $discovery .= "</select></td>"; $discovery .= "</tr>"; $credentials = Vulnerabilities::get_credentials($dbconn, 'smb'); $discovery .= "<tr class='advanced'>"; $discovery .= "<td class='job_option'>" . Util::strong(_("SMB Credential:")) . "</td>"; $discovery .= "<td style='text-align:left'><select id='smb_credential' name='smb_credential'>"; $discovery .= "<option value=''>--</option>"; foreach ($credentials as $cred) { $login_text = $cred["login"]; if ($cred["login"] == '0') { $login_text = _("All"); } elseif (valid_hex32($cred["login"])) { $login_text = Session::get_entity_name($dbconn, $cred["login"]); } $selected = $found[2] == $cred["name"] . "#" . $cred["login"] || $cred["name"] . "#" . $cred["login"] == $smb_credential ? " selected='selected'" : ""; $discovery .= "<option value='" . $cred["name"] . "#" . $cred["login"] . "' {$selected}>" . $cred["name"] . " (" . $login_text . ")</option>"; } $discovery .= "</select></td>"; $discovery .= "</tr>"; } $discovery .= "<tr class='job_option advanced'>"; $discovery .= "<td class='job_option'>" . Util::strong(_("Timeout:")) . "</td>"; $discovery .= "<td style=\"text-align:left;\" nowrap><input type='text' style='width:80px' name='timeout' value='" . ($timeout_selected == "" ? "{$timeout}" : "{$timeout_selected}") . "'>"; $discovery .= "<font color='black'> " . _("Max scan run time in seconds") . " </font></td>"; $discovery .= "</tr>"; $discovery .= "<tr class='advanced'><td class='job_option'>" . Util::strong(_("Send an email notification:")); $discovery .= "</td>"; $discovery .= "<td style=\"text-align:left;\">"; $discovery .= "<input type=\"radio\" name=\"semail\" value=\"0\"" . (count($editdata) <= 1 && intval($semail) == 0 || intval($editdata['meth_Wfile']) == 0 ? " checked" : "") . "/>" . _("No"); $discovery .= "<input type=\"radio\" name=\"semail\" value=\"1\"" . (count($editdata) <= 1 && intval($semail) == 1 || intval($editdata['meth_Wfile']) == 1 ? " checked" : "") . "/>" . _("Yes"); $discovery .= "</td></tr>"; $discovery .= "<tr class='advanced'>\n\t\t\t\t\t\t<td class='job_option'>" . Util::strong(_("Scan job visible for:")) . "</td>\n\t\t\t\t\t\t<td style='text-align: left'>\n\t\t\t\t\t\t\t<table cellspacing='0' cellpadding='0' class='transparent' style='margin: 5px 0px;'>\n\t\t\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t\t\t<td class='nobborder'><span style='margin-right:3px'>" . _('User:'******'nobborder'>\t\t\t\t\n\t\t\t\t\t\t\t\t\t\t<select name='user' id='user' onchange=\"switch_user('user');return false;\">"; $num_users = 0; foreach ($users as $k => $v) { $login = $v->get_login(); $selected = $editdata["username"] == $login || $user_selected == $login ? "selected='selected'" : ""; $options .= "<option value='" . $login . "' {$selected}>{$login}</option>\n"; $num_users++; } if ($num_users == 0) { $discovery .= "<option value='' style='text-align:center !important;'>- " . _("No users found") . " -</option>"; } else { $discovery .= "<option value='' style='text-align:center !important;'>- " . _("Select one user") . " -</option>\n"; $discovery .= $options; } $discovery .= "\t\t\t\t\t\t</select>\n\t\t\t\t\t\t\t\t\t</td>"; if (!empty($entities_to_assign)) { $discovery .= "\t \t\t\t<td style='text-align:center; border:none; !important'><span style='padding:5px;'>" . _("OR") . "<span></td>\n\t\t\t\t\t\t\t\t\t<td class='nobborder'><span style='margin-right:3px'>" . _("Entity:") . "</span></td>\n\t\t\t\t\t\t\t\t\t<td class='nobborder'>\t\n\t\t\t\t\t\t\t\t\t\t<select name='entity' id='entity' onchange=\"switch_user('entity');return false;\">\n\t\t\t\t\t\t\t\t\t\t\t<option value='' style='text-align:center !important;'>-" . _("Select one entity") . "-</option>"; foreach ($entities_to_assign as $k => $v) { $selected = $editdata["username"] == $k || $entity_selected == $k ? "selected='selected'" : ""; $discovery .= "<option value='{$k}' {$selected}>{$v}</option>"; } $discovery .= "\t\t\t\t\t</select>\n\t\t\t\t\t\t\t\t\t</td>"; } $discovery .= " \t \t</tr>\n\t\t\t\t\t\t\t</table>\n\t\t\t\t\t\t</td>\n\t\t\t\t\t</tr>"; $discovery .= "<tr><td valign=\"top\" width=\"15%\" class=\"job_option noborder\"><br>"; // conditions to exclude IPs $condition1 = count($editdata) <= 1 && intval($hosts_alive) == 1 ? TRUE : FALSE; $condition2 = preg_match('/' . EXCLUDING_IP2 . '/', trim($editdata["meth_TARGET"])); $condition3 = intval($editdata['meth_CRED']) == 1 ? TRUE : FALSE; $condition4 = count($ip_exceptions_list) > 0 ? TRUE : FALSE; $host_alive_check = $condition1 || $condition2 || $condition3 || $condition4 ? ' checked' : ''; $host_alive_status = $condition2 || $condition4 ? ' disabled=\\"disabled\\"' : ''; $discovery .= "<input onclick=\"toggle_scan_locally()\" type=\"checkbox\" id=\"hosts_alive\" name=\"hosts_alive\" value=\"1\"" . $host_alive_check . $host_alive_status . ">" . Util::strong(_("Only scan hosts that are alive")) . "<br>(" . Util::strong(_("greatly speeds up the scanning process")) . ")<br><br>"; $discovery .= "<input type=\"checkbox\" id=\"scan_locally\" name=\"scan_locally\" value=\"1\"" . ($pre_scan_locally_status == 0 ? " disabled=\"disabled\"" : "") . ($pre_scan_locally_status == 1 && (intval($editdata['authorized']) == 1 || intval($scan_locally) == 1) ? " checked" : "") . ">" . Util::strong(_("Pre-Scan locally")) . "<br>(" . Util::strong(_("do not pre-scan from scanning sensor")) . ")<br><br>"; $discovery .= "<input type=\"checkbox\" id=\"not_resolve\" name=\"not_resolve\" value=\"1\" " . ($editdata['resolve_names'] === "0" || $not_resolve == "1" ? "checked=\"checked\"" : "") . "/>" . Util::strong(_("Do not resolve names")); $discovery .= <<<EOT </td> EOT; $discovery .= ' <td class="noborder" valign="top">'; $discovery .= ' <table width="100%" class="transparent" cellspacing="0" cellpadding="0">'; $discovery .= ' <tr>'; $discovery .= ' <td class="nobborder" style="vertical-align: top;text-align:left;padding:10px 0px 0px 0px;">'; $discovery .= ' <table class="transparent" cellspacing="4">'; $discovery .= ' <tr>'; $discovery .= ' <td class="nobborder" style="text-align:left;"><input class="greyfont" type="text" id="searchBox" value="' . _("Type here to search assets (Hosts/Networks)") . '" /></td>'; $discovery .= ' </tr>'; $discovery .= ' <tr>'; $discovery .= ' <td class="nobborder"><select id="targets" name="targets[]" multiple="multiple">'; if (!empty($editdata["meth_TARGET"])) { $ip_list = explode("\n", trim($editdata["meth_TARGET"])); } if (!empty($ip_list)) { foreach ($ip_list as $asset) { if (preg_match("/([a-f\\d]+)#(.*)/i", $asset, $found)) { if (Asset_host::is_in_db($dbconn, $found[1])) { $_asset_name = Asset_host::get_name_by_id($dbconn, $found[1]) . " (" . $found[2] . ")"; } else { $_asset_name = Asset_net::get_name_by_id($dbconn, $found[1]) . " (" . $found[2] . ")"; } $discovery .= '<option value="' . $asset . '">' . $_asset_name . '</option>'; } else { $discovery .= '<option value="' . $asset . '">' . $asset . '</option>'; } } foreach ($ip_exceptions_list as $asset) { $discovery .= '<option value="' . $asset . '">' . $asset . '</option>'; } } $discovery .= ' </select></td>'; $discovery .= ' </tr>'; $discovery .= ' <tr>'; $discovery .= ' <td class="nobborder" style="text-align:right"><input type="button" value=" [X] " id="delete_target" class="av_b_secondary small"/>'; $discovery .= ' <input type="button" style="margin-right:0px;"value="Delete all" id="delete_all" class="av_b_secondary small"/></td>'; $discovery .= ' </tr>'; $discovery .= ' </table>'; $discovery .= ' </td>'; $discovery .= ' <td class="nobborder" width="450px;" style="vertical-align: top;padding:0px 0px 0px 5px;">'; $discovery .= ' <div id="vtree" style="text-align:left;width:100%;"></div>'; $discovery .= ' </td>'; $discovery .= ' </tr>'; $discovery .= ' </table>'; $discovery .= ' </td>'; $discovery .= '</tr>'; $discovery .= '</table>'; $discovery .= '</tr></td></table>'; $discovery .= $show; return $discovery; }