Example #1
0
function global_score($conn)
{
    global $conf_threshold;
    //
    $sql = "SELECT host_ip, compromise, attack FROM host_qualification";
    if (!($rs =& $conn->Execute($sql))) {
        die($conn->ErrorMsg());
    }
    $score_a = 0;
    $score_c = 0;
    while (!$rs->EOF) {
        if (Session::hostAllowed($conn, $rs->fields['host_ip'])) {
            $score_a += $rs->fields['attack'];
            $score_c = $rs->fields['compromise'];
        }
        $rs->MoveNext();
    }
    $risk_a = round($score_a / $conf_threshold * 100);
    $risk_c = round($score_c / $conf_threshold * 100);
    $risk = $risk_a > $risk_c ? $risk_a : $risk_c;
    $img = 'green';
    // 'off'
    $color = '';
    if ($risk > 500) {
        $img = 'red';
    } elseif ($risk > 300) {
        $img = 'yellow';
    } elseif ($risk > 100) {
        $img = 'green';
    }
    $alt = "{$risk} " . _("metric/threshold");
    return array($img, $alt);
}
Example #2
0
     }
 }
 if (!empty($net_id)) {
     // Net with ID
     $total_host += Util::host_in_net($ip_cidr);
     $name = Asset_net::get_name_by_id($conn, $net_id);
     $perm = Session::netAllowed($conn, $net_id);
     if (count($sensors) == 0) {
         $sensors = array_keys(Asset_net_sensors::get_sensors_by_id($conn, $net_id));
     }
 } else {
     if (!empty($host_id)) {
         // Host with ID
         $total_host++;
         $name = Asset_host::get_name_by_id($conn, $host_id);
         $perm = $unresolved ? TRUE : Session::hostAllowed($conn, $host_id);
         if (count($sensors) == 0) {
             $sensors = array_keys(Asset_host_sensors::get_sensors_by_id($conn, $host_id));
         }
     } else {
         if (preg_match("/^\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\/\\d{1,2}?\$/", $ip_cidr)) {
             // Net without ID
             $total_host += Util::host_in_net($ip_cidr);
             $name = $target;
             $perm = TRUE;
         } else {
             if (preg_match("/^\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\$/", $ip_cidr)) {
                 // Host without ID
                 $total_host++;
                 $name = $target;
                 $perm = TRUE;
Example #3
0
                return IP[1] * (IP[0] === 1 || 16777216) + IP[2] * (IP[0] <= 2 || 65536) + IP[3] * (IP[0] <= 3 || 256) + IP[4] * 1;
            }

            // Hosts autocomplete
            <?php 
    $hosts = array();
    try {
        $_hosts_data = Asset_host::get_basic_list($conn);
        $hosts = $_hosts_data[1];
    } catch (Exception $e) {
        $hosts = array();
    }
    foreach ($hosts as $host) {
        $_ip = $host['ips'];
        $_hostname = $host['name'];
        if (Session::hostAllowed($conn, $_ip)) {
            //Load available hosts (Autocompleted)
            if ($_hostname != $_ip) {
                $h_list .= '{ txt:"' . $_hostname . ' [Host:' . $_ip . ']", id: "' . Asset_host_ips::ip2ulong($_ip) . '" },';
            } else {
                $h_list .= '{ txt:"' . $_ip . '", id: "' . Asset_host_ips::ip2ulong($_ip) . '" },';
            }
        }
    }
    // Protocol list
    if ($protocol_list = Protocol::get_list()) {
        echo "var protocols = new Array(" . count($protocol_list) . ")\n";
        foreach ($protocol_list as $proto) {
            //$_SESSION[$id] = $plugin->get_name();
            echo "protocols['proto_" . $proto['id'] . "'] = '" . $proto['name'] . "'\n";
            //Load available protocols (Autocompleted)
            }
        } elseif ($found[1] == 8) {
            $sql = "SELECT DISTINCT (hp.ip), h.hostname\n                    FROM host_properties AS hp LEFT JOIN host AS h\n                    ON hp.ip = h.ip\n                    WHERE hp.property_ref=" . $found[1] . " AND MD5(hp.value)='" . $found[2] . "' \n                    UNION \n\t\t\t\t\tSELECT inet_ntoa(hs.ip) as ip, h.hostname\n\t\t\t\t\tFROM host_services AS hs LEFT JOIN host AS h\n\t\t\t\t\tON inet_ntoa(hs.ip) = h.ip LEFT JOIN protocol p ON p.id=hs.protocol\n\t\t\t\t\tWHERE MD5(CONCAT(hs.service,' (',hs.port,'/',LCASE(p.alias),')'))='" . $found[2] . "'\n\t\t\t\t\tORDER BY ip";
        } else {
            $sql = "SELECT DISTINCT (hp.ip), h.hostname\n                    FROM host_properties AS hp LEFT JOIN host AS h\n                    ON hp.ip = h.ip\n                    WHERE hp.property_ref=" . $found[1] . " AND MD5(hp.value)='" . $found[2] . "' ORDER BY hp.ip";
        }
    } else {
        $sql = "SELECT DISTINCT (hp.ip), h.hostname FROM host_properties AS hp LEFT JOIN host AS h ON hp.ip = h.ip";
    }
    //print_r($sql);
    if (!($rs =& $conn->Execute($sql))) {
        print $conn->ErrorMsg();
        exit;
    } else {
        while (!$rs->EOF) {
            if (Session::hostAllowed($conn, $rs->fields['ip'])) {
                $cclass = preg_replace("/(\\d+\\.)(\\d+\\.)(\\d+)\\.\\d+/", "\\1\\2\\3", $rs->fields['ip']);
                $all_cclass_hosts[$cclass][] = array($rs->fields['ip'], $rs->fields['hostname']);
            }
            $rs->MoveNext();
        }
    }
}
if ($key == "") {
    $props = Host::get_properties_types($conn);
    $buffer .= "[ {title: '" . _("Asset by Property") . "', isFolder: true, key:'main', icon:'../../pixmaps/theme/any.png', expand:true, children:[\n";
    $icons = array("software" => "software", "operating-system" => "host_os", "cpu" => "cpu", "service" => "ports", "memory" => "ram", "department" => "host_group", "macaddress" => "mac", "workgroup" => "net_group", "role" => "server_role", "acl" => "acl", "storage" => "storage", "route" => "route");
    foreach ($props as $prop) {
        $png = $icons[strtolower($prop["name"])];
        $png = empty($png) ? "folder" : $png;
        if (count(Host::get_property_values($conn, $prop["id"])) > 0) {
Example #5
0
function hosts_to_insert($dbconn, $report_id)
{
    $in_assets = array();
    $ips = array();
    $result = $dbconn->Execute("SELECT distinct v.hostIP FROM vuln_nessus_results v,host h WHERE v.report_id='{$report_id}' AND v.hostIP NOT IN (SELECT ip FROM host)");
    while (!$result->EOF) {
        if (Session::hostAllowed($dbconn, $result->fields["hostIP"])) {
            $ips[] = $result->fields["hostIP"];
        }
        $result->MoveNext();
    }
    return $ips;
}
Example #6
0
function server_get_servers($conn)
{
    $name = GET('name');
    ossim_valid($name, OSS_ALPHA, OSS_PUNC, OSS_SPACE, 'illegal:' . _("Server name"));
    require_once 'ossim_conf.inc';
    $ossim_conf = $GLOBALS["CONF"];
    /* get the port and IP address of the server */
    $address = $ossim_conf->get_conf("server_address");
    $port = $ossim_conf->get_conf("server_port");
    /* create socket */
    $socket = socket_create(AF_INET, SOCK_STREAM, 0);
    if ($socket < 0) {
        echo _("socket_create() failed: reason: ") . socket_strerror($socket) . "\n";
    }
    $list = array();
    $err = "";
    /* connect */
    $result = @socket_connect($socket, $address, $port);
    if (!$result) {
        $err = "<p><b>" . _("socket error") . "</b>: " . gettext("Is OSSIM server running at") . " {$address}:{$port}?</p>";
        return array($list, $err);
    }
    /* first send a connect message to server */
    $in = 'connect id="1" type="web"' . "\n";
    $out = '';
    socket_write($socket, $in, strlen($in));
    $out = @socket_read($socket, 2048, PHP_NORMAL_READ);
    if (strncmp($out, "ok id=", 4)) {
        $err = "<p><b>" . gettext("Bad response from server") . "</b></p>";
        $err .= "<p><b>" . _("socket error") . "</b>: " . gettext("Is OSSIM server running at") . " {$address}:{$port}?</p>";
        return array($list, $err);
    }
    /* get servers from server */
    if ($name != NULL) {
        $in = 'server-get-servers id="2" servername="' . $name . '"' . "\n";
    } else {
        $in = 'server-get-servers id="2"' . "\n";
    }
    $out = '';
    socket_write($socket, $in, strlen($in));
    $pattern = '/server host="([^"]*)" servername="([^"]*)"/ ';
    while ($out = socket_read($socket, 2048, PHP_NORMAL_READ)) {
        if (preg_match($pattern, $out, $regs)) {
            if (Session::hostAllowed($conn, $regs[1])) {
                $s["host"] = $regs[1];
                $s["servername"] = $regs[2];
                //# This should be checked in the server TODO FIXME
                if (!in_array($s, $list)) {
                    $list[] = $s;
                }
            }
        } elseif (!strncmp($out, "ok id=", 4)) {
            break;
        }
    }
    socket_close($socket);
    return array($list, $err);
}
Example #7
0
				document.location.href='host_report.php?host=<?php 
echo $host;
?>
&start_date='+g_date_from+'&end_date='+g_date_to;
			}
		}
	</script>
</head>

<body style="margin:0px">

<?php 
if ($host == 'any') {
    include "../hmenu.php";
}
if (!Session::hostAllowed($conn, $host)) {
    ?>
		<div class='ossim_error center'> <?php 
    echo _("Host");
    ?>
<span style='font-style:italic; font-weight: bold;'> <?php 
    echo $host;
    ?>
 </span><?php 
    echo _("not allowed");
    ?>
</div>
		</body>
		</html>
		<?php 
    exit;
Example #8
0
}
// targets
foreach ($targets as $target) {
    if (preg_match("/^!/", $target)) {
        continue;
    }
    $unresolved = !preg_match("/\\d+\\.\\d+\\.\\d+\\.\\d+/", $target) && $not_resolve ? true : false;
    if (preg_match("/\\//", $target)) {
        // Net
        $name = Net::get_name_by_ip($conn, $target);
        $perm = Session::netAllowed($conn, $name);
        $sensors = Net::get_related_sensors($conn, $name);
    } else {
        // Host
        $name = $unresolved ? $target : Host::ip2hostname($conn, $target);
        $perm = $unresolved ? true : Session::hostAllowed($conn, $name);
        $sensors = Host::get_related_sensors($conn, $target);
    }
    if ($unresolved || Session::am_i_admin() && count($sensors) == 0 && $scan_server == "0") {
        if ($unresolved) {
            foreach ($all_sensors as $ip => $unused) {
                $sensors[] = $ip;
            }
        } else {
            $local_ip = `grep framework_ip /etc/ossim/ossim_setup.conf | cut -f 2 -d "="`;
            $local_ip = trim($local_ip);
            $result = $conn->Execute("SELECT name FROM vuln_nessus_servers WHERE hostname like '{$local_ip}'");
            if ($result->fields["name"] != "") {
                $sensors[] = $local_ip;
            }
        }
Example #9
0
function is_indicator_allowed($conn, $type, $asset_id)
{
    $has_perm = 1;
    if (Session::am_i_admin()) {
        return $has_perm;
    }
    if ($type == 'host') {
        $has_perm = Session::hostAllowed($conn, $asset_id);
    } elseif ($type == 'sensor' || $type == 'server') {
        $has_perm = Session::sensorAllowed($asset_id);
    } elseif ($type == 'net') {
        $has_perm = Session::netAllowed($conn, $asset_id);
    } elseif ($type == 'host_group' || $type == 'hostgroup') {
        $has_perm = Session::groupHostAllowed($conn, $asset_id);
    } elseif ($type == 'net_group' || $type == 'netgroup') {
        $has_perm = Session::groupAllowed($conn, $asset_id);
    }
    return $has_perm;
}
Example #10
0
function submit_scan($op, $sched_id, $sname, $notify_email, $schedule_type, $ROYEAR, $ROMONTH, $ROday, $time_hour, $time_min, $dayofweek, $dayofmonth, $timeout, $SVRid, $sid, $tarSel, $ip_list, $ip_exceptions_list, $ip_start, $ip_end, $named_list, $cidr, $subnet, $system, $cred_type, $credid, $acc, $domain, $accpass, $acctype, $passtype, $passstore, $wpolicies, $wfpolicies, $upolicies, $custadd_type, $cust_plugins, $is_enabled, $hosts_alive, $scan_locally, $nthweekday, $semail, $not_resolve)
{
    global $wdaysMap, $daysMap, $allowscan, $uroles, $username, $schedOptions, $adminmail, $mailfrom, $dbk, $dbconn;
    require_once "classes/Util.inc";
    $tz = Util::get_timezone();
    if (empty($ROYEAR)) {
        $ROYEAR = gmdate("Y");
    }
    if (empty($ROMONTH)) {
        $ROMONTH = gmdate("m");
    }
    if (empty($ROday)) {
        $ROday = gmdate("d");
    }
    list($_y, $_m, $_d, $_h, $_u, $_s, $_time) = Util::get_utc_from_date($dbconn, "{$ROYEAR}-{$ROMONTH}-{$ROday} {$time_hour}:{$time_min}:00", $tz);
    $ROYEAR = $_y;
    $ROMONTH = $_m;
    $ROday = $_d;
    $time_hour = $_h;
    $time_min = $_u;
    if ($not_resolve == "1") {
        $resolve_names = 0;
    } else {
        $resolve_names = 1;
    }
    $notify_email = str_replace(";", ",", $notify_email);
    $requested_run = "";
    $jobType = "M";
    $recurring = False;
    $targets = array();
    $time_value = "";
    $profile_desc = getProfileName($sid);
    $target_list = "";
    $need_authorized = "";
    $request = "";
    $plugs_list = "NULL";
    $fk_name = "NULL";
    $target_list = "NULL";
    $tmp_target_list = "";
    $jobs_names = array();
    $sjobs_names = array();
    //$I3crID = getCredentialId ( $cred_type, $passstore, $credid, $acc, $domain, $accpass, $acctype, $passtype );
    $I3crID = "";
    if ($hosts_alive == "1") {
        // option: Only scan hosts that are alive
        $I3crID = "1";
    } else {
        $I3crID = "0";
    }
    if ($custadd_type == "") {
        $custadd_type = "N";
    }
    if ($custadd_type != "N" && $cust_plugins != "") {
        $plugs_list = "";
        $vals = preg_split("/\\s+|\r\n|,|;/", $cust_plugins);
        foreach ($vals as $v) {
            $v = trim($v);
            if (strlen($v) > 0) {
                $plugs_list .= $v . "\n";
            }
        }
        $plugs_list = "'" . $plugs_list . "'";
    }
    /*     echo <<<EOT
         <h3>Job Details:</h3>
         <center>
         <table>
         <tr><th align="right">Job Name</th><td>$sname</td></tr>
         <tr><th align="right">Notify</th><td>$notify_email</td></tr>
         <tr><th align="right">Timeout</th><td>$timeout</td></tr>
         <tr><th align="right">Profile</th><td>$profile_desc</td></tr>
         <tr><th></th><td>&nbsp;</td></tr>
         <tr><th align="right">Schedule Info</th><td>&nbsp;</td></tr>
    EOT;*/
    //$arrTime = localtime((int)gmdate('U'), true);
    $arrTime = explode(":", gmdate('Y:m:d:w:H:i:s'));
    $year = $arrTime[0];
    $mon = $arrTime[1];
    $mday = $arrTime[2];
    $wday = $arrTime[3];
    $hour = $arrTime[4];
    $min = $arrTime[5];
    $sec = $arrTime[6];
    $timenow = $hour . $min . $sec;
    if ($time_hour) {
        $hour = $time_hour;
    }
    if ($time_min) {
        $min = $time_min;
    }
    #echo "hour=$hour<br>";
    #$hour = $hour - $tz_offset;
    #echo "offset=$tz_offset<br>hour=$hour<br>";
    #if ( $hour < "0" ) { echo "change 1<br>"; $hour = $hour + 24; }
    #if ( $hour >= "24" ) { echo "change 2<br>"; $hour = $hour - 24; }
    #echo "hour_changed=$hour<br>";
    $run_wday = $wdaysMap[$dayofweek];
    #echo "run_day=$run_wday<br>dayofweek=$dayofweek<br>";
    $run_time = sprintf("%02d%02d%02d", $time_hour, $time_min, "00");
    $run_mday = $dayofmonth;
    $time_value = "{$time_hour}:{$time_min}:00";
    //echo "schedule_type: ".$schedule_type;
    //echo "$run_time : $timenow\n"; exit();
    $ndays = array("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday");
    switch ($schedule_type) {
        case "N":
            $requested_run = gmdate("YmdHis");
            $sched_message = "No reccurring Jobs Necessary";
            break;
        case "O":
            $requested_run = sprintf("%04d%02d%02d%06d", $ROYEAR, $ROMONTH, $ROday, $run_time);
            $sched_message = "No reccurring Jobs Necessary";
            //var_dump($schedule_type);
            $recurring = True;
            $reccur_type = "Run Once";
            break;
        case "D":
            if ($run_time > $timenow) {
                $next_day = $year . $mon . $mday;
            } else {
                $next_day = gmdate("Ymd", strtotime("+1 day GMT", gmdate("U")));
            }
            // next day
            $requested_run = sprintf("%08d%06d", $next_day, $run_time);
            $recurring = True;
            $sched_message = "Schedule Reccurring";
            $reccur_type = "Daily";
            break;
        case "W":
            if ($run_wday == $wday && $run_time > $timenow) {
                $next_day = $year . $mon . $mday;
            } else {
                $next_day = gmdate("Ymd", strtotime("next " . $ndays[$run_wday] . " GMT", gmdate("U")));
            }
            // next week
            $requested_run = sprintf("%08d%06d", $next_day, $run_time);
            $recurring = True;
            $sched_message = "Schedule Reccurring";
            $reccur_type = "Weekly";
            break;
        case "M":
            if ($run_mday > $mday || $run_mday == $mday && $run_time > $timenow) {
                $next_day = $year . $mon . ($run_mday < 10 ? "0" : "") . $run_mday;
                // this month
                #echo "date selected is in the future<br>";
            } else {
                $next_day = sprintf("%06d%02d", gmdate("Ym", strtotime("next month GMT", gmdate("U"))), $run_mday);
                #$next_day = gmdate("Ymd", mktime(0, 0, 0, date("m")+1, $run_mday, date("y"))); // next month
                #echo "date selected is in the past<br>";
            }
            #echo "run_mday=$run_mday mday=$mday rtime=$run_time now=$timenow next_day=$next_day<br>";
            $requested_run = sprintf("%08d%06d", $next_day, $run_time);
            $recurring = True;
            $sched_message = "Schedule Reccurring";
            $reccur_type = "Montly";
            break;
        case "NW":
            $dayweektonum = array("Mo" => 1, "Tu" => 2, "We" => 3, "Th" => 4, "Fr" => 5, "Sa" => 6, "Su" => 7);
            $next_day = nthweekdaymonth($year, gmdate("n"), 1, $dayweektonum[$dayofweek], $nthweekday);
            $requested_run = sprintf("%08d%06d", $next_day, $run_time);
            $dayofmonth = $nthweekday;
            $recurring = True;
            $sched_message = "Schedule Reccurring";
            $reccur_type = "Nth weekday of the month";
            break;
        default:
            break;
    }
    //if ( $schedule_type != "N" ){
    //$requested_run  = switchTime_TimeZone( $requested_run, "server" );
    //}
    /*     echo <<<EOT
    
         <tr><th align="right">Type</th><td>$schedOptions[$schedule_type]</td></tr>
         <tr><th align="right">First Occurrence</th><td>$requested_run</td></tr>
         <tr><th align="right">Recurring</th><td>$sched_message</td></tr>
         <tr><th align="right">&nbsp;</th><td></td></tr>
         <tr><th colspan="2">Target Selection</th></tr>
    EOT;*/
    switch ($tarSel) {
        case "1":
            #SINGLE
            $vals = preg_split("/\\s+|\r\n|;/", $ip_list);
            foreach ($vals as $v) {
                $v = trim($v);
                if (strlen($v) > 0) {
                    array_push($targets, $v);
                }
            }
            break;
        case "2":
            #IP RANGE
            if ($ip_start || $ip_end) {
                if ($ip_start && $ip_end) {
                    $targets = range2List($ip_start, $ip_end);
                } else {
                    //     echo "<tr><td colspan=2>incomplete target list</td></tr>";
                }
            }
            break;
        case "3":
            #NAMED TARGET
            $vals = preg_split("/\\s+|\n|,|;/", $named_list);
            foreach ($vals as $v) {
                $v = trim($v);
                if (strlen($v) > 0) {
                    $ip = gethostbyname($v);
                    if (strlen($ip) > 0) {
                        array_push($targets, $ip);
                    } else {
                        //     echo "<tr><td colspan=2>$v&nbsp;&nbsp;Name could not be resolved</td></tr>";
                    }
                }
            }
            break;
        case "4":
            #SUBNET
            array_push($targets, $cidr);
            break;
        case "5":
            if ($uroles['auditAll'] && $subnet == "ALL") {
                array_push($targets, "all_live_subnets");
            } else {
                array_push($targets, $subnet);
            }
            $fk_name = "'" . $subnet . "'";
            break;
        case "6":
            #$query = "SELECT isso_email, admin_sys, admin_dba, admin_network from vuln_systems WHERE acronym='$system'";
            #$result = $dbconn->Execute($query);
            #list( $isso_poc, $poc_sa, $poc_dba, $poc_network ) = $result->fields;
            $all_pocs = $isso_poc;
            if ($all_pocs != "" && $poc_sa != "") {
                $all_pocs .= ", {$poc_sa}";
            }
            if ($all_pocs != "" && $poc_dba != "") {
                $all_pocs .= ", {$poc_dba}";
            }
            if ($all_pocs != "" && $poc_network != "") {
                $all_pocs .= ", {$poc_network}";
            }
            $notify_email = $all_pocs;
            $fk_name = "'" . $system . "'";
            break;
        default:
            #INPUT FILE
            break;
    }
    if ($tarSel < "4") {
        foreach ($targets as $hostip) {
            if (!$allowscan && !inrange($hostip, $dbconn)) {
                $need_authorized .= $hostip . "\n";
            }
            $tmp_target_list .= $hostip . "\n";
            //echo "<tr><td colspan=2>$hostip</td></tr>";
        }
        if ($need_authorized != "") {
            //echo "<tr><th colspan=2><font color=red>NOT IN APPROVED ZONE</font></th></tr>";
            $html_needs_auth = str_replace("\n", "<br>", $need_authorized);
            //echo "<tr><td colspan=2>$html_needs_auth</td></tr>";
        }
    } elseif ($tarSel == "4") {
        $tmp_target_list = $cidr;
        //echo "<tr><td colspan=2>$cidr</td></tr>";
    } elseif ($tarSel == "6") {
        $jobType = "S";
        if ($recurring == True) {
            #$tmp_target_list="";
            #DO NOT PUT THE LIST OF IP'S IN UNTIL THE JOB STARTS FOR REOCCURING ( LIST MAY BE FREQUENT TO CHANGE )
        } else {
            /*$query = "SELECT hostip from vuln_systems t1
                         LEFT JOIN vuln_system_hosts t2 on t2.sysID = t1.id
                         WHERE t1.acronym='$system'";
                      $result = $dbconn->Execute($query);
            
                      while ( !$result->EOF ) {
                         list($hostip) = $result->fields;
                         if ( strlen($hostip)>0) {
                            $tmp_target_list .= "$hostip\n";
                            array_push($targets, $hostip );
                         }
                         $result->MoveNext();
                      }*/
        }
        //       echo "<tr><td colspan=2>$system</td></tr>";
    } else {
        $jobType = "C";
        $tmp_target_list = $subnet;
        //       echo "<tr><td colspan=2>$subnet</td></tr>";
    }
    if (!($tarSel == "6" && $recurring == True) && count($targets) == 0) {
        //      echo "<p><center><font color=red>Missing Host Selection or BAD LIST:$targets[0]<br><br></font>"
        //         ."[ <a href=\"javascript:history.go(-1)\">Go Back</a> ]</center></p>";
        //logAccess( "USER $username Fubared: Missing Host Selection or BAD LIST:$targets[0]" );
        require_once "footer.php";
        exit;
    } elseif (!$sname) {
        //      echo "<p><center><font color=red>Missing or BAD SNAME:[$sname]<br><br></font>"
        //         ."[ <a href=\"javascript:history.go(-1)\">Go Back</a> ]</center></p>";
        //logAccess( "USER $username Fubared something on job name [$sname]" );
        require_once "footer.php";
        exit;
    }
    if ($subnet == "" or $subnet == "0") {
        $subnet = "Null";
    } else {
        $subnet = "'{$subnet}'";
    }
    if ($SVRid == "" or $SVRid == "Null") {
        $SVRid = "Null";
    } else {
        $SVRid = "'{$SVRid}'";
    }
    if ($tmp_target_list != "") {
        $target_list = "'" . $tmp_target_list . "'";
    }
    $arrChecks = array("w" => $wpolicies, "f" => $wfpolicies, "u" => $upolicies);
    $arrAudits = array('w', 'f', 'u');
    foreach ($arrChecks as $check => $policydata) {
        $i = 1;
        $audit_data = "";
        if ($policydata) {
            if ($i <= 5) {
                foreach ($policydata as $policy) {
                    $audit_data .= "{$policy}\n";
                    $i++;
                }
            }
        }
        if ($audit_data != "") {
            $arrAudits[$check] = "'{$audit_data}'";
        } else {
            $arrAudits[$check] = "NULL";
        }
    }
    $insert_time = gmdate("YmdHis");
    //   if ( $need_authorized != "" || !($uroles['nessus']) ) {
    //      $jobType="R";  #REQUEST JOB
    //      #DO not wrap $subnet / $SVRid with ticks '' as 'Null' is not Null
    //      $query = "INSERT INTO vuln_jobs ( name, fk_name, username, job_TYPE, meth_SCHED, meth_TARGET, meth_CRED,
    //          meth_VSET, meth_CUSTOM, meth_CPLUGINS, meth_Wcheck, meth_Wfile, meth_Ucheck, meth_TIMEOUT, scan_ASSIGNED, scan_SUBMIT,
    //          scan_next, scan_PRIORITY, status, notify ) VALUES ( '$sname', $fk_name, '$username', '$jobType', '$schedule_type', $target_list, $I3crID,
    //          '$sid', '$custadd_type', $plugs_list, $arrAudits[w], $arrAudits[f], $arrAudits[u], '$timeout', $SVRid, '$insert_time',
    //          '$requested_run', '3' , 'H', '$notify_email' )";
    //      $request = "for Approval";
    //      $subject = "Scan request [$sname]";
    //      $message = "HELLO SOC TEAM, \tThe following User [ $username ] has requested a scan against:\n"
    //         ." $target_list\n\nPlease Promptly Accept/Reject the request!"
    //         ."Thank You\n\nThe SOC TEAM!\n";
    // mail($adminmail, $subject, $message, "From: $mailfrom\nX-Mailer: PHP/" . phpversion());
    //   echo "needs authorization<br>";
    //logAccess( "USER $username Submitted Scan Request [$sname]" );
    // } else {
    require_once "classes/Host_sensor_reference.inc";
    require_once "classes/Net_sensor_reference.inc";
    require_once "classes/Net.inc";
    require_once "classes/Scan.inc";
    require_once "classes/Sensor.inc";
    //Check Permissions
    $allowed = array();
    $notallowed = array();
    $ftargets = explode("\\r\\n", $target_list);
    foreach ($ftargets as $ftarget) {
        $ftarget = preg_replace("/\r|\n|\t|\\s|\\'/", "", $ftarget);
        $unresolved = !preg_match("/\\d+\\.\\d+\\.\\d+\\.\\d+/", $ftarget) && $not_resolve ? true : false;
        if (preg_match("/\\//", $ftarget) && Session::netAllowed($dbconn, Net::get_name_by_ip($dbconn, $ftarget))) {
            //, $username
            $allowed[] = $ftarget;
        } else {
            if (Session::hostAllowed($dbconn, $ftarget) || $unresolved) {
                // , $username
                $allowed[] = $ftarget;
            } else {
                $notallowed[] = $ftarget;
            }
        }
    }
    if (count($allowed) > 0) {
        $forced_server = "";
        $all_sensors = array();
        $sensor_list = Sensor::get_all($dbconn, "", false);
        foreach ($sensor_list as $s) {
            $all_sensors[$s->get_ip()] = $s->get_name();
        }
        // force scanner
        if ($SVRid != "Null") {
            $query = "SELECT hostname FROM vuln_nessus_servers WHERE id={$SVRid}";
            $result = $dbconn->execute($query);
            list($forced_server) = $result->fields;
        } elseif ($not_resolve) {
            $result = $dbconn->Execute("SELECT name,hostname FROM vuln_nessus_servers WHERE enabled=1");
            while (!$result->EOF) {
                list($name, $hostname) = $result->fields;
                if (Session::sensorAllowed($hostname)) {
                    $all_sensors[$hostname] = $name;
                }
                $result->MoveNext();
            }
        }
        // remote nmap
        $rscan = new RemoteScan("", "");
        if ($rscan->available_scan()) {
            $reports = $rscan->get_scans();
            $ids = is_array($reports) ? array_keys($reports) : array();
        } else {
            $ids = array();
        }
        //if ($forced_server!="") $ids = array_merge(array($forced_server),$ids);
        //$tsjobs = explode("\\r\\n", $target_list);
        $sgr = array();
        $unables = array();
        $tsjobs = $allowed;
        foreach ($tsjobs as $tjobs) {
            $tjobs = preg_replace("/\r|\n|\t|\\s|\\'/", "", $tjobs);
            $unresolved = !preg_match("/\\d+\\.\\d+\\.\\d+\\.\\d+/", $tjobs) && $not_resolve ? true : false;
            if (preg_match("/\\//", $tjobs)) {
                $sensor = Net_sensor_reference::get_list_array($dbconn, $tjobs);
            } else {
                $sensor = Host_sensor_reference::get_list_array($dbconn, $tjobs);
            }
            if ($forced_server != "") {
                $sensor = array_merge(array($forced_server), $sensor);
            }
            if ($unresolved || Session::am_i_admin() && count($sensor) == 0 && $forced_server == "") {
                if ($unresolved) {
                    foreach ($all_sensors as $sip => $unused) {
                        $sensor[] = $sip;
                    }
                } else {
                    $local_ip = `grep framework_ip /etc/ossim/ossim_setup.conf | cut -f 2 -d "="`;
                    $local_ip = trim($local_ip);
                    $results = $dbconn->Execute("SELECT name FROM vuln_nessus_servers WHERE hostname like '{$local_ip}'");
                    if ($results->fields["name"] != "") {
                        $sensor[] = $local_ip;
                    }
                }
            }
            // reorder sensors with load
            if ($forced_server != "") {
                $sensor = Sensor::reorder_sensors($dbconn, $sensor);
            }
            // select best sensor with available nmap and vulnmeter
            $selected = array();
            foreach ($sensor as $sen) {
                $properties = Sensor::get_properties($dbconn, $sen);
                $withnmap = in_array($all_sensors[$sen], $ids) || !$hosts_alive || $unresolved;
                //echo "$sen:".$all_sensors[$sen].":$withnmap || $scan_locally:".$properties["has_vuln_scanner"]." || $SVRid:$forced_server<br>\n";
                if ((Session::sensorAllowed($sen) || $forced_server != "") && ($withnmap || $scan_locally) && ($properties["has_vuln_scanner"] || $forced_server != "")) {
                    //$selected = ($SVRid!="Null" && $all_sensors[$sen]!="") ? $all_sensors[$sen] : $sen;
                    //echo "sel:$selected<br>\n";
                    //break;
                    $selected[] = $forced_server != "" ? $forced_server : $sen;
                }
            }
            if (count($selected) > 0) {
                $sgr[implode(",", array_unique($selected))][] = $tjobs;
            } else {
                $unables[] = $tjobs;
            }
        }
        $query = array();
        /*    if($tz!=0) {
                  list ($y,$m,$d,$h,$u,$s,$time) = Util::get_utc_from_date($dbconn, $requested_run, $tz);
                  $requested_run = $y.$m.$d.$h.$u.$s;
              }*/
        if ($op == "editrecurring" && $sched_id > 0) {
            $query[] = "DELETE FROM vuln_job_schedule WHERE id='{$sched_id}'";
            $i = 1;
            foreach ($sgr as $notify_sensor => $targets) {
                $target_list = implode("\n", $targets);
                $target_list .= "\n" . implode("\n", $ip_exceptions_list);
                $query[] = "INSERT INTO vuln_job_schedule ( name, username, fk_name, job_TYPE, schedule_type, day_of_week, day_of_month, \n                            time, email, meth_TARGET, meth_CRED, meth_VSET, meth_CUSTOM, meth_CPLUGINS, meth_Wcheck, meth_Wfile, \n                            meth_Ucheck, meth_TIMEOUT, scan_ASSIGNED, next_CHECK, createdate, enabled, resolve_names ) VALUES ( '{$sname}', '{$username}', '" . Session::get_session_user() . "', '{$jobType}',\n                            '{$schedule_type}', '{$dayofweek}', '{$dayofmonth}', '{$time_value}', '{$notify_sensor}', '{$target_list}',\n                            {$I3crID}, '{$sid}', '{$custadd_type}', {$plugs_list}, {$arrAudits['w']}, {$semail}, '{$scan_locally}',\n                            '{$timeout}', {$SVRid}, '{$requested_run}', '{$insert_time}', '1', '{$resolve_names}' ) ";
                $sjobs_names[] = $sname . $i;
                $i++;
            }
        } elseif ($recurring) {
            $i = 1;
            foreach ($sgr as $notify_sensor => $targets) {
                $target_list = implode("\n", $targets);
                $target_list .= "\n" . implode("\n", $ip_exceptions_list);
                $query[] = "INSERT INTO vuln_job_schedule ( name, username, fk_name, job_TYPE, schedule_type, day_of_week, day_of_month, \n                                time, email, meth_TARGET, meth_CRED, meth_VSET, meth_CUSTOM, meth_CPLUGINS, meth_Wcheck, meth_Wfile, \n                                meth_Ucheck, meth_TIMEOUT, scan_ASSIGNED, next_CHECK, createdate, enabled, resolve_names ) VALUES ( '{$sname}', '{$username}', '" . Session::get_session_user() . "', '{$jobType}',\n                                '{$schedule_type}', '{$dayofweek}', '{$dayofmonth}', '{$time_value}', '{$notify_sensor}', '{$target_list}',\n                                {$I3crID}, '{$sid}', '{$custadd_type}', {$plugs_list}, {$arrAudits['w']}, {$semail}, '{$scan_locally}',\n                                '{$timeout}', {$SVRid}, '{$requested_run}', '{$insert_time}', '1', '{$resolve_names}' ) ";
                $sjobs_names[] = $sname . $i;
                $i++;
            }
        } else {
            $i = 1;
            foreach ($sgr as $notify_sensor => $targets) {
                $target_list = implode("\n", $targets);
                $target_list .= "\n" . implode("\n", $ip_exceptions_list);
                $query[] = "INSERT INTO vuln_jobs ( name, username, fk_name, job_TYPE, meth_SCHED, meth_TARGET,  meth_CRED,\n                        meth_VSET, meth_CUSTOM, meth_CPLUGINS, meth_Wcheck, meth_Wfile, meth_Ucheck, meth_TIMEOUT, scan_ASSIGNED,\n                        scan_SUBMIT, scan_next, scan_PRIORITY, status, notify, authorized, author_uname, resolve_names ) VALUES ( '{$sname}',\n                        '{$username}', '" . Session::get_session_user() . "', '{$jobType}', '{$schedule_type}', '{$target_list}', {$I3crID}, '{$sid}', '{$custadd_type}', {$plugs_list},\n                        {$arrAudits['w']}, {$semail}, {$arrAudits['u']}, '{$timeout}', {$SVRid}, '{$insert_time}', '{$requested_run}', '3',\n                        'S', '{$notify_sensor}', '{$scan_locally}', 'ACL', '{$resolve_names}' ) ";
                $jobs_names[] = $sname . $i;
                $i++;
            }
        }
        $query_insert_time = gen_strtotime($insert_time, "");
        foreach ($query as $sql) {
            $error_updating = false;
            $error_inserting = false;
            $sql = str_replace(", ',", ", '',", str_replace("''", "'", $sql));
            if ($dbconn->execute($sql) === false) {
                echo _("Error creating scan job") . ": " . $dbconn->ErrorMsg();
                if ($op == "editrecurring") {
                    $error_updating = true;
                } else {
                    $error_creating = true;
                }
            } else {
                if ($op == "editrecurring" && !$error_updating) {
                    echo "<br><center>" . _("Successfully Updated Recurring Job") . "</center>";
                    if (count($notallowed) == 0 && count($unables) == 0) {
                        ?>
<script type="text/javascript">
                        //<![CDATA[
                        document.location.href='manage_jobs.php?hmenu=Vulnerabilities&smenu=Jobs'; 
                        //]]>
                        </script><?php 
                    }
                    //logAccess( "Updated Recurring Job [ $jid ]" );
                } elseif (!$error_creating) {
                    echo "<br><center>" . _("Successfully Submitted Job") . " {$request}</center>";
                    //logAccess( "Submitted Job [ $jid ] $request" );
                    foreach ($jobs_names as $job_name) {
                        $infolog = array($job_name);
                        Log_action::log(66, $infolog);
                    }
                    foreach ($sjobs_names as $job_name) {
                        $infolog = array($job_name);
                        Log_action::log(67, $infolog);
                    }
                    if (count($notallowed) == 0 && count($unables) == 0) {
                        ?>
<script type="text/javascript">
                        //<![CDATA[
                        document.location.href='manage_jobs.php?hmenu=Vulnerabilities&smenu=Jobs';
                        //]]>
                        </script><?php 
                    }
                } else {
                    echo "<br><center>" . _("Failed Job Creation") . "</center>";
                    //logAccess( "Failed Job Creation" );
                    if (count($notallowed) == 0 && count($unables) == 0) {
                        ?>
<script type="text/javascript">
                        //<![CDATA[
                        document.location.href='manage_jobs.php?hmenu=Vulnerabilities&smenu=Jobs';
                        //]]>
                        </script><?php 
                    }
                }
            }
        }
    }
    //end count($alowed)>0
    if (count($notallowed) > 0 || count($unables) > 0) {
        echo "<center>";
        echo "<table class=\"noborder\" width=\"400\" style=\"background-color:transparent;\">";
        echo "<tr><td class=\"nobborder\" style=\"text-align:left;\"><b>" . _("Errors Found") . ":</b></td></tr>";
        if (count($notallowed) > 0) {
            if (!preg_match("/^\\d+\$/", $username)) {
                echo "<tr><td class=\"nobborder\" style=\"text-align:left;\">" . _("User") . " <b>{$username}</b> " . _("is not allowed for the following targets") . ":</td></tr>";
            } else {
                $entity_query = "SELECT name FROM acl_entities WHERE id={$username}";
                $result = $dbconn->execute($entity_query);
                list($username) = $result->fields;
                echo "<tr><td class=\"nobborder\" style=\"text-align:left;\">" . _("Entiy") . " <b>{$username}</b> " . _("is not allowed for the following targets") . ":</td></tr>";
            }
            foreach ($notallowed as $target) {
                echo "<tr><td class=\"nobborder\" style=\"text-align:left;padding-left:5px;\">- <b>{$target}</b></tr>";
            }
            echo "<tr height=\"30\"><td class=\"nobborder\">&nbsp;</td></tr>";
        }
        if (count($unables) > 0) {
            echo "<tr><td class=\"nobborder\" style=\"text-align:left;\">" . _("No remote vulnerability scanners available for the following targets") . ":</td></tr>";
            foreach ($unables as $target) {
                echo "<tr><td class=\"nobborder\" style=\"text-align:left;padding-left:5px;\">- <b>{$target}</b></tr>";
            }
            echo "<tr height=\"30\"><td class=\"nobborder\">&nbsp;</td></tr>";
        }
        echo "<tr><td class=\"nobborder\" style=\"text-align:center;\">";
        echo "<form action=\"sched.php\" method=\"post\">";
        ?>
              <input type="hidden" name="sname" value="<?php 
        echo $sname;
        ?>
"/>
              <?php 
        $SVRid = str_replace("'", "", $SVRid);
        ?>
              <input type="hidden" name="SVRid" value="<?php 
        echo $SVRid;
        ?>
"/>
              <input type="hidden" name="sid" value="<?php 
        echo $sid;
        ?>
"/>
              <input type="hidden" name="timeout" value="<?php 
        echo $timeout;
        ?>
"/>
              <input type="hidden" name="schedule_type" value="<?php 
        echo $schedule_type;
        ?>
"/>
              <input type="hidden" name="ROYEAR" value="<?php 
        echo $ROYEAR;
        ?>
"/>
              <input type="hidden" name="ROMONTH" value="<?php 
        echo $ROMONTH;
        ?>
"/>
              <input type="hidden" name="ROday" value="<?php 
        echo $ROday;
        ?>
"/>
              <input type="hidden" name="time_hour" value="<?php 
        echo $time_hour;
        ?>
"/>
              <input type="hidden" name="time_min" value="<?php 
        echo $time_min;
        ?>
"/>
              <input type="hidden" name="dayofweek" value="<?php 
        echo $dayofweek;
        ?>
"/>
              <input type="hidden" name="nthweekday" value="<?php 
        echo $nthweekday;
        ?>
"/>
              <input type="hidden" name="dayofmonth" value="<?php 
        echo $dayofmonth;
        ?>
"/>
              <input type="hidden" name="ip_list" value="<?php 
        echo str_replace("\\r\\n", ";;", $ip_list);
        ?>
"/>
              <?php 
        if (is_numeric($username)) {
            ?>
                <input type="hidden" name="entity" value="<?php 
            echo $username;
            ?>
"/>
              <?php 
        } else {
            ?>
                <input type="hidden" name="user" value="<?php 
            echo $username;
            ?>
"/>
              <?php 
        }
        ?>
              <input type="hidden" name="hosts_alive" value="<?php 
        echo $hosts_alive;
        ?>
"/>
              <input type="hidden" name="scan_locally" value="<?php 
        echo $scan_locally;
        ?>
"/> 
              <input type="hidden" name="semail" value="<?php 
        echo $semail;
        ?>
"/>
              <input type="hidden" name="not_resolve" value="<?php 
        echo $not_resolve;
        ?>
"/>
        <?php 
        echo "<input type=\"submit\" value=\"" . _("Back") . "\" class=\"button\"/> &nbsp; ";
        echo "<input value=\"" . _("Continue") . "\" class=\"button\" type=\"button\" onclick=\"document.location.href='manage_jobs.php?hmenu=Vulnerabilities&smenu=Jobs'\"></form>";
        echo "</td></tr>";
        echo "</table>";
        echo "</center>";
    }
    echo "</b></center>";
}
Example #11
0
    $sensor = $tmp[0]->get_ip();
}
$ntop_links = Sensor::get_ntop_link($sensor);
$ntop = $ntop_links["ntop"];
$testntop = $ntop_links["testntop"];
if ($link_ip != "") {
    $testntop .= (!preg_match("/\\/\$/", $testntop) ? "/" : "") . $link_ip . ".html";
    $ntop .= (!preg_match("/\\/\$/", $ntop) ? "/" : "") . $link_ip . ".html";
}
// check $ntop valid
error_reporting(0);
$testlink = get_headers($testntop);
error_reporting(E_ALL ^ E_NOTICE);
if (!preg_match("/200 OK/", $testlink[0])) {
    $ntop = "errmsg.php";
} elseif (!Session::hostAllowed($conn, $sensor)) {
    $ntop = "errmsg.php?msgcode=1";
}
?>
<script type="text/javascript">
    parent.document.getElementById('fr_down').src="<?php 
echo $ntop;
?>
"
</script>
<table class="noborder"><td><td valign="top" class="nobborder">
<!-- change sensor -->
<form method="GET" action="menu.php" style="margin:1px">
<input type="hidden" name="opc" value="<?php 
echo $opc;
?>
Example #12
0
ossim_valid($type, OSS_ALPHA, OSS_SPACE, OSS_NULLABLE, 'illegal:' . _("type"));
ossim_valid($subtype, OSS_ALPHA, OSS_SPACE, OSS_NULLABLE, 'illegal:' . _("subtype"));
if (ossim_error()) {
    die(ossim_error());
}
$sql = $rules[$type][$subtype]['list'];
if (!($rs =& $conn->Execute($sql))) {
    echo $conn->ErrorMsg();
} else {
    $i = 0;
    while (!$rs->EOF) {
        if ($rs->fields[0] != "") {
            // Filter by sensor user perms
            $aux = str_replace(",", "", $rs->fields[0]);
            if (preg_match("/^\\d+\\.\\d+\\.\\d+\\.\\d+\$/", $aux)) {
                if (!Session::hostAllowed($conn, $aux)) {
                    $rs->MoveNext();
                    continue;
                }
            }
            if ($i) {
                echo "###";
            }
            echo str_replace(",", "", $rs->fields[0]);
            if ($rules[$type][$subtype]['match'] == "fixed" || $rules[$type][$subtype]['match'] == "concat" || $rules[$type][$subtype]['match'] == "fixedText") {
                if ($rs->fields[1] != "") {
                    echo "_#_" . str_replace(",", "", $rs->fields[1]);
                } else {
                    echo "_#_" . str_replace(",", "", $rs->fields[0]);
                }
                //name;name
Example #13
0
                 }
                 // resolve to ip
                 ossim_valid($destination, OSS_IP_ADDR, 'illegal:' . _("Destination ip"));
                 $destination_type = 'host';
             } else {
                 ossim_valid($destination, OSS_IP_CIDR, 'illegal:' . _("Destination cidr"));
                 $destination_type = 'net';
             }
         }
         if (ossim_error()) {
             $info_error[] = ossim_get_error();
             ossim_clean_error();
             $error = true;
         } else {
             if ($destination_type == 'host') {
                 if (Session::hostAllowed($dbconn, $destination)) {
                     $tdestinations[] = $destination;
                 }
             } elseif ($destination_type == 'net') {
                 if (Session::netAllowed($dbconn, $destination)) {
                     $tdestinations[] = $destination;
                 }
             }
         }
     }
 } else {
     $tdestinations = array();
 }
 // launch scan
 $info_sensor = $sensors_status[Sensor::get_sensor_name($dbconn, $sensor_ip)];
 if ($sensor_ip != "" && $sensor_interface != "" && intval($timeout) > 0 && count($info_error) == 0 && ($info_sensor[0] == 0 || $info_sensor[0] == -1)) {