Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 19 Apr 2005 13:40:22 +0200
From:      stephen <dinzdale@gmail.com>
To:        pf <pf@benzedrine.cx>, freebsd-pf@freebsd.org
Subject:   Re: pflog and traffic via gif_if
Message-ID:  <ee918c780504190440397842f0@mail.gmail.com>
In-Reply-To: <ee918c7805041900084d075436@mail.gmail.com>
References:  <ee918c7805041200513d8f36a@mail.gmail.com> <ee918c7805041313292aa99ef1@mail.gmail.com> <42b49716050413161030e7abea@mail.gmail.com> <ee918c780504132325572ffce0@mail.gmail.com> <42b49716050414060657eacab9@mail.gmail.com> <ee918c78050414064151a58c4@mail.gmail.com> <42b4971605041409206c74fc53@mail.gmail.com> <ee918c780504142258480b2d5e@mail.gmail.com> <42b497160504170906c56fb6d@mail.gmail.com> <ee918c7805041900084d075436@mail.gmail.com>

next in thread | previous in thread | raw e-mail | index | archive | help
Hi,

I've found something that perhaps someone could explain to me...


Previously I had problems allowing traffic to pass via my gif
interface.. as far as the gif tunnel is setup, it works 100% as when I
flushed my ruleset or disabled PF, there wasn't a problem.  Before I
started out blocking outbound services , I had a

 pass out on $ext_if from any to any keep state

rule, and the gif seemed to work fine...

Once I had blocked all traffic in/out on the $ext_if and $int_if, I
had to open ports one by one on both so that traffic could pass...

The initial rule for the tunnel was:

###tunnel filters
 pass  in on $gif_if all
 pass out on $gif_if all
 pass  in on $ext_if inet proto ipencap   from any  to any
 pass out on $ext_if inet proto ipencap   from any  to any

Once I was logging stuff properly, and using tcpdump, I noticed i had
to open $int_if/rl0 to allow traffic on ports 135,137-139 so my
windows boxes from behind firewall could talk to the windows boxes on
the other side of the tunnel... this makes sense as traffic would have
to enter the box per se, via my NIC, before being routed to the other
lan through the gif tunnel.

000000 rule 6/0(match): block in on rl0: IP (tos 0x0, ttl 128, id
61411, offset 0, flags [DF], length: 48) 10.0.88.23.3736 >
10.0.89.1.445: S [tcp sum ok] 3464632695:3464632695(0) win 65535 <mss
1460,nop,nop,sackOK>
000483 rule 6/0(match): block in on rl0: IP (tos 0x0, ttl 128, id
61412, offset 0, flags [DF], length: 48) 10.0.88.23.3737 >
10.0.89.1.139: S [tcp sum ok] 2514062872:2514062872(0) win 65535 <mss
1460,nop,nop,sackOK>
530734 rule 6/0(match): block in on rl0: IP (tos 0x0, ttl 128, id
61413, offset 0, flags [DF], length: 48) 10.0.88.23.3736 >
10.0.89.1.445: S [tcp sum ok] 3464632695:3464632695(0) win 65535 <mss
1460,nop,nop,sackOK>
000230 rule 6/0(match): block in on rl0: IP (tos 0x0, ttl 128, id
61414, offset 0, flags [DF], length: 48) 10.0.88.23.3737 >
10.0.89.1.139: S [tcp sum ok] 2514062872:2514062872(0) win 65535 <mss
1460,nop,nop,sackOK>
437281 rule 6/0(match): block in on rl0: IP (tos 0x0, ttl 128, id
61419, offset 0, flags [DF], length: 48) 10.0.88.23.3736 >
10.0.89.1.445: S [tcp sum ok] 3464632695:3464632695(0) win 65535 <mss
1460,nop,nop,sackOK>
000247 rule 6/0(match): block in on rl0: IP (tos 0x0, ttl 128, id
61420, offset 0, flags [DF], length: 48) 10.0.88.23.3737 >
10.0.89.1.139: S [tcp sum ok] 2514062872:2514062872(0) win 65535 <mss
1460,nop,nop,sackOK>
000477 rule 6/0(match): block in on rl0: IP (tos 0x0, ttl 128, id
61421, offset 0, flags [none], length: 78) 10.0.88.23.137 >
10.0.89.1.137:
>>> NBT UDP PACKET(137): QUERY; REQUEST; UNICAST
TrnID=3D0x864C
OpCode=3D0
NmFlags=3D0x0
Rcode=3D0
QueryCount=3D1
AnswerCount=3D0
AuthorityCount=3D0
AddressRecCount=3D0
QuestionRecords:
Name=3D
WARNING: Short packet. Try increasing the snap length

^C
7 packets captured
7 packets received by filter
0 packets dropped by kernel


So I added rules for the $int_if/$int_if:

###tunnel filters
 pass  in on $gif_if all
 pass out on $gif_if all
 pass  in on $ext_if inet proto ipencap   from any  to any
 pass out on $ext_if inet proto ipencap   from any  to any
 pass  in on $int_if proto { udp,tcp }    from any  to any port {
135,137:139,445 }  keep state
 pass out on $int_if proto { udp,tcp }    from any  to any port {
135,137:139,445 }  keep state


and ran tcpdump again:

Tue Apr 19 09:17:10 root@bollox:/home/stephen# tcpdump -n -e -ttt -vv -i pf=
log0
tcpdump: WARNING: pflog0: no IPv4 address assigned
tcpdump: listening on pflog0, link-type PFLOG (OpenBSD pflog file),
capture size 96 bytes
000000 rule 31/0(match): block in on tun0: IP (tos 0x0, ttl 126, id
34146, offset 0, flags [DF], length: 48) 165.165.153.89.3479 >
165.165.167.17.445: S [tcp sum ok] 2834692615:2834692615(0) win 64800
<mss 1440,nop,nop,sackOK>
395435 rule 31/0(match): block in on tun0: IP (tos 0x0, ttl 126, id
34156, offset 0, flags [DF], length: 48) 165.165.153.89.3479 >
165.165.167.17.445: S [tcp sum ok] 2834692615:2834692615(0) win 64800
<mss 1440,nop,nop,sackOK>
 -snipped out some other packets that were not relevant-
546633 rule 31/0(match): block in on tun0: IP (tos 0x0, ttl 126, id
34194, offset 0, flags [DF], length: 48) 165.165.153.89.3479 >
165.165.167.17.445: S [tcp sum ok] 2834692615:2834692615(0) win 64800
<mss 1440,nop,nop,sackOK>
^C
6 packets captured
6 packets received by filter
0 packets dropped by kernel


The way I see it traffic destined for 10.0.89.0 should be allowed to
enter via the NIC (10.0.88.254) as PF is allowing any source IP to
reach any destination IP if ports are 135,137-139,445

But now here's what I don't get..

I then had to allow traffic to pass via the same ports on
$ext_if/tun0, when the routing table is routing the traffic via the
gif tunnel (routing is set up fine, when ruleset flushed, works 100%).
 So I thought let me just try it out (as thats what tcpdump is telling
me is blocked) even though it sounds a little sketchy...

###tunnel filters
 pass  in on $gif_if all
 pass out on $gif_if all
 pass  in on $ext_if inet proto ipencap   from any  to any
 pass out on $ext_if inet proto ipencap   from any  to any
 pass  in on $int_if proto { udp,tcp }    from any  to any port {
135,137:139,445 }  keep state
 pass out on $int_if proto { udp,tcp }    from any  to any port {
135,137:139,445 }  keep state
 pass  in on $ext_if proto { udp,tcp }    from any  to any port {
135,137:139,445 }  keep state
 pass out on $ext_if proto { udp,tcp }    from any  to any port {
135,137:139,445 }  keep state

and that works perfectly.


The only thing I can think of is that pf sees the gif interface as a
virtual device and doesnt apply the rule to the virtual device but
rather the physical device the virtual device uses (tun0/$ext_if)
which seems very unlikely but i can't think what else it could be as i
see references to the tun0 device in tcpdump (the rl0/$int_if
references in tcpump in the first instance seems obvious... have to
allow the traffic in via the NIC to the local lan before being able to
transport it to the other lan via the gif tunnel)

Any comments/ views on this?

Perhaps there is something not 100% with my conf?   (although it is
working now, it's not really ideal passing netbios traffic from any to
any)


Tue Apr 19 09:26:53 root@bollox:/home/stephen# uname -a
FreeBSD bollox.soh.local 5.3-STABLE FreeBSD 5.3-STABLE #2: Mon Mar  7
18:09:46 SAST 2005   =20
stephen@bollox.soh.local:/usr/obj/usr/src/sys/BOLLOX  i386

Tue Apr 19 10:21:13 root@bollox:/home/stephen# cat /etc/pf.conf
########## /etc/pf.conf
##### macros
int_if =3D "rl0"
ext_if =3D "tun0"
gif_if =3D "gif3"

icmp_types =3D "echoreq"

dns =3D "{ 196.25.1.1 }"
mail1 =3D "{ dbn.stormnet.co.za }"
mail2 =3D "{ smtp.saix.net }"

p2p_ports =3D " { 6346 }"
p2p_clients =3D "{ 10.0.88.5 , 10.0.88.11 , 10.0.88.12 , 10.0.88.23 }"
studio =3D "{ 10.0.88.5 , 10.0.88.11 , 10.0.88.12 }"

sh =3D "10.0.88.23/24"

priv_nets =3D "{ 127.0.0.0/8, 192.168.0.0/16, 172.16.0.0/12, 10.0.0.0/8 }"
soh =3D"{ 10.0.88.1 , 10.0.88.2 , 10.0.88.3 , 10.0.88.4 , 10.0.88.5 ,
10.0.88.6 , 10.0.88.7 , 10.0.88.8 , 10.0.88.9 , 10.0.88.10 ,
10.0.88.11 , 10.0.88.12 , 10.0.88.13 , 10.0.88.14 , 10.0.88.15 ,
10.0.88.16 , 10.0.88.17 , 10.0.88.18 , 10.0.88.19 , 10.0.88.20 ,
10.0.88.21 , 10.0.88.22 , 10.0.88.23 , 10.0.88.24 , 10.0.88.25 ,
10.0.88.26 , 10.0.88.27 , 10.0.88.28 , 10.0.88.29 , 10.0.88.30 }"

vpn_conf =3D "{ x.y.z.237 }"


##### aliases
int_net=09=09=3D "{" $int_if:network "}"

##### behavior options
set optimization aggressive
set block-policy return
set loginterface $ext_if
set fingerprints "/etc/pf.os"

##### scrub
scrub in all

##### nat/rdr
nat on $ext_if from $int_net to any -> ($ext_if)
rdr on $int_if proto tcp from any to any port 80 -> 127.0.0.1 port 3128
rdr on $int_if proto tcp from any to any port 21 -> 127.0.0.1 port 8021

##### anti spoofing protection
#antispoof quick for $int_if inet
#antispoof quick for $ext_if inet
#antispoof quick for lo0

#block drop in  on $ext_if from $priv_nets to any
#block drop out on $ext_if from any to $priv_nets

#####filter rules
###default block and log all
 block log all
 block in log quick  inet6 all
 block out log quick inet6 all
 pass in  quick=09     inet proto icmp all icmp-type $icmp_types keep state
 pass out quick      inet proto icmp all icmp-type $icmp_types keep state
 pass quick =09     on lo0 all


###filter rules for $int_if inbound
 block in log =09on $int_if all
#pass in on $int_if from $soh to $int_if keep state
 pass in on $int_if proto tcp from any to $int_if port 2222 keep state
#pass in on $int_if proto tcp  from any to $dns keep state=20
 pass in on $int_if proto { udp,tcp } from $int_net to any port =3D 53 keep=
 state
 pass in on $int_if proto tcp from $soh to any port =3D 3128 flags S/SA
keep state
 pass in on $int_if proto tcp from $soh to any port =3D 443 flags S/SA keep=
 state=20
#pass in on $int_if proto tcp from $int_net to $int_if port { 21,20 } keep =
state
#pass in on $int_if proto tcp from $int_net to any port 8021 keep state
 pass in on $int_if proto tcp from $soh to $int_if port 25 keep state=20
 pass in on $int_if proto tcp from $soh to $int_if port 110 keep state=20
 pass in on $int_if proto { udp,tcp } from $int_net to any port 6346 keep s=
tate
 pass in on $int_if proto tcp from $int_net to ($ext_if) port { 25,110
} keep state
 pass in on $int_if proto tcp from $int_net to $mail1 port { 25,110 } keep =
state
 pass in on $int_if proto tcp from $int_net to $mail2 port { 25,110 } keep =
state
 pass in on $int_if proto tcp from $int_net to any port { 2222 } keep state

###filter rules for $int_if outbound
 block out log on $int_if all
#pass out on $int_if all keep state
#pass out on $int_if inet proto tcp from $int_if to $int_net port 20 keep s=
tate

###filter rules for $ext_if inbound
 block in log on $ext_if all
#pass in on $ext_if inet proto tcp from any to ($ext_if)  port 20  keep sta=
te
#pass in on $ext_if inet proto tcp from any to ($ext_if)  port 21  keep sta=
te
 pass in on $ext_if inet proto tcp from any to ($ext_if)  port 25  keep sta=
te
 pass in on $ext_if inet proto tcp from any to ($ext_if)  port 110 keep sta=
te
#pass in on $ext_if inet proto tcp from any to ($ext_if)  port 2222 keep st=
ate
#pass in on $ext_if inet proto tcp from any to any=09  port 55000:57000 kee=
p state

##block nmap's fingerprinting attempt(FIN, URG, PSH)
 block in log quick on $ext_if inet proto tcp from any to any flags FUP/FUP


###filter rules for $ext_if outbound
 block out log =09on $ext_if all
 pass out on $ext_if inet proto udp from any =09   to $dns  port 53 keep st=
ate=20
#pass out on $ext_if inet proto tcp from any =09   to $dns port 53 flags
S/SA keep state
 pass out on $ext_if inet proto tcp from ($ext_if) to $vpn_conf=09flags
S/SA keep state
#pass out on $ext_if inet proto tcp from ($ext_if) to any port 21 keep stat=
e
#pass out on $ext_if inet proto tcp from ($ext_if) to any port 20 keep stat=
e=20
#pass out on $ext_if inet proto tcp from ($ext_if) to any port 8021 keep st=
ate
 pass out on $ext_if inet proto tcp from ($ext_if) to $mail1 port 25 keep s=
tate=20
 pass out on $ext_if inet proto tcp from ($ext_if) to $mail1 port 110
keep state
 pass out on $ext_if inet proto tcp from ($ext_if) to $mail2 port 25 keep s=
tate=20
 pass out on $ext_if inet proto tcp from ($ext_if) to any port 80 keep stat=
e=20
 pass out on $ext_if inet proto tcp from ($ext_if) to any port 443 keep sta=
te=20
 pass out on $ext_if inet proto tcp from ($ext_if) to any port 6346 keep st=
ate=20
 pass out on $ext_if inet proto tcp from ($ext_if) to any port {
22,2222 } keep state

=20
###tunnel filters
 pass in  on $gif_if all
 pass out on $gif_if all
 pass in  on $ext_if inet proto ipencap from any to any =09=09=09=09=20
 pass out on $ext_if inet proto ipencap from any to any  =09=09=09=20
 pass in  on $int_if proto { udp,tcp }  from any to any port {
135,137:139,445 } keep state
 pass out on $int_if proto { udp,tcp }  from any to any port {
135,137:139,445 } keep state
 pass in  on $ext_if proto { udp,tcp }  from any to any port {
135,137:139,445 } keep state
 pass out on $ext_if proto { udp,tcp }  from any to any port {
135,137:139,445 } keep state


ps: the reason ports and hosts are seperated is because of labelling
pps: everything related to ftp has been commented out because I cant
get it working, but thats another battle for another day =3D]


Thanks,


Stephen



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?ee918c780504190440397842f0>