-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathmain.go
More file actions
81 lines (69 loc) · 2.06 KB
/
main.go
File metadata and controls
81 lines (69 loc) · 2.06 KB
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
package main
import (
"flag"
"github.com/google/gopacket"
"github.com/sirupsen/logrus"
"github.com/sirupsen/logrus/hooks/syslog"
"golang.org/x/sys/unix"
"io/ioutil"
)
var log = logrus.New()
func logPacket(device string, packet gopacket.Packet) {
packetString := packet.String()
if config.Logging.DebugPackets {
packetString = packet.Dump()
}
log.WithFields(logrus.Fields{"interface": device, "packet": packetString}).Debug("Received EAP/EAPOL packet")
}
// Configure logging
func initLogging() {
log.Formatter = &logrus.TextFormatter{FullTimestamp: true}
if config.Logging.Debug || config.Logging.DebugPackets {
log.SetLevel(logrus.DebugLevel)
} else {
log.SetLevel(logrus.InfoLevel)
}
if config.Logging.Syslog {
hook, err := syslog.NewSyslogHook("", "", 7, "")
if err != nil {
log.Error("Unable to connect to local syslog daemon")
} else {
log.AddHook(hook)
log.Out = ioutil.Discard
}
}
}
func main() {
configFile := flag.String("config", "/etc/eap_parrot.toml", "Full path to the config file")
flag.Parse()
initConfiguration(*configFile)
initLogging()
log.Info("eap_parrot starting up...")
// Open devices
wanInterface := setupCaptureDevice(config.Network.Wan)
rtrInterface := setupCaptureDevice(config.Network.Router)
// Close devices on shutdown
shutdownHandler := func() {
defer wanInterface.handle.Close()
defer unix.Close(wanInterface.fd)
defer rtrInterface.handle.Close()
defer unix.Close(rtrInterface.fd)
}
logrus.RegisterExitHandler(shutdownHandler)
// Use the handle as a packet source to process all packets
wanSource := gopacket.NewPacketSource(wanInterface.handle, wanInterface.handle.LinkType())
rtrSource := gopacket.NewPacketSource(rtrInterface.handle, rtrInterface.handle.LinkType())
for {
select {
case packet := <-wanSource.Packets():
logPacket(config.Network.Wan, packet)
emitPacket(packet, rtrInterface.handle)
case packet := <-rtrSource.Packets():
logPacket(config.Network.Router, packet)
if handleRouterPacket(packet) {
emitPacket(packet, wanInterface.handle)
}
}
}
logrus.Exit(0)
}