From b18fc7924e43b0b6c628fb779d9ac16c8b5e68d9 Mon Sep 17 00:00:00 2001 From: Jack Halford Date: Sun, 8 Oct 2017 21:30:05 +0200 Subject: [PATCH] libft submoduel gone --- nmap/.gitmodules | 3 --- nmap/Makefile | 7 ++++-- nmap/includes/nmap.h | 56 ++++++++++++++++++++------------------------ nmap/libft | 1 - nmap/srcs/listener.c | 9 ++++--- nmap/srcs/main.c | 24 +++++++++++++++---- nmap/srcs/nmap.c | 22 +++++++++++++---- nmap/srcs/parser.c | 12 ++++++++++ 8 files changed, 83 insertions(+), 51 deletions(-) delete mode 160000 nmap/libft diff --git a/nmap/.gitmodules b/nmap/.gitmodules index c82793fb..e69de29b 100644 --- a/nmap/.gitmodules +++ b/nmap/.gitmodules @@ -1,3 +0,0 @@ -[submodule "libft"] - path = libft - url = https://github.com/jzck/libft diff --git a/nmap/Makefile b/nmap/Makefile index 28a81d37..ee1854d1 100644 --- a/nmap/Makefile +++ b/nmap/Makefile @@ -6,7 +6,7 @@ # By: wescande +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2016/08/29 21:32:58 by wescande #+# #+# # -# Updated: 2017/04/22 19:26:34 by jhalford ### ########.fr # +# Updated: 2017/10/08 19:09:21 by jhalford ### ########.fr # # # # **************************************************************************** # @@ -48,7 +48,9 @@ all : $(NAME): $(LIBFT_LIB) $(OBJ_DIR) $(OBJS) $(CLIENT_OBJ) @$(CC) $(OBJS) -o $@ \ -I $(INC_DIR) \ + -I $(HOME)/.bin/include \ -I $(LIBFT_INC) \ + -L $(HOME)/.bin/lib \ $(LIBFT_LIB) $(CLIENT_OBJ) $(FLAGS) \ -lm -lpcap -lpthread /usr/local/lib/libdill.a @printf "\r\033[38;5;117m✓ MAKE $@ \033[0m\033[K\n" @@ -66,7 +68,8 @@ $(OBJ_DIR)%.o : $(SRC_DIR)%.c | $(OBJ_DIR) @$(eval COLOR=$(shell list=(160 196 202 208 215 221 226 227 190 154 118 82 46); index=$$(($(PERCENT) * $${#list[@]} / 100)); echo "$${list[$$index]}")) @printf "\r\033[38;5;%dm⌛ [%s]: %2d%% `printf '█%.0s' {0..$(DONE)}`%*s❙%*.*s\033[0m\033[K" $(COLOR) $(NAME) $(PERCENT) $(TO_DO) "" $(DELTA) $(DELTA) "$(shell echo "$@" | sed 's/^.*\///')" @$(CC) $(FLAGS) $(OBJ_FLAG) -MMD -c $< -o $@\ - -I $(INC_DIR)\ + -I $(INC_DIR) \ + -I $(HOME)/.bin/include \ -I $(LIBFT_INC) @$(eval INDEX=$(shell echo $$(($(INDEX)+1)))) diff --git a/nmap/includes/nmap.h b/nmap/includes/nmap.h index a1271171..efd1bc14 100644 --- a/nmap/includes/nmap.h +++ b/nmap/includes/nmap.h @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/04/22 14:10:24 by jhalford #+# #+# */ -/* Updated: 2017/04/22 15:52:07 by jhalford ### ########.fr */ +/* Updated: 2017/10/08 21:27:51 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -30,7 +30,7 @@ # include # include -# include +# include "libdill.h" # define SCAN_TCP (1 << 0) # define SCAN_SYN (1 << 1) @@ -46,28 +46,20 @@ typedef struct s_host t_host; typedef struct s_tcp_packet t_tcp_packet; typedef enum e_port_status t_port_status; -struct s_data +struct s_data { - t_flag flag; - char **av_data; - t_list *host; - struct sockaddr source_addr; - int ports[USHRT_MAX + 1]; - int threads; - int scan; + t_flag flag; + char **av_data; + t_list *host; + + int sock_tcp; + int threads; + int scan; }; -/* enum e_scan_type */ -/* { */ -/* SCAN_SYN, */ -/* SCAN_NULL, */ -/* SCAN_ACK, */ -/* SCAN_FIN, */ -/* SCAN_XMAS, */ -/* SCAN_UDP, */ -/* }; */ +struct -enum e_port_status +enum e_port_status { OPEN, FILTERED, @@ -76,18 +68,20 @@ enum e_port_status OPEN_FILTERED, }; -struct s_host +struct s_host { - char *host; // user input host (ip or dn) - char *dn; // ai_canonname - char ip[INET6_ADDRSTRLEN]; // readable ip address (4 or 6) - int sock_tcp; - int sock_udp; - int sock_icmp; - t_port_status results[USHRT_MAX + 1]; - int channels[USHRT_MAX + 1]; - struct sockaddr *addr; - size_t addrlen; + char *host; // user input host (ip or dn) + char *dn; // ai_canonname + char ip[INET6_ADDRSTRLEN]; // readable ip address (4 or 6) + struct s_target ports[USHRT_MAX + 1]; + struct sockaddr *addr; + size_t addrlen; +}; + +struct s_target +{ + int in_channel; + t_port_status results[SCAN_MAX]; }; struct s_tcp_packet diff --git a/nmap/libft b/nmap/libft deleted file mode 160000 index 8c0961c5..00000000 --- a/nmap/libft +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 8c0961c50468d42c3527c208d7f4ae3c98646882 diff --git a/nmap/srcs/listener.c b/nmap/srcs/listener.c index 33138458..b71f7cbe 100644 --- a/nmap/srcs/listener.c +++ b/nmap/srcs/listener.c @@ -8,11 +8,11 @@ static void packet_callback(u_char *arg, const struct pcap_pkthdr *pkthdr, const (void)pkthdr; (void)packet; t_data *data = (t_data*)arg; - printf("received packet !!!\n"); + ft_printf("received packet !!!\n"); hexdump(&packet, sizeof(packet)); } -coroutine void nmap_listener(void *arg) +coroutine void nmap_listener(t_data *data) { t_data *data; char errbuf[PCAP_ERRBUF_SIZE]; @@ -44,11 +44,10 @@ coroutine void nmap_listener(void *arg) exit(EXIT_FAILURE); } /* signal(SIGALRM, sigalrm_handler); */ - printf("listener loop\n"); - fflush(stdout); + ft_printf("listener loop\n"); if (pcap_loop(pcap_obj, -1, packet_callback, (u_char*)data) == -1) { - printf("pcap_loop fail\n"); + ft_printf("pcap_loop fail\n"); exit(EXIT_FAILURE); } free(str); diff --git a/nmap/srcs/main.c b/nmap/srcs/main.c index 22af1671..2e9ec60d 100644 --- a/nmap/srcs/main.c +++ b/nmap/srcs/main.c @@ -1,3 +1,15 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* main.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2017/10/08 19:10:04 by jhalford #+# #+# */ +/* Updated: 2017/10/08 21:27:57 by jhalford ### ########.fr */ +/* */ +/* ************************************************************************** */ + #include "nmap.h" #define NMAP_USAGE1 " [--ip HOST] [--file FILE]" @@ -20,15 +32,19 @@ int main(int ac, char **av) printf("or nmap"NMAP_USAGE1 NMAP_USAGE2"\n"); exit(1); } - if (reserve_port(&data.src_port)) + + // single tcp port + struct sockaddr_in sa; + sa.sin_family = AF_INET; + sa.sin_addr.s_addr = INADDR_ANY; + if (reserve_port(data.sock_tcp, &sa)) { fprintf(stderr, "couldn't reserve port\n"); exit(1); } - int port_chan = chmake(sizeof(int)); + go(nmap_listener(&data)); - /* go(nmap_ports(&data, port_chan)); */ - /* go(nmap_collector(&data)); */ int chan = nmap(&data); + nmap_collector(chan, &data); return (0); } diff --git a/nmap/srcs/nmap.c b/nmap/srcs/nmap.c index 523d6a96..4071982e 100644 --- a/nmap/srcs/nmap.c +++ b/nmap/srcs/nmap.c @@ -1,3 +1,15 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* nmap.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2017/10/08 19:10:07 by jhalford #+# #+# */ +/* Updated: 2017/10/08 21:27:50 by jhalford ### ########.fr */ +/* */ +/* ************************************************************************** */ + #include "nmap.h" unsigned short cksum(void *b, int len) @@ -36,7 +48,8 @@ coroutine void nmap_scan_node(t_host *host, struct iphdr *iph, int port) return (1); - if (sendto(host->sock_tcp, &packet, sizeof(packet), 0, host->addr, host->addrlen) < 0) + if (sendto(data->sock_tcp, &packet, sizeof(packet), 0, + host->addr, host->addrlen) < 0) { perror("sendto"); exit(1); @@ -48,8 +61,8 @@ coroutine void nmap_scan_node(t_host *host, struct iphdr *iph, int port) void nmap(t_data *data) { - t_list *list; - t_host *host; + t_list *list; + t_host *host; struct iphdr iph; iphdr_init(&iph); @@ -57,8 +70,7 @@ void nmap(t_data *data) iph.daddr = *(uint32_t*)&((struct sockaddr_in*)host->addr)->sin_addr; iph.saddr = *(uint32_t*)&((struct sockaddr_in*)&data->source_addr)->sin_addr; iph.tot_len = htons(sizeof(t_tcp_packet)); - - int fan_in = chmake(); + int fan_in = chmake(sizeof()); for (t_list *list = data->host; list != NULL; list = list->next) { t_host *host = list->content; diff --git a/nmap/srcs/parser.c b/nmap/srcs/parser.c index f0e15e6d..4e4cc31b 100644 --- a/nmap/srcs/parser.c +++ b/nmap/srcs/parser.c @@ -1,3 +1,15 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* parser.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2017/10/08 19:10:05 by jhalford #+# #+# */ +/* Updated: 2017/10/08 21:05:14 by jhalford ### ########.fr */ +/* */ +/* ************************************************************************** */ + #include "nmap.h" static t_cliopts g_opts[] =