-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathForbidConnection.guard.go
99 lines (63 loc) · 2.56 KB
/
ForbidConnection.guard.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
95
96
97
98
99
//go:build (guard || guard_openwrt || guard_almalinux || guard_alpinelinux || guard_amazonlinux || guard_antergos || guard_archlinux || guard_cblmariner || guard_centos || guard_debian || guard_fedora || guard_gentoolinux || guard_linuxmint || guard_manjaro || guard_opensuse || guard_oraclelinux || guard_photonos || guard_redhat || guard_rockylinux || guard_trisquel || guard_ubuntu)
package ebpf
import "tholian-firewall/adapters/mitigations/ebpf/module"
import "tholian-firewall/console"
import "tholian-firewall/types"
import "strconv"
func ForbidConnection(connection types.Connection) bool {
var result bool = false
if SUPPORTED == true {
result_source := false
result_target := false
if connection.Type == "client" || connection.Type == "peer" {
// local client is connecting to remote server
if connection.Target.Host == "*" {
if connection.Target.Port != 0 {
if module.IsForbiddenPort(connection.Target.Port) {
result_target = true
} else {
console.Warn("adapters/ebpf: Forbid Connection \"*:" + strconv.FormatUint(uint64(connection.Target.Port), 10) + "\"")
result_target = module.ForbidPort(connection.Target.Port)
}
}
} else if connection.Target.Host != ".arpa" {
if module.IsForbiddenAddress(connection.Target.Host) {
result_target = true
} else {
console.Warn("adapters/ebpf: Forbid Connection \"" + connection.Target.Host + ":*\"")
result_target = module.ForbidAddress(connection.Target.Host)
}
}
}
if connection.Type == "server" || connection.Type == "peer" {
// remote client is connecting to local server
if connection.Source.Host == "*" {
if connection.Source.Port != 0 {
if module.IsForbiddenPort(connection.Source.Port) {
result_source = true
} else {
console.Warn("adapters/ebpf: Forbid Connection \"*:" + strconv.FormatUint(uint64(connection.Source.Port), 10) + "\"")
result_source = module.ForbidPort(connection.Source.Port)
}
}
} else if connection.Source.Host != ".arpa" {
if module.IsForbiddenAddress(connection.Source.Host) {
result_source = true
} else {
console.Warn("adapters/ebpf: Forbid Connection \"" + connection.Source.Host + ":*\"")
result_source = module.ForbidAddress(connection.Source.Host)
}
}
}
if connection.Type == "client" {
result = result_target
} else if connection.Type == "server" {
result = result_source
} else if connection.Type == "peer" {
if result_source == true && result_target == true {
result = true
}
}
}
return result
}