Firewalls Implementation IPTables Firewall Implementation Taken from Red Hat Linux Firewalls, Bill McCarty Copyright Red Hat and Bill McCarty.

Slides:



Advertisements
Similar presentations
IUT– Network Security Course 1 Network Security Firewalls.
Advertisements

Ipchains and Iptables Linux operating system natively supports packet-filtering rules: Kernel versions 2.2 and earlier support the ipchains command. Kernel.
Firewalls and Intrusion Detection Systems
TCP/IP Network and Firewall. IP Packet Protocol  1 ICMP packet  6 TCP packet  17 UDP packet.
Packet Filtering CS-480b Dick Steflik. Stateless Packet Filters A border router configured to pass or reject packets based on information in the header.
Ipchains A packet-filtering Firewalls supported by Linux distributions.
FIREWALLS & NETWORK SECURITY with Intrusion Detection and VPNs, 2 nd ed. 6 Packet Filtering By Whitman, Mattord, & Austin© 2008 Course Technology.
Poor Man’s Firewall A firewall that can be setup and implemented with a minimum amount of time and money.
1 © 2005 Cisco Systems, Inc. All rights reserved. 111 © 2004, Cisco Systems, Inc. All rights reserved.
1 Chapter 6 Network Security Threats. 2 Objectives In this chapter, you will: Learn how to defend against packet sniffers Understand the TCP, UDP, and.
1 Figure 5-4: Drivers of Performance Requirements: Traffic Volume and Complexity of Filtering Performance Requirements Traffic Volume (Packets per Second)
Packet Filtering. 2 Objectives Describe packets and packet filtering Explain the approaches to packet filtering Recommend specific filtering rules.
FIREWALL Mạng máy tính nâng cao-V1.
NetFilter – IPtables Firewall –Series of rules to govern what Kind of access to allow on your system –Packet filtering –Drop or Accept packets NAT –Network.
07/11/ L10/1/63 COM342 Networks and Data Communications Ian McCrumRoom 5B18 Tel: voice.
Packet Filtering and Firewall
Karlstad University Introduction to Vulnerability Assessment Labs Ge Zhang Dvg-C03.
Firewalls. Evil Hackers FirewallYour network Firewalls mitigate risk Block many threats They have vulnerabilities.
Chapter 6: Packet Filtering
IPtables Objectives –to learn the basics of iptables Contents –Start and stop IPtables –Checking IPtables status –Input and Output chain –Pre and Post.
SCSC 455 Computer Security Network Security. Control access to system Access control mechanisms in specific network programs  e.g. 1, wu-FTP server support.
Iptables and apache 魏凡琮 (Jerry Wei). Agenda iptables apache.
1 The Firewall Menu. 2 Firewall Overview The GD eSeries appliance provides multiple pre-defined firewall components/sections which you can configure uniquely.
1 Tutorial 6: Networking Utilities & Firewall. 2 Internet Control Message Protocol (ICMP) designed to compensate for the deficiencies of IP protocol.
1 Domain Name System. 2 Resolve IP to a Name /etc/hosts  The /etc/hosts file is just a list of IP addresses and their corresponding server names.  Your.
Packet Filtering Chapter 4. Learning Objectives Understand packets and packet filtering Understand approaches to packet filtering Set specific filtering.
Access Control List (ACL)
1 Firewalls. ECE Internetwork Security 2 Overview Background General Firewall setup Iptables Introduction Iptables commands “Limit” Function Explanation.
Beginning Network Security Monitor and control flow into and out of the LAN Ingress Egress Only let in the good guys Only let out the corp. business.
Firewalling With Netfilter/Iptables. What Is Netfilter/Iptables? Improved successor to ipchains available in linux kernel 2.4/2.6. Netfilter is a set.
IPtables Objectives Contents Practicals Summary
Firewall Tutorial Hyukjae Jang Nc lab, CS dept, Kaist.
© 2006 Cisco Systems, Inc. All rights reserved. Cisco IOS Threat Defense Features.
Le firewall Technofutur. Table des matières Schémas du réseau Routage sans VPN Routage avec VPN Le NAT Le firewall.
CSN09101 Networked Services Week 6 : Firewalls + Security Module Leader: Dr Gordon Russell Lecturers: G. Russell.
Firewalls & Network Monitoring Advanced Registry Operations Curriculum.
Network Configuration in Linux
Error and Control An IP datagram travels from node to node on the way to its destination Each router operates autonomously Failures or problems may occur.
1 Firewalls. ECE Internetwork Security 2 Overview Background General Firewall setup Iptables Introduction Iptables commands “Limit” Function Explanation.
Firewalls Group 11Group 12 Bryan Chapman Richard Dillard Rohan Bansal Huang Chen Peijie Shen.
Chapter 8 Network Security Thanks and enjoy! JFK/KWR All material copyright J.F Kurose and K.W. Ross, All Rights Reserved Computer Networking:
IPTABLES -FIREWALL. IPTABLES IPTABLE BASIC IMPORTANT FILES SIMPLE SECURITY IMPLEMENTATION (GRAPHICAL WAY) IMPLEMENTING FIREWALL RULE WITH EXAMPLE (COMMAND.
Introduction to Linux Firewall
CCNA4 Perrine / Brierley Page 12/20/2016 Chapter 05 Access Control Non e0e1 s server.
Access Control List (ACL) W.lilakiatsakun. Transport Layer Review (1) TCP (Transmission Control Protocol) – HTTP (Web) – SMTP (Mail) UDP (User Datagram.
Firewalls Chien-Chung Shen The Need for Firewalls Internet connectivity is essential –however it creates a threat (from the network) vs.
IP packet filtering Breno de Medeiros. Florida State University Fall 2005 Packet filtering Packet filtering is a network security mechanism that works.
LINUX® Netfilter The Linux Firewall Engine. Overview LINUX® Netfilter is a firewall engine built into the Linux kernel Sometimes called “iptables” for.
Linux Firewall Iptables.
Routing with Linux 'cause you really love the command line
防火牆 Firewall All rights reserved. No part of this publication and file may be reproduced, stored in a retrieval system, or transmitted in any form or.
Polytechnic University Firewall and Trusted Systems Presented by, Lekshmi. V. S cos
Firewalls. A Firewall is: a) Device that interconnects two networks b) Network device that regulates the access to an internal network c) Program that.

NAT、DHCP、Firewall、FTP、Proxy
FIREWALL configuration in linux
CITA 352 Chapter 5 Port Scanning.
Cisco IOS Firewall Context-Based Access Control Configuration
Port Scanning (based on nmap tool)
Packet Filtering Dick Steflik.
CIT 480: Securing Computer Systems
IS3440 Linux Security Unit 6 Using Layered Security for Access Control
Setting Up Firewall using Netfilter and Iptables
Firewalls By conventional definition, a firewall is a partition made
Firewalls.
From ACCEPT to MASQUERADE Tim(othy) Clark (eclipse)
Session 20 INST 346 Technologies, Infrastructure and Architecture
Presentation transcript:

Firewalls Implementation IPTables Firewall Implementation Taken from Red Hat Linux Firewalls, Bill McCarty Copyright Red Hat and Bill McCarty

Scripting Intro Brief introduction to shell scripts in Unix – Shell script is a command interpreter – Standard in – Standard out – Standard error – Redirection “ > “, “<” – “>|” forced overwrite – “>>” append

Scripts Start Create a firewall file – Make it executable – Chmod 777 acklers_firewall All scripts will start with #!/bin/bash - will execute the remaining lines as commands except comments Comments start with a # Variables are defined before using IP=” ” Variables are referenced with $name $IP does a lexical substitution for IP def.

Scripts Control flow If-then-else if [ condition ] then “do something” else “something to do goes here” fi if – fi act as parentheses exit 1 exits the script [ ] - needs white space around the condition

Control flow example if [ ! -x /sbin/iptables ] then echo “Firewall: can't execute iptables” exit 1 fi Which iptables gets th path to iptables.

Scripts Control flow for loop for var in list: do stuff to do done var a variable that takes on each value in turn in list list is a list of values that var takes on BADIPS=” / /12” for ip in $BADIPS; do iptables -A INPUT -s $ip -j DROP done

Firewall Construction Plan Firewall policies High level design Detailed design Test

Firewall Policies Egress filtering Restrictive: Only explicitly authorized packets may exit the protected host. Ingress filtering Restrictive: Only explicitly authorized packets may enter the protected host. Hostile hosts Hostile hosts may be shunned. Special IPsTraffic from special IPs are blocked, e.g. RFC 1918

Firewall Policies cont'd Inbound servicesRemote clients can access SSH and HTTP services provided by the protected host. All other services are blocked. Outbound servicesLocal clients can access only these remote services: DNS, FTP, HTTP, HTTPS, RSYNC, SMTP, SSH, and WHOIS servers. All other services are block to local clients

Firewall Policies cont'd Inbound ICMPOnly dest unreachable, parameter problem, source quench, and time exceeded are the only authorized ICMP messages. Outbound ICMPOnly dest unreachable, fragmentation needed, parameter problem, and source quench are the only authorized ICMP messages. LoggingAll blocked packets are logged via the Syslog facility

Firewall Policies cont'd Ping Only specified hosts can ping, or be pinged, by the protected host. SYN Flood The firewall will block SYNs when their rate of arrival exceeds a specified threshold. TCP Flags TCP flags are validated, blocking certain types of TCP scans.

Packet Path with NAT and MANGLE mangle PREROUTING nat PREROUTING filter INPUT filter OUTPUT nat POSTROUTING filter FORWARD Mangle OUTPUT route Local Process Network

Our Firewall no NAT, no MANGLE, no FORWARD Firewall for a single-homed protected host No FORWARD chain in the FILTER table No NAT table No MANGLE table Only INPUT and OUTPUT chains in the FILTER table

Our Packet Path filter INPUT filter OUTPUT Network

Setup Some Assignments # Abreviation for iptables IPT=/sbin/iptables # Loop back address LO= “ ” # Ip address of firewall host IP=”xxx.xxx.xxx.xxx” /sbin/ifconfig eth0 | grep 'inet addr:' | cut -d: -f2 | awk '{ print $1}'

Setting Up the Chains & Tables Ensure that iptables is installed. Set default policy to protect system while rules are installed. Flush and delete all user chains. Flush and delete all built-in chains. Reset all counters. If [ ! -x $IPT ] then echo “Firewall: Can't find iptables” exit 1 fi $IPT-P INPUTDROP#Set default policy to DROP $IPT-P OUTPUTDROP#Set default policy to DROP $IPT-P FORWARDDROP#Set default policy to DROP $IPT-F#Flush all chains $IPT-X#Delete all user chains for table in filter nat mangle do $IPT-t $table-F#Flush table's rules $IPT-t $table-X#Delete table's chains $IPT-t $table-Z#Zero the table's counters done

INPUT Chain Policy filter table Loopback OK » Accept Bad IP » Log and drop Shunned IPs » Log and drop Branches » ICMP or TCP/UDP? Logs and drops the rest

INPUT Chain Network LOG_DROP IN_TCP_UDP IN_ICMP ICMP? SHUN_IP BAD_IP Loopback?ACCEPT $IPT-A INPUT-i lo-j ACCEPT $IPT-A INPUT-j BAD_IP $IPT-A INPUT-j SHUN_IP $IPT-A INPUT-p ! icmp-j IN_TCP_UDP $IPT-A INPUT-p icmp-j IN_ICMP $IPT-A INPUT-j LOG_DROP

OUTPUT Chain Policy filter table Loopback OK » Accept Bad IP » Log and drop Shunned IPs » Log and drop Branches » ICMP or TCP/UDP? Logs and drops the rest

OUTPUT Chain LOG_DROP OUT_TCP_UDP OUT_ICMP ICMP? SHUN_IP BAD_IP Loopback?ACCEPT $IPT-A OUTPUT -o lo-j ACCEPT $IPT-A OUTPUT-j BAD_IP $IPT-A OUTPUT-j SHUN_IP $IPT-A OUTPUT-p ! icmp-j OUT_TCP_UDP $IPT-A OUTPUT-p icmp-j OUT_ICMP $IPT-A OUTPUT-j LOG_DROP

User chains User chains: IN_TCP_UDP Further filters TCP & UDP datagrams IN_ICMP Further filters ICMP datagrams OUT_TCP_UDP Further filters TCP & UDP datagrams OUT_ICMP Further filters ICMP datagrams FLOOD Stops SYN flood attacks FLAGS Drops packets with incorrect tcp flags set BAD_IP Drops packets from bad IP addresses SHUN_IP Drops packets from IP addresses that have been identified as hostile

User logging chains Logging chains: LOG_DROP Logs and drops various packets selected to be dropped LOG_FLOOD Logs and drops various packets judged to be a SYN flood LOG_FLAGS Logs and drops various packets judged to have incorrect TCP flags set LOG_BAD_IP Logs and drops various packets coming from or going to bad IP addresses LOG_SHUN_IP Logs and drops various packets coming from or going to IP addresses that are to be sunned

IN_TCP_UDP User Chain Remote clients can access SSH and HTTP services provided by the protected host. All other services are blocked. Source IP spoofed? Established or related state? FLAGS FLOOD Invalid state? ACCEPTLOG_DROP ACCEPT Yes No $IPT -N IN_TCP_UDP $IPT -A IN_TCP_UDP -m state –-state INVALID -j LOG_DROP $IPT -A IN_TCP_UDP -p tcp –-syn -j FLOOD $IPT -A IN_TCP_UDP -p tcp -j FLAGS $IPT -A IN_TCP_UDP -m state –-state ESTABLISHED,RELATED / -j ACCEPT $IPT -A IN_TCP_UDP -s $IP -j LOG_DROP

IN_TCP_UDP User Chain cont'd AUTH request? Authorized service? ACCEPT RETURN ACCEPT REJECT Yes No SSH=”my_IP_addr your_IP_addr” WWW=”my_IP_addr your_IP_addr” for sip in $SSH; do $IPT -A IN_TCP_UDP -p tcp -s $sip –-dport 22 -m state / –-state NEW -j ACCEPT done for sip in $WWW; do $IPT -A IN_TCP_UDP -p tcp -s $sip –-dport 80 -m state / –-state NEW -j ACCEPT done # Authentication request $IPT -A IN_TCP_UDP -p tcp –-dport 113 -j REJECT # Add rules for other required services, for example: # # services=”IP addresses” # # for sip in $services; do # $IPT -A IN_TCP_UDP -p proto -s $sip –dport port -m state / # –-state NEW -j ACCEPT # done

OUT_TCP_UDP User Chain Protected host can access ftp, ssh, smtp, whois, DNS, http, https, rsync services. All other services are blocked. Authorized service? Established or related state? RETURN Source IP OK? ACCEPTLOG_DROP ACCEPT Yes No OUT_SERVICES=” ” # Permitted outbound connections # ftp, ssh, smtp, whois, DNS, http, https, rsync $IPT -N OUT_TCP_UDP $IPT -A OUT_TCP_UDP -p tcp -j FLAGS $IPT -A OUT_TCP_UDP -s ! $IP -j LOG_DROP $IPT -A OUT_TCP_UDP -m state –-state ESTABLISHED,RELATED / -j ACCEPT for dpt in $OUT_SERVICES; do $IPT -A OUT_TCP_UDP -m state –-state NEW -p tcp / –-dport $dpt -j ACCEPT done $IPT -A OUT_TCP_UDP -m state –-state NEW -p udp / –-dport 53 -j ACCEPT FLAGS No ACCEPT

IN_ICMP User Chain Only dest unreachable, parameter problem, source quench, and time exceeded are the only authorized ICMP messages. Parameter problem? Time exceeded? Source quench? Destination unreachable? Authorized ping? ACCEPT RETURN ACCEPT PING=”my_IP_addr your_IP_addr” $IPT -N IN_ICMP for sip in $PING; do $IPT -A IN_ICMP -p icmp –-icmp-type echo-request / -s $sip-d $IP -j ACCEPT $IPT -A IN_ICMP -p icmp –-icmp-type echo-reply / -s $sip-d $IP -j ACCEPT done $IPT -A IN_ICMP -p icmp –-icmp-type destination-unreachable -j ACCEPT $IPT -A IN_ICMP -p icmp –-icmp-type source-quench -j ACCEPT $IPT -A IN_ICMP -p icmp –-icmp-type time-exceeded -j ACCEPT $IPT -A IN_ICMP -p icmp –-icmp-type parameter-problem -j ACCEPT # default is to return on pass through Yes No

OUT_ICMP User Chain Only dest unreachable, parameter problem, source quench, and time exceeded are the only authorized ICMP messages. Parameter problem? Fragmentation needed? Source quench? Destination unreachable? Authorized ping? ACCEPT RETURN ACCEPT $IPT -N OUT_ICMP for sip in $PING; do $IPT -A OUT_ICMP -p icmp –-icmp-type echo-request / -s $sip-d $IP -j ACCEPT $IPT -A OUT_ICMP -p icmp –-icmp-type echo-reply / -s $sip-d $IP -j ACCEPT done $IPT -A OUT_ICMP -p icmp –-icmp-type destination-unreachable -j ACCEPT $IPT -A OUT_ICMP -p icmp –-icmp-type fragmentation-needed -j ACCEPT $IPT -A OUT_ICMP -p icmp –-icmp-type source-quench -j ACCEPT $IPT -A OUT_ICMP -p icmp –-icmp-type parameter-problem -j ACCEPT # default is to return on pass through Yes No

Bad IP User Chain Traffic from special IPs are blocked, e.g. RFC 1918 RETURN Bad dest IP? Bad source IP? LOG_BAD_IP Yes No # Broadcast addresses BAD_IPS=” / ” # RFC 1918 addresses BAD_IPS=”$BAD_IPS / / /16” ” # Loop back address BAD_IPS=”$BAD_IPS /4” # Multicast addresses BAD_IPS=”$BAD_IPS / /5” $IPT-N BAD_IP for ip in $BAD_IPS; do $IPT-A BAD_IP-s $ip-j LOG_BAD_IP done for ip in $BAD_IPS; do $IPT-A BAD_IP-d $ip-j LOG_BAD_IP done # Returns to the calling chain by default

Hostile Hosts User Chain Hostil hosts may be shunned – inbound and outbound can be blocked RETURN Hostile dest IP? Hostile source IP? LOG_SHUN_IP Yes No # Hostile ips starts out empty SHUN_IPS=”” # To add an address to the list # iptables -S SHUN_IP -s address -j SHUN_IPS # To delete an address from the list # iptables -D SHUN_IP -s address -j SHUN_IPS # To clear the list # iptables -F SHUN_IP $IPT-N SHUN_IP for ip in $SHUN_IPS; do $IPT-A SHUN_IP-s $ip-j LOG_SHUN_IP done for ip in $SHUN_IPS; do $IPT-A SHUN_IP-d $ip-j LOG_SHUN_IP done # Returns to the calling chain by default

FLOOD The firewall will block SYNs when their rate of arrival exceeds a specified threshold. LOG_FLOOD SYN rate exceeded? RETURN Yes No SYN_OPT=”-m limit –-limit 5/second –-limit-burst 10” $IPT -N FLOOD $IPT -A FLOOD $SYN_OPT -j RETURN $IPT -A FLOOD -j LOG_FLOOD

TCP Flags TCP flags are validataed, blocking certain types of TCP scans. LOG_FLAGS Bad TCP flags? RETURN Yes No $IPT -N FLAGS $IPT -A FLAGS -p tcp –-tcp-flags ACK,FIN FIN -j LOG_FLAGS $IPT -A FLAGS -p tcp –-tcp-flags ACK,PSH PSH -j LOG_FLAGS $IPT -A FLAGS -p tcp –-tcp-flags ACK,URG URG -j LOG_FLAGS $IPT -A FLAGS -p tcp –-tcp-flags FIN,RST FIN,RST -j LOG_FLAGS $IPT -A FLAGS -p tcp –-tcp-flags SYN,FIN SYN,FIN -j LOG_FLAGS $IPT -A FLAGS -p tcp –-tcp-flags SYN,RST SYN,RST -j LOG_FLAGS $IPT -A FLAGS -p tcp –-tcp-flags ALL ALL -j LOG_FLAGS $IPT -A FLAGS -p tcp –-tcp-flags ALL NONE -j LOG_FLAGS $IPT -A FLAGS -p tcp –-tcp-flags ALL FIN,PSH,URG-j LOG_FLAGS $IPT -A FLAGS -p tcp –-tcp-flags ALL SYN,FIN,PSH,URG -j LOG_FLAGS $IPT -A FLAGS -p tcp –-tcp-flags ALL SYN,RST,ACK,FIN,URG -j LOG_FLAGS

Logging Chains Log and drop all that is bad LOG_OPT=”--log-level=3 -m limit –-limit 1/second –-limit-burst 10” # This limits the rate of logging $IPT -N LOG_DROP $IPT -A LOG_DROP-j LOG –-log-prefix “IPT Drop:“ $LOG_OPT $IPT -A LOG_DROP-j DROP $IPT -N LOG_BAD_IP $IPT -A LOG_BAD_IP-p tcp –-dport 137:139 -j DROP # MS Broadcast $IPT -A LOG_BAD_IP-p udp –-dport 137:139 -j DROP # MS Broadcast $IPT -A LOG_BAD_IP-j LOG –-log-prefix “IPT BAD_IP:“ $IPT -A LOG_BAD_IP-j DROP $IPT -N LOG_SHUN_IP $IPT -A LOG_SHUN_IP-j LOG –-log-prefix “IPT SHUN:“ $LOG_OPT $IPT -A LOG_SHUN_IP-j DROP $IPT -N LOG_FLOOD $IPT -A LOG_FLOOD-j LOG –-log-prefix “IPT FLOOD:“ $LOG_OPT $IPT -A LOG_FLOOD-j DROP $IPT -N LOG_FLAGS $IPT -A LOG_FLAGS-j LOG –-log-prefix “IPT FLAGS:“ $LOG_OPT $IPT -A LOG_FLAGS-j DROP

Configuring IPTables – Configure IPTables to run on startup chkconfig iptables on – Disables IPTables at startup chkconfig iptables off – Starting and stopping IPTables service iptables start service iptables save service iptables stop service iptables restart

Assignment Using the example in these slides build a script to install this firewall Comment the script List the rules and comment the listing Install the firewall, i.e. run the script ftp to an ftp server Have some one run nmap against your IP address Print and comment the log file