From 69d5cc574f9947bb3b2b1408fe7613eb75e8bc76 Mon Sep 17 00:00:00 2001 From: Kent Gruber Date: Wed, 28 Feb 2018 00:25:07 -0500 Subject: [PATCH] Use the MacChanger struct's originalMac field to determine if the module has already been configured MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This goal of this commit is to provide a simple way to deal with the original mac resotation issue I was facing where the MacChanger struct was being overwritten if called twice/more than once. This should lock up users from doing that but provide them a way around it ( not locking them into an original mac address when I could want to change it outside my bettercap session) with a consistent-ish experience until I figure something else out. Or someone else does. It’s also late and I need to be studying for my windows administration class midterm. It’s supposed to be an Advanced Windows Administration class. But it’s not. Anyways. I’m sure this commit isn’t perfect. But. What code is? :joy: --- modules/mac_changer.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/modules/mac_changer.go b/modules/mac_changer.go index bf2232fb..4a046d07 100644 --- a/modules/mac_changer.go +++ b/modules/mac_changer.go @@ -1,6 +1,7 @@ package modules import ( + "errors" "fmt" "net" "runtime" @@ -64,6 +65,10 @@ func (mc *MacChanger) Author() string { func (mc *MacChanger) Configure() (err error) { var changeTo string + if mc.originalMac != nil { + return errors.New("mac.changer has already been configured, you will need to turn it off to re-configure") + } + if err, mc.iface = mc.StringParam("mac.changer.iface"); err != nil { return err } @@ -119,6 +124,9 @@ func (mc *MacChanger) Stop() error { return err } + // the the module can now be reconfigured + mc.originalMac = nil + return mc.SetRunning(false, func() { log.Info("Interface mac address restored to %s", core.Bold(mc.originalMac.String())) })