Bettercap: mac.changer error: not restoring original mac address when called more than once

Created on 28 Feb 2018  路  5Comments  路  Source: bettercap/bettercap

Prerequisites

  • [x] I read the README.
  • [x] I am running the latest stable version.
  • [x] I already searched other issues to see if this problem was already reported.
  • [x] I understand I don't necessarily have to paste this Prerequisites section in the issue.

Description

mac.changer will fail to reset back to the old mac address if accidentally called twice ( maybe more? ).

Environment

  • macOS
sudo bettercap
bettercap v2.0.0 (type 'help' for a list of commands)

10.0.0.0/24 > 10.0.0.37  禄 mac.changer on
10.0.0.0/24 > 10.0.0.37  禄 [23:21:49] [sys.log] [inf] Interface mac address set to d1:59:38:f4:a1:f5
10.0.0.0/24 > 10.0.0.37  禄 mac.changer off
[23:21:52] [sys.log] [inf] Interface mac address restored to 98:7b:f3:1e:a0:5e
10.0.0.0/24 > 10.0.0.37  禄 mac.changer off
[23:21:55] [sys.log] [err] Module is not running.
10.0.0.0/24 > 10.0.0.37  禄 mac.changer on
[23:22:00] [sys.log] [inf] Interface mac address set to e6:e0:76:22:2f:b6
10.0.0.0/24 > 10.0.0.37  禄 mac.changer on
[23:22:03] [sys.log] [err] Module is already running.
10.0.0.0/24 > 10.0.0.37  禄 mac.changer off
[23:22:05] [sys.log] [inf] Interface mac address restored to e6:e0:76:22:2f:b6
10.0.0.0/24 > 10.0.0.37  禄 mac.changer off
[23:22:10] [sys.log] [err] Module is not runni

Steps to Reproduce

I turn on the mac.changer module for the first time:

  1. mac.changer on
    I accidentally call it again:
  2. mac.changer on again
    I then decide I'm done with that.
  3. mac.changer off
    But now I see that the mac address hasn't been restored properly.

Expected behavior: I would expect the second mac.changer on to error out and not cause the subsequent mac.changer off to fail to reset the mac address properly.

Actual behavior: The mac address changed in the first on was _probably_ written to a variable or something, even in the event of the error. So when the module was turned off, the mac address wasn't able to restore properly.

bug

All 5 comments

Source of Bug

I think I found the source of the bug?

So, whenever the module is ran, return mc.Start() will Configure() the MacChanger struct, effectively overwriting the "original mac" with whatever the current one is.

I'm working on a fix to this now / I'm sure @evilsocket or @Matrix86 could easily beat me to it. 馃檹

馃 This might not be perfect or anything -- but I think it'd basically solve the problem in a way without creating another function like isConfigured() or something -- which I did consider. But I think this is pretty simple. Maybe I need to sleep on it / open to whatever of course!

Commit

https://github.com/picatz/bettercap-ng/commit/69d5cc574f9947bb3b2b1408fe7613eb75e8bc76

Yay, congrats for the PR :D

Did a quick refactor :)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

cyrus104 picture cyrus104  路  5Comments

xyzNOTNOOB picture xyzNOTNOOB  路  4Comments

vasiliyph picture vasiliyph  路  4Comments

picatz picture picatz  路  6Comments

feddgs picture feddgs  路  6Comments