Exemple #1
0
function do_scan($wizard)
{
    try {
        $next_step = 1;
        $data = array('finish' => FALSE);
        //File to cache scan object
        $user = Session::get_session_user();
        $scan_file = 'w_last_asset_object-' . md5($user);
        $step = intval($wizard->get_step_data('scan_step'));
        if ($step == 0) {
            @unlink($scan_file);
        }
        $obj = Av_scan::get_object_from_file($scan_file);
        if (!is_object($obj) || empty($obj)) {
            $nets = $wizard->get_step_data('scan_nets');
            if (count($nets) < 1) {
                $e_msg = _('Invalid networks selected to scan');
                Av_exception::throw_error(Av_exception::USER_ERROR, $e_msg);
            }
            $nets = implode(' ', $nets);
            $scan_options = array('scan_type' => 'fast', 'scan_timing' => 'T3', 'autodetect_os' => 'true', 'reverse_dns' => 'true', 'scan_ports' => '', 'idm' => 'false');
            $obj = new Av_scan($nets, 'local', $scan_options);
            $obj->run();
            Av_scan::set_object_in_file($obj, $scan_file);
        }
        $aux_status = $obj->get_status();
        $status = $aux_status['status']['code'];
        $total = $aux_status['number_of_targets'];
        switch ($status) {
            case Av_scan::ST_SEARCH_FINISHED:
            case Av_scan::ST_SCANNING_HOSTS:
            case Av_scan::ST_SCAN_FINISHED:
                $next_step = $total > 0 ? 2 : 3;
                $wizard->set_step_data('scan_hosts', $total);
                $data = array('finish' => TRUE);
                break;
        }
        $wizard->set_step_data('scan_step', $next_step);
        //error_log("Step: $step\n", 3, '/tmp/test_wizard');
        //error_log("Next Step: $next_step\n", 3, '/tmp/test_wizard');
        //error_log(var_export($aux_status, TRUE)."\n", 3, '/tmp/test_wizard');
        $response['error'] = FALSE;
        $response['data'] = $data;
        $wizard->save_status();
    } catch (Exception $e) {
        //error_log("Error: ".$e->getMessage()."\n", 3, '/tmp/test_wizard');
        $msg = _('Error! Asset scan cannot be completed.  Please try again');
        set_scan_error_message($wizard, $msg);
        $response['error'] = TRUE;
    }
    return $response;
}
Exemple #2
0
 if ($is_disabled == TRUE) {
     $e_msg = _('Error! Scan cannot be completed: Scan owner is disabled');
     Av_exception::throw_error(Av_exception::USER_ERROR, $e_msg);
 }
 $client = new Alienvault_client($user);
 $client->auth()->login($user, $pass);
 //Launching scan
 $autodetect = $autodetect == 1 ? 'true' : 'false';
 $rdns = $rdns == 1 ? 'true' : 'false';
 $timing_template = empty($timing_template) ? 'T3' : $timing_template;
 $scan_options = array('scan_type' => $scan_type, 'scan_timing' => $timing_template, 'autodetect_os' => $autodetect, 'reverse_dns' => $rdns, 'scan_ports' => $custom_ports, 'idm' => 'false');
 $av_scan = new Av_scan($targets_p, $sensor, $scan_options);
 $av_scan->run();
 //File to cache scan object
 $scan_file = 'last_asset_object-' . md5($user);
 Av_scan::set_object_in_file($av_scan, $scan_file);
 echo "Asset scan:\n";
 echo "\tTargets: " . $av_scan->get_targets('scan_format') . "\n";
 echo "\tSensor: " . $av_scan->get_sensor() . "\n";
 echo "\tScan Options: \n";
 $sc_options = $av_scan->get_scan_options();
 foreach ($sc_options as $sc_type => $sc_value) {
     echo "\t\t{$sc_type}: {$sc_value}\n";
 }
 if ($display_results == 1) {
     $status = $av_scan->get_status();
     while ($status['status']['code'] != Av_scan::ST_SCAN_FINISHED) {
         sleep(2);
         $status = $av_scan->get_status();
     }
     // Getting discovered hosts