Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 344311 - net-analyzer/macchanger: pseudo-random MAC address generation is too weak
Summary: net-analyzer/macchanger: pseudo-random MAC address generation is too weak
Status: RESOLVED UPSTREAM
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: Current packages (show other bugs)
Hardware: All Linux
: High normal (vote)
Assignee: Robin Johnson
URL:
Whiteboard:
Keywords: PATCH
Depends on: 496504
Blocks:
  Show dependency tree
 
Reported: 2010-11-05 19:28 UTC by Faustus
Modified: 2014-02-02 20:06 UTC (History)
3 users (show)

See Also:
Package list:
Runtime testing required: ---


Attachments
Find out when a MAC address was faked with macchanger (mac-attack.c,1.94 KB, text/plain)
2010-11-05 20:42 UTC, Faustus
Details
Use /dev/urandom when available (macchanger-1.5.0-fix-randomness.patch,1.62 KB, patch)
2012-07-12 14:36 UTC, Faustus
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Faustus 2010-11-05 19:28:08 UTC
I am posting this bug here, and not to upstream, since the last version of macchanger was released 6 years ago, and this problem is easy to patch.

In main.c:
  srandom(time(NULL));
then in mac.c, 3 or 6 (depending on macchanger parameters) MAC bytes are filled with random()%255.

time() returns time in seconds, so even if the user randomizes just the MAC ending (macchanger -e), and assuming that the MAC address has been changed in the last 24 hours (in a typical use case, a much more precise estimate can be made), it is possible to say whether a given MAC address is faked with 99.5% confidence (1-24*60^2/256^3).

In addition, running macchanger for several interfaces in sequence (e.g., during boot) sets the same MAC addresses for them (full or just the last 3 bytes, depending on parameters). This is for the same reason - resolution of time() which is used for srandom() is too low.

Suggestion:

1(a). Replace time() with 4 bytes from /dev/urandom, or
1(b). Replace time() with fields from gettimeofday() struct, which gives microsecond precision
2. Replace %255 with %256 in mac.c

If the math doesn't make sense for you, post your MAC address, and I will say whether it was faked with macchanger in the last 24 hours (and will also give the time when it was faked).
Comment 1 Faustus 2010-11-05 20:42:20 UTC
Created attachment 253345 [details]
Find out when a MAC address was faked with macchanger

Example of output:

> ./mac-attack 5a:59:a9:8f:a5:0b
Match: full
Time: Fri Nov  5 22:31:45 2010
Confidence: 100.00%

> ./mac-attack 00:25:d3:f5:09:a9
Match: 3-byte ending
Time: Fri Nov  5 16:08:01 2010
Confidence: 99.86%

> ./mac-attack 11:22:33:aa:bb:cc
Match: 3-byte ending
Time: Tue Mar 30 02:17:10 2010
Confidence: -13.75%
Comment 2 Alec Meyers 2010-11-09 19:15:26 UTC
(In reply to comment #0)
> Suggestion:
> 
> 1(a). Replace time() with 4 bytes from /dev/urandom, or
> 1(b). Replace time() with fields from gettimeofday() struct, which gives
> microsecond precision
> 2. Replace %255 with %256 in mac.c

Do you have a patch for that? :)
Comment 3 SpanKY gentoo-dev 2010-11-09 22:53:14 UTC
i dont see this being a security issue
Comment 4 Faustus 2010-11-11 11:17:59 UTC
> Do you have a patch for that? :)

Well, I can write a patch for say using /dev/urandom instead of time(), but I think that in its current form, net-analyzer/macchanger does more harm than good. Just changing 3/6 bytes of a MAC address to given or random bytes is easily achieved using a simple shell script (ifconfig hw ether). The main benefit of macchanger is its database of MAC vendors, but it is severely outdated (6 years old). Given that macchanger is mostly useful for Wi-Fi, which is a rapidly changing market, the database in its current form is pretty useless.

So I don't know what's the best course of action here. Maybe a warning in the ebuild about the database age and the pseudo-randomness issue should be enough.

SpanKY, the last time I submitted a security-related bug, I tagged it as "Applications", and it was moved to "Security". Go figure. I think it is a security issue, since the main purpose of macchanger (hiding your MAC-based identity) is defeated for typical use cases: the user is the only one using macchanger for a given wireless access point, and checking his laptop will show that macchanger has been used -> proof that an earlier connection was done from this laptop.
Comment 5 SpanKY gentoo-dev 2010-11-12 03:55:07 UTC
"hiding your mac" means "breaking industry and world-wide standards".  dont do that.  this is not a security issue.
Comment 6 Faustus 2010-11-12 11:59:22 UTC
Don't listen to SpanKY, MAC spoofing is great, enhances privacy, and it's (almost) standard-compliant (see IEEE Std 802-2001 Sec. 9.2.2).

I found a relevant paper:
http://www.springerlink.com/content/f20m055215623707/
50 citations, I could write one too...

Anyway, according to IEEE Std 802-2001, macchanger has another bug: in full 6-byte MAC randomization mode, the most significant byte should be and'ed with 0xFC, not 0xFE (the next-to-LSB bit in the first octet must be set to 0) - see Sec. 9.1.
Comment 7 SpanKY gentoo-dev 2010-11-13 05:30:46 UTC
actually, that's the exact opposite of what it should be doing.  0x02 should always be set in the first LSB.  picking any other MAC is wrong regardless of whatever you might wrongly believe.
Comment 8 Faustus 2010-11-13 12:20:55 UTC
Oh come on... The standard says that bit 0x02 = 0 means that the address is universal, not that you can set 0x02 = 1 if the address is not universal. Bit 0x02 = 0 -> standard-conforming, bit 0x02 = 1 -> actually "breaks industry and world-wide standards", and might break some hardware for real. :)
Comment 9 Faustus 2012-07-11 12:16:05 UTC
Note for anyone that uses macchanger: Debian added an ugly patch a year ago to partially mitigate the issue described in this bug (two years ago):
http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=633998
Comment 10 Rick Farina (Zero_Chaos) gentoo-dev 2012-07-11 13:35:01 UTC
(In reply to comment #9)
> Note for anyone that uses macchanger: Debian added an ugly patch a year ago
> to partially mitigate the issue described in this bug (two years ago):
> http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=633998

I may not have the best C skills, but it looks to me that the first patch makes the same mac *error* into an acceptable thing, rather than preventing it from making the same mac on two random calls.  I'd be interested in a patch which uses actual /dev/random or /dev/urandom instead of a time check, or at least a time check in microseconds instead of seconds...

thanks
Comment 11 Faustus 2012-07-12 14:31:22 UTC
(In reply to comment #10)
> I may not have the best C skills, but it looks to me that the first patch
> makes the same mac *error* into an acceptable thing, rather than preventing
> it from making the same mac on two random calls.

You are right -- I misunderstood the purpose of Debian patches. It might be a good idea to include them as well, though.

> I'd be interested in a
> patch which uses actual /dev/random or /dev/urandom instead of a time check,
> or at least a time check in microseconds instead of seconds...

Attaching shortly (reasonably tested with different switches and with /dev/urandom available or not). It might be possible to also put randomness source detection into autoconf, for non-Linux architectures (and then pass -DRANDOM_SRC=...), but I am not familiar with autoconf, unfortunately.
Comment 12 Faustus 2012-07-12 14:36:34 UTC
Created attachment 318002 [details, diff]
Use /dev/urandom when available

Uses /dev/urandom when available, and also resets next-to-LSB bit in first MAC octet if it is changed.
Comment 13 Matthias-Christian Ott 2013-12-30 14:37:38 UTC
macchanger-1.6.0 seeds the PRNG from /dev/urandom or /dev/random. I'm not sure about the other issues, but I think it would make sense to mark 1.6.0 stable.
Comment 14 Robin Johnson archtester Gentoo Infrastructure gentoo-dev Security 2014-02-02 20:06:00 UTC
faustus:
can you please confirm the issues are fixed in 1.6 or 1.7?
if not, please send them upstream (they have a github now that takes contributions easily, see the updated HOMEPAGE variable).