| 1 | package mac_changerscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/mac_changer`/ |
| 2 | |
| 3 | import ( |
| 4 | "fmtscip-go gomod github.com/golang/go/src go1.16 fmt/" |
| 5 | "netscip-go gomod github.com/golang/go/src go1.16 net/" |
| 6 | "runtimescip-go gomod github.com/golang/go/src go1.16 runtime/" |
| 7 | "stringsscip-go gomod github.com/golang/go/src go1.16 strings/" |
| 8 | |
| 9 | "github.com/bettercap/bettercap/corescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/core`/" |
| 10 | "github.com/bettercap/bettercap/networkscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/" |
| 11 | "github.com/bettercap/bettercap/sessionscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/" |
| 12 | |
| 13 | "github.com/evilsocket/islazy/tuiscip-go gomod github.com/evilsocket/islazy v1.11.0 `github.com/evilsocket/islazy/tui`/" |
| 14 | ) |
| 15 | |
| 16 | type MacChangerscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/mac_changer`/MacChanger# struct { |
| 17 | sessionscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/.SessionModulescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/mac_changer`/MacChanger#SessionModule. |
| 18 | ifacescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/mac_changer`/MacChanger#iface. string |
| 19 | originalMacscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/mac_changer`/MacChanger#originalMac. netscip-go gomod github.com/golang/go/src go1.16 net/.HardwareAddrscip-go gomod github.com/golang/go/src go1.16 net/HardwareAddr# |
| 20 | fakeMacscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/mac_changer`/MacChanger#fakeMac. netscip-go gomod github.com/golang/go/src go1.16 net/.HardwareAddrscip-go gomod github.com/golang/go/src go1.16 net/HardwareAddr# |
| 21 | } |
| 22 | |
| 23 | func NewMacChangerscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/mac_changer`/NewMacChanger().(s *sessionscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/.Sessionscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/Session#) *MacChangerscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/mac_changer`/MacChanger# { |
| 24 | mod := &MacChangerscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/mac_changer`/MacChanger#{ |
| 25 | SessionModulescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/mac_changer`/MacChanger#SessionModule.: sessionscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/.NewSessionModulescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/NewSessionModule().("mac.changer", s), |
| 26 | } |
| 27 | |
| 28 | mod.AddParamscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/SessionModule#AddParam().(sessionscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/.NewStringParameterscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/NewStringParameter().("mac.changer.iface", |
| 29 | sessionscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/.ParamIfaceNamescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/ParamIfaceName., |
| 30 | "", |
| 31 | "Name of the interface to use.")) |
| 32 | |
| 33 | mod.AddParamscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/SessionModule#AddParam().(sessionscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/.NewStringParameterscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/NewStringParameter().("mac.changer.address", |
| 34 | sessionscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/.ParamRandomMACscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/ParamRandomMAC., |
| 35 | "[a-fA-F0-9]{2}:[a-fA-F0-9]{2}:[a-fA-F0-9]{2}:[a-fA-F0-9]{2}:[a-fA-F0-9]{2}:[a-fA-F0-9]{2}", |
| 36 | "Hardware address to apply to the interface.")) |
| 37 | |
| 38 | mod.AddHandlerscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/SessionModule#AddHandler().(sessionscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/.NewModuleHandlerscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/NewModuleHandler().("mac.changer on", "", |
| 39 | "Start mac changer module.", |
| 40 | func(args []string) error { |
| 41 | return mod.Startscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/mac_changer`/MacChanger#Start().() |
| 42 | })) |
| 43 | |
| 44 | mod.AddHandlerscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/SessionModule#AddHandler().(sessionscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/.NewModuleHandlerscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/NewModuleHandler().("mac.changer off", "", |
| 45 | "Stop mac changer module and restore original mac address.", |
| 46 | func(args []string) error { |
| 47 | return mod.Stopscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/mac_changer`/MacChanger#Stop().() |
| 48 | })) |
| 49 | |
| 50 | return mod |
| 51 | } |
| 52 | |
| 53 | func (mod *MacChangerscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/mac_changer`/MacChanger#) Namescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/mac_changer`/MacChanger#Name().() string { |
| 54 | return "mac.changer" |
| 55 | } |
| 56 | |
| 57 | func (mod *MacChangerscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/mac_changer`/MacChanger#) Descriptionscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/mac_changer`/MacChanger#Description().() string { |
| 58 | return "Change active interface mac address." |
| 59 | } |
| 60 | |
| 61 | func (mod *MacChangerscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/mac_changer`/MacChanger#) Authorscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/mac_changer`/MacChanger#Author().() string { |
| 62 | return "Simone Margaritelli <[email protected]>" |
| 63 | } |
| 64 | |
| 65 | func (mod *MacChangerscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/mac_changer`/MacChanger#) Configurescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/mac_changer`/MacChanger#Configure().() (err error) { |
| 66 | var changeTo string |
| 67 | |
| 68 | if err, mod.ifacescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/mac_changer`/MacChanger#iface. = mod.StringParamscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/SessionModule#StringParam().("mac.changer.iface"); err != nil { |
| 69 | return err |
| 70 | } else if err, changeTo = mod.StringParamscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/SessionModule#StringParam().("mac.changer.address"); err != nil { |
| 71 | return err |
| 72 | } |
| 73 | |
| 74 | changeTo = networkscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/.NormalizeMacscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/NormalizeMac().(changeTo) |
| 75 | if mod.fakeMacscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/mac_changer`/MacChanger#fakeMac., err = netscip-go gomod github.com/golang/go/src go1.16 net/.ParseMACscip-go gomod github.com/golang/go/src go1.16 net/ParseMAC().(changeTo); err != nil { |
| 76 | return err |
| 77 | } |
| 78 | |
| 79 | mod.originalMacscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/mac_changer`/MacChanger#originalMac. = mod.Sessionscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/SessionModule#Session..Interfacescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/Session#Interface..HWscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/Endpoint#HW. |
| 80 | |
| 81 | return nil |
| 82 | } |
| 83 | |
| 84 | func (mod *MacChangerscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/mac_changer`/MacChanger#) setMacscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/mac_changer`/MacChanger#setMac().(mac netscip-go gomod github.com/golang/go/src go1.16 net/.HardwareAddrscip-go gomod github.com/golang/go/src go1.16 net/HardwareAddr#) error { |
| 85 | var args []string |
| 86 | |
| 87 | os := runtimescip-go gomod github.com/golang/go/src go1.16 runtime/.GOOSscip-go gomod github.com/golang/go/src go1.16 runtime/GOOS. |
| 88 | if stringsscip-go gomod github.com/golang/go/src go1.16 strings/.Containsscip-go gomod github.com/golang/go/src go1.16 strings/Contains().(os, "bsd") || os == "darwin" { |
| 89 | args = []string{mod.ifacescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/mac_changer`/MacChanger#iface., "ether", mac.Stringscip-go gomod github.com/golang/go/src go1.16 net/HardwareAddr#String().()} |
| 90 | } else if os == "linux" || os == "android" { |
| 91 | args = []string{mod.ifacescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/mac_changer`/MacChanger#iface., "hw", "ether", mac.Stringscip-go gomod github.com/golang/go/src go1.16 net/HardwareAddr#String().()} |
| 92 | } else { |
| 93 | return fmtscip-go gomod github.com/golang/go/src go1.16 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.16 fmt/Errorf().("OS %s is not supported by mac.changer module.", os) |
| 94 | } |
| 95 | |
| 96 | _, err := corescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/core`/.Execscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/core`/Exec().("ifconfig", args) |
| 97 | if err == nil { |
| 98 | mod.Sessionscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/SessionModule#Session..Interfacescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/Session#Interface..HWscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/Endpoint#HW. = mac |
| 99 | } |
| 100 | |
| 101 | return err |
| 102 | } |
| 103 | |
| 104 | func (mod *MacChangerscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/mac_changer`/MacChanger#) Startscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/mac_changer`/MacChanger#Start().() error { |
| 105 | if mod.Runningscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/SessionModule#Running().() { |
| 106 | return sessionscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/.ErrAlreadyStartedscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/ErrAlreadyStarted().(mod.Namescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/mac_changer`/MacChanger#Name().()) |
| 107 | } else if err := mod.Configurescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/mac_changer`/MacChanger#Configure().(); err != nil { |
| 108 | return err |
| 109 | } else if err := mod.setMacscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/mac_changer`/MacChanger#setMac().(mod.fakeMacscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/mac_changer`/MacChanger#fakeMac.); err != nil { |
| 110 | return err |
| 111 | } |
| 112 | |
| 113 | return mod.SetRunningscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/SessionModule#SetRunning().(true, func() { |
| 114 | mod.Infoscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/SessionModule#Info().("interface mac address set to %s", tuiscip-go gomod github.com/evilsocket/islazy v1.11.0 `github.com/evilsocket/islazy/tui`/.Boldscip-go gomod github.com/evilsocket/islazy v1.11.0 `github.com/evilsocket/islazy/tui`/Bold().(mod.fakeMacscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/mac_changer`/MacChanger#fakeMac..Stringscip-go gomod github.com/golang/go/src go1.16 net/HardwareAddr#String().())) |
| 115 | }) |
| 116 | } |
| 117 | |
| 118 | func (mod *MacChangerscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/mac_changer`/MacChanger#) Stopscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/mac_changer`/MacChanger#Stop().() error { |
| 119 | return mod.SetRunningscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/SessionModule#SetRunning().(false, func() { |
| 120 | if err := mod.setMacscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/mac_changer`/MacChanger#setMac().(mod.originalMacscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/mac_changer`/MacChanger#originalMac.); err == nil { |
| 121 | mod.Infoscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/SessionModule#Info().("interface mac address restored to %s", tuiscip-go gomod github.com/evilsocket/islazy v1.11.0 `github.com/evilsocket/islazy/tui`/.Boldscip-go gomod github.com/evilsocket/islazy v1.11.0 `github.com/evilsocket/islazy/tui`/Bold().(mod.originalMacscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/mac_changer`/MacChanger#originalMac..Stringscip-go gomod github.com/golang/go/src go1.16 net/HardwareAddr#String().())) |
| 122 | } else { |
| 123 | mod.Errorscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/SessionModule#Error().("error while restoring mac address: %s", err) |
| 124 | } |
| 125 | }) |
| 126 | } |