-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
94 lines (78 loc) · 1.95 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
package main
import (
"net"
// "flag"
"fmt"
// "os"
// "sync"
"time"
"github.com/google/gopacket"
"github.com/google/gopacket/pcap"
)
var (
debug bool
blackTargetList [1 << 29]uint8
whiteTargetList [1 << 29]uint8
pblackTargetList *[1 << 29]uint8
pwhiteTargetList *[1 << 29]uint8
statsListMap map[string]int
srcMac net.HardwareAddr
dstMac net.HardwareAddr
// lock sync.RWMutex
)
func main() {
/*
parseFlags()
// Exit on invalid parameters
flagsComplete, errString := flagsComplete()
if !flagsComplete {
fmt.Println(errString)
flag.PrintDefaults()
os.Exit(1)
}
*/
configMap := initConfig("conf.txt")
//init nic
mirrorNetworkDevice := configMap["mirrornetworkdevice"]
mgtNetworkDevice := configMap["mgtnetworkdevice"]
//init targets
targetListPath := configMap["targetlistpath"]
getTargetList(targetListPath)
//init nic mac for send packets
srcMac, dstMac = initMacs(configMap["srcmac"], configMap["dstmac"])
if (srcMac != nil) && (dstMac != nil) {
fmt.Println("set src and dst mac: ", srcMac, dstMac)
}
initBullets()
statsListMap = initStats()
// Open connection
handleMirror, errHandleMirror := pcap.OpenLive(
mirrorNetworkDevice, // network device
int32(65535),
true,
time.Microsecond,
)
if errHandleMirror != nil {
fmt.Println("Mirror Handler error", errHandleMirror.Error())
}
handleMgt, errHandleMgt := pcap.OpenLive(
mgtNetworkDevice, // network device
int32(65535),
false,
time.Microsecond,
)
if errHandleMgt != nil {
fmt.Println("MGT Handler error", errHandleMgt.Error())
}
//init send packet channel
c := make(chan [2]gopacket.Packet)
go sendResetPacket(handleMgt, c)
//Close when done
//defer handleMirror.Close()
//defer handleMgt.Close()
//Capture Live Traffic
packetSource := gopacket.NewPacketSource(handleMirror, handleMirror.LinkType())
for packet := range packetSource.Packets() {
go analysePacket(packet, handleMgt, c)
}
}