Repository navigation
Expand file tree
/
Copy pathpf.conf
More file actions
180 lines (148 loc) · 8.16 KB
/
Copy pathpf.conf
File metadata and controls
180 lines (148 loc) · 8.16 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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
### My master pf.conf
### Interfaces
EXTIF ="em0"
INTIF ="em1"
DMZ = "em2"
EXTRAIF ="em3"
### Hosts
ADMIN ="10.0.11.1"
ADMIN1 ="10.0.11.31"
BOTHADMIN ="{" $ADMIN $ADMIN1 "}"
EXTDNSSERVER ="4.2.2.2"
INTDNSSERVER ="$INTIF:0"
#DNSSERVERS ="{" $INTDNSSERVER $EXTDNSSERVER "}"
DNSSERVER ="{$INTDNSSERVER}"
LOGSERVER = "{ 10.0.11.22, 10.0.11.31 }"
### states, Types
ICMPTYPE = "icmp-type 8 code 0"
ICMPMTUD = "icmp-type 3 code 4"
SYNSTATE = "flags S/SA synproxy state"
TCPSTATE = "flags S/SA modulate state"
#FLOWSTATE = "keep state (pflow)"
UDPSTATE = "keep state"
# Ports
TCPPORTS = "{ 80, 443 }"
SSHPORT = "22"
FTPPORT = "8021"
## Statefule tracking options
FTPSTO ="(tcp.established 7200)"
EXTIFSTO ="(max 2000, source-track rule, max-src-conn 1000, max-src-nodes 10)"
INTIFSTO ="(max 250, source-track rule, max-src-conn 60, max-src-nodes 10, max-src-conn-rate 200/10)"
#SMTPSTO ="(max 200, source-track rule, max-src-states 50, max-src-conn-rate 50/30, overload <BLOCKTEMP> flush global)"
SSHSTO ="(max 6, source-track rule, max-src-states 5, max-src-nodes 10, max-src-conn-rate 5/60)"
## Tables ##
table <BLOCKTEMP> counters
table <BLOCKPERM> counters file "/root/pf_files/pf_block_permanent"
table <spamd-white>
### Options ###
set skip on lo
set debug urgent
set reassemble yes
set block-policy return
set loginterface $INTIF
set state-policy if-bound
set fingerprints "/etc/pf.os"
set ruleset-optimization none
set state-defaults pflow
## Timeouts options for normal operations
set optimization normal
set timeout { tcp.established 600, tcp.closing 60 }
## Queueing ##
# FIOS upload = 356Kb/s (queue at 97%)
#altq on $EXTIF bandwidth 284Kb hfsc queue { ack, dns, web, bulk }
#queue ack bandwidth 20% priority 8 qlimit 500 hfsc ( realtime 20% )
#queue dns bandwidth 10% priority 7 qlimit 500 hfsc ( realtime 10% )
#queue bulk bandwith 20% priority 6 qlimit 500 hfsc ( realtime 20% default ecn )
#queue web bandwidth 20% priority 4 qlimit 500 hfsc ( realtime ( 20%, 500, 10%) )
#Anchor Antiscanner
#anchor "ANTISCAN"
load anchor "ANTISCAN" from "/root/pf_files/antiscan.pf"
#anchor "/ANTISCAN" all
#anchor "ANTISCAN" in on $INTIF inet proto tcp
anchor "ANTISCAN"
#anchor "PORTKNOCK"
#load anchor "PORTKNOCK" from "/root/pf_files/portknow.pf"
#Anchors didn't work so I am on my own.
#We made it work as it is. So be proud.
#You will have to specify perfect order in order for it to work.
#anchor "ftp-proxy/*" in on $INTIF inet proto tcp
## Queueing ##
# FIOS upload = 356Kb/s (queue at 97%)
altq on $EXTIF bandwidth 384Kb hfsc queue { ack, dns, web, bulk }
queue ack bandwidth 10% priority 8 qlimit 500 hfsc (realtime 10%)
queue dns bandwidth 10% priority 7 qlimit 500 hfsc (realtime 10%)
queue bulk bandwidth 40% priority 6 qlimit 500 hfsc (realtime 40% default upperlimit 95% ecn)
queue web bandwidth 20% priority 4 qlimit 500 hfsc (realtime 20% upperlimit 95%)
#Internal interface altq
altq on $INTIF bandwidth 1Mb hfsc queue { ackin, ssh, def }
queue ackin bandwidth 10% priority 8 qlimit 500 hfsc (realtime 10%)
queue ssh bandwidth 20% priority 1 qlimit 500 hfsc (realtime 20% upperlimit 50%) {ssh_bulk, ssh_ack}
queue ssh_bulk bandwidth 50% priority 1 qlimit 500 hfsc
queue ssh_ack bandwidth 50% priority 8 qlimit 500 hfsc
queue def bandwidth 50% priority 1 qlimit 500 hfsc (realtime 50% upperlimit 90% default ecn)
#pass in quick log (to pflog1) on $INTIF inet keep state (pflow)
pass in quick log (to pflog1) on $INTIF inet proto tcp from $BOTHADMIN to $INTIF port $SSHPORT $TCPSTATE $SSHSTO queue (ssh, ack)
## Block from/to illegal sources/destinations But we will have this on Internal interface
block in quick on $INTIF inet proto tcp from <BLOCKTEMP> to any port != ssh
block in quick on $INTIF inet proto tcp from <BLOCKPERM> to any port != ssh
block in quick on $INTIF inet proto udp from <BLOCKTEMP> to any port != ssh
block in quick on $INTIF inet proto udp from <BLOCKPERM> to any port != ssh
#Block all the broadcasting addresses
#block in quick on $INTIF inet from any to 255.255.255.255
#block in quick on $INTIF inet from urpf-failed to any
#block in log quick on $INTIF inet from no-route to any
#External Interface
#Block all on External interface
block log on $EXTIF
## Network address translation with outgoing source
#match out log on $EXTIF from $INTIF to any received-on $INTIF tag EGRESS nat-to ($EXTIF:0)
match out log on $EXTIF from $INTIF:network to any received-on $INTIF tag EGRESS nat-to ($EXTIF:0)
#If you have difficulties with any box with static port forwarding then you should use
#match out log on $EXTIF from $INTIF to any received-on $INTIF tag EGRESS nat-to ($EXTIF:0) static-port
#Traffic generated from firewall it self will be tagged as EGRESS
match out log on $EXTIF from $EXTIF to any tag EGRESS
#Packet normalization ("scrubbing")
#Find out why it's not working
match log on $EXTIF all scrub (random-id no-df min-ttl 64 reassemble tcp max-mss 1440)
#EXTIF inbound
pass in log (to pflog1) on $EXTIF inet proto tcp from any to any port 22
pass in on $EXTIF inet proto tcp from any to $EXTIF port >10000
#External interface outbound
pass out log on $EXTIF inet from ($EXTIF) to any $TCPSTATE $EXTIFSTO queue (bulk, ack) tagged EGRESS
#pass out log on $EXTIF inet proto udp from ($EXTIF) to any $UDPSTATE $EXTIFSTO queue (bulk, ack) tagged EGRESS
pass out log on $EXTIF inet proto tcp from ($EXTIF) to any port $TCPPORTS $TCPSTATE $EXTIFSTO queue (web, ack) tagged EGRESS
pass out log on $EXTIF inet proto udp from ($EXTIF) to any port 53 $UDPSTATE $EXTIFSTO queue (dns, ack) tagged EGRESS
#External interface outbound
#pass out log on $EXTIF inet proto tcp from ($EXTIF) to any $TCPSTATE $EXTIFSTO tagged EGRESS
#pass out log on $EXTIF inet proto tcp from ($EXTIF) to any port $TCPPORTS $TCPSTATE $EXTIFSTO tagged EGRESS
#pass out log on $EXTIF inet proto udp from ($EXTIF) to any port 53 $UDPSTATE $EXTIFSTO tagged EGRESS
## Internal Interface pcn1
block return log on $INTIF
#Internal interface inbound
pass in log (to pflog1) inet proto tcp from $ADMIN1 to $INTIF port 9102 $UDPSTATE
pass in log on $INTIF inet proto tcp from $INTIF:network to any port $TCPPORTS $TCPSTATE $EXTIFSTO queue (def, ackin)
pass in log on $INTIF inet proto tcp from $INTIF:network to any port $TCPPORTS $UDPSTATE queue (def, ackin)
pass in log (to pflog1) inet proto tcp from $INTIF:network to any port 443 $TCPSTATE $EXTIFSTO
pass in log on $INTIF inet proto tcp from $INTIF:network to any port 21 $TCPSTATE $EXTIFSTO queue (def, ackin) divert-to 127.0.0.1 port $FTPPORT
pass in log (to pflog1) on $INTIF inet proto tcp from $INTIF:network to $INTIF:0 port 21 $TCPSTATE $INTIFSTO queue (def, ackin)
pass in log (to pflog1) on $INTIF inet proto tcp from $INTIF:network to $INTIF port 25 $TCPSTATE $INTIFSTO
pass in log on $INTIF inet proto tcp from $INTIF:network to any port 22 $TCPSTATE $SSHSTO queue (ssh_bulk, ssh_ack)
pass in log on $INTIF inet proto udp from $INTIF:network to $INTIF:0 port 53 $UDPSTATE $INTIFSTO
pass in log on $INTIF inet proto udp from $INTIF:network to ($INTIF:0) port 123 $UDPSTATE $INTIFSTO
pass in log on $INTIF inet proto udp from any to any port {67,68}
pass in log on $INTIF inet proto icmp from $INTIF:network to any $ICMPMTUD $UDPSTATE $INTIFSTO
pass in log on $INTIF inet proto icmp from $INTIF:network to any $ICMPTYPE $UDPSTATE $INTIFSTO
## FTP-proxy for LAN Note: this is secure one.
anchor "ftp-proxy/*" in on $INTIF inet proto tcp
anchor "tftp-proxy/*" in on $INTIF inet proto udp
#INTIF outbound
pass out log on $INTIF inet proto tcp from $INTIF to $INTIF:network port 22 $TCPSTATE $SSHSTO
pass out log (to pflog1) proto tcp from $INTIF to $ADMIN1 port {9101, 9103} $UDPSTATE $INTIFSTO
pass out log on $INTIF inet proto icmp from $INTIF to any $ICMPTYPE $UDPSTATE $INTIFSTO
pass out log (to pflog1, all) on $INTIF inet proto udp from $INTIF to $LOGSERVER port 514 $UDPSTATE $INTIFSTO
pass out log (to pflog1, all) proto udp from any to any port {67,68,69} $UDPSTATE $INTIFSTO
pass out log (to pflog1) proto udp from $INTIF to $ADMIN1 port 9995 $UDPSTATE $INTIFSTO
pass out log (to pflog1) proto udp from $INTIF to $ADMIN1 port 53 $UDPSTATE
pass out quick from 127.0.0.1 divert-reply
#PFLOW Related Later on convert to anchor so Main config file doesn't get too crowded
#pass in inet proto icmp keep state(pflow)