Example #1
0
function Logger_trends()
{
    require_once "forensics_stats.inc";
    require_once "../sem/process.inc";
    require_once 'ossim_db.inc';
    global $tz;
    $data = array();
    $db = new ossim_db();
    $dbconn = $db->connect();
    // Get remote logger servers
    list($logger_servers, $ip_to_name, $ip_list, $fcolors, $bcolors, $from_remote, $logger_colors) = get_logger_servers($dbconn);
    $db->close($dbconn);
    foreach ($logger_servers as $ip) {
        if ($ip != "127.0.0.1") {
            $cmd = "sudo /usr/share/ossim/www/sem/fetchremote_graph.pl panel {$tz} {$ip}";
            //echo $cmd;
            exec($cmd, $aux);
            foreach ($aux as $line) {
                if (preg_match("/(.*);(.*)\\=(.*)/", $line, $fnd)) {
                    // 9 12h;192.168.10.1=703
                    if (Session::sensorAllowed($fnd[2])) {
                        $data[$fnd[1]] = trim($fnd[3]);
                    }
                }
            }
        }
    }
    // local server
    $today = gmdate("j");
    $beforeyesterday = gmdate("j", strtotime("-2 day"));
    $yesterday = gmdate("j", strtotime("-1 day"));
    $tomorrow = gmdate("j", strtotime("+1 day"));
    $csy = get_day_csv(gmdate("Y", strtotime("-1 day")), gmdate("m", strtotime("-1 day")), gmdate("d", strtotime("-1 day")));
    $csv = get_day_csv(gmdate("Y"), gmdate("m"), gmdate("d"));
    //print_r($csy); print_r($csv);
    foreach ($csy as $key => $value) {
        $tzhour = $key + $tz;
        $day = $yesterday;
        if ($tzhour < 0) {
            $tzhour += 24;
            $day = $beforeyesterday;
        } elseif ($tzhour > 23) {
            $tzhour -= 24;
            $day = $today;
        }
        $data[$day . " " . $tzhour . "h"] += $value;
    }
    foreach ($csv as $key => $value) {
        $tzhour = $key + $tz;
        $day = $today;
        if ($tzhour < 0) {
            $tzhour += 24;
            $day = $yesterday;
        } elseif ($tzhour > 23) {
            $tzhour -= 24;
            $day = $tomorrow;
        }
        $data[$day . " " . $tzhour . "h"] += $value;
    }
    //print_r($data);
    return $data;
}
Example #2
0
*
*
* On Debian GNU/Linux systems, the complete text of the GNU General
* Public License can be found in `/usr/share/common-licenses/GPL-2'.
*
* Otherwise you can read it here: http://www.gnu.org/licenses/gpl-2.0.txt
*
*/
require_once 'av_init.php';
require_once 'get_sensors.php';
$ip = GET('sensor_ip');
ossim_valid($ip, OSS_IP_ADDR, 'illegal:' . _('Sensor ip'));
if (ossim_error()) {
    die(ossim_error());
}
if (!Session::sensorAllowed($ip)) {
    exit;
}
list($sensor_list, $err) = server_get_sensors();
foreach ($sensor_list as $sip => $info) {
    foreach ($info as $plugin_id => $data) {
        $data['sensor'] = $sip;
        $data['plugin_id'] = $plugin_id;
        $sensor_plugins_list[] = $data;
    }
}
$sensor_plugins_list = server_get_sensor_plugins($ip);
$db = new ossim_db(TRUE);
$conn = $db->connect();
$acid_link = $conf->get_conf('acid_link');
$acid_prefix = $conf->get_conf('event_viewer');
Example #3
0
$conn = $db->connect();
// Getting correspondence between sensor ip and device
$ip_device = array();
$device_ip = array();
$ip_name = array();
$dev_perms = array();
$query1 = "SELECT d.id,s.ip as sensor_ip, s.name, HEX(s.id) as sensor_id FROM alienvault_siem.device d, alienvault.sensor s WHERE d.sensor_id=s.id";
if (!($rs =& $conn->Execute($query1))) {
    print $conn->ErrorMsg();
    exit;
}
while (!$rs->EOF) {
    $_sip = inet_ntop($rs->fields["sensor_ip"]);
    $_dev = $rs->fields["id"];
    $_sid = $rs->fields["sensor_id"];
    if (Session::sensorAllowed($_sid)) {
        $device_ip[$_dev] = $_sip;
        $ip_device[$_sip][$_dev] = $_dev;
        $ip_name[$_sip] = $rs->fields["name"];
        $dev_perms[] = $_dev;
    }
    $rs->MoveNext();
}
// Allowed Sensors filter
$criteria_sql = "WHERE plugin.id=acid_event.plugin_id AND device_id IN ('" . implode("','", $dev_perms) . "')";
//$query_where
$query_where = Security_report::make_where($conn, '', '', array(), array());
$query_where = preg_replace('/AND \\(timestamp.*/', '', $query_where);
$query = "SELECT DISTINCT device_id, plugin_id, name, sum( acid_event.cnt ) as event_cnt FROM alienvault.plugin, alienvault_siem.ac_acid_event as acid_event {$criteria_sql} {$query_where} GROUP BY device_id, plugin_id ORDER BY event_cnt DESC";
//print_r($query);
if (!($rs =& $conn->Execute($query))) {
Example #4
0
                     $ctest[$sid] = $connection;
                     $sensor_error = TRUE;
                 }
             }
         }
         $sname[] = $sensor_name;
         $sperm[] = "<img {$sclass} src='../pixmaps/" . (Session::sensorAllowed($sid) ? "tick" : "cross") . ".png' border='0'>";
         $vs[] = "<img {$vsclass} src='../pixmaps/" . (valid_hex32($scan_server) && $sid == $sensor_id ? "tick" : ($has_vuln_scanner ? "tick" : "cross")) . ".png' border='0'>";
         if (!$hosts_alive) {
             // don't do a Nmap scan
             $snmap[] = '<span style="font-size:9px;color:gray">' . _('No selected') . '</span>';
         } else {
             $snmap[] = "<img {$nmsclass} align='absmiddle' src='../pixmaps/" . ($scan_locally || $withnmap && $withnmapforced ? "tick" : ($withnmap ? "tick" : "cross")) . ".png' border='0'>" . ($scan_locally || $withnmap && $withnmapforced ? "<span style='font-size:9px;color:gray'>{$message_pre_scan}</span>" : ($withnmap ? "" : "<span style='font-size:9px;color:gray'>{$message_force_pre_scan}</span>"));
         }
         if ($ttargets[$target]['sensor'] == $sid) {
             $ttargets[$target]['sperm'] = Session::sensorAllowed($sid) ? TRUE : FALSE;
             $ttargets[$target]['vs'] = valid_hex32($scan_server) && $sid == $sensor_id ? TRUE : ($has_vuln_scanner ? TRUE : FALSE);
             if (!$hosts_alive) {
                 $ttargets[$target]['snmap'] = TRUE;
             } else {
                 $ttargets[$target]['snmap'] = $scan_locally || $withnmap && $withnmapforced ? TRUE : ($withnmap ? TRUE : FALSE);
             }
         }
     }
     $snames = implode('<br><br>', $sname);
 } else {
     $snames = '<span style="font-weight:bold;color:#ff0000">' . _('Sensor not found') . '</span>';
 }
 $sperms = implode('<br>', $sperm);
 $vulns = implode('<br>', $vs);
 $nmaps = implode('<br>', $snmap);
Example #5
0
				
				$(this).css("background-color",bgcolor);
				
				$('td img',this).attr("src", img);
			});
			
            if (show_processing == true)
            {
                setTimeout(function(){$('#selector_'+id+ ' .m_button').removeClass('av_b_processing');},200);
            }		
		}
		
		$(document).ready(function() {
			
			<?php 
if ($ip_get != '' && Session::sensorAllowed($ip_get)) {
    ?>
				var loading = '<img width="16" align="absmiddle" src="../pixmaps/loading3.gif">';
				var id      = '<?php 
    echo $ip_get;
    ?>
'; 				
				    id = id.replace(/\./g, "_");
				    id = 'capa'+id;
				    
				$("#icono"+id).attr('src','../pixmaps/server--minus.png');
				$("#"+id).html(loading+' <?php 
    echo _("Loading data...");
    ?>
');
				$("#"+id).css({ padding: "5px 0px 5px 0px" }); 
if ($op == 'delete' && $scan_name != '' && $sensor_ip != '') {
    $content = _('Deleting capture... wait a few seconds');
    $type = 'nf_success';
    $scan_info = explode('_', $scan_name);
    $users = Session::get_users_to_assign($dbconn);
    $my_users = array();
    foreach ($users as $k => $v) {
        $my_users[$v->get_login()] = 1;
    }
    if ($my_users[$scan_info[1]] == 1 || Session::am_i_admin()) {
        $scan->delete_scan($scan_name, $sensor_ip);
    }
}
// Stop capture
if ($op == 'stop' && $sensor_ip != '') {
    if (Session::sensorAllowed($sensor_ip)) {
        $scan->stop_capture($sensor_ip);
    }
    $db->close();
    exit;
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<title><?php 
echo gettext("OSSIM Framework  - Traffic capture");
?>
</title>
	<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"/>
	<meta http-equiv="Pragma" content="no-cache"/>
Example #7
0
    }
    // info per each related sensor
    foreach ($sensors as $sensor) {
        $properties = Sensor::get_properties($conn, $sensor);
        $load[] = Sensor::get_load($conn, $sensor);
        $withnmap = in_array($all_sensors[$sensor], $ids) || $unresolved;
        $sensor_name = $sensor == "Local" ? $sensor : $sensor . " [" . $all_sensors[$sensor] . "]";
        if (!$selected && (Session::sensorAllowed($sensor) || $scan_server > 0) && ($withnmap || $scan_locally) && ($properties["has_vuln_scanner"] || $scan_server > 0)) {
            $selected = true;
            $sensor_name = "<b>{$sensor_name}</b>";
        }
        $sname[] = $sensor_name;
        //$sperm[] = "<img src='../pixmaps/".(Session::sensorAllowed($sensor) ? "tick" : "cross").".png' border='0'>";
        //$vs[] = "<img src='../pixmaps/".(($scan_server>0 && $sensor==$hostname) ? "tickblue" : (($properties["has_vuln_scanner"]) ? "tick" : "cross")).".png' border='0'>";
        //$snmap[] = "<img src='../pixmaps/".(($scan_locally || ($withnmap && $withnmapforced)) ? "tickblue": (($withnmap) ? "tick" : "cross")).".png' border='0'>";
        $sperm[] = "<img src='../pixmaps/" . (Session::sensorAllowed($sensor) ? "tick" : "cross") . ".png' border='0'>";
        $vs[] = "<img src='../pixmaps/" . ($scan_server > 0 && $sensor == $hostname ? "tick" : ($properties["has_vuln_scanner"] ? "tick" : "cross")) . ".png' border='0'>";
        $snmap[] = "<img align='absmiddle' src='../pixmaps/" . ($scan_locally || $withnmap && $withnmapforced ? "tick" : ($withnmap ? "tick" : "cross")) . ".png' border='0'>" . ($scan_locally || $withnmap && $withnmapforced ? "<span style='font-size:9px;color:gray'>{$message_pre_scan}</span>" : ($withnmap ? "" : "<span style='font-size:9px;color:gray'>{$message_force_pre_scan}</span>"));
    }
    $snames = implode("<br>", $sname);
    $sperms = implode("<br>", $sperm);
    $vulns = implode("<br>", $vs);
    $nmaps = implode("<br>", $snmap);
    $load = implode("<br>", $load);
    ?>
    <tr>
        <td><?php 
    echo $target;
    ?>
</td>
        <td style="padding-left:10px;padding-right:10px" nowrap><?php 
Example #8
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 #9
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 #10
0
    } else {
        $hinterfaces = false;
    }
    ?>
                            <table class="transparent">
                            <?php 
    foreach ($interfaces as $interface) {
        ?>
                                <tr><td class="nobborder">
                                <?php 
        $checked = "";
        if ($sensor_ip == $ip && $interface == $sensor_interface) {
            $checked = "checked=\"checked\"";
        }
        $disabled = "";
        if (!$hinterfaces || !Session::sensorAllowed($ip)) {
            $disabled = " disabled=\"disabled\"";
        }
        ?>
                                <input type="radio" <?php 
        echo $checked;
        ?>
 name="sensor" value="<?php 
        echo $ip . "-" . $interface;
        ?>
" <?php 
        echo $disabled;
        ?>
/>
                                <?php 
        if ($hinterfaces) {