From 9a446154fa1a82c83372b133aaf220c5bd552c30 Mon Sep 17 00:00:00 2001 From: rafael-santiago Date: Wed, 20 Sep 2023 23:12:20 -0300 Subject: [PATCH] Implement maddaddy task --- README.md | 4 +- src/cmd/macgonuts_exec.c | 2 + src/cmd/macgonuts_maddaddy_task.c | 400 ++++++++++++++++++++++++++++++ src/cmd/macgonuts_maddaddy_task.h | 17 ++ 4 files changed, 421 insertions(+), 2 deletions(-) create mode 100644 src/cmd/macgonuts_maddaddy_task.c create mode 100644 src/cmd/macgonuts_maddaddy_task.h diff --git a/README.md b/README.md index fd7c090..43fc311 100644 --- a/README.md +++ b/README.md @@ -38,8 +38,8 @@ red teams. *Once it stated, when using this tool you are assuming that any damag law infringements that some wrong action taken by you could cause is of your entire responsibility*. **Sponsoring**: I have not been running this project for profit. It is only a thing that I do at my spare time. It is a -weekend project. I try to evolve it according to necessities I have been facing up during my information security -professional career. If you liked it or it is being useful to you somehow and you really want to contribute +weekend project. A pet project. I try to evolve it according to necessities I have been facing up during my information +security professional career. If you liked it or it is being useful to you somehow and you really want to contribute with money, try to redirect it to a local charity institution, an ONG of your choice or even your own community. You can also do [pull requests](https://github.com/rafael-santiago/macgonuts/pulls) proposing improvements. Do some [bug report](https://github.com/rafael-santiago/macgonuts/issues) if a bug is annoying you. Maybe you should diff --git a/src/cmd/macgonuts_exec.c b/src/cmd/macgonuts_exec.c index c48864b..6486929 100644 --- a/src/cmd/macgonuts_exec.c +++ b/src/cmd/macgonuts_exec.c @@ -17,6 +17,7 @@ #include #include #include +#include #include #include #include @@ -49,6 +50,7 @@ struct macgonuts_task_ctx { MACGONUTS_CMD_REGISTER_TASK(dnsspoof), MACGONUTS_CMD_REGISTER_TASK(xablau), MACGONUTS_CMD_REGISTER_TASK(caleaboqui), + MACGONUTS_CMD_REGISTER_TASK(maddaddy), MACGONUTS_CMD_REGISTER_TASK_ALIAS(xablau, neighscan), MACGONUTS_CMD_REGISTER_TASK_ALIAS(caleaboqui, shh), MACGONUTS_CMD_REGISTER_TASK(version), diff --git a/src/cmd/macgonuts_maddaddy_task.c b/src/cmd/macgonuts_maddaddy_task.c new file mode 100644 index 0000000..e30c80b --- /dev/null +++ b/src/cmd/macgonuts_maddaddy_task.c @@ -0,0 +1,400 @@ +/* + * Copyright (c) 2023, Rafael Santiago + * All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. + */ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +static int g_QuitMadDaddy = 0; + +static int do_mad_daddy(const char *iface, const uint8_t *hw_addrs, const size_t hw_addrs_size); + +static inline __attribute__((unused)) int send_fake_na(const macgonuts_socket_t rsk, + const uint8_t *ethbuf, const ssize_t ethbuf_size); + +static void sigint_watchdog(int signo); + +static uint8_t *preprocess_targets_array(char **targets, const size_t targets_nr, size_t *macs_buf_size); + +static uint8_t *preprocess_targets_array(char **targets, const size_t targets_nr, size_t *macs_buf_size); + +static inline int is_solicited_node_multicast_link(const uint8_t *ethbuf, const ssize_t ethbuf_size); + +static inline int is_solicited_node_multicast_proto(const uint8_t *ethbuf, const ssize_t ethbuf_size); + +static inline int is_ndp_ns(const uint8_t *ethbuf, const ssize_t ethbuf_size); + +static inline int should_dad_go_bad(const uint8_t *ethbuf, const ssize_t ethbuf_size, + const uint8_t *hw_addrs, const size_t hw_addrs_size); + +int macgonuts_maddaddy_task(void) { + int err = EXIT_FAILURE; + const char *lo_iface = macgonuts_get_option("lo-iface", NULL); + char **targets = NULL; + size_t targets_nr = 0; + uint8_t *hw_addrs = NULL; + size_t hw_addrs_size = 0; + + if (lo_iface == NULL) { + macgonuts_si_error("--lo-iface option is missing.\n"); + goto macgonuts_maddaddy_task_epilogue; + } + + targets = macgonuts_get_array_option("targets", NULL, &targets_nr); + if (targets != NULL) { + hw_addrs = preprocess_targets_array(targets, targets_nr, &hw_addrs_size); + macgonuts_free_array_option_value(targets, targets_nr); + targets = NULL; + } + + err = do_mad_daddy(lo_iface, hw_addrs, hw_addrs_size); + +macgonuts_maddaddy_task_epilogue: + + if (hw_addrs != NULL) { + free(hw_addrs); + } + + if (targets != NULL) { + macgonuts_free_array_option_value(targets, targets_nr); + } + + return err; +} + +int macgonuts_maddaddy_task_help(void) { + macgonuts_si_print("use: macgonuts maddady --lo-iface=