From 0ad866c550c5460700bfa904c375ac153a2579b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-Michel=20Vourg=C3=A8re?= Date: Fri, 11 Jul 2014 17:39:04 +0200 Subject: [PATCH 1/2] Added option to force a different mac address Occasionally, a random address can be the same as the previous one. That patch adds a --different option that will try again if the we are unlucky enough to get a random one that is the same one. Some distributions such as tails are paranoid enough not to trust the exit code and will take drastic measures if macchange doesn't actually change the mac address. That option should help them. --- doc/macchanger.texi | 7 +++++++ macchanger.1 | 4 ++++ src/main.c | 26 ++++++++++++++++++++------ 3 files changed, 31 insertions(+), 6 deletions(-) diff --git a/doc/macchanger.texi b/doc/macchanger.texi index 60f0191..ee1074a 100644 --- a/doc/macchanger.texi +++ b/doc/macchanger.texi @@ -138,6 +138,13 @@ Change the MAC address setting a random vendor MAC of any kind. @cindex @code{--random} Set fully random MAC address: Any kind and any vendor. +@item -d +@cindex @code{-d} +@itemx --different +@cindex @code{--different} +Make sure the random MAC address is different from last one. That option must +be used with either -e, -a, -A, or -r. + @item -p @cindex @code{-p} @itemx --permanent diff --git a/macchanger.1 b/macchanger.1 index cac1c5e..2f2cc89 100644 --- a/macchanger.1 +++ b/macchanger.1 @@ -60,6 +60,10 @@ Set random vendor MAC of any kind. .B \-r, \-\-random Set fully random MAC. .TP +.B \-d, \-\-different +Make sure the random MAC address is different from last one. That option must +be used with either \-e, \-a, \-A, or \-r. +.TP .B \-p, \-\-permanent Reset MAC address to its original, permanent hardware value. .TP diff --git a/src/main.c b/src/main.c index 711ffe7..a1abe17 100644 --- a/src/main.c +++ b/src/main.c @@ -58,7 +58,8 @@ print_help (void) " -r, --random Set fully random MAC\n" " -l, --list[=keyword] Print known vendors\n" " -b, --bia Pretend to be a burned-in-address\n" - " -m, --mac=XX:XX:XX:XX:XX:XX Set the MAC XX:XX:XX:XX:XX:XX\n\n" + " -m, --mac=XX:XX:XX:XX:XX:XX Set the MAC XX:XX:XX:XX:XX:XX\n" + " -d, --different Make sure the random MAC address is different\n\n" "Report bugs to https://github.com/alobbs/macchanger/issues\n"); } @@ -120,6 +121,7 @@ main (int argc, char *argv[]) char print_list = 0; char show = 0; char set_bia = 0; + char different = 0; char *set_mac = NULL; char *search_word = NULL; @@ -135,6 +137,7 @@ main (int argc, char *argv[]) {"show", no_argument, NULL, 's'}, {"another_any", no_argument, NULL, 'A'}, {"bia", no_argument, NULL, 'b'}, + {"different", no_argument, NULL, 'd'}, {"list", optional_argument, NULL, 'l'}, {"mac", required_argument, NULL, 'm'}, {NULL, 0, NULL, 0} @@ -149,7 +152,7 @@ main (int argc, char *argv[]) int ret; /* Read the parameters */ - while ((val = getopt_long (argc, argv, "VasAbrephlm:", long_options, NULL)) != -1) { + while ((val = getopt_long (argc, argv, "VasAbrepdhlm:", long_options, NULL)) != -1) { switch (val) { case 'V': printf ("GNU MAC changer %s\n" @@ -185,6 +188,9 @@ main (int argc, char *argv[]) case 'p': permanent = 1; break; + case 'd': + different = 1; + break; case 'm': set_mac = optarg; break; @@ -244,16 +250,24 @@ main (int argc, char *argv[]) exit (EXIT_ERROR); } } else if (random) { - mc_mac_random (mac_faked, 6, set_bia); + do + mc_mac_random (mac_faked, 6, set_bia); + while (different && mc_mac_equal (mac, mac_faked)); } else if (ending) { - mc_mac_random (mac_faked, 3, 1); + do + mc_mac_random (mac_faked, 3, 1); + while (different && mc_mac_equal (mac, mac_faked)); } else if (another_same) { val = mc_maclist_is_wireless (mac); mc_maclist_set_random_vendor (mac_faked, val); - mc_mac_random (mac_faked, 3, 1); + do + mc_mac_random (mac_faked, 3, 1); + while (different && mc_mac_equal (mac, mac_faked)); } else if (another_any) { mc_maclist_set_random_vendor(mac_faked, mac_is_anykind); - mc_mac_random (mac_faked, 3, 1); + do + mc_mac_random (mac_faked, 3, 1); + while (different && mc_mac_equal (mac, mac_faked)); } else if (permanent) { mac_faked = mc_mac_dup (mac_permanent); } else { From 5e251be1570ec5cf2b101a50b5474981b40c03d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-Michel=20Vourg=C3=A8re?= Date: Fri, 11 Jul 2014 18:00:08 +0200 Subject: [PATCH 2/2] Exit with an error if required change failed Use the MAC address reading at the end as a double check. --- src/main.c | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/src/main.c b/src/main.c index a1abe17..97b61c1 100644 --- a/src/main.c +++ b/src/main.c @@ -274,20 +274,26 @@ main (int argc, char *argv[]) exit (EXIT_OK); /* default to show */ } - /* Set the new MAC */ - ret = mc_net_info_set_mac (net, mac_faked); - if (ret == 0) { - /* Re-read the MAC */ - mc_mac_free (mac_faked); - mac_faked = mc_net_info_get_mac(net); - - /* Print it */ - print_mac ("New MAC: ", mac_faked); - - /* Is the same MAC? */ - if (mc_mac_equal (mac, mac_faked)) { - printf ("It's the same MAC!!\n"); + if (!mc_mac_equal (mac, mac_faked)) { + /* Set the new MAC */ + ret = mc_net_info_set_mac (net, mac_faked); + if (ret == 0) { + /* Re-read the MAC */ + mc_mac_free (mac_faked); + mac_faked = mc_net_info_get_mac(net); + + /* Print it */ + print_mac ("New MAC: ", mac_faked); + + /* Is the same MAC? */ + if (mc_mac_equal (mac, mac_faked)) { + printf ("It's the same MAC!!\n"); + exit (EXIT_ERROR); + } } + } else { + // No change required + ret = 0; } /* Memory free */