FreeBSD Firewalls SS- E 2014. Kevin Chege ISOC



Similar documents
Murus. OS X PF Manual

DHCP & Firewall & NAT

Firewalling with OpenBSD and PF

OpenBSD in the wild...a personal journey

FIREWALL AND NAT Lecture 7a

Jason Dixon DixonGroup Consulting. September 17, 2005 NYCBSDCON 2005

Firewalls. Chien-Chung Shen

ΕΠΛ 674: Εργαστήριο 5 Firewalls

Network Security. Chapter 3. Cornelius Diekmann. Version: October 21, Lehrstuhl für Netzarchitekturen und Netzdienste Institut für Informatik

How To Set Up An Ip Firewall On Linux With Iptables (For Ubuntu) And Iptable (For Windows)

ΕΠΛ 475: Εργαστήριο 9 Firewalls Τοίχοι πυρασφάλειας. University of Cyprus Department of Computer Science

IPv6 Firewalls. ITU/APNIC/MICT IPv6 Security Workshop 23 rd 27 th May 2016 Bangkok. Last updated 17 th May 2016

CMPT 471 Networking II

Firewalls. Pehr Söderman KTH-CSC

Track 2 Workshop PacNOG 7 American Samoa. Firewalling and NAT

Firewalling with OpenBSD s PF packet filter

Firewalling with OpenBSD s PF packet filter

7. Firewall - Concept

Firewalls P+S Linux Router & Firewall 2013

HOWTO. Bandwidth Management for ADSL with OpenBSD

IPv6 Security from point of view firewalls

Firewalls. ITS335: IT Security. Sirindhorn International Institute of Technology Thammasat University ITS335. Firewalls. Characteristics.

Firewalls. Contents. ITS335: IT Security. Firewall Characteristics. Types of Firewalls. Firewall Locations. Summary

Chapter 7. Firewalls

Firewall Firewall August, 2003

Firewalls. Ola Flygt Växjö University, Sweden Firewall Design Principles

Status of Open Source and commercial IPv6 firewall implementations

CSE331: Introduction to Networks and Security. Lecture 12 Fall 2006

Building a Home Firewall/Router Using OpenBSD-Sparc. Joshua Malone (jmalone@ubergeeks.com)

CIS 433/533 - Computer and Network Security Firewalls

CSE543 - Computer and Network Security Module: Firewalls

What is a Firewall? A choke point of control and monitoring Interconnects networks with differing trust Imposes restrictions on network services

CS Computer and Network Security: Firewalls

FIREWALLS & CBAC. philip.heimer@hh.se

Firewall Testing. Cameron Kerr Telecommunications Programme University of Otago. May 16, 2005

TECHNICAL NOTES. Security Firewall IP Tables

A host-based firewall can be used in addition to a network-based firewall to provide multiple layers of protection.

Firewalls with IPTables. Jason Healy, Director of Networks and Systems

INTRODUCTION TO FIREWALL SECURITY

Firewalls. Network Security. Firewalls Defined. Firewalls

+ iptables. packet filtering && firewall

Linux Routers and Community Networks

Virtual private network. Network security protocols VPN VPN. Instead of a dedicated data link Packets securely sent over a shared network Internet VPN

Protecting and controlling Virtual LANs by Linux router-firewall

Module: Firewalls. Professor Patrick McDaniel Spring CMPSC443 - Introduction to Computer and Network Security

Firewalls. CEN 448 Security and Internet Protocols Chapter 20 Firewalls

Firewalls, NAT and Intrusion Detection and Prevention Systems (IDS)

accf_smtp: FreeBSD kernel protection measures against SMTP DDoS and DoS attacks

Cryptography and network security

CIT 480: Securing Computer Systems. Firewalls

Murus 1.1. User Manual

Firewalls & Intrusion Detection

Lehrstuhl für Informatik 4 Kommunikation und verteilte Systeme. Firewall

CS Computer and Network Security: Firewalls

Lecture 23: Firewalls

Introduction to Firewalls

Cisco PIX vs. Checkpoint Firewall

20-CS X Network Security Spring, An Introduction To. Network Security. Week 1. January 7

CSE 4482 Computer Security Management: Assessment and Forensics. Protection Mechanisms: Firewalls

Firewalls. Firewalls. Idea: separate local network from the Internet 2/24/15. Intranet DMZ. Trusted hosts and networks. Firewall.

We will give some overview of firewalls. Figure 1 explains the position of a firewall. Figure 1: A Firewall

Securing Networks with PIX and ASA

A S B

Dante a BSD licensed SOCKS implementation. Inferno Nettverk A/S. Bergen Linux User Group

Firewalls. Test your Firewall knowledge. Test your Firewall knowledge (cont) (March 4, 2015)

CSC574 - Computer and Network Security Module: Firewalls

CIT 480: Securing Computer Systems. Firewalls

Firewalls. Chapter 3

Chapter 20 Firewalls. Cryptography and Network Security Chapter 22. What is a Firewall? Introduction 4/19/2010

Distributed Systems. Firewalls: Defending the Network. Paul Krzyzanowski

12. Firewalls Content

Netfilter / IPtables

Host Discovery with nmap

Overview. Firewall Security. Perimeter Security Devices. Routers

MULTI WAN TECHNICAL OVERVIEW

Lab 3: Recon and Firewalls

Lecture slides by Lawrie Brown for Cryptography and Network Security, 5/e, by William Stallings, Chapter 22 Firewalls.

Security Technology: Firewalls and VPNs

Optimisacion del ancho de banda (Introduccion al Firewall de Linux)

CS 356 Lecture 19 and 20 Firewalls and Intrusion Prevention. Spring 2013

Security threats and network. Software firewall. Hardware firewall. Firewalls

ECE 578 Term Paper Network Security through IP packet Filtering

Firewall. IPTables and its use in a realistic scenario. José Bateira ei10133 Pedro Cunha ei05064 Pedro Grilo ei09137 FEUP MIEIC SSIN

Linux Cluster Security Neil Gorsuch NCSA, University of Illinois, Urbana, Illinois.

Technical Note. ISP Protection against BlackListing. FORTIMAIL Deployment for Outbound Spam Filtering. Rev 2.2

Firewall. Vyatta System. REFERENCE GUIDE IPv4 Firewall IPv6 Firewall Zone Based Firewall VYATTA, INC.

FreeBSD 8, ipfw and OpenVPN 2.1 server (bridged mode)

How To Load balance traffic of Mail server hosted in the Internal network and redirect traffic over preferred Interface

Security+ Guide to Network Security Fundamentals, Fourth Edition. Chapter 6 Network Security

CSCI Firewalls and Packet Filtering

Firewall. Vyatta System. REFERENCE GUIDE IPv4 Firewall IPv6 Firewall Zone Based Firewall VYATTA, INC.

Firewall Defaults, Public Server Rule, and Secondary WAN IP Address

Linux firewall. Need of firewall Single connection between network Allows restricted traffic between networks Denies un authorized users

Firewalls and System Protection

Computer Security CS 426 Lecture 36. CS426 Fall 2010/Lecture 36 1

Allocating Network Bandwidth to Match Business Priorities

Transcription:

FreeBSD Firewalls SS- E 2014 Kevin Chege ISOC

What s a Firewall? Computer network security device to protect devices, or restrict access to or from a network Analyzes traffic coming in or going out (or through it) and determines a course of acbon based on a pre- defined rule set Firewalls can be found anywhere: On your laptop OS On routers On server OS On network hardware appliances

Types of firewalls Packet Filters analyze network packets and decide a course of acbon based on configurabon Stateful Filters track network conversabons and maintain a table of which connecbons are in an acbve conversabons ApplicaBon layer aka Layer 7 firewalls are able to detect if an unwanted protocol is anempbng to bypass the firewall on an allowed port

Keeping State vs Stateless Stateful inspecbon refers to ability to track the state, or progress, of a network connecbon By storing informabon about each connecbon in a state table, a firewall is able to quickly determine if a packet passing through the firewall belongs to an already established connecbon. If it does, it is passed through the firewall without going through ruleset evaluabon saving Bme and avoiding extra processing.

Typical features of a Firewall Rule Syntax NAT control Able to pass, redirect or drop traffic based on the rules Logging feature to allow audit of acbvibes and of traffic Stateful inspecbon - not all and may need to be enabled with extra config opbons Ability to be either inclusive or exclusive - An exclusive firewall allows all traffic through except for the traffic matching the ruleset (default is to allow). Inclusive firewall does the reverse (default is to block)

FreeBSD Firewalls FreeBSD ships with 3 Main firewalls: IPFW IP FireWall is (by default) a stateless firewall. FreeBSD sponsored firewall sozware applicabon authored and maintained by FreeBSD volunteer staff members. IPF IP Filter can be configured as stateful or stateless. Open source applicabon and has been ported to FreeBSD, NetBSD, OpenBSD, SunOS, HP/ UX, and Solaris operabng systems. IPFILTER is acbvely being supported and maintained, with updated versions being released regularly. PF Packet Filter can be configured as stateful or stateless. Maintained by OpenBSD Project

PF (Packet Filter) Was inibally developed for OpenBSD Has been successfully ported to many other operabng systems including all the other BSDs and Mac OS X WriNen by Daniel Hartmeier Derived its rule syntax from IPFilter Has many features

Features Can do both stateless or state- full firewalling Can do Network Address TranslaBon AddiBonally can do BidirecBonal NAT aka One to One NAT Combined with ALTQ (ALTernate Queueing framework for BSD) can perform QoS Priority queuing assign certain traffic a higher priority than others before forwarding Class Based Queuing assigning bandwidth to certain queues and reducing bandwidth for others Can be configured for automabc fail- over between 2 boxes using CARP Common Address Redundancy Protocol

Features cont d FTP- proxy integrabon to handle FTP firewalling Configurable logging per rule to pflogd Logs can be further monitored with tcpdump Simple IP Filter rule syntax Eg: pass in quick on em0 inet proto tcp all Macro definibon to simplify rule creabon Eg idenbfy an interface as LAN instead of em0 Support for transparent proxying with SQUID Redirect all traffic desbned for a port 80 to the Squid port 8080 for Squid to process Among many others

Working with PF Installed by default on FreeBSD since FreeBSD 5.3 but is disabled Can start in from boot by adding the following to /etc/ rc.conf: pf_enable=yes Or by kldload pf.ko Start it by doing /etc/rc.d/pf start OR pfctl e You may want to compile pf support into the kernel to enable: Pfsync seudo device CARP for automabc failover ALTQ for prioribzabon, bandwidth thronling

OpJons in rc.conf pf_enable="yes" # Enable PF (load module if required) pf_rules="/etc/pf.conf" # rules definibon file for pf pf_flags="" # addibonal flags for pfctl startup pflog_enable="yes" # start pflogd(8) pflog_logfile="/var/log/pflog" # where pflogd should store the logfile pflog_flags="" # addibonal flags for pflogd startup You will also want to enable packet forwarding between interfaces and this can be done by gateway_enable= YES in /etc/rc.conf

Working with PF pfctl e Enable PF pfctl - d Disable PF pfctl - F all - f /etc/pf.conf Flush all rules (nat, filter, state, table, etc.) and reload pfctl - s [ rules nat state ] Report on the filter rules, nat rules, or state table pfctl - vnf /etc/pf.conf Check /etc/pf.conf for errors, but do not load ruleset

Packet Filtering with PF Rules are loaded from a file usually /etc/pf.conf Packets can be passed, redirected or dropped as they pass through an interface PF inspects packets based on Layer 3 (IPv4/IPV6) and Layer 4 headers (TCP, UDP, ICMP/v6) Can check for source/desbnabon address, protocol (Layer 4) and source/desbnabon port Rules evaluated in sequenbal order top to bonom of the file

Packet Filtering with PF cont d A packet is evaluated against all the rules UNLESS the key word quick is specified If quick is not specified then the last rule to match wins and acbon is taken on the packet There is an implicit pass all at the beginning meaning that if a packet does not match any rule then it will be passed You are free to circumvent this feature if you want by having a block all at the top of the file

Rule Syntax acbon [direcbon] [log] [quick] [on interface] [af] [proto protocol] [from src_addr [port src_port]] [to dst_addr [port dst_port]] [flags tcp_flags] [state] acjon pass or block direcjon in or out log should this be logged or not quick specified acbon is taken immediately on interface name of the interface inet address family, inet6 for ipv6 protocol tcp, udp, icmp, icmp6 or others in /etc/protocols src_addr/dst_addr source port or desbnabon address src_port/dst_port Number between 1 65535 (/etc/services tcp_flags eg flags S/SA look only for SYN and ACK state whether to check state. PF checks state by default

Good pracjce Recommended to have default deny at the beginning of the file so that what you do not specify is denied by default. i.e. to make it an exclusive firewall This is to counter the default pass rule Done by adding the below at the top of the file block in all Also good idea to leave out the loopback interface and link local addresses set skip on lo0 You can set a macro eg: ipv6_ll= fe80::/10

Keeping state in PF Keeping state has many advantages including simpler rulesets and bener packet filtering performance. PF is able to match packets moving in either direcbon to state table entries meaning that filter rules which pass returning traffic don't need to be wrinen. Since packets matching stateful connecbons don't go through ruleset evaluabon, the Bme PF spends processing those packets can be greatly lessened.

Keeping state cont d When a rule creates state, the first packet matching the rule creates a "state" between the sender and receiver. Not only do packets going from the sender to receiver match the state entry and bypass ruleset evaluabon, but so do the reply packets from receiver to sender. All pass rules automabcally create a state entry when a packet matches the rule. This can be explicitly disabled by using the no state opbon.

Understanding the PF Rules Rules are red from top to bonom A matching pass rule in one direcbon automabcally creates a matching pass rule in the other direcbon Eg pass out all automabcally creates a pass in all PF allows everything in or out by default and you may (or may not) want this The last rule to match the packet wins If the packet is not matched it is allowed through anyway (default allow exclusive) If you don t want this, you must set an implicit block in the direcbon you want to block

What about default deny? The recommended pracbce when setng up a firewall is to take a "default deny" approach. That is, to deny everything and then selecbvely allow certain traffic through the firewall. This approach is recommended because it errs on the side of caubon and also makes wribng a ruleset easier. the first two filter rules should be: block in all block out all This will block all traffic on all interfaces in either direcbon from anywhere to anywhere. HOWEVER, you may opt to approach your firewall rules differently depending on the scenario

Passing Traffic pass in on dc0 from 192.168.0.0/24 to 192.168.0.1! pass out on dc0 from 192.168.0.1 to 192.168.0.0/24! pass in quick on em0 from 172.16.1.1 to any! pass out on em0 from any to 172.16.1.1! pass in quick on em0 inet proto icmp from any to any! pass in quick on rl0 inet proto udp from any port 53 to 192.168.0.1! block in quick all! block out quick all! What will the above rules do?

Sample File block in all #block stuff by default! set skip on lo0! pass in log on em0 inet proto tcp all! pass out on em0 inet proto tcp all! Will UDP traffic pass? Why? Will ICMP Traffic pass? Why?

Sample Rules 2 block in all #block stuff by default! set skip on lo0! block in quick on em0 inet proto tcp from 192.168.0.1 80 to any! pass in on em0 inet proto tcp all! What happens here?

Macros Use macros to make rules simpler. Macros are usually idenbfied at the top of the file ruleset. Sample Macros: ext_if= em0! int_if= em1! LAN= 192.168.0.0/24! good_ports= { 80, 22, 110}! bad_ips= { 172.16.0.0/23, 10.10.0.0/16,}! my_pc= 172.16.1.1! Macros cannot contain a hyphen however so ext- if= em0 will not work

Macros cont d Macros are then called using the $ sign in the ruleset: block in all #block stuff by default! set skip on lo0! pass in on $int_if inet proto tcp from any\ $good_ports to any! block in quick on $ext_if from any $bad_ips\!!

Sample Web Server 1 good_ports= { 22, 443, 80 } me= 192.168.0.1 #Web Server IP set skip on lo0! block in all! pass out all! pass in on em0 inet proto tcp from any to $me port \ $good_ports ##This is sufficient to allow any communicabon that the server inibates (pass out all), allow all incoming tcp traffic to the good ports and block all other incoming traffic. The pass out all is needed despite PF having an implicit pass rule. Removing it will mean traffic out will not match any rule but incoming replies to conversabons inibated by the server will be matched against the block in all rule.

Sample Web Server 2 good_ports= { 22, 443, 80 } me= 192.168.0.1 #Web server IP! set skip on lo0! pass in quick on em0 inet proto tcp from any to $me \ port $good_ports! block in all! pass out all! ##These rules will pass the good ports first (due to quick word) then block all incoming traffic (block in all). Outgoing traffic will be allowed as long as the server sent the first packet (pass out all)

Sample Web Server 3 good_ports= { 22, 443, 80 } me= 192.168.0.1 #Web Server! set skip on lo0! pass in on em0 inet proto tcp from any to $me port \ $good_ports! block in all! pass out all! ##These rules will block all incoming traffic (block in all) including traffic to the good ports hence this is a badly formaned ruleset. Outgoing traffic will be allowed out but incoming replies will be dropped so this a broken ruleset

Simple Mail Server example 1 good_ports= { 22, 25, 110, 143, 993, 995, 443, 80 } good_udp= 53! block in all! pass out all! set skip on lo0! pass in on em0 inet proto tcp from $good_ports to \ any! pass in on em0 inet proto udp from any port \ $good_udp! ##These rules will pass the good ports on tcp, pass any udp traffic with a source port of 53 then block all incoming traffic (block in all). Outgoing traffic will be allowed as long as the server sent the first packet (pass out all)

Simplest way to organize the ruleset Put your Macros at the top If you are on IPv6 add a macro for link local (fe80::/10) Skip the lo0 set skip on lo0 Put the block in all at the top so that all traffic that you do not specify is dropped Allow traffic that your server inibates pass out all However if the machine gets compromised, for example, is hacked and is used to anack other networks, you will have to change this rule Allow link local addresses (if you are on an IPv6 network) Allow the traffic and ports that you wish

Logging When you acbvate logging, a new virtual interface will be created called pflog0 Doing a tcpdump on this interface will provide details of all traffic that you have chosen to log You can also direct all logs to /var/logs/pflog by adding the following to /etc/rc.conf pflog_logfile="/var/log/pflog"

Other PF Features AnJspoofing - when a malicious user fakes the source IP address in packets they transmit in order to either hide their real address or to impersonate another node on the network AnJ- SPAM when used with a sozware called spamd which downloads a list a blacklisted IP Addresses which can be fed to PF to block (spamd is not spamassassin) Gateway Firewall add to /etc/rc.conf gateway_enable="yes" #for ipv4 ipv6_gateway_enable="yes" #for ipv6!

References and more reading hnp://en.wikipedia.org/wiki/pf_%28firewall %29 hnp://www.openbsd.org/faq/pf/filter.html hnp://www.freebsd.org/doc/ en_us.iso8859-1/books/handbook/firewalls- pf.html hnp://en.wikipedia.org/wiki/firewall_ %28compuBng%29