if ($progress['remaining'] == -1) { $data['progress']['time'] = _('Calculating Remaining Time'); } else { $data['progress']['time'] = Welcome_wizard::format_time($progress['remaining']) . ' ' . _('remaining'); } } else { $data['message'] = NULL; $data['progress'] = NULL; $data['debug_info'] = NULL; } $data['debug_info'] = NULL; } } } else { $scan = new Scan(); if (preg_match('/finished/i', $scan->get_status())) { $lastscan = $scan->get_results(); $debug_info = ''; if (is_array($lastscan['nmap_data']) && !empty($lastscan['nmap_data'])) { $debug_info = $lastscan['nmap_data']['cmd'] . '|' . $lastscan['nmap_data']['version'] . '|' . $lastscan['nmap_data']['xmloutputversion']; unset($lastscan['nmap_data']); } $data['state'] = 'finished'; $data['message'] = NULL; $data['progress'] = NULL; $data['debug_info'] = $debug_info; if (is_array($lastscan['scanned_ips']) && count($lastscan['scanned_ips']) == 0) { $scan->delete_data(); } } else { $data['state'] = 'idle';
if (!$rdns) { $scan->append_option('-n'); } if ($scan_type == 'fast') { $scan->append_option('-p21,22,23,25,53,80,113,115,135,139,161,389,443,445,554,1194,1241,1433,3000,3306,3389,8080,9390,27017'); } elseif ($scan_type == 'custom') { $scan->append_option("-sS -p {$ports}"); } elseif ($scan_type == 'normal') { $scan->append_option('-sS'); } elseif ($scan_type == 'full') { $scan->append_option('-sS -p 1-65535'); } } // ping scan $scan->search_hosts(); $status = $scan->get_status(); while ($status == 'Searching Hosts') { $status = $scan->get_status(); sleep(2); } // normal scan if ($scan_type != 'ping' && $argv[3] != 'vulnscan') { $scan->launch_scan(); while ($scan->get_status() == 'Scanning Hosts') { $progress = $scan->get_progress(); echo $scan->get_status() . ': ' . $progress['hosts_scanned'] . '/' . $progress['total_hosts'] . ' ' . $progress['remaining'] . "\n"; sleep(2); } } $ips = $scan->get_results(); // delete results (only for vulnerabilities scans)
function check_scan_progress($conn, $wizard) { $data = array(); $obj = new Scan(); $status = $obj->get_status(); //Get status if ($status == 'Scan Finished') { $info = array(); $result = $obj->get_results(); $obj->delete_data(); $info = Welcome_wizard::format_result_scan($conn, $result); $wizard->set_step_data('scan_step', 3); $wizard->set_step_data('scan_info', $info); $data['finish'] = TRUE; } elseif ($status == 'Scanning Hosts') { $progress = $obj->get_progress(); $percent = $progress['hosts_scanned'] / $progress['total_hosts'] * 100; $data['finish'] = FALSE; $data['percent'] = round($percent); $data['current'] = $progress['hosts_scanned']; $data['total'] = $progress['total_hosts']; if ($progress['remaining'] == -1) { $data['time'] = _('Calculating Remaining Time'); } else { $data['time'] = Welcome_wizard::format_time($progress['remaining']) . ' ' . _('remaining'); } } else { $msg = _("Invalid NMAP status ({$status}). Expecting 'Scanning Hosts' or 'Scan Finished'"); set_scan_error_message($wizard, $msg); $response['error'] = TRUE; return $response; } $response['error'] = FALSE; $response['data'] = $data; $wizard->save_status(); return $response; }