Exemplo n.º 1
0
    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
        $scan_report = $av_scan->download_scan_report();
        // Deleting Scan Report
        $av_scan->delete_scan();
        //Parsing scan report
        $nmap_parser = new Nmap_parser();
        $scan_report = $nmap_parser->parse_json($scan_report, $av_scan->get_sensor());
        if (!empty($scan_report['scanned_ips'])) {
            foreach ($scan_report['scanned_ips'] as $ip => $hdata) {
                if ($hdata['status'] == 'up') {
                    echo "Host {$ip} appears to be up\n";
                }
            }
        }
    }
} catch (Exception $e) {
    echo strip_tags($e->getMessage());
}
echo "\n\n";
Exemplo n.º 2
0
function check_scan_progress($conn, $wizard)
{
    //File to cache scan object
    $user = Session::get_session_user();
    $scan_file = 'w_last_asset_object-' . md5($user);
    $data = array();
    try {
        $obj = Av_scan::get_object_from_file($scan_file);
        //Get status
        $aux_status = $obj->get_status();
        $status = $aux_status['status']['code'];
        if ($status == Av_scan::ST_SCAN_FINISHED) {
            //Scanning has finished properly
            $info = array();
            $scan_report = $obj->download_scan_report();
            //Delete scan
            $obj->delete_scan();
            Cache_file::remove_file($scan_file);
            //Parsing scan report
            $nmap_parser = new Nmap_parser();
            $scan_report = $nmap_parser->parse_json($scan_report, $obj->get_sensor());
            // Add summary
            $scan_report['nmap_data']['elapsed'] = $aux_status['elapsed_time'];
            $info = Welcome_wizard::format_result_scan($conn, $scan_report);
            $wizard->set_step_data('scan_step', 3);
            $wizard->set_step_data('scan_info', $info);
            $data['finish'] = TRUE;
        } else {
            $percent = $aux_status['scanned_targets'] / $aux_status['number_of_targets'] * 100;
            $data['finish'] = FALSE;
            $data['percent'] = round($percent);
            $data['current'] = $aux_status['scanned_targets'];
            $data['total'] = $aux_status['number_of_targets'];
            if ($aux_status['remaining_time'] == -1) {
                $data['time'] = _('Calculating Remaining Time');
            } else {
                $data['time'] = Welcome_wizard::format_time($aux_status['remaining_time']) . ' ' . _('remaining');
            }
        }
        $response['error'] = FALSE;
        $response['data'] = $data;
        $wizard->save_status();
    } catch (Exception $e) {
        $msg = _('Error! Asset scan cannot be completed.  Please try again');
        set_scan_error_message($wizard, $msg);
        $response['error'] = TRUE;
    }
    return $response;
}