diff --git a/.gitignore b/.gitignore index 9d73907..704764a 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ ft_nmap .cache compile_commands.json tags +dlopen.supp diff --git a/include/response.h b/include/response.h index bbab904..9e3e6bd 100644 --- a/include/response.h +++ b/include/response.h @@ -8,7 +8,7 @@ #include "scan.h" typedef enum { - OPEN, + OPEN = 1, CLOSE, FILTERED, UNFILTERED, diff --git a/src/dns.c b/src/dns.c index 4ef1c0a..14d4fdd 100644 --- a/src/dns.c +++ b/src/dns.c @@ -10,7 +10,7 @@ int dns_lookup(char *ip_addr, char *hostname, struct sockaddr_in *addr_con) { struct hostent *host = gethostbyname2(hostname, AF_INET); if (!host) { - dprintf(2, "Hostname %s doesn't exist or has invalid format.", + dprintf(2, "Hostname %s doesn't exist or has invalid format.\n", hostname); return -1; } diff --git a/src/main.c b/src/main.c index 4faa132..bace86c 100644 --- a/src/main.c +++ b/src/main.c @@ -3,6 +3,7 @@ #include #include #include +#include #include "dns.h" #include "interface.h" @@ -29,7 +30,7 @@ int main(int ac, char **av) return 1; } - struct response responses[1024]; + struct response responses[1024] = {0}; struct thread *single_thread = malloc(sizeof(struct thread)); if (get_interface_name(&single_thread->host) < 0) diff --git a/src/packet.c b/src/packet.c index b829c03..ee8b35a 100644 --- a/src/packet.c +++ b/src/packet.c @@ -15,7 +15,6 @@ void create_udp_packet(struct udphdr *udphdr, const struct scan *data) udphdr->source = htons(1234); udphdr->dest = htons(data->port); udphdr->len = sizeof(struct udphdr); - udphdr->check = 0; udphdr->check = checksum(udphdr, sizeof(struct udphdr)); } @@ -23,17 +22,13 @@ int create_tcp_packet(struct tcphdr *tcphdr, const struct scan *data) { tcphdr->source = htons(1234); tcphdr->dest = htons(data->port); - tcphdr->seq = 0; - tcphdr->ack_seq = 0; tcphdr->doff = sizeof(struct tcphdr) / sizeof(int); tcphdr->fin = data->type == SCAN_XMAS || data->type == SCAN_FIN; tcphdr->syn = data->type == SCAN_SYN; - tcphdr->rst = 0; tcphdr->psh = data->type == SCAN_XMAS; tcphdr->ack = data->type == SCAN_ACK; tcphdr->urg = data->type == SCAN_XMAS; tcphdr->window = htons(5840); - tcphdr->check = 0; tcphdr->urg_ptr = 0; struct pshdr pshdr; @@ -58,7 +53,7 @@ int create_tcp_packet(struct tcphdr *tcphdr, const struct scan *data) static void *create_packet(const struct scan *data, size_t packet_size) { const bool isudp = data->type == SCAN_UDP; - void *packet = malloc(packet_size); + void *packet = calloc(packet_size, 1); if (!packet) { dprintf(2, "ft_nmap: allocation failed during packet creation\n"); @@ -74,7 +69,6 @@ static void *create_packet(const struct scan *data, size_t packet_size) iphdr->frag_off = 0; iphdr->ttl = 48; iphdr->protocol = isudp ? IPPROTO_UDP : IPPROTO_TCP; - iphdr->check = 0; iphdr->saddr = inet_addr(data->host->ip); iphdr->daddr = inet_addr(data->dest_addr); @@ -96,6 +90,7 @@ int send_packets(const struct scan *data, int sockfd) { struct sockaddr_in conn_addr; conn_addr.sin_family = AF_INET; + conn_addr.sin_port = htons(80); conn_addr.sin_addr.s_addr = inet_addr(data->dest_addr); size_t packet_size = sizeof(struct iphdr) + diff --git a/src/scan.c b/src/scan.c index cf3e145..c1bc05d 100644 --- a/src/scan.c +++ b/src/scan.c @@ -7,6 +7,7 @@ #include #include #include +#include #include "packet.h" #include "response.h" @@ -89,10 +90,11 @@ int scan(const struct scan *data) send_packets(data, sockfd); - // TODO test with another cnt value - if (pcap_dispatch(handle, 10, dispatch_callback, (u_char *)data)) { - ; + if (!pcap_dispatch(handle, 1, dispatch_callback, (u_char *)data)) { + printf("timeout\n"); } + pcap_close(handle); + close(sockfd); return 0; }