From 9f823c3c3df7af17e50d63c979b3c6bb3f238ca2 Mon Sep 17 00:00:00 2001 From: lrodham Date: Sat, 18 Mar 2017 23:05:52 +0000 Subject: [PATCH] Inital commit --- .gitignore | 1 + Godeps/Godeps.json | 27 ++++++++++ Godeps/Readme | 5 ++ main.go | 126 +++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 159 insertions(+) create mode 100644 .gitignore create mode 100644 Godeps/Godeps.json create mode 100644 Godeps/Readme create mode 100644 main.go diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..61ead86 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/vendor diff --git a/Godeps/Godeps.json b/Godeps/Godeps.json new file mode 100644 index 0000000..58d5083 --- /dev/null +++ b/Godeps/Godeps.json @@ -0,0 +1,27 @@ +{ + "ImportPath": "wifi-hijacker", + "GoVersion": "go1.7", + "GodepVersion": "v79", + "Deps": [ + { + "ImportPath": "github.com/google/gopacket", + "Comment": "v1.1.12-49-gb28ce71", + "Rev": "b28ce7147a06b23a37cacd4bf2119f9da8dd51c4" + }, + { + "ImportPath": "github.com/google/gopacket/layers", + "Comment": "v1.1.12-49-gb28ce71", + "Rev": "b28ce7147a06b23a37cacd4bf2119f9da8dd51c4" + }, + { + "ImportPath": "github.com/google/gopacket/pcap", + "Comment": "v1.1.12-49-gb28ce71", + "Rev": "b28ce7147a06b23a37cacd4bf2119f9da8dd51c4" + }, + { + "ImportPath": "gopkg.in/urfave/cli.v1", + "Comment": "v1.19.1", + "Rev": "0bdeddeeb0f650497d603c4ad7b20cfe685682f6" + } + ] +} diff --git a/Godeps/Readme b/Godeps/Readme new file mode 100644 index 0000000..4cdaa53 --- /dev/null +++ b/Godeps/Readme @@ -0,0 +1,5 @@ +This directory tree is generated automatically by godep. + +Please do not edit. + +See https://github.com/tools/godep for more information. diff --git a/main.go b/main.go new file mode 100644 index 0000000..813e8c3 --- /dev/null +++ b/main.go @@ -0,0 +1,126 @@ +package main + +import ( + "errors" + "fmt" + "log" + "math/rand" + "net" + "os" + "time" + + "github.com/google/gopacket" + "github.com/google/gopacket/layers" + "github.com/google/gopacket/pcap" + "gopkg.in/urfave/cli.v1" +) + +var ( + gatewayMac string + timeout time.Duration = 30 * time.Second + macAddrs []string +) + +func main() { + app := cli.NewApp() + app.Flags = []cli.Flag{ + cli.StringFlag{ + Name: "interface, i", + Usage: "The interface you want to use for the hack.", + }, + cli.IntFlag{ + Name: "packet-limit, l", + Usage: "Limit the number of packets to capture. Default: 10", + }, + cli.BoolFlag{ + Name: "promiscuous, p", + Usage: "Put the interface into promiscuous mode. Default: false", + }, + } + + app.Action = func(c *cli.Context) error { + packetLimit := c.Int("packet-limit") + log.Println(packetLimit) + if packetLimit == 0 { + packetLimit = 10 + } + + iface := c.String("interface") + if len(iface) == 0 { + return errors.New("Please supply a network interface.") + } + + promiscuousMode := c.Bool("promiscuous") + + interfaceToUse, err := net.InterfaceByName(iface) + if err != nil { + return err + } + + gatewayMac = interfaceToUse.HardwareAddr.String() // log to file. + log.Println("Your Mac Address: " + gatewayMac) + + macAddrs := findMacAddrs(interfaceToUse, int32(1024), promiscuousMode, timeout, int32(packetLimit)) + + // use a random mac address and spoof the users. + rand.Seed(time.Now().Unix()) + macAddr := macAddrs[rand.Intn(len(macAddrs))] + log.Println("Going to use: " + macAddr) + log.Println(macAddr) + + log.Println("We will now disconnect you from the network and spoof your mac address.") + + return nil + } + + app.Run(os.Args) +} + +func findMacAddrs(iface *net.Interface, snapshotLength int32, promiscuous bool, timeout time.Duration, packetLimit int32) []string { + handle, err := pcap.OpenLive(iface.Name, snapshotLength, promiscuous, timeout) + if err != nil { + log.Fatal(err) + } + defer handle.Close() + + // Use the handle as a packet source to process all packets + packetSource := gopacket.NewPacketSource(handle, handle.LinkType()) + packetCount := int32(0) + log.Println("Finding client MAC addresses.") + log.Println("=============================") + for packet := range packetSource.Packets() { + // Process packet here + if packetCount <= packetLimit { + if ethernetLayer := packet.Layer(layers.LayerTypeEthernet); ethernetLayer != nil { + // store mac addresses. + etherPacket, _ := ethernetLayer.(*layers.Ethernet) + + if contains(macAddrs, etherPacket.SrcMAC.String()) == false && etherPacket.SrcMAC.String() != gatewayMac { + macAddrs = append(macAddrs, etherPacket.SrcMAC.String()) + } + + if contains(macAddrs, etherPacket.DstMAC.String()) == false && etherPacket.DstMAC.String() != gatewayMac { + macAddrs = append(macAddrs, etherPacket.DstMAC.String()) + } + } + packetCount++ + fmt.Print("▓") + } else { + handle.Close() + fmt.Println("") + break + } + } + + return macAddrs +} + +func contains(macAddrs []string, addr string) bool { + for _, v := range macAddrs { + if v == addr { + return true + } + } + + return false +}