From c7c176394ad2b87f56b0aed2731eb9dde29750f0 Mon Sep 17 00:00:00 2001 From: Matteo Croce Date: Tue, 21 Aug 2018 16:38:09 +0200 Subject: mausezahn: improve random mac address generation Modify -b option to generate all random MAC addresses. Improve the random generation algorithm, use nrand48() which fills the ethernet address in two calls instead of six calls to rand() and six floating point calculations. Set the locally administered bit of generated MAC addresses. Signed-off-by: Matteo Croce Signed-off-by: Tobias Klauser --- mausezahn.8 | 10 ++++------ staging/mausezahn.c | 1 + staging/modifications.c | 39 +++++++++++---------------------------- staging/mz.h | 6 +++--- staging/send_eth.c | 16 +++++++++++++--- staging/tools.c | 8 +------- 6 files changed, 33 insertions(+), 47 deletions(-) diff --git a/mausezahn.8 b/mausezahn.8 index 1ad7667..44a76ab 100644 --- a/mausezahn.8 +++ b/mausezahn.8 @@ -105,18 +105,16 @@ higher layer packets the number of additional padding bytes are specified. .PP .SS -a Use specified source MAC address with hexadecimal notation such as 00:00:aa:bb:cc:dd. -By default the interface MAC address will be used. The keywords ''rand'' and - ''own'' refer to a random MAC address (only unicast addresses are created) +By default the interface MAC address will be used. The keywords ''rand'' and ''own'' +refer to a random MAC address (only unicast addresses are created) and the own address, respectively. You can also use the keywords mentioned below although broadcast-type source addresses are officially invalid. .PP .SS -b Use specified destination MAC address. By default, a broadcast is sent in raw layer 2 mode or to the destination hosts or gateway interface MAC address in normal -(IP) mode. You can use the same keywords as mentioned above, as well as - ''bc'' or ''bcast'', ''cisco'', and ''stp''. Please note that for the destination -MAC address the ''rand'' keyword is supported but creates a random address only -once, even when you send multiple packets. +(IP) mode. You can use the same keywords as mentioned above, as well as ''bc'' +or ''bcast'', ''cisco'', and ''stp''. .PP .SS -A Use specified source IP address, default is own interface address. Optionally, the diff --git a/staging/mausezahn.c b/staging/mausezahn.c index d3d037b..80bfe7d 100644 --- a/staging/mausezahn.c +++ b/staging/mausezahn.c @@ -339,6 +339,7 @@ int reset(void) // Initialize random generator time(&t); srand((unsigned int)t); + srand48(t); // Reset device_list for (i=0; i use normal 'l' context: { - if (eth_src_rand) update_Eth_SA(l, t); + if (eth_dst_rand) rand_addr(tx.eth_dst); + if (eth_src_rand) rand_addr(tx.eth_src); + t = libnet_build_ethernet (tx.eth_dst, + tx.eth_src, + tx.eth_type, + NULL, + 0, + l, + t); if (verbose) (void) print_frame_details(); libnet_write(l); } diff --git a/staging/tools.c b/staging/tools.c index 72445b6..f7c4131 100644 --- a/staging/tools.c +++ b/staging/tools.c @@ -687,15 +687,9 @@ int check_eth_mac_txt(int src_or_dst) // Okay, lets check the commandline argument: // // Do you want a random MAC? - // TODO: Consider enforcement of unicast addresses if (strncmp(eth_mac_txt, "rand", 4)==0) { - eth_mac[0] = (u_int8_t) ( ((float) rand()/RAND_MAX)*256); - eth_mac[1] = (u_int8_t) ( ((float) rand()/RAND_MAX)*256); - eth_mac[2] = (u_int8_t) ( ((float) rand()/RAND_MAX)*256); - eth_mac[3] = (u_int8_t) ( ((float) rand()/RAND_MAX)*256); - eth_mac[4] = (u_int8_t) ( ((float) rand()/RAND_MAX)*256); - eth_mac[5] = (u_int8_t) ( ((float) rand()/RAND_MAX)*256); + rand_addr(eth_mac); *eth_rand = 1; } // Do you want your own interface MAC? -- cgit v1.2.3-54-g00ecf