Written by Muhammad Kamran Azeem Wednesday, 02 July :48 - Last Updated Saturday, 25 December :45

Similar documents
Web Server ( ): FTP, SSH, HTTP, HTTPS, SMTP, POP3, IMAP, POP3S, IMAPS, MySQL (for some local services[qmail/vpopmail])

Introduction to Firewalls using IPTables

This material is based on work supported by the National Science Foundation under Grant No

Certification. Securing Networks

VG422R. User s Manual. Rev , 5

Network security Exercise 9 How to build a wall of fire Linux Netfilter

UNIVERSITY OF BOLTON SCHOOL OF CREATIVE TECHNOLOGIES COMPUTER AND NETWORK SECURITY SEMESTER TWO EXAMINATIONS 2016/2017 NETWORK SECURITY

Dual-stack Firewalling with husk

11 aid sheets., A non-programmable calculator.

Linux-Kurs, Samba-Server - Copyright 5. November 2002, Pierre Burri -Michel Bisson

Università Ca Foscari Venezia

Masquerading Made Simple HOWTO

Definition of firewall

Assignment 3 Firewalls

IP Packet. Deny-everything-by-default-policy

Network Address Translation

Firewalls N E T W O R K ( A N D D ATA ) S E C U R I T Y / P E D R O B R A N D Ã O M A N U E L E D U A R D O C O R R E I A

Firewalls, VPNs, and SSL Tunnels

Worksheet 8. Linux as a router, packet filtering, traffic shaping

Firewalls. Content. Location of firewalls Design of firewalls. Definitions. Forwarding. Gateways, routers, firewalls.

IPv6. The Future of the Internet Some Day

PXC loves firewalls (and System Admins loves iptables) Written by Marco Tusa Monday, 18 June :00 - Last Updated Wednesday, 18 July :25

Firewalls. IT443 Network Security Administration Slides courtesy of Bo Sheng

Distributed Systems. 29. Firewalls. Paul Krzyzanowski. Rutgers University. Fall 2015

Linux System Administration, level 2


R (2) Implementation of following spoofing assignments using C++ multi-core Programming a) IP Spoofing b) Web spoofing.

History Page. Barracuda NextGen Firewall F

ECE 435 Network Engineering Lecture 23

THE INTERNET PROTOCOL/1

THE INTERNET PROTOCOL INTERFACES

Kernel Korner A NATural Progression

The Internet Protocol

FireHOL Manual. Firewalling with FireHOL. FireHOL Team. Release pre3 Built 28 Oct 2013

Security and network design

iptables and ip6tables An introduction to LINUX firewall

Nat & Publish -

Network Security. Routing and Firewalls. Radboud University, The Netherlands. Spring 2018

Configure. Version: Copyright ImageStream Internet Solutions, Inc., All rights Reserved.

Linux 2.4 stateful firewall design

IPtables and Netfilter

Hands-On Ethical Hacking and Network Defense Chapter 5 Port Scanning

Hands-On Ethical Hacking and Network Defense Chapter 5 Port Scanning

Stateless Firewall Implementation

The Research and Application of Firewall based on Netfilter

sottotitolo A.A. 2016/17 Federico Reghenzani, Alessandro Barenghi

Broadband Router DC 202

IK2206 Internet Security and Privacy Firewall & IP Tables

Firewalls. Firewall. means of protecting a local system or network of systems from network-based security threats creates a perimeter of defense

Netfilter. Fedora Core 5 setting up firewall for NIS and NFS labs. June 2006

Computer Security Spring Firewalls. Aggelos Kiayias University of Connecticut

TP5 Sécurité IPTABLE. * :sunrpc, localhost :domain,* :ssh, localhost :smtp, localhost:953,*: Tous sont des protocoles TCP

Introduction TELE 301. Routers. Firewalls. Gateways. Sample Large Network

Module: Firewalls. Professor Patrick McDaniel Fall CSE543 - Introduction to Computer and Network Security

Distributed Systems. 27. Firewalls and Virtual Private Networks Paul Krzyzanowski. Rutgers University. Fall 2013

Firewalls. Firewall types. Packet filter. Proxy server. linux, iptables-based Windows XP s built-in router device built-ins single TCP conversation

Once the VM is started, the VirtualBox OS Manager window can be closed. But our Ubuntu VM is still running.

Linux Firewalls. Frank Kuse, AfNOG / 30

Contents. Preventing Brute Force Attacks. The First Method: Basic Protection. Introduction. Prerequisites

Broadband Router DC-202. User's Guide

Network and Filesystem Security

CS Computer and Network Security: Firewalls

Unit 4: Firewalls (I)

Broadband Router User s Manual. Broadband Router User s Manual

Overview. Computer Network Lab, SS Security. Type of attacks. Firewalls. Protocols. Packet filter

10 A Security Primer. Copyright 2011 by The McGraw-Hill Companies CERTIFICATION OBJECTIVES. Q&A Self Test

ECE 435 Network Engineering Lecture 23

A Technique for improving the scheduling of network communicating processes in MOSIX

Packet Filtering and NAT

PVS Deployment in the Cloud. Last Updated: June 17, 2016

Some of the slides borrowed from the book Computer Security: A Hands on Approach by Wenliang Du. Firewalls. Chester Rebeiro IIT Madras

ipro-04n Security Configuration Guide

Arion Router and Firewall User s Manual. Rev 1.0 Mar 2004

Configuring the EN-2000 s VPN Firewall

IPv6 NAT. Open Source Days 9th-10th March 2013 Copenhagen, Denmark. Patrick McHardy

Firewall Simulation COMP620

ICS 451: Today's plan

Lecture 18: Packet Filtering Firewalls (Linux) Lecture Notes on Computer and Network Security. by Avi Kak

Scanning. Course Learning Outcomes for Unit III. Reading Assignment. Unit Lesson UNIT III STUDY GUIDE

Chapter 8 roadmap. Network Security

Linux. Sirindhorn International Institute of Technology Thammasat University. Linux. Firewalls with iptables. Concepts. Examples

CHAPTER 7 ADVANCED ADMINISTRATION PC

Firewall. Access Control, Port Forwarding, Custom NAT and Packet Filtering. Applies to the xrd and ADSL Range. APPLICATION NOTE: AN-005-WUK

Load Balancing Bloxx Web Filter. Deployment Guide v Copyright Loadbalancer.org

Cisco PCP-PNR Port Usage Information

Firewalls. October 13, 2017

Module 19 : Threats in Network What makes a Network Vulnerable?

Linux Systems Security. Firewalls and Filters NETS1028 Fall 2016

DNS & Iodine. Christian Grothoff.

LevelOne FBR User s Manual. 1W, 4L 10/100 Mbps ADSL Router. Ver

Load Balancing Web Proxies / Filters / Gateways. Deployment Guide v Copyright Loadbalancer.org

Sirindhorn International Institute of Technology Thammasat University

This guide provides a quick reference for setting up SIP load balancing using Loadbalancer.org appliances.

MyFirewall (Pierre Burri)

SLE in Virtual Private Networks

Grandstream Networks, Inc. GWN Firewall Features Advanced NAT Configuration Guide

CSCI 680: Computer & Network Security

Corso di Sicurezza delle Reti e dei Sistemi Software aa 2015/16

Computer Security and Privacy

Firewalls and NAT. Firewalls. firewall isolates organization s internal net from larger Internet, allowing some packets to pass, blocking others.

Transcription:

Assalam-u-alaikum, I have been receiving many mails for few years now to provide with a firewall script. Lately I received one such mail and I decided to publish, what I replied him with. The names and email are changed for privacy reasons. I hope this firewall script will be helpful to many. The Scenario: [Internet]---[DSLRouter/DialUp Modem]---[LinuxFirewall]---[LAN switch/users] First, the mail from one of the community members: A.o.A My name is Farrukh Irfan.I am facing one problem, which I want to discuss with you. In my office different developers using different ports like pop,smtp,ftp,imap etc. by default all the ports are block,no entry in iptables. When i use one rule iptables -t nat -A POSTROUTING -j MASQUERADE this will open every port,so many users also using p2p software,p2p software using different ports and changing port every time,soo i need your help how to i block this p2p software.also some times when some one open any site,the problem occours like this "not to resolve request",please tell me why its come. Thanx Waiting ur reply Allah Hafiz 1 / 6

Here is my reply and the firewall script I have attached below it. Wa-alaikum "A.o.A", Alhumdulillah. Nice to know you. The solution to your problem is simple. Block all traffic and allow only interested ports to be forwarded. That way you can easily stop P2P traffic. I am attaching a sample firewall. You can customize it and use it for yourself. This will work 100%, InshaAllah. This firewall needs some adjustment as per your setup, such as the name of your PUBLIC and LOCAL interfaces and their IPs. Any way, this is currently in place, at one of the offices somewhere in the city. Feel free to use it for your setup. Ma' ssalama, Kamran Now, the (much awaited) actual firewall script:!/bin/bash Author: Muhammad Kamran Azeem (kamran@wbitt.com) Disclaimer: Use this firewall script on your own risk! Revision History :- 20080702, 20080622, 20080222, 20070314 If you have fixed IP from your ISP, you should provide PUBLICIP below, and use SNAT instead of MASQUERADE. If you have dynamic IP (on dialup) (or changing everytime, for some reason), then you should comment the PUBLICIP below and use MASQUERADE instead of SNAT. Define interfaces. Please specify your interfaces carefully. On a dial up connection, the PUBLICIF would most likely be ppp0. On a DSL connection, the PUBLICIF may be eth0 or eth1, 2 / 6

depending on what you use for your internal LAN. Also specify your PUBLICIP, if you have a static IP given to you from your ISP. PUBLICIF=eth0 PUBLICIP=202.203.103.211 LOCALIF=eth1 LOCALIP=192.168.0.254 IPTABLES=/sbin/iptables Load Modules - Start Load FTP connection tracking module. Without it, FTP to this server will NOT work modprobe ip_conntrack_ftp modprobe ip_conntrack Load Modules - End Kernel Parameters - Start Various Kernel parameters which you can (also) setup in /etc/sysctl.conf This following enables source address verification,, which is inbuilt into Linux kernel itself. net.ipv4.conf.all.rp_filter = 1 echo 1 > /proc/sys/net/ipv4/conf/all/rp_filter echo 1 > /proc/sys/net/ipv4/ip_forward Kernel Parameters - End Main firewall engine (Start) First clear the tables: $IPTABLES -t nat -F $IPTABLES -F Block spoofing $IPTABLES -A INPUT -s 127.0.0.0/8 -i! lo -j DROP OR more sophisticated / wide ranged method is below. USE CAREFULLY:- Let it remain commented if you do not understand this:- Add your IP range/ips here, Yes, I am sure that the last address has 16 bit subnet for a VALID reason 3 / 6

SPOOFLIST="0.0.0.0/8 127.0.0.0/8 10.0.0.0/8 172.16.0.0/16 192.168.0.0/16 224.0.0.0/3" for ip in $SPOOFLIST do $IPTABLES -A INPUT -i $PUBLICIF -s $ip -j DROP done Stop bad packets $IPTABLES -A INPUT -m state --state INVALID -j DROP NMAP FIN/URG/PSH $IPTABLES -A INPUT -p tcp --tcp-flags ALL FIN,URG,PSH -j DROP stop Xmas Tree type scanning $IPTABLES -A INPUT -p tcp --tcp-flags ALL ALL -j DROP $IPTABLES -A INPUT -p tcp --tcp-flags ALL SYN,RST,ACK,FIN,URG -j DROP stop null scanning $IPTABLES -A INPUT -p tcp --tcp-flags ALL NONE -j DROP SYN/RST $IPTABLES -A INPUT -p tcp --tcp-flags SYN,RST SYN,RST -j DROP SYN/FIN $IPTABLES -A INPUT -p tcp --tcp-flags SYN,FIN SYN,FIN -j DROP If the incoming SYN packets are not NEW, we need to DROP them:- $IPTABLES -A INPUT -p tcp! --syn -m state --state NEW -j DROP In case of dynamic IP, use this on your public interface:- $IPTABLES -t nat -A POSTROUTING -o $PUBLICIF -j MASQUERADE In case of static IP, use this on your public interface:- $IPTABLES -t nat -A POSTROUTING -o $PUBLICIF -j SNAT --to-source $PUBLICIP echo -n "Enabling Transparent Proxying (SQUID on same machine)..." $IPTABLES -t nat -A PREROUTING -i $LOCALIF -p tcp -d! $LOCALIP --dport 80 -j REDIRECT --to-port 3128 123 TCP/UDP is Network Time Protocol Allow diagnostic/admin ports, i.e SSH, web from internet (and NTP).. $IPTABLES -A INPUT -i $PUBLICIF -p tcp -m multiport --dport 22,80,123 -j ACCEPT 4 / 6

$IPTABLES -A INPUT -i $PUBLICIF -p udp -m multiport --dport 123 -j ACCEPT Lets allow traffic for outgoing 20,21,80,1863 MSN,5050 yahoo, TCP/UDP 123 is NTP 11999 is yahoo games MSN needs both 1863 and 443, Yahoo messenger needs 5050 (and 443 as well) 1433 MS SQL server 51215 is web2sms for mobilink 5001:5020 TCP PalTalk 2091 UDP Paltalk incoming control 1025-2500 UDP Paltalk out control TCP 5222, 443 to anywhere GoogleTalk TCP 1111, 1935 Flash Communications ports GMAIL - POP - 995 GMAIL - IMAP - 993 4080 / TCP - MLNET set default FORWARD policy to drop. $IPTABLES -P FORWARD DROP We will only allow specific connections. $IPTABLES -A FORWARD -i $LOCALIF -o $PUBLICIF -p tcp -m multiport --dports 21,22,80,110,143,443,1863,5050 -j ACCEPT $IPTABLES -A FORWARD -m state --state RELATED,ESTABLISHED -j ACCEPT Stop ping flood attack $IPTABLES -A INPUT -p icmp --icmp-type echo-request -m length --length 85: -j REJECT --reject-with icmp-host-prohibited Allow maximum two incoming ICMP packets per second $IPTABLES -A INPUT -p icmp --icmp-type echo-request -m limit --limit 1/s -j ACCEPT The following DROPS icmp packets coming from internet $IPTABLES -A INPUT -i $PUBLICIF -p icmp -j DROP 5 / 6

Drop all connections, by default, from internet, which are destined for public interface of this machine. This will serve as default policy. :- $IPTABLES -A INPUT -i $PUBLICIF -j DROP That should be all. 6 / 6