mirror of
https://github.com/cubixle/wifi-hijacker.git
synced 2026-04-24 21:24:47 +01:00
Inital commit
This commit is contained in:
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
/vendor
|
||||
27
Godeps/Godeps.json
generated
Normal file
27
Godeps/Godeps.json
generated
Normal file
@@ -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"
|
||||
}
|
||||
]
|
||||
}
|
||||
5
Godeps/Readme
generated
Normal file
5
Godeps/Readme
generated
Normal file
@@ -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.
|
||||
126
main.go
Normal file
126
main.go
Normal file
@@ -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
|
||||
}
|
||||
Reference in New Issue
Block a user