-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathdefault-rules.nft
62 lines (50 loc) · 3.34 KB
/
default-rules.nft
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
table ip yuki-script {
chain prerouting {
# Drop policy and optimal priority.
# ========================================
type filter hook prerouting priority -200; policy drop;
# Allow the local interface and block spoofing.
# ========================================
iif "lo" ip saddr 127.0.0.0/8 accept
ip saddr 127.0.0.0/8 iif != "lo" log prefix "[yuki-script] Possible Spoofing: " level debug limit rate 1/minute counter drop
# Allow valid conntrack states.
# ========================================
ct state established,related counter accept
# Combat some TCP flood attacks by applying rate-limits.
# ========================================
tcp flags syn limit rate over 4/second log prefix "[yuki-script] Possible SYN Flood: " level debug limit rate 1/minute counter drop
tcp flags syn,ack limit rate over 4/second log prefix "[yuki-script] Possible SYN-ACK Flood: " level debug limit rate 1/minute counter drop
tcp flags rst,ack limit rate over 2/second log prefix "[yuki-script] Possible RST-ACK Flood: " level debug limit rate 1/minute counter drop
# Allow only legitimate TCP flags and their combinations.
# ========================================
tcp flags { ack, fin,ack, psh,ack, ack,urg } counter accept
# Mitigate UDP Floods with a ratelimit.
# ========================================
ip protocol udp limit rate 3200/second log prefix "[yuki-script] Possible UDP Flood: " level debug limit rate 1/minute counter drop
# ICMP type whitelisting with state tracking and rate-limiting.
# ========================================
icmp type echo-request limit rate 2/second ct state new counter accept
icmp type parameter-problem limit rate 15/minute ct state related counter accept
icmp type { echo-reply, timestamp-reply, address-mask-reply } limit rate 15/minute ct state established counter accept
icmp type { destination-unreachable, time-exceeded } limit rate 2/second ct state established,related counter accept
# Drop SYN packets with source-port <1024 to prevent some attacks.
# ========================================
tcp sport != 1024-65535 tcp flags syn / fin,syn,rst,ack log prefix "[yuki-script] Invalid TCP SYN Source port: " level debug limit rate 1/minute counter drop
# Drop all packets with bad states.
# ========================================
ct state invalid,untracked log prefix "[yuki-script] Bad packet state: " level debug limit rate 1/minute counter drop
# Stateful TCP filters.
# ========================================
tcp flags ! syn ct state new log prefix "[yuki-script] TCP != SYN but state NEW: " level debug limit rate 1/minute counter drop
tcp flags syn ct state ! new log prefix "[yuki-script] TCP SYN but state != NEW: " level debug limit rate 1/minute counter drop
# MSS Filter.
# ========================================
tcp option maxseg size != 536-1460 log prefix "[yuki-script] Invalid MSS value: " level debug limit rate 1/minute counter drop
# Drop packets with incorrect TTL values.
# ========================================
ip ttl != 1-128 log prefix "[yuki-script] Invalid TTL: " level debug limit rate 1/minute counter drop
# Drop fragmented packets.
# ========================================
ip frag-off & 0x1fff != 0x0 log prefix "[yuki-script] Fragmented packet dropped: " level debug limit rate 1/minute counter drop
}
}