$session->login(TRUE); $db->close(); $is_disabled = $session->is_user_disabled(); 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(); 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
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; }
if (ossim_error()) { $e_msg = ossim_get_error_clean(); } else { // Run remote nmap scans $targets = array(); foreach ($explain_scan as $sensor_id => $s_data) { //Sensor status: Idle(0), Running (1) or Down(2) $code = $s_data['status']['code']; if ($code == 0) { foreach ($s_data['assets'] as $assets) { $targets[] = $assets['ip']; } $targets = implode(' ', $targets); $scan_options = array('scan_type' => $scan_type, 'timing_template' => $timing_template, 'autodetect_os' => $autodetect, 'reverse_dns' => $rdns, 'ports' => $custom_ports, 'idm' => 'true'); $av_scan = new Av_scan($targets, $sensor_id, $scan_options); $res = $av_scan->run(); $close = TRUE; unset($av_scan); $explain_scan[$sensor_id]['status'] = array('code' => 1, 'desc' => _('Running')); } } } } } catch (Exception $e) { $e_msg = $e->getMessage(); } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <head>
} $assets_p = implode(' ', $assets_string); } else { $validation_errors['assets[]'] = _("Error in the 'Target selection' field (missing required field)"); } } if (is_array($validation_errors) && !empty($validation_errors)) { //Formatted message $error_msg = '<div>' . _('The following errors occurred') . ":</div>\n <div style='padding: 5px;'>" . implode('<br/>', $validation_errors) . '</div>'; Util::response_bad_request($error_msg); } else { $autodetect = $autodetect == 1 ? 'true' : 'false'; $rdns = $rdns == 1 ? 'true' : 'false'; $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($assets_p, $sensor, $scan_options); $job_id = $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); $data['status'] = 'success'; $data['data'] = $job_id; } break; case 'scan_status': $av_scan = Av_scan::get_object_from_file($scan_file); if (!is_object($av_scan) || empty($av_scan)) { $scan_running = FALSE; $scan_message = _('No asset scan running'); $scan_status = array('code' => 0, 'descr' => Av_scan::ST_IDLE); $scan_status = array('message' => $scan_message, 'status' => $scan_status, 'progress' => array('percent' => 0, 'current' => 0, 'total' => 0, 'time' => 0)); } else {