Ejemplo n.º 1
0
/**
* Create the machine list
*
* The machine list is the "dirty" list of machines.
* All the machines that a user specified in the list
* input need to be checked against the list of
* machines that the user is allowed to scan. The
* machine list is the initial list that is created.
* Machines that have been verified are then moved
* to the ok_computers list. Only machines in the
* ok_computers list will be saved to the database
* for use by Nessus later on.
*
* @param array $data Array of list items as would be
*	generated by the list_entries_to_array function
* @return array Machine list that can be used later
*	in processing as a starting point for what
*	needs to be verified.
* @see list_entries_to_array
*/
function list_items_to_machine_list($data)
{
    $_net = Netmask::getInstance();
    $machine_list = array();
    foreach ($data as $key => $val) {
        $val = trim($val);
        $tmp = array();
        $cidrs = array();
        if (is_ip($val)) {
            $machine_list[] = $val;
        } else {
            if (is_cidr($val)) {
                $machine_list[] = $val;
            } else {
                if (is_range($val)) {
                    $cidrs = $_net->split_cidrs($val);
                    $machine_list = array_merge($machine_list, $cidrs);
                } else {
                    if (is_short_range($val)) {
                        $cidrs = $_net->split_cidrs($val);
                        $machine_list = array_merge($machine_list, $cidrs);
                    } else {
                        if (is_vhost($val)) {
                            $machine_list[] = $val;
                        } else {
                            $machine_list[] = strtoupper($val);
                        }
                    }
                }
            }
        }
    }
    // Filter out empty array elements if there are any
    $machine_list = array_filter($machine_list, "strip_empty");
    return $machine_list;
}
Ejemplo n.º 2
0
    /**
     * I need to check for cidrs and ranges here because otherwise the
     * total number of targets could be really small.
     *
     * example:
     *
     *	the target 111.222.111.0/24 is 1 target to nessquik
     *	but to Nessus it is 255-2 targets. The progress will
     *	involves 253 targets but the total would only be calculated
     *	off of 1 target. This same problem occurs with ranges.
     */
    if (is_cidr($val)) {
        $_nm->init($val);
        $targets += $_nm->hosts_per_subnet();
    } else {
        if (is_range($val)) {
            $tmp = explode('-', $val);
            $start_ip = $tmp[0];
            $end_ip = $tmp[1];
            $cidrs = $_nm->range2cidrlist($start_ip, $end_ip);
            foreach ($cidrs as $key => $val) {
                $_nm->init($val);
                $targets += $_nm->hosts_per_subnet();
            }
        } else {
            // Better be an IP address
            $targets += 1;
        }
    }
}
$max_progress = $targets * 100;