-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.go
executable file
·88 lines (80 loc) · 1.93 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
package main
import (
"./netlinkAudit"
"log"
"os"
"syscall"
"time"
)
var done chan bool
var debug bool
func main() {
s, err := netlinkAudit.GetNetlinkSocket()
if err != nil {
log.Println(err)
log.Fatalln("Error while availing socket! Exiting!")
}
defer s.Close()
debug = false
if os.Getuid() != 0 {
log.Fatalln("Not Root User! Exiting!")
}
err = netlinkAudit.AuditSetEnabled(s)
if err != nil {
log.Fatal("Error while enabling Audit !", err)
}
err = netlinkAudit.AuditIsEnabled(s)
if debug == true {
log.Println(netlinkAudit.ParsedResult)
}
if err == nil && netlinkAudit.ParsedResult.Enabled == 1 {
log.Println("Enabled Audit!!")
} else {
log.Fatalln("Audit Not Enabled! Exiting")
}
err = netlinkAudit.AuditSetRateLimit(s, 600)
if err != nil {
log.Fatalln("Error Setting Rate Limit!!", err)
}
err = netlinkAudit.AuditSetBacklogLimit(s, 420)
if err != nil {
log.Fatalln("Error Setting Backlog Limit!!", err)
}
err = netlinkAudit.AuditSetPid(s, uint32(syscall.Getpid()))
if err == nil {
log.Println("Set pid successful!!")
}
err = netlinkAudit.SetRules(s)
// err = netlinkAudit.DeleteAllRules(s)
if err != nil {
log.Fatalln("Setting Rules Unsuccessful! Exiting")
}
done := make(chan bool, 1)
msg := make(chan string)
errchan := make(chan error)
f, err := os.OpenFile("/tmp/log", os.O_CREATE|os.O_RDWR|os.O_APPEND, 0660)
if err != nil {
log.Fatalln("Error Creating File!!")
}
defer f.Close()
go func() {
for {
select {
case ev := <-msg:
log.Println(ev + "\n")
_, err := f.WriteString(ev + "\n")
if err != nil {
log.Println("Writing Error!!")
}
case ev := <-errchan:
log.Println(ev)
}
}
}()
go netlinkAudit.Getreply(s, done, msg, errchan)
time.Sleep(time.Second * 10)
done <- true
close(done)
//Important point is that NLMSG_ERROR is also an acknowledgement from Kernel.
//If the first 4 bytes of Data part are zero then it means the message is acknowledged
}