fix: multiple scans (more than 2 now works)
fix: more threads than ports to scan works too
This commit is contained in:
@ -6,6 +6,7 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
#include <sys/param.h>
|
||||
|
||||
#include "dns.h"
|
||||
#include "interface.h"
|
||||
@ -66,10 +67,10 @@ int main(int ac, char **av)
|
||||
return -1;
|
||||
|
||||
char *nb_threads_str = get_option_arg(options, FL_SPEEDUP);
|
||||
uint8_t nb_threads = 1;
|
||||
uint8_t nb_threads = 0;
|
||||
if (nb_threads_str)
|
||||
nb_threads = atoi(nb_threads_str);
|
||||
|
||||
nb_threads = MIN(atoi(nb_threads_str), general.port_end - general.port_start + 1);
|
||||
|
||||
char *dest_addr = get_option_arg(options, FL_IP);
|
||||
if (dest_addr) {
|
||||
general.dest_addr = dest_addr;
|
||||
|
@ -45,29 +45,27 @@ uint8_t parse_type(char *arg)
|
||||
if (!arg)
|
||||
return SCAN_ALL;
|
||||
uint8_t type = 0;
|
||||
char *current_arg = arg;
|
||||
while (current_arg[0] != '\0')
|
||||
char *current_arg = strtok(arg, ",");
|
||||
while (current_arg)
|
||||
{
|
||||
if (strncmp(current_arg, "NULL", 4) == 0)
|
||||
if (strcmp(current_arg, "NULL") == 0)
|
||||
type |= SCAN_NULL;
|
||||
else if (strncmp(current_arg, "SYN", 3) == 0)
|
||||
else if (strcmp(current_arg, "SYN") == 0)
|
||||
type |= SCAN_SYN;
|
||||
else if (strncmp(current_arg, "ACK", 3) == 0)
|
||||
else if (strcmp(current_arg, "ACK") == 0)
|
||||
type |= SCAN_ACK;
|
||||
else if (strncmp(current_arg, "FIN", 3) == 0)
|
||||
else if (strcmp(current_arg, "FIN") == 0)
|
||||
type |= SCAN_FIN;
|
||||
else if (strncmp(current_arg, "XMAS", 4) == 0)
|
||||
else if (strcmp(current_arg, "XMAS") == 0)
|
||||
type |= SCAN_XMAS;
|
||||
else if (strncmp(current_arg, "UDP", 5) == 0)
|
||||
else if (strcmp(current_arg, "UDP") == 0)
|
||||
type |= SCAN_UDP;
|
||||
else
|
||||
{
|
||||
dprintf(2, "ft_nmap: invalid argument to --scan: '%s'\n", arg);
|
||||
return -1;
|
||||
}
|
||||
current_arg += strcspn(current_arg, ",");
|
||||
if (current_arg[0] == ',')
|
||||
current_arg++;
|
||||
current_arg = strtok(NULL, ",");
|
||||
}
|
||||
return type;
|
||||
}
|
||||
@ -267,7 +265,6 @@ int parsing(struct scan *general, const struct option_lst *options)
|
||||
dprintf(2, "ft_nmap: number of threads to use must be "
|
||||
"superior "
|
||||
"or equals to the ports range\n");
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
@ -39,7 +39,7 @@ void print_config(const struct scan *general, const char *hosts_path,
|
||||
printf("No of threads: %d\n", nb_threads);
|
||||
}
|
||||
|
||||
bool is_port_opened(const e_state states[6], uint8_t type)
|
||||
bool is_port_opened(const e_state states[6])
|
||||
{
|
||||
for (uint8_t i = 0; i < NB_SCAN; i++)
|
||||
if (states[i] == OPENED)
|
||||
@ -71,7 +71,7 @@ void print_host_results(const struct scan *general, double scan_time)
|
||||
port++) {
|
||||
const struct response *response =
|
||||
&general->responses[port - general->port_start];
|
||||
if (is_port_opened(response->states, general->type))
|
||||
if (is_port_opened(response->states))
|
||||
print_port_state(port, general->type, response);
|
||||
}
|
||||
printf("\n");
|
||||
@ -80,7 +80,7 @@ void print_host_results(const struct scan *general, double scan_time)
|
||||
port++) {
|
||||
const struct response *response =
|
||||
&general->responses[port - general->port_start];
|
||||
if (!is_port_opened(response->states, general->type))
|
||||
if (!is_port_opened(response->states))
|
||||
print_port_state(port, general->type, response);
|
||||
}
|
||||
printf("\nScan took %lf secs\n", scan_time);
|
||||
|
Reference in New Issue
Block a user