Skip to content

Commit

Permalink
Implement maddaddy task
Browse files Browse the repository at this point in the history
  • Loading branch information
rafael-santiago committed Sep 18, 2023
1 parent 9b05a8a commit 01d1a1f
Show file tree
Hide file tree
Showing 4 changed files with 140 additions and 2 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions src/cmd/macgonuts_exec.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include <cmd/macgonuts_dnsspoof_task.h>
#include <cmd/macgonuts_xablau_task.h>
#include <cmd/macgonuts_caleaboqui_task.h>
#include <cmd/macgonuts_maddaddy_task.h>
#include <cmd/macgonuts_version_task.h>
#include <cmd/macgonuts_banners.h>
#include <macgonuts_status_info.h>
Expand Down Expand Up @@ -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),
Expand Down
119 changes: 119 additions & 0 deletions src/cmd/macgonuts_maddaddy_task.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
/*
* 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 <cmd/macgonuts_maddaddy_task.h>
#include <cmd/macgonuts_option.h>
#include <macgonuts_etherconv.h>
#include <macgonuts_socket_common.h>
#include <macgonuts_status_info.h>

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 __attribute__((unused)) int send_fake_na(const macgonuts_socket_t rsk, const uint8_t *hw_addr);

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);

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=<label> [ --targets=<hw-addr-list> ]\n");
return EXIT_SUCCESS;
}

static int do_mad_daddy(const char *iface, const uint8_t *hw_addrs, const size_t hw_addrs_size) {
char buf[256];

if (macgonuts_get_addr_from_iface_unix(buf, sizeof(buf) - 1, 6, iface) != EXIT_SUCCESS) {
macgonuts_si_error("interface `%s` does not support IPv6.\n");
return EXIT_FAILURE;
}

signal(SIGINT, sigint_watchdog);
signal(SIGTERM, sigint_watchdog);

// TODO(Rafael): - Sniff network.
// - If hw_addrs is not null inspect relevant packets for relevant MAC address.
// - Being a NS send a fake NA.

return EXIT_SUCCESS;
}

static void sigint_watchdog(int signo) {
g_QuitMadDaddy = 1;
}

static int send_fake_na(const macgonuts_socket_t rsk, const uint8_t *hw_addr) {
return EXIT_FAILURE;
}

static uint8_t *preprocess_targets_array(char **targets, const size_t targets_nr, size_t *macs_buf_size) {
char **target = targets;
char **targets_end = targets + targets_nr;
uint8_t *macs_buf = NULL;
uint8_t *mp = NULL;

*macs_buf_size = targets_nr * 6;
macs_buf = (uint8_t *)malloc(*macs_buf_size);

if (macs_buf == NULL) {
macgonuts_si_error("unable to allocate MAC bufs list.\n");
return NULL;
}

mp = macs_buf;

while (target != targets_end) {
if (macgonuts_get_raw_ether_addr(mp, 6, *target, strlen(*target)) != EXIT_SUCCESS) {
macgonuts_si_error("unable to pre-process MAC `%s`.\n", *target);
free(macs_buf);
return NULL;
}
target++;
mp += 6;
}

return macs_buf;
}
17 changes: 17 additions & 0 deletions src/cmd/macgonuts_maddaddy_task.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
* 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.
*/
#ifndef MACGONUTS_CMD_MACGONUTS_MADDADDY_TASK_H
#define MACGONUTS_CMD_MACGONUTS_MADDADDY_TASK_H 1

#include <macgonuts_types.h>

int macgonuts_maddaddy_task(void);

int macgonuts_maddaddy_task_help(void);

#endif // MACGONUTS_CMD_MACGONUTS_MADDADDY_TASK_H

0 comments on commit 01d1a1f

Please sign in to comment.