Unix Technical Forum

SEO

vBulletin Search Engine Optimization


Go Back   Unix Technical Forum > Unix Operating Systems > OpenBSD > comp.unix.bsd.openbsd.misc

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-16-2008, 04:17 AM
theman@theworld.com
 
Posts: n/a
Default please check my pf rule

hi

need some help refining my pf rules
the majority of the rules are from various sources on the net
so you might find some rules that are redundent

general details
connection type = cable
ip address = dynamic (dhcp)


thanx
Shadrock
--------------------------------------------------------------------------------





# PF ruleset, 14 June 2003
# # Liberally adapted from the pf man page,
# the OpenBSD "Network How-To",
# and my own rulesets.
# Ras Shadrock Uhuru
#--------------------------------------------------------------------------
# MACROS
# INTERFACES

# internal network
INT_IFACE = "xl0"
# demilitarised network
DEMIL_IFACE = "xl1"
# external network
EXT_IFACE = "ep0"
# local host interface
LO_IFACE = "lo0"
# wireless network
# WIRE_IFACE = ""

# NETWORKS
INT_ZONE = "192.168.1.0/24"
DEMIL_ZONE = "172.16.1.0/12"

++++++++++++++++++++++++++++++++++++++++++++++++++ ++
================================================== ==
(Q1) how do i refer to the external zone
how do i refer to the firewall itself e.g. to ssh to the
firewall for administration
================================================== ==
EXT_ZONE = "x.x.x.0/24"
FIREWALL = x.x.x.x
++++++++++++++++++++++++++++++++++++++++++++++++++ +++

# DMZ SERVERS
DNS_SERV1 = "172.16.1.1"
DNS_SERV2 = "172.16.1.2"
MAIL_SERV = "172.16.1.3"
WEB_SERV = "172.16.1.4"

++++++++++++++++++++++++++++++++++++++++++++++++++ +++
================================================== ====
(Q2) these are macros for the binat rule,
should they have proper inet address instead of the x's
==================================================
DNS_EXT1 = "x.x.x.1"
DNS_EXT2 = "x.x.x.2"
MAIL_EXT = "x.x.x.3"
WEB_EXT = "x.x.x.4"
++++++++++++++++++++++++++++++++++++++++++++++++++ +++

# SPECIALS
# Non-routable IP numbers
#-----------------------------------------------------------------------
#192.168.0.0/16 #RFC 1918 private IP
#172.16.0.0/12 #RFC 1918 private IP
#10.0.0.0/8 #RFC 1918 private IP
#127.0.0.0/8 #loopback
#0.0.0.0/8 #loopback
#169.254.0.0/16 #DHCP auto-config
#192.0.2.0/24 #reserved for doc's
#204.152.64.0/23 #Sun cluster interconnect
#224.0.0.0/3 #Class D & E multicast


RESERVED = "{ 192.168.0.0/16, 127.0.0.0/8, 172.16.0.0/12, 10.0.0.0/8,
0.0.0.0/8, 169.254.0.0/16, 192.0.2.0/24, 204.152.64.0/23,
224.0.0.0/3}"

# TRUSTED = "{tba}"

InServicesTCP = "{ ssh, smtp, auth, http, https, pop3 }"
OutServicesTCP = "{ http, https, smtp, pop3,pop3s, whois, domain,
ssh,telnet, ftp, ftp-data, sftp, nntp, auth, ntp }"
# OUTTCP =
"{21,22,23,25,43,53,80,110,443,554,871,1214,1863,2 401,5050}"
++++++++++++++++++++++++++++++++++++++++++++++++++ +++
InServicesUDP = "{ domain }"
================================================== ===
(Q3) should i add port 67/68 to InServicesUDP
================================================== ===
#INUDP = "{68}"
OutServicesUDP = "{ domain,ntp }"
# OUTUDP = "{53,123}"
INICMP = "{3,11}"

+++++++++++++++++++++++++++++++++++++++++++++
============================================
(Q4) are these correct
===========================================
OUTTRACEROUTE = "{33434><33525}"
FTPPORTS="{ 55000 >< 57000 }"
++++++++++++++++++++++++++++++++++++++++++++

XMMS = "{ 6000, 7500, 8000, 8004, 8044, 8034, 8052, 8038, 8010, 8400,
8014, 8026, 8048, 8002, 8024, 8028, 8080 }"
RealAudio = "{ 554, 7070, 8080 }"


#--------------------------------------------------------------------------
# OPTIONS
#--------------------------------------------------------------------------
# log all packets on external interface
set loginterface $EXT_IFACE

# set max of 20k keep states and 20k scrub entries
set limit {state 20000,frag 20000}

# set optimisation to normal
set optimisation normal

#
#--------------------------------------------------------------------------
# Clean up fragmented and abnormal packets
# By default in pf, packets which contain IP options are blocked.
Good.
# scrub in on { $EXT_IFACE , $INT_IFACE} all
scrub in all


#--------------------------------------------------------------------------
# QUEUEING
#-------------------------------------------------------------------------
# NAT


# nat internal ip addr range 192.168.1.0/24
# to external ip routable ip on external interface
nat on $EXT_IFACE from $INT_ZONE to any -> ($EXT_IFACE )

++++++++++++++++++++++++++++++++++++++++++++++++++ +++++++++++++
================================================== =============
(Q5) is the first binat rule ok
i've modified if from
binat on $EXT_IFACE inet from $WEB_SERV to any ->
$WEB_EXT
the idea was to let the EXT_IFACE be the final
address
================================================== ===========
# web servers in dmz
# binat on $EXT_IFACE inet from $WEB_SERV to any -> $EXT_IFACE
# binat on $INT_IFACE inet from $WEB_SERV to any -> $INT_IFACE

# mail servers in dmz
# binat on $EXT_ZONE inet from $MAIL_SERV to any -> $MAIL_EXT
# binat on $INT_ZONE inet from $MAIL_SERV to any -> $MAIL_EXT

# dns servers in dmz
# binat on $EXT_ZONE inet from $DNS_SERV to any -> $DNS_EXT
# binat on $INT_ZONE inet from $DNS_SERV to any -> $DNS_EXT
++++++++++++++++++++++++++++++++++++++++++++++++++ +++++++++++++


# add to /etc/inetd.conf
# 127.0.0.1:8081 stream tcp nowait root /usr/libexec/ftp_proxy

# redirect ftp client behind nat on external interface to ftp proxy
daemon
rdr on $INT_IFACE inet proto tcp from any to $EXT_ZONE port 21 ->
127.0.0.1 port 8081

# redirect web
rdr on $INT_IFACE inet proto tcp from any to any port www ->
127.0.0.1 port 3128



# FILTERS


# Defaults

# Immediate blocks
# fuzz any 'nmap' fingerfrinting attempt

++++++++++++++++++++++++++++++++++++++++++++++++++ +++++++++++++
block in log quick on $EXT_IFACE inet proto tcp from any to any \
flags { FUP/FUP, SF/SFRA,P/SFRA, F/SFRA, U/SFRAU }
#SFUP,/SFRA
=============================================
(Q6) do i use all the flags above or just these below
=============================================

block in log quick on $EXT_IFACE inet proto tcp from any to any
flags FUP/FUP
block in log quick on $EXT_IFACE inet proto tcp from any to any
flags SF/SFRA
block in log quick on $EXT_IFACE inet proto tcp from any to any
flags /SFRA
++++++++++++++++++++++++++++++++++++++++++++++++++ +++++++++++++

++++++++++++++++++++++++++++++++++++++++++++++++++ +++++++++++++
# prevent spoofing of non-routable addresses on DMZ network
===============================
(Q7) do i need this
==============================
block in log quick on $DEMIL_IFACE inet proto tcp from ! $DEMIL_ZONE
to any
block out log quick on $DEMIL_IFACE inet proto tcp from any to !
$DEMIL_ZONE
++++++++++++++++++++++++++++++++++++++++++++++++++ +++++++++++++

# don't allow anyone to spoof non-routeable addresses
# block anything coming from source we have no back routes for

block in log quick on $EXT_IFACE inet proto tcp from $RESERVED to
any
block out log quick on $EXT_IFACE inet proto tcp from any to
$RESERVED


# antispoof for local interface
antispoof for lo0
# antispoof for internal interface
antispoof for xl0
# antispoof for demilitary interface
antispoof for xl1
# antispoof for external interface
antispoof for ep0
# antispoof for wireless interface
# antispoof for wp0

# silently drop broadcasts (cable modem noise)
block in quick on $EXT_IFACE from any to 255.255.255.255/32
block out quick on $EXT_IFACE from 255.255.255.255/32 to any

block in quick inet6 all
block out quick inet6 all

# egress filtering
# filter outbound traffic that doesn't have a valid external address
as source
block out log quick on $EXT_IFACE inet proto tcp from !$EXT_ZONE
to any

# loopback packets left unmolested
pass in quick on $LO_IFACE all
pass out quick on $LO_IFACE all

#allow internal traffic to flow freely
pass in quick on $INT_IFACE all
pass out quick on $INT_IFACE all

#allow outgoing DMZ traffic to flow freely(not to internal network)
pass in quick on $DMZ_IFACE inet proto tcp from $DMZ_ZONE to
!$INT_ZONE flag S/SA keep state

# block and log everything
# block out log all
# block in log all

block return log all
================================================== =========
(Q8) as some of the rules are from various source
there my be some redundency in the rules
please remove redundent rules
================================================== ==========

# ICMP (ping)

# Pass desired ICMP traffic
pass in log quick inet proto icmp all icmp-type 3 code 4 keep state

# traceroute from internal host , recieving error code of icmp-type 11
(time exceeded)
pass in log quick inet proto icmp all icmp-type 11 keep state

pass in log quick on $EXT_IFACE inet proto icmp all icmp-type 8 code 0
keep state

pass in log quick on $EXT_IFACE inet proto icmp all icmp-type 30 code
0 keep state
#--------------------------------------------------------------------------------

# traceroute to internal host , recieving error code of icmp-type 11
(time exceeded)
pass out quick on $EXT_IFACE inet proto icmp from any to any icmp-type
$INICMP

pass out quick on $EXT_IFACE inet proto icmp all icmp-type 8 code 0
keep state

pass out quick on $EXT_IFACE inet proto icmp all icmp-type 30 code 0
keep state

#
-----------------------------------------------------------------------------

block in on $EXT_IFACE inet proto icmp all

# handle outgoing icmp traffic , allow everything directed to the
internet from
# LAN/DMZ and related replies
# allow icmp packets dir3ected to the DMZ server
# block and log all other icmp packets (especially from DMZ to LAN)

# enable internet access
pass out on $EXT_IFACE inet proto icmp from $EXT_ZONE to any keep
state

# enable dmz access
pass in on $EXT_IFACE inet proto icmp from any to $DEMIL_ZONE keep
state

# dmz -> internet
pass in on $DMZ_IFACE inet proto icmp from $DEMIL_ZONE to $EXT_ZONE
keep state

# internet-> dmz
pass out on $DMZ_IFACE inet proto icmp from any to $DEMIL_ZONE keep
state

#
-----------------------------------------------------------------------------


# handle outgoing udp traffic , everything directed at the internet
from LAN/DMZ and related replies
#block and log all other udp packets

# traceroute
pass out quick on $EXT_IFACE inet proto udp from any to any port
$OUTTRACEROUTE
# allow internal and firewall initiated connection from behind network

#Services we provide to the outside world
# Bootpc to fw
pass in quick on $EXT_IFACE inet proto udp from any to any port
$InServicesUDP keep state

# Standard services we want to access in the world
pass out quick on $EXT_IFACE inet proto udp from any to any port
$OutServicesUDP keep state

# syslog is open by default, if not used remove with next rule
#### block in quick log on $INT_IFACE proto udp from any to any port
524
#-------------------------------------------------------------------------------

block in on $EXT_IFACE inet proto udp all

# enable internet access
pass out on $EXT_IFACE inet proto udp from $EXT_ZONE to any keep state

# enable dmz access
pass in on $EXT_IFACE inet proto udp from any to $DEMIL_ZONE port 53
keep state

# enable dmz to internet access
pass in on $DEMIL_IFACE inet proto udp from $DEMIL_ZONE to $INT_ZONE
keep state

# enable internet to dmz access
pass out on $DEMIL_IFACE inet proto udp from any to $DEMIL_ZONE port
53 keep state

================================================== ==================
(Q9) do i need the following two rules
================================================== ==================
# These two rules make BOOTP/DHCP services available to the protected
hosts, via a server on the
# public side of the network. They may be overly restrictive, but have
worked properly during testing.
pass out on $EXT_IFACE inet proto udp from any port = bootpc to {
$INT_ZONE, 255.255.255.255 } port = bootps
pass in on $EXT_IFACE inet proto udp from $INT_ZONE port = bootps to
{ $INT_ZONE, 255.255.255.255 } port = bootpc


#
-----------------------------------------------------------------------------
# handle outgoing tcp traffic , allow everything directed to the
internet and related replies
# block and log all other tcp packets
pass out quick on $EXT_IFACE inet proto tcp all keep state


# ACK+PUSH usually for already established ssh/irc sessions
pass in log quick inet proto tcp from any to any flags AP/FSRPAU
pass in log quick inet proto tcp from any to any flags AF/FSRAU
pass in log quick inet proto tcp from any to any flags R/FSRPAU


# DCC
#### pass in on $INT_IFACE inet proto tcp from any to 10.0.1.3 port
65400>

#
-----------------------------------------------------------------------------
# allow all traffic to DMZ servers on port 21(ftp),80(http)
# also allow connection to the ssh remote admin server coming from
trusted address
# all other tcp packets are blocked and logged epeacially those coming
from DMZ to LAN
# note the specification of the "flags S/SA" allow us to accept only
tcp packet with
# SYN flag (and not ACK) set this is more restrictive than " flags
S/S"

# remote management
#pass in on $EXT_IFACE inet proto tcp from $TRUSTED to any(firewall)
port 22 flag S/SA

# only allow ssh connections from the local network if it's from the
trusted computer,
# 192.168.1.10. use "block drop" so that a TCP RST is sent to close
blocked connections right away.
# use "quick" so that this rule is not overridden by the "pass" rules
below.
block drop in quick on $INT_IFACE inet proto tcp from ! 192.168.1.10
to $INT_IFACE port ssh flags S/SA

# allow ssh connections in on the external interface as long as
they're
# NOT destined for the firewall (ie, they're destined for a machine on
# the local network). log the initial packet so that we can later tell
who is trying to connect.
pass in log on $EXT_IFACE inet proto tcp from any to { !$EXT_IFACE ,
!$INT_IFACE } port ssh flags S/SA keep state

#
-----------------------------------------------------------------------------
# enable internet access
pass out on $EXT_IFACE inet proto tcp from $EXT_ZONE to any flag
S/SA keep state


# enable dmz web server access
pass in on $EXT_IFACE inet proto tcp from any to $WEB_DMZ port {21,80}
pass out on $DMZ_IFACE inet proto tcp from any to $WEB_DMZ port
{21,80}

# enable dmz mail server access
pass in on $EXT_IFACE inet proto tcp from any to $MAIL_DMZ port
{25,11}
pass out on $DMZ_IFACE inet proto tcp from any to $MAIL_DMZ port
{25,11}

# enable dmz dns server access
pass in on $EXT_IFACE inet proto tcp from any to $DNS_DMZ port {68}
pass out on $DMZ_IFACE inet proto tcp from any to $DNS_DMZ port {68}

# web proxy
pass in on $INT_IFACE inet proto tcp from any to 127.0.0.1 port 3128
keep state
pass out on $EXT_IFACE inet proto tcp from any to any port www keep
state

# passsive ftp
pass out log quick on $EXT_IFACE inet proto tcp from any to any port >
1023 flags S/SA keep state

#pass in data mode connections for ftp-proxy running on this host.
#active ftp
pass in log quick on $EXT_IFACE inet proto tcp from any port 20 to any
port $FTPPORTS flags S/SA keep state

# IMPORTANT: Note that the "rdr" rule in the NAT section refers to the
INTERNAL
# network interface. Its purpose is to redirect all ftp-data requests
from the intranet to be redirected to
# the ftp-proxy on the firewall. Then the ftp-proxy channels those
into ports 49152-65535, and outputs # them on the internet. This is
why we have this hole in the firewall starting at port 49152. I know,
it is # in the IN direction, but that is how passive ftp works... It
is quite a broken protocol.

# Special services
pass out quick on $EXT_IFACE inet proto tcp from any to any port $XMMS
flags S/SA modulate state
pass out quick on $EXT_IFACE inet proto tcp from any to any port
$RealAudio flags S/SA modulate state

# Standard services we want to access in the world
pass out quick on $EXT_IFACE inet proto tcp from any to any port
$OutServicesTCP flags S/SA modulate state

# Services we provide to the outside world
pass in quick on $EXT_IFACE inet proto tcp from any to any port
$InServicesTCP flags S/SA keep state

# allow internal and firewall initiated connection from behind network
pass out quick on $EXT_IFACE inet proto tcp from any to any port
$OUTTCP



###----------------------------------------------------------------------
###
### WIRELESS INTERFACE
###

# INCOMING: traffic to fw, accept ssh & dhcp only, block the rest
pass in quick on $WIRE_IFACE proto tcp from $WIRE_IFACE /24 to
$WIRE_IFACE /32 port = 22 flags S/SA keep state

pass in quick on $WIRE_IFACE proto { tcp,udp } from $WIRE_IFACE /24 to
$WIRE_IFACE /32 port = 67 keep state

block in quick on $WIRE_IFACE from any to $WIRE_IFACE /32

# INCOMING: forward traffic to all over destinations (except bad ports
& broadcasts)
pass in quick on $WIRE_IFACE from $WIRE_IFACE /24 to any

# INCOMING DEFAULT: block the rest (spoofed packets...)
# OUTGOING: pass all.
pass out quick on $WIRE_IFACE proto { tcp,udp,icmp } from any to
$WIRE_IFACE /24 keep state



================================================== ======================

VPN ACCESS
The following ruleset is configured on the office firewall (firewall
A). Firewall B will be similar.

# xl0 is external interface
# ep0 is internal interface

# Default Deny and Log Everything
block in log all
block out log all

# Passing in encrypted traffic from security gateways
pass in on ep0 proto sipp-esp from 192.168.1.254 to 192.168.2.1
pass out on ep0 proto sipp-esp from 192.168.2.1 to 192.168.1.254

# Allow packets to pass from the internal (local) side of the VPN
# to the internal (remote) side of the VPN. This traffic will get
# encapsulated within the VPN tunnel on enc0 before going
# out the physical interface.

pass in quick on xl0 from 10.0.0.0/24 to 10.0.3.0/24
pass out quick on xl0 from 10.0.3.0/24 to 10.0.0.0/24

# If packets are on the encrypted interface, enc0, they have been
# authenticated / decrypted. Pass them.

pass in quick on enc0
pass out quick on enc0



Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 08:26 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
UnixAdminTalk.com

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 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006