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