stuff
This commit is contained in:
parent
7940136560
commit
d9955513c0
20 changed files with 318 additions and 438 deletions
|
|
@ -31,12 +31,12 @@ INC_DIR = includes/
|
||||||
OBJ_DIR = objs/
|
OBJ_DIR = objs/
|
||||||
|
|
||||||
SRC_BASE = \
|
SRC_BASE = \
|
||||||
format.c\
|
scanners.c\
|
||||||
ip.c\
|
|
||||||
listener.c\
|
|
||||||
main.c\
|
|
||||||
parser.c\
|
parser.c\
|
||||||
scanners.c
|
main.c\
|
||||||
|
capture.c\
|
||||||
|
format.c\
|
||||||
|
ip.c
|
||||||
|
|
||||||
SRCS = $(addprefix $(SRC_DIR), $(SRC_BASE))
|
SRCS = $(addprefix $(SRC_DIR), $(SRC_BASE))
|
||||||
OBJS = $(addprefix $(OBJ_DIR), $(SRC_BASE:.c=.o))
|
OBJS = $(addprefix $(OBJ_DIR), $(SRC_BASE:.c=.o))
|
||||||
|
|
|
||||||
|
|
@ -95,7 +95,7 @@ chan nmap_parse(int ac, char **av);
|
||||||
void nmap_format(chan results);
|
void nmap_format(chan results);
|
||||||
|
|
||||||
coroutine void nmap_scan_tcp(chan results, t_job job);
|
coroutine void nmap_scan_tcp(chan results, t_job job);
|
||||||
chan nmap_listener(ipaddr dst, ipaddr src);
|
pcap_t *nmap_capture(ipaddr dst, ipaddr src);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** IP helpers
|
** IP helpers
|
||||||
|
|
|
||||||
|
|
@ -24,191 +24,190 @@ OBJ_DIR = objs/
|
||||||
|
|
||||||
SRC_BASE = \
|
SRC_BASE = \
|
||||||
btree/btree_apply_by_level.c\
|
btree/btree_apply_by_level.c\
|
||||||
btree/btree_apply_infix.c\
|
|
||||||
btree/btree_apply_prefix.c\
|
|
||||||
btree/btree_apply_suffix.c\
|
|
||||||
btree/btree_create_node.c\
|
|
||||||
btree/btree_del.c\
|
btree/btree_del.c\
|
||||||
btree/btree_delone.c\
|
btree/btree_delone.c\
|
||||||
btree/btree_insert_data.c\
|
|
||||||
btree/btree_level_count.c\
|
|
||||||
btree/btree_map.c\
|
|
||||||
btree/btree_print.c\
|
|
||||||
btree/btree_search_item.c\
|
btree/btree_search_item.c\
|
||||||
char/ft_isalnum.c\
|
btree/btree_create_node.c\
|
||||||
char/ft_isalpha.c\
|
btree/btree_apply_suffix.c\
|
||||||
char/ft_isascii.c\
|
btree/btree_level_count.c\
|
||||||
char/ft_isdigit.c\
|
btree/btree_insert_data.c\
|
||||||
char/ft_isprint.c\
|
btree/btree_apply_prefix.c\
|
||||||
char/ft_tolower.c\
|
btree/btree_print.c\
|
||||||
char/ft_toupper.c\
|
btree/btree_apply_infix.c\
|
||||||
cliopts/cliopts_get.c\
|
btree/btree_map.c\
|
||||||
cliopts/cliopts_getmap.c\
|
|
||||||
color/ft_color_mk.c\
|
|
||||||
color/ft_color_mkif.c\
|
|
||||||
color/ft_color_reset.c\
|
|
||||||
color/ft_color_set.c\
|
|
||||||
dlst/ft_dlstadd_after.c\
|
|
||||||
dlst/ft_dlstadd_before.c\
|
|
||||||
dlst/ft_dlstdel.c\
|
|
||||||
dlst/ft_dlstdelone.c\
|
|
||||||
dlst/ft_dlstlast.c\
|
|
||||||
dlst/ft_dlstnew.c\
|
|
||||||
dlst/ft_dlstrtostr.c\
|
|
||||||
dlst/ft_dlstsize.c\
|
|
||||||
error/error.c\
|
|
||||||
error/ft_usage.c\
|
|
||||||
ft_printf/ft_conversion.c\
|
|
||||||
ft_printf/ft_fmt_simplify.c\
|
|
||||||
ft_printf/ft_fmt_validate_conv.c\
|
|
||||||
ft_printf/ft_fmt_validate_flags.c\
|
|
||||||
ft_printf/ft_fmt_validate_mod.c\
|
|
||||||
ft_printf/ft_printf.c\
|
|
||||||
ft_printf/ft_printf_color.c\
|
|
||||||
ft_printf/ft_printf_parse.c\
|
|
||||||
ft_printf/ft_transform.c\
|
|
||||||
ft_printf/ft_vprintf.c\
|
|
||||||
ft_printf/lib_fmt.c\
|
|
||||||
ft_printf/lib_fmt_error.c\
|
|
||||||
ft_printf/lib_pad.c\
|
|
||||||
ft_printf/lib_pad_sharp.c\
|
|
||||||
get_next_line/get_next_line.c\
|
|
||||||
lst/ft_id.c\
|
|
||||||
lst/ft_lst2str.c\
|
|
||||||
lst/ft_lst_at.c\
|
|
||||||
lst/ft_lst_bfree.c\
|
|
||||||
lst/ft_lst_cfree.c\
|
|
||||||
lst/ft_lst_delif.c\
|
|
||||||
lst/ft_lst_delsub.c\
|
|
||||||
lst/ft_lst_filter.c\
|
|
||||||
lst/ft_lst_filterout.c\
|
|
||||||
lst/ft_lst_find.c\
|
|
||||||
lst/ft_lst_merge.c\
|
|
||||||
lst/ft_lst_order_delsub.c\
|
|
||||||
lst/ft_lst_pop.c\
|
|
||||||
lst/ft_lst_print.c\
|
|
||||||
lst/ft_lst_print2.c\
|
|
||||||
lst/ft_lst_removeif.c\
|
|
||||||
lst/ft_lst_reverse.c\
|
|
||||||
lst/ft_lst_size.c\
|
|
||||||
lst/ft_lst_sorted_insert.c\
|
|
||||||
lst/ft_lst_sorted_merge.c\
|
|
||||||
lst/ft_lstadd.c\
|
|
||||||
lst/ft_lstdel.c\
|
|
||||||
lst/ft_lstdelone.c\
|
|
||||||
lst/ft_lsteadd.c\
|
|
||||||
lst/ft_lstiter.c\
|
|
||||||
lst/ft_lstlast.c\
|
|
||||||
lst/ft_lstmap.c\
|
|
||||||
lst/ft_lstnadd.c\
|
|
||||||
lst/ft_lstnew.c\
|
|
||||||
lst/ft_lstnew_range.c\
|
|
||||||
lst/ft_lstsort.c\
|
|
||||||
lst/lst_insert_sort.c\
|
|
||||||
lst/pop.c\
|
|
||||||
lst/push.c\
|
|
||||||
lst/top.c\
|
|
||||||
math/bitfield.c\
|
|
||||||
math/ft_addrcmp.c\
|
|
||||||
math/ft_ilen.c\
|
|
||||||
math/ft_ilen_base.c\
|
|
||||||
math/ft_itoa.c\
|
|
||||||
math/ft_itoa_base.c\
|
|
||||||
math/ft_lllen.c\
|
|
||||||
math/ft_lllen_base.c\
|
|
||||||
math/ft_lltoa_base.c\
|
|
||||||
math/ft_uilen.c\
|
|
||||||
math/ft_uitoa_base.c\
|
|
||||||
math/ft_ulltoa_base.c\
|
|
||||||
math/id.c\
|
|
||||||
mem/ft_bzero.c\
|
|
||||||
mem/ft_malloc.c\
|
|
||||||
mem/ft_memalloc.c\
|
|
||||||
mem/ft_memccpy.c\
|
|
||||||
mem/ft_memchr.c\
|
|
||||||
mem/ft_memcmp.c\
|
|
||||||
mem/ft_memcpy.c\
|
|
||||||
mem/ft_memdel.c\
|
|
||||||
mem/ft_memmove.c\
|
|
||||||
mem/ft_memset.c\
|
|
||||||
mem/ft_realloc.c\
|
|
||||||
net/cksum.c\
|
|
||||||
net/create_client.c\
|
|
||||||
net/create_server.c\
|
|
||||||
net/host.c\
|
|
||||||
net/ip.c\
|
|
||||||
net/net_get.c\
|
|
||||||
net/net_send.c\
|
|
||||||
net/prettypacket.c\
|
|
||||||
net/reserve_port.c\
|
|
||||||
net/tcp.c\
|
|
||||||
path/ft_path_notdir.c\
|
|
||||||
printing/ft_putchar.c\
|
printing/ft_putchar.c\
|
||||||
printing/ft_putendl.c\
|
printing/ft_putendl.c\
|
||||||
|
printing/hexdump.c\
|
||||||
printing/ft_putnbr.c\
|
printing/ft_putnbr.c\
|
||||||
printing/ft_putstr.c\
|
printing/ft_putstr.c\
|
||||||
printing/hexdump.c\
|
cliopts/cliopts_getmap.c\
|
||||||
rs/rs.c\
|
cliopts/cliopts_get.c\
|
||||||
sstr/ft_sstradd.c\
|
error/error.c\
|
||||||
sstr/ft_sstrcat.c\
|
error/ft_usage.c\
|
||||||
|
get_next_line/get_next_line.c\
|
||||||
|
path/ft_path_notdir.c\
|
||||||
|
lst/ft_lst_at.c\
|
||||||
|
lst/ft_lst_size.c\
|
||||||
|
lst/ft_lst_sorted_merge.c\
|
||||||
|
lst/ft_id.c\
|
||||||
|
lst/ft_lstnew.c\
|
||||||
|
lst/ft_lst_bfree.c\
|
||||||
|
lst/push.c\
|
||||||
|
lst/ft_lstadd.c\
|
||||||
|
lst/ft_lstsort.c\
|
||||||
|
lst/ft_lst_find.c\
|
||||||
|
lst/ft_lstnew_range.c\
|
||||||
|
lst/ft_lst_print.c\
|
||||||
|
lst/top.c\
|
||||||
|
lst/ft_lstnadd.c\
|
||||||
|
lst/ft_lst_reverse.c\
|
||||||
|
lst/ft_lst_filter.c\
|
||||||
|
lst/ft_lst_delif.c\
|
||||||
|
lst/ft_lstdelone.c\
|
||||||
|
lst/ft_lst_order_delsub.c\
|
||||||
|
lst/ft_lsteadd.c\
|
||||||
|
lst/ft_lst_print2.c\
|
||||||
|
lst/ft_lst_pop.c\
|
||||||
|
lst/ft_lst_cfree.c\
|
||||||
|
lst/ft_lst2str.c\
|
||||||
|
lst/ft_lst_removeif.c\
|
||||||
|
lst/ft_lstlast.c\
|
||||||
|
lst/ft_lst_delsub.c\
|
||||||
|
lst/ft_lst_filterout.c\
|
||||||
|
lst/lst_insert_sort.c\
|
||||||
|
lst/ft_lst_sorted_insert.c\
|
||||||
|
lst/ft_lstiter.c\
|
||||||
|
lst/pop.c\
|
||||||
|
lst/ft_lstmap.c\
|
||||||
|
lst/ft_lstdel.c\
|
||||||
|
lst/ft_lst_merge.c\
|
||||||
|
sstr/ft_sstrmerge.c\
|
||||||
|
sstr/ft_sstrstr.c\
|
||||||
|
sstr/ft_sstrsort.c\
|
||||||
sstr/ft_sstrdel.c\
|
sstr/ft_sstrdel.c\
|
||||||
sstr/ft_sstrdup.c\
|
sstr/ft_sstrdup.c\
|
||||||
|
sstr/ft_sstradd.c\
|
||||||
|
sstr/ft_sstrcat.c\
|
||||||
sstr/ft_sstrfree.c\
|
sstr/ft_sstrfree.c\
|
||||||
sstr/ft_sstrmerge.c\
|
|
||||||
sstr/ft_sstrprint.c\
|
sstr/ft_sstrprint.c\
|
||||||
sstr/ft_sstrprint_fd.c\
|
sstr/ft_sstrprint_fd.c\
|
||||||
sstr/ft_sstrsort.c\
|
char/ft_toupper.c\
|
||||||
sstr/ft_sstrstr.c\
|
char/ft_isprint.c\
|
||||||
str/ft_atoi.c\
|
char/ft_isalpha.c\
|
||||||
str/ft_convert_base.c\
|
char/ft_isascii.c\
|
||||||
str/ft_putaddr_fd.c\
|
char/ft_tolower.c\
|
||||||
str/ft_split_whitespaces.c\
|
char/ft_isalnum.c\
|
||||||
str/ft_str3join.c\
|
char/ft_isdigit.c\
|
||||||
str/ft_strappend.c\
|
color/ft_color_set.c\
|
||||||
str/ft_strbetween.c\
|
color/ft_color_reset.c\
|
||||||
str/ft_strcat.c\
|
color/ft_color_mk.c\
|
||||||
str/ft_strcatf.c\
|
color/ft_color_mkif.c\
|
||||||
str/ft_strchr.c\
|
net/host.c\
|
||||||
str/ft_strchrcpy.c\
|
net/create_client.c\
|
||||||
str/ft_strclr.c\
|
net/net_get.c\
|
||||||
str/ft_strcmp.c\
|
net/net_send.c\
|
||||||
str/ft_strcpy.c\
|
net/reserve_port.c\
|
||||||
str/ft_strcspn.c\
|
net/tcp.c\
|
||||||
str/ft_strcut.c\
|
net/prettypacket.c\
|
||||||
str/ft_strdel.c\
|
net/ip.c\
|
||||||
str/ft_strdup.c\
|
net/create_server.c\
|
||||||
str/ft_strdupchr.c\
|
net/cksum.c\
|
||||||
str/ft_strduptr.c\
|
dlst/ft_dlstrtostr.c\
|
||||||
str/ft_strequ.c\
|
dlst/ft_dlstdel.c\
|
||||||
str/ft_strinsert.c\
|
dlst/ft_dlstadd_after.c\
|
||||||
str/ft_stris.c\
|
dlst/ft_dlstdelone.c\
|
||||||
str/ft_striter.c\
|
dlst/ft_dlstsize.c\
|
||||||
str/ft_striteri.c\
|
dlst/ft_dlstadd_before.c\
|
||||||
str/ft_strjoin.c\
|
dlst/ft_dlstnew.c\
|
||||||
str/ft_strlcat.c\
|
dlst/ft_dlstlast.c\
|
||||||
str/ft_strlen.c\
|
rs/rs.c\
|
||||||
str/ft_strlenchr.c\
|
mem/ft_memmove.c\
|
||||||
str/ft_strmap.c\
|
mem/ft_realloc.c\
|
||||||
str/ft_strmapi.c\
|
mem/ft_memcpy.c\
|
||||||
str/ft_strncat.c\
|
mem/ft_memchr.c\
|
||||||
str/ft_strncmp.c\
|
mem/ft_malloc.c\
|
||||||
str/ft_strncpy.c\
|
mem/ft_memalloc.c\
|
||||||
str/ft_strndup.c\
|
mem/ft_memset.c\
|
||||||
str/ft_strnequ.c\
|
mem/ft_memdel.c\
|
||||||
str/ft_strnew.c\
|
mem/ft_memcmp.c\
|
||||||
str/ft_strnstr.c\
|
mem/ft_bzero.c\
|
||||||
str/ft_strrchr.c\
|
mem/ft_memccpy.c\
|
||||||
str/ft_strreplace.c\
|
time/epoch.c\
|
||||||
str/ft_strrev.c\
|
|
||||||
str/ft_strsepjoin.c\
|
|
||||||
str/ft_strsplit.c\
|
|
||||||
str/ft_strstr.c\
|
str/ft_strstr.c\
|
||||||
str/ft_strsub.c\
|
str/ft_strlenchr.c\
|
||||||
str/ft_strtok.c\
|
str/ft_strcpy.c\
|
||||||
|
str/ft_str3join.c\
|
||||||
|
str/ft_striteri.c\
|
||||||
|
str/ft_strappend.c\
|
||||||
|
str/ft_strclr.c\
|
||||||
|
str/ft_strnew.c\
|
||||||
|
str/ft_strmapi.c\
|
||||||
|
str/ft_strcatf.c\
|
||||||
|
str/ft_strdup.c\
|
||||||
|
str/ft_striter.c\
|
||||||
|
str/ft_strncmp.c\
|
||||||
str/ft_strtrim.c\
|
str/ft_strtrim.c\
|
||||||
|
str/ft_strduptr.c\
|
||||||
|
str/ft_split_whitespaces.c\
|
||||||
|
str/ft_strbetween.c\
|
||||||
|
str/ft_strdupchr.c\
|
||||||
|
str/ft_strsub.c\
|
||||||
|
str/ft_strsepjoin.c\
|
||||||
|
str/ft_strlcat.c\
|
||||||
|
str/ft_strcspn.c\
|
||||||
|
str/ft_strchr.c\
|
||||||
|
str/ft_strequ.c\
|
||||||
|
str/ft_strcat.c\
|
||||||
|
str/ft_strlen.c\
|
||||||
|
str/ft_strsplit.c\
|
||||||
|
str/ft_strrchr.c\
|
||||||
|
str/ft_strjoin.c\
|
||||||
|
str/ft_strncat.c\
|
||||||
|
str/ft_strmap.c\
|
||||||
|
str/ft_strcmp.c\
|
||||||
|
str/ft_putaddr_fd.c\
|
||||||
|
str/ft_strchrcpy.c\
|
||||||
|
str/ft_strrev.c\
|
||||||
|
str/ft_strinsert.c\
|
||||||
|
str/ft_strnequ.c\
|
||||||
str/hexstring.c\
|
str/hexstring.c\
|
||||||
|
str/ft_strncpy.c\
|
||||||
|
str/ft_strcut.c\
|
||||||
|
str/ft_strndup.c\
|
||||||
|
str/ft_convert_base.c\
|
||||||
|
str/ft_strreplace.c\
|
||||||
|
str/ft_atoi.c\
|
||||||
|
str/ft_stris.c\
|
||||||
|
str/ft_strdel.c\
|
||||||
|
str/ft_strtok.c\
|
||||||
|
str/ft_strnstr.c\
|
||||||
sys/open_new.c\
|
sys/open_new.c\
|
||||||
time/epoch.c
|
ft_printf/ft_conversion.c\
|
||||||
|
ft_printf/lib_fmt.c\
|
||||||
|
ft_printf/ft_printf_parse.c\
|
||||||
|
ft_printf/ft_fmt_simplify.c\
|
||||||
|
ft_printf/ft_vprintf.c\
|
||||||
|
ft_printf/ft_transform.c\
|
||||||
|
ft_printf/ft_printf_color.c\
|
||||||
|
ft_printf/ft_printf.c\
|
||||||
|
ft_printf/lib_pad_sharp.c\
|
||||||
|
ft_printf/ft_fmt_validate_mod.c\
|
||||||
|
ft_printf/lib_pad.c\
|
||||||
|
ft_printf/lib_fmt_error.c\
|
||||||
|
ft_printf/ft_fmt_validate_conv.c\
|
||||||
|
ft_printf/ft_fmt_validate_flags.c\
|
||||||
|
math/ft_uilen.c\
|
||||||
|
math/ft_ilen_base.c\
|
||||||
|
math/ft_ilen.c\
|
||||||
|
math/ft_itoa_base.c\
|
||||||
|
math/ft_lllen_base.c\
|
||||||
|
math/ft_addrcmp.c\
|
||||||
|
math/ft_lllen.c\
|
||||||
|
math/ft_itoa.c\
|
||||||
|
math/ft_lltoa_base.c\
|
||||||
|
math/id.c\
|
||||||
|
math/ft_ulltoa_base.c\
|
||||||
|
math/ft_uitoa_base.c
|
||||||
|
|
||||||
SRCS = $(addprefix $(SRC_DIR), $(SRC_BASE))
|
SRCS = $(addprefix $(SRC_DIR), $(SRC_BASE))
|
||||||
OBJS = $(addprefix $(OBJ_DIR), $(SRC_BASE:.c=.o))
|
OBJS = $(addprefix $(OBJ_DIR), $(SRC_BASE:.c=.o))
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,7 @@
|
||||||
*/
|
*/
|
||||||
# define DG_MSG "{inv}{ran}%5i{yel}%21s {bol}{blu}%-3d{eoc}"
|
# define DG_MSG "{inv}{ran}%5i{yel}%21s {bol}{blu}%-3d{eoc}"
|
||||||
# define DG_ARGS getpid(), getpid(), ft_path_notdir(__FILE__), __LINE__
|
# define DG_ARGS getpid(), getpid(), ft_path_notdir(__FILE__), __LINE__
|
||||||
# define DG(s, ...) ft_dprintf(STDBUG,DG_MSG s "{eoc}\n",DG_ARGS,##__VA_ARGS__)
|
# define DG(s, ...) ft_dprintf(STDERR,DG_MSG s "{eoc}\n",DG_ARGS,##__VA_ARGS__)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** DEBUG with no malloc
|
** DEBUG with no malloc
|
||||||
|
|
|
||||||
|
|
@ -10,8 +10,8 @@
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#ifndef MYTIME_H
|
#ifndef TIME_H
|
||||||
# define MYTIME_H
|
# define TIME_H
|
||||||
|
|
||||||
# include <sys/time.h>
|
# include <sys/time.h>
|
||||||
|
|
||||||
|
|
@ -20,7 +20,8 @@
|
||||||
# include <unistd.h>
|
# include <unistd.h>
|
||||||
# include <stdio.h>
|
# include <stdio.h>
|
||||||
# include <stdlib.h>
|
# include <stdlib.h>
|
||||||
# include <time.h>
|
# include <stdint.h>
|
||||||
|
# include <ft_time.h>
|
||||||
|
|
||||||
# include "ft_types.h"
|
# include "ft_types.h"
|
||||||
# include "error.h"
|
# include "error.h"
|
||||||
|
|
@ -35,7 +36,7 @@
|
||||||
# include "str.h"
|
# include "str.h"
|
||||||
# include "sstr.h"
|
# include "sstr.h"
|
||||||
# include "math.h"
|
# include "math.h"
|
||||||
# include "mytime.h"
|
# include "time.h"
|
||||||
# include "get_next_line.h"
|
# include "get_next_line.h"
|
||||||
# include "sys.h"
|
# include "sys.h"
|
||||||
# include "net.h"
|
# include "net.h"
|
||||||
|
|
|
||||||
|
|
@ -36,14 +36,4 @@ size_t ft_lllen_base(long long n, int base);
|
||||||
int ft_addrcmp(void *a, void *b);
|
int ft_addrcmp(void *a, void *b);
|
||||||
void *id(void *data);
|
void *id(void *data);
|
||||||
|
|
||||||
typedef uint64_t t_bitblock;
|
|
||||||
#define BITFIELD(var, size) t_bitblock var[size / sizeof(t_bitblock) + 1]\
|
|
||||||
= {[0] = size}
|
|
||||||
#define BLOCKSIZE (8 * sizeof(t_bitblock))
|
|
||||||
|
|
||||||
|
|
||||||
extern inline void bitfield_biton(t_bitblock field[], uint64_t bit);
|
|
||||||
extern inline void bitfield_bitoff(t_bitblock field[], uint64_t bit);
|
|
||||||
extern inline uint64_t bitfield_lsb(t_bitblock field[]);
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -26,14 +26,14 @@
|
||||||
# include <netinet/ip_icmp.h>
|
# include <netinet/ip_icmp.h>
|
||||||
# include <arpa/inet.h>
|
# include <arpa/inet.h>
|
||||||
|
|
||||||
# include "mytime.h"
|
# include "ft_time.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** utilities
|
** utilities
|
||||||
*/
|
*/
|
||||||
|
|
||||||
int reserve_port(int s, struct sockaddr *sa);
|
int reserve_port(int s, struct sockaddr *sa);
|
||||||
unsigned short cksum(void *b, int len);
|
unsigned short cksum(const void *b, size_t len);
|
||||||
int host_format(struct sockaddr *addr);
|
int host_format(struct sockaddr *addr);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
@ -69,5 +69,8 @@ void tcp_hdrinit(struct tcphdr *header);
|
||||||
** prettypacket
|
** prettypacket
|
||||||
*/
|
*/
|
||||||
int prettypacket(void *pkt, size_t size);
|
int prettypacket(void *pkt, size_t size);
|
||||||
|
void tcp_print(const char *packet_buffer, int size);
|
||||||
|
void udp_print(const char *packet_buffer, int size);
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -18,78 +18,6 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include "hexstring.h"
|
#include "hexstring.h"
|
||||||
|
|
||||||
/**
|
|
||||||
* Enable disable colored output (enabled by default)
|
|
||||||
*/
|
|
||||||
static int colored_output = 1;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* List of available colors
|
|
||||||
*/
|
|
||||||
static const char *colors[] = {
|
|
||||||
/// Black
|
|
||||||
"\\e[0;30m",
|
|
||||||
/// Red
|
|
||||||
"\\e[0;31m",
|
|
||||||
/// Green
|
|
||||||
"\\e[0;32m",
|
|
||||||
/// Yellow
|
|
||||||
"\\e[0;33m",
|
|
||||||
/// Blue
|
|
||||||
"\\e[0;34m",
|
|
||||||
/// Purple
|
|
||||||
"\\e[0;35m",
|
|
||||||
/// Cyan
|
|
||||||
"\\e[0;36m",
|
|
||||||
/// White
|
|
||||||
"\\e[0;37m",
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Reset color
|
|
||||||
*/
|
|
||||||
static const char *color_reset = "\\e[0m";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Default terminal rows
|
|
||||||
*/
|
|
||||||
static const int rows = 24;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Default terminal columns
|
|
||||||
*/
|
|
||||||
static const int cols = 80;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Example ARP packet
|
|
||||||
*/
|
|
||||||
static const char arp_packet[] = "\xFF\xFF\xFF\xFF\xFF\xFF\xAA\x00\x04\x00\x0A\x04\x08\x06\x00\x01\x08\x00\x06\x04\x00\x01\xAA\x00\x04\x00\x0A\x04\xC0\xA8\x01\x09\x00\x00\x00\x00\x00\x00\xC0\xA8\x01\x04";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Example TCP packet
|
|
||||||
*/
|
|
||||||
static const char tcp_packet[] = "\x1C\xAF\xF7\x6B\x0E\x4D\xAA\x00\x04\x00\x0A\x04\x08\x00\x45\x00\x00\x34\x5A\xAE\x40\x00\x40\x06\x5E\x67\xC0\xA8\x01\x09\x58\xBF\x67\x3E\x9B\x44\x00\x50\x8E\xB5\xC6\xAC\x15\x93\x47\x9E\x80\x10\x00\x58\xA5\xA0\x00\x00\x01\x01\x08\x0A\x00\x09\xC3\xB2\x42\x5B\xFA\xD6";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Example ICMP packet
|
|
||||||
*/
|
|
||||||
static const char icmp_packet[] = "\x1C\xAF\xF7\x6B\x0E\x4D\xAA\x00\x04\x00\x0A\x04\x08\x00\x45\x00\x00\x54\x00\x00\x40\x00\x40\x01\x54\x4E\xC0\xA8\x01\x09\xC0\xA8\x64\x01\x08\x00\x34\x98\xD7\x10\x00\x01\x5B\x68\x98\x4C\x00\x00\x00\x00\x2D\xCE\x0C\x00\x00\x00\x00\x00\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1A\x1B\x1C\x1D\x1E\x1F\x20\x21\x22\x23\x24\x25\x26\x27\x28\x29\x2A\x2B\x2C\x2D\x2E\x2F\x30\x31\x32\x33\x34\x35\x36\x37";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Example UDP packet
|
|
||||||
*/
|
|
||||||
static const char udp_packet[] = "\x1C\xAF\xF7\x6B\x0E\x4D\xAA\x00\x04\x00\x0A\x04\x08\x00\x45\x00\x00\x3C\x9B\x23\x00\x00\x40\x11\x70\xBC\xC0\xA8\x01\x09\xD0\x43\xDC\xDC\x91\x02\x00\x35\x00\x28\x6F\x0B\xAE\x9C\x01\x00\x00\x01\x00\x00\x00\x00\x00\x00\x03\x77\x77\x77\x06\x67\x6F\x6F\x67\x6C\x65\x03\x63\x6F\x6D\x00\x00\x01\x00\x01";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Example IGMP packet
|
|
||||||
*/
|
|
||||||
static const char igmp_packet[] = "\x1C\xAF\xF7\x6B\x0E\x4D\xAA\x00\x04\x00\x0A\x04\x08\x00\x45\x00\x00\x1C\x00\x00\x40\x00\x40\x02\x54\x4E\xC0\xA8\x01\x09\xC0\xA8\x64\x01\x11\xFF\x0D\xFF\xE0\x00\x00\x01";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Example Spanning Tree Protocol (STP) packet
|
|
||||||
*/
|
|
||||||
static const char stp_packet[]="\x01\x80\xc2\x00\x00\x00\x00\x1c\x0e\x87\x85\x04\x00\x26\x42\x42\x03\x00\x00\x00\x00\x00\x80\x64\x00\x1c\x0e\x87\x78\x00\x00\x00\x00\x04\x80\x64\x00\x1c\x0e\x87\x85\x00\x80\x04\x01\x00\x14\x00\x02\x00\x0f\x00";
|
|
||||||
|
|
||||||
// functions that need prototypes
|
// functions that need prototypes
|
||||||
void layer_2_dispatcher(const char *, int, uint64_t);
|
void layer_2_dispatcher(const char *, int, uint64_t);
|
||||||
void layer_3_dispatcher(const char *, int, uint64_t);
|
void layer_3_dispatcher(const char *, int, uint64_t);
|
||||||
|
|
|
||||||
|
|
@ -1,67 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* bitfield.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2017/10/09 14:44:16 by jhalford #+# #+# */
|
|
||||||
/* Updated: 2017/10/24 21:04:39 by jhalford ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "libft.h"
|
|
||||||
#include <stdlib.h>
|
|
||||||
|
|
||||||
/*
|
|
||||||
** ==== Wrapper around GCC builtins for ====
|
|
||||||
** ==== arbitrarily large sized bitfields ====
|
|
||||||
**
|
|
||||||
** todo
|
|
||||||
** - up and down iterator
|
|
||||||
**
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
|
||||||
** Turn bit on
|
|
||||||
*/
|
|
||||||
extern inline void bitfield_biton(t_bitblock field[], uint64_t bit)
|
|
||||||
{
|
|
||||||
field[bit / BLOCKSIZE + 1] |= (1 << (bit % BLOCKSIZE));
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
** Turn bit off
|
|
||||||
*/
|
|
||||||
extern inline void bitfield_bitoff(t_bitblock field[], uint64_t bit)
|
|
||||||
{
|
|
||||||
field[bit / BLOCKSIZE + 1] &= ~(1 << bit % BLOCKSIZE);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
** Least Significant Bit (rightmost)
|
|
||||||
*/
|
|
||||||
extern inline uint64_t bitfield_lsb(t_bitblock field[])
|
|
||||||
{
|
|
||||||
int block;
|
|
||||||
uint64_t size;
|
|
||||||
|
|
||||||
block = 0;
|
|
||||||
size = field[0];
|
|
||||||
while (!field[++block])
|
|
||||||
if ((block+1) * BLOCKSIZE > size) return (-1);
|
|
||||||
return (block * BLOCKSIZE + __builtin_ctzll(field[block] ^ (~field[block] + 1)) - 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
** Count the number of 1-bits in field
|
|
||||||
*/
|
|
||||||
extern inline uint64_t bitfield_popcount(t_bitblock field[], uint64_t size)
|
|
||||||
{
|
|
||||||
int block = -1;
|
|
||||||
int count = 0;
|
|
||||||
|
|
||||||
while (++block * BLOCKSIZE < size)
|
|
||||||
count += __builtin_popcountll(field[block]);
|
|
||||||
return (count);
|
|
||||||
}
|
|
||||||
|
|
@ -12,20 +12,19 @@
|
||||||
|
|
||||||
#include "net.h"
|
#include "net.h"
|
||||||
|
|
||||||
unsigned short cksum(void *b, int len)
|
unsigned short cksum(const void *b, size_t len)
|
||||||
{
|
{
|
||||||
unsigned short *buf;
|
|
||||||
unsigned int sum;
|
unsigned int sum;
|
||||||
|
|
||||||
buf = b;
|
|
||||||
sum = 0;
|
sum = 0;
|
||||||
while (len > 1)
|
while (len > 1)
|
||||||
{
|
{
|
||||||
sum += *((unsigned short*)buf++);
|
sum += *((uint16_t*)b++);
|
||||||
|
b++;
|
||||||
len -= 2;
|
len -= 2;
|
||||||
}
|
}
|
||||||
if (len == 1)
|
if (len == 1)
|
||||||
sum += *(unsigned char*)buf;
|
sum += *(uint8_t*)b;
|
||||||
sum = (sum >> 16) + (sum & 0xFFFF);
|
while (sum >> 16) sum = (sum & 0xFFFF)+(sum >> 16);
|
||||||
return (~(sum + (sum >> 16)));
|
return (~sum);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -35,6 +35,38 @@ enum packet_type {
|
||||||
stp
|
stp
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* List of available colors
|
||||||
|
*/
|
||||||
|
static const char *colors[] = {
|
||||||
|
/// Black
|
||||||
|
"\\e[0;30m",
|
||||||
|
/// Red
|
||||||
|
"\\e[0;31m",
|
||||||
|
/// Green
|
||||||
|
"\\e[0;32m",
|
||||||
|
/// Yellow
|
||||||
|
"\\e[0;33m",
|
||||||
|
/// Blue
|
||||||
|
"\\e[0;34m",
|
||||||
|
/// Purple
|
||||||
|
"\\e[0;35m",
|
||||||
|
/// Cyan
|
||||||
|
"\\e[0;36m",
|
||||||
|
/// White
|
||||||
|
"\\e[0;37m",
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Default terminal rows
|
||||||
|
*/
|
||||||
|
static const int rows = 24;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Default terminal columns
|
||||||
|
*/
|
||||||
|
static const int cols = 80;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** Packets disassembling loop
|
** Packets disassembling loop
|
||||||
** layer 2: isl, llc1, llc2, ethenet or payload
|
** layer 2: isl, llc1, llc2, ethenet or payload
|
||||||
|
|
@ -115,11 +147,22 @@ static inline void field_print (const char *packet_buffer, int field_size,
|
||||||
int *counter, const char *field_text) {
|
int *counter, const char *field_text) {
|
||||||
|
|
||||||
char *tmp_hexstr = raw_to_hexstr(packet_buffer + *counter, field_size);
|
char *tmp_hexstr = raw_to_hexstr(packet_buffer + *counter, field_size);
|
||||||
*counter += field_size;
|
|
||||||
|
|
||||||
printf(" %-24s %s\n", tmp_hexstr, field_text);
|
printf(" %-24s %s", tmp_hexstr, field_text);
|
||||||
|
if (strstr(field_text, "port") && field_size == 2)
|
||||||
|
{
|
||||||
|
short port = *(short*)(packet_buffer + *counter);
|
||||||
|
char service[20];
|
||||||
|
struct sockaddr sa;
|
||||||
|
|
||||||
|
((struct sockaddr_in *)&sa)->sin_family = AF_INET;
|
||||||
|
((struct sockaddr_in *)&sa)->sin_port = port;
|
||||||
|
getnameinfo(&sa, sizeof sa, NULL, 0, service, sizeof service, 0);
|
||||||
|
printf(" (%s)", service);
|
||||||
|
}
|
||||||
|
printf("\n");
|
||||||
free(tmp_hexstr);
|
free(tmp_hexstr);
|
||||||
|
*counter += field_size;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -163,10 +206,13 @@ void payload_print (const char *packet_buffer, int size) {
|
||||||
* @param packet_buffer raw packet captured from the network, starting at the part to process
|
* @param packet_buffer raw packet captured from the network, starting at the part to process
|
||||||
* @param size packet_buffer size
|
* @param size packet_buffer size
|
||||||
*/
|
*/
|
||||||
void tcp_print (const char *packet_buffer, int size) {
|
void tcp_print(const char *packet_buffer, int size) {
|
||||||
int counter = 0;
|
int counter = 0;
|
||||||
|
unsigned short check = cksum(packet_buffer, 20);
|
||||||
puts("\nTCP Header:");
|
if (check == 0)
|
||||||
|
printf("\nTCP Header: (20 bytes), cksum OK\n");
|
||||||
|
else
|
||||||
|
printf("\nTCP Header: (20 bytes), cksum incorrect, malformed packet! (%x)\n", check);
|
||||||
|
|
||||||
if (size < 8) {
|
if (size < 8) {
|
||||||
puts (" invalid header size");
|
puts (" invalid header size");
|
||||||
|
|
@ -197,7 +243,7 @@ void tcp_print (const char *packet_buffer, int size) {
|
||||||
void udp_print (const char *packet_buffer, int size) {
|
void udp_print (const char *packet_buffer, int size) {
|
||||||
int counter = 0;
|
int counter = 0;
|
||||||
|
|
||||||
puts("\nUDP Header:");
|
puts("\nUDP Header: (8 bytes)");
|
||||||
|
|
||||||
if (size < 8) {
|
if (size < 8) {
|
||||||
puts (" invalid header size");
|
puts (" invalid header size");
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,8 @@ void tcp_hdrinit(struct tcphdr *header)
|
||||||
memset(header, 0, sizeof(*header));
|
memset(header, 0, sizeof(*header));
|
||||||
header->th_sport = htons(0);
|
header->th_sport = htons(0);
|
||||||
header->th_dport = htons(0);
|
header->th_dport = htons(0);
|
||||||
header->th_seq = epoch_micro();
|
/* header->th_seq = epoch_micro(); */
|
||||||
|
header->th_seq = 0;
|
||||||
header->th_ack = 0;
|
header->th_ack = 0;
|
||||||
header->th_off = 5;
|
header->th_off = 5;
|
||||||
header->th_flags = 0;
|
header->th_flags = 0;
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "mytime.h"
|
#include "ft_time.h"
|
||||||
|
|
||||||
uint64_t epoch_micro(void)
|
uint64_t epoch_micro(void)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
36
nmap/srcs/capture.c
Normal file
36
nmap/srcs/capture.c
Normal file
|
|
@ -0,0 +1,36 @@
|
||||||
|
|
||||||
|
#include "nmap.h"
|
||||||
|
|
||||||
|
#define PCAP_FILTER "src host %s and src port %i and dst host %s and dst port %i"
|
||||||
|
|
||||||
|
pcap_t *nmap_capture(ipaddr dst, ipaddr src)
|
||||||
|
{
|
||||||
|
char errbuf[PCAP_ERRBUF_SIZE];
|
||||||
|
pcap_t *handle;
|
||||||
|
bpf_u_int32 netp;
|
||||||
|
bpf_u_int32 maskp;
|
||||||
|
char buf[IPADDR_MAXSTRLEN];
|
||||||
|
struct bpf_program fp;
|
||||||
|
char str[100];
|
||||||
|
|
||||||
|
if (pcap_lookupnet("any", &netp, &maskp, errbuf) == -1)
|
||||||
|
{
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
if (!(handle = pcap_open_live("any", BUFSIZ, 0, -1, errbuf)))
|
||||||
|
{
|
||||||
|
fprintf(stderr, "pcap_open_live: %s", errbuf);
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
if (pcap_setdirection(handle, PCAP_D_IN))
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
if (!(sprintf(str, PCAP_FILTER, ipaddrstr(dst, buf), ipport(dst),
|
||||||
|
ipaddrstr(src, buf), ipport(src))))
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
DG("filter is: %s", str);
|
||||||
|
if (pcap_compile(handle, &fp, str, 1, netp) == -1)
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
if (pcap_setfilter(handle, &fp) == -1)
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
return (handle);
|
||||||
|
}
|
||||||
|
|
@ -38,5 +38,5 @@ void nmap_format(chan results)
|
||||||
g_port_status[result.status],
|
g_port_status[result.status],
|
||||||
result.scan);
|
result.scan);
|
||||||
}
|
}
|
||||||
printf("finished reading %i jobs\n", g_njobs);
|
DG("finished reading %i jobs\n", g_njobs);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,70 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* listener.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2017/10/23 19:16:39 by jhalford #+# #+# */
|
|
||||||
/* Updated: 2017/10/24 21:28:44 by jhalford ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "nmap.h"
|
|
||||||
|
|
||||||
#define PCAP_FILTER\
|
|
||||||
"src host %s and src port %i and dst host %s and dst port %i"
|
|
||||||
|
|
||||||
static void packet_callback(u_char *arg, const struct pcap_pkthdr *pkthdr,
|
|
||||||
const u_char *packet)
|
|
||||||
|
|
||||||
{
|
|
||||||
(void)pkthdr;
|
|
||||||
(void)packet;
|
|
||||||
chan ch = (chan)arg;
|
|
||||||
ft_printf("received packet !!!\n");
|
|
||||||
prettypacket((void*)packet, pkthdr->len);
|
|
||||||
(void)ch;
|
|
||||||
/* chs(ch, struct tcphdr, *(t_tcp_packet*)packet); */
|
|
||||||
}
|
|
||||||
|
|
||||||
coroutine void listener_loop(chan ch, pcap_t *pcap_obj)
|
|
||||||
{
|
|
||||||
ft_printf("listener loop\n");
|
|
||||||
if (pcap_loop(pcap_obj, -1, packet_callback, (u_char*)ch) == -1)
|
|
||||||
{
|
|
||||||
ft_printf("pcap_loop fail\n");
|
|
||||||
exit(EXIT_FAILURE);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
chan nmap_listener(ipaddr dst, ipaddr src)
|
|
||||||
{
|
|
||||||
char errbuf[PCAP_ERRBUF_SIZE];
|
|
||||||
pcap_t *pcap_obj;
|
|
||||||
bpf_u_int32 netp;
|
|
||||||
bpf_u_int32 maskp;
|
|
||||||
struct bpf_program fp;
|
|
||||||
char str[100];
|
|
||||||
chan pkts;
|
|
||||||
|
|
||||||
pkts = chmake(struct tcphdr, 10);
|
|
||||||
if (pcap_lookupnet("any", &netp, &maskp, errbuf) == -1)
|
|
||||||
{
|
|
||||||
exit(EXIT_FAILURE);
|
|
||||||
}
|
|
||||||
if (!(pcap_obj = pcap_open_live("any", BUFSIZ, 0, -1, errbuf)))
|
|
||||||
{
|
|
||||||
fprintf(stderr, "pcap_open_live: %s", errbuf);
|
|
||||||
exit(EXIT_FAILURE);
|
|
||||||
}
|
|
||||||
if (!(sprintf(str, PCAP_FILTER, ipaddrstr(dst, str), ipport(dst),
|
|
||||||
ipaddrstr(src, str), ipport(src))))
|
|
||||||
exit(EXIT_FAILURE);
|
|
||||||
if (pcap_compile(pcap_obj, &fp, str, 1, netp) == -1)
|
|
||||||
exit(EXIT_FAILURE);
|
|
||||||
if (pcap_setfilter(pcap_obj, &fp) == -1)
|
|
||||||
exit(EXIT_FAILURE);
|
|
||||||
go(listener_loop(pkts, pcap_obj));
|
|
||||||
return (chdup(pkts));
|
|
||||||
}
|
|
||||||
|
|
@ -24,9 +24,11 @@ coroutine void jobs_loop(chan jobs, chan results)
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
i = 0;
|
i = 0;
|
||||||
while (true)
|
while (1)
|
||||||
{
|
{
|
||||||
|
DG("before chr jobs");
|
||||||
job = chr(jobs, t_job);
|
job = chr(jobs, t_job);
|
||||||
|
DG("after chr jobs");
|
||||||
if (job.scan == NULL)
|
if (job.scan == NULL)
|
||||||
break ;
|
break ;
|
||||||
copy = chdup(results);
|
copy = chdup(results);
|
||||||
|
|
@ -52,15 +54,10 @@ int main(int ac, char **av)
|
||||||
|
|
||||||
/* if (getuid() != 0) */
|
/* if (getuid() != 0) */
|
||||||
/* { */
|
/* { */
|
||||||
/* fprintf(stderr, "You must have root privileges to use nmap!\n"); */
|
/* fprintf(stderr, "You must have root privileges to use nmap\n"); */
|
||||||
/* return(1); */
|
/* return(1); */
|
||||||
/* } */
|
/* } */
|
||||||
if ((jobs = nmap_parse(ac, av)) < 0)
|
jobs = nmap_parse(ac, av);
|
||||||
{
|
|
||||||
printf("usage: nmap --help\n");
|
|
||||||
printf("or nmap"NMAP_USAGE1 NMAP_USAGE2"\n");
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
results = nmap(jobs);
|
results = nmap(jobs);
|
||||||
nmap_format(results);
|
nmap_format(results);
|
||||||
return (0);
|
return (0);
|
||||||
|
|
|
||||||
|
|
@ -108,10 +108,11 @@ coroutine void coarse_dispatcher(chan jobs)
|
||||||
|
|
||||||
job.dest = ipremote("scanme.nmap.org", 80, IPADDR_IPV4, -1);
|
job.dest = ipremote("scanme.nmap.org", 80, IPADDR_IPV4, -1);
|
||||||
chs(jobs, t_job, job);
|
chs(jobs, t_job, job);
|
||||||
job.dest = ipremote("scanme.nmap.org", 81, IPADDR_IPV4, -1);
|
/* job.dest = ipremote("scanme.nmap.org", 81, IPADDR_IPV4, -1); */
|
||||||
chs(jobs, t_job, job);
|
/* chs(jobs, t_job, job); */
|
||||||
|
|
||||||
job.scan = 0;
|
job.scan = 0;
|
||||||
|
DG("sending done job");
|
||||||
chdone(jobs, t_job, job);
|
chdone(jobs, t_job, job);
|
||||||
chclose(jobs);
|
chclose(jobs);
|
||||||
}
|
}
|
||||||
|
|
@ -127,8 +128,11 @@ chan nmap_parse(int ac, char **av)
|
||||||
|
|
||||||
chan jobs;
|
chan jobs;
|
||||||
jobs = chmake(t_job, 0);
|
jobs = chmake(t_job, 0);
|
||||||
go(coarse_dispatcher(jobs));
|
|
||||||
g_njobs = 2;
|
|
||||||
|
|
||||||
return (jobs);
|
/* ft_usage("nmap"NMAP_USAGE1 NMAP_USAGE2); */
|
||||||
|
|
||||||
|
go(coarse_dispatcher(jobs));
|
||||||
|
g_njobs = 1;
|
||||||
|
|
||||||
|
return (chdup(jobs));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -15,13 +15,17 @@
|
||||||
coroutine void nmap_scan_tcp(chan results, t_job job)
|
coroutine void nmap_scan_tcp(chan results, t_job job)
|
||||||
{
|
{
|
||||||
t_result result;
|
t_result result;
|
||||||
chan pkts;
|
|
||||||
ipaddr src;
|
ipaddr src;
|
||||||
int sock;
|
int sock;
|
||||||
|
|
||||||
sock = socket(ipfamily(job.dest), SOCK_STREAM, IPPROTO_TCP);
|
sock = socket(ipfamily(job.dest), SOCK_STREAM, IPPROTO_TCP);
|
||||||
src = iplocal_randport(NULL, ipmode(job.dest), sock);
|
src = iplocal_randport(NULL, ipmode(job.dest), sock);
|
||||||
pkts = nmap_listener(job.dest, src);
|
|
||||||
|
pcap_t *handle = nmap_capture(job.dest, src);
|
||||||
|
/* chan pkts; */
|
||||||
|
/* pkts = nmap_listener(job.dest, src); */
|
||||||
|
/* (void)pkts; */
|
||||||
|
/* DG("after listener"); */
|
||||||
|
|
||||||
result.dest = job.dest;
|
result.dest = job.dest;
|
||||||
ft_strcpy(result.scan, "TCP");
|
ft_strcpy(result.scan, "TCP");
|
||||||
|
|
@ -32,16 +36,25 @@ coroutine void nmap_scan_tcp(chan results, t_job job)
|
||||||
tcp_hdrinit(&pkt);
|
tcp_hdrinit(&pkt);
|
||||||
pkt.th_dport = htons(ipport(job.dest));
|
pkt.th_dport = htons(ipport(job.dest));
|
||||||
pkt.th_sport = htons(ipport(src));
|
pkt.th_sport = htons(ipport(src));
|
||||||
/* pkt.th_flags = 0; */
|
pkt.th_flags = 0;
|
||||||
pkt.th_sum = cksum(&pkt, sizeof(pkt));
|
pkt.th_sum = cksum(&pkt, sizeof(pkt));
|
||||||
|
|
||||||
if (sendto(sock, &pkt, sizeof(pkt), 0,
|
tcp_print((char *)&pkt, sizeof(pkt));
|
||||||
(struct sockaddr*)&job.dest, sizeof(job.dest)) < 0)
|
|
||||||
|
// REQ
|
||||||
|
DG("check");
|
||||||
|
if (sendto(sock, &pkt, sizeof(pkt), 0, (struct sockaddr*)&job.dest, sizeof(job.dest)) < 0)
|
||||||
{
|
{
|
||||||
|
DG("check 1");
|
||||||
perror("sendto");
|
perror("sendto");
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
pkt = chr(pkts, struct tcphdr);
|
DG("check 2");
|
||||||
|
|
||||||
|
// RESP
|
||||||
|
struct pcap_pkthdr pkthdr;
|
||||||
|
const u_char *resp;
|
||||||
|
resp = pcap_next(handle, &pkthdr);
|
||||||
|
tcp_print((char *)resp, pkthdr.len);
|
||||||
|
|
||||||
chs(results, t_result, result);
|
chs(results, t_result, result);
|
||||||
chclose(results);
|
chclose(results);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue