Categories

A sample text widget

Etiam pulvinar consectetur dolor sed malesuada. Ut convallis euismod dolor nec pretium. Nunc ut tristique massa.

Nam sodales mi vitae dolor ullamcorper et vulputate enim accumsan. Morbi orci magna, tincidunt vitae molestie nec, molestie at mi. Nulla nulla lorem, suscipit in posuere in, interdum non magna.

Configure Advanced Policy-based Firewall (APF), Brute Force Detection (BFD), DDoS Deflate

Configure Advanced Policy-based Firewall (APF), Brute Force Detection (BFD), DDoS Deflate

Advanced Policy Firewall

Description:
Advanced Policy Firewall (APF) is an iptables(netfilter) based firewall system designed around the essential needs of today’s Linux servers. The configuration is designed to be very informative and easy to follow. The management on a day-to-day basis is conducted from the command line with the ‘apf’ command, which includes detailed usage information on all the features.

The technical side of APF is such that it utilizes the latest stable features from the iptables (netfilter) project to provide a very robust and powerful firewall. The filtering performed by APF is three fold:
1) Static rule based policies (not to be confused with a “static firewall”)
2) Connection based stateful policies
3) Sanity based policies

Features:
– detailed and well commented configuration file
– granular inbound and outbound network filtering
– user id based outbound network filtering
– application based network filtering
– trust based rule files with an optional advanced syntax
– global trust system where rules can be downloaded from a central management server
– reactive address blocking (RAB), next generation in-line intrusion prevention
– debug mode provided for testing new features and configuration setups
– fast load feature that allows for 1000+ rules to load in under 1 second
– inbound and outbound network interfaces can be independently configured
– global tcp/udp port & icmp filtering with multiple filters (drop, reject, prohibit)
– configurable policies for each ip on the system with convenience variables to import settings
– packet flow rate limiting that prevents abuse on the most widely abused protocol, icmp
– prerouting and postrouting rules for optimal network performance
– dshield.org block list support to ban networks exhibiting suspicious activity
– spamhaus Don’t Route Or Peer List support to ban known “hijacked zombie” IP blocks
– any number of additional interfaces may be configured as trusted or untrusted
– additional firewalled interfaces can have there own unique firewall policies applied
– intelligent route verification to prevent embarrassing configuration errors
– advanced packet sanity checks to make sure traffic coming and going meets the strictest of standards
– filter attacks such as fragmented UDP, port zero floods, stuffed routing, arp poisoning and more
– configurable type of service options to dictate the priority of different types of network traffic
– intelligent default settings to meet every day server setups
– dynamic configuration of your servers local DNS revolvers into the firewall
– optional filtering of common p2p applications
– optional filtering of private & reserved IP address space
– optional implicit blocks of the ident service
– configurable connection tracking settings to scale the firewall to the size of your network
– configurable kernel hooks (ties) to harden the system further to syn-flood attacks & routing abuses
– advanced network control such as explicit congestion notification and overflow control
– helper chains for FTP DATA and SSH connections to prevent client side issues
– optional rate limited event logging
– logging subsystem that allows for logging data to user space programs or standard syslog files
– comprehensive logging of every rule added
– detailed startup error checking
– if you are familiar with netfilter you can create your own rules in any of the policy files
– pluggable and ready advanced use of QoS algorithms provided by the Linux
– 3rd party add-on projects that compliment APF features

Install Procedure

mkdir /software
cd software
wget -c http://rfxnetworks.com/downloads/apf-current.tar.gz
tar -zxvf apf-current.tar.gz
cd apf-9.7-2/
./install.sh
cp /etc/apf/conf.apf /etc/apf/conf.apf.bk
vi /etc/apf/conf.apf

DEVEL_MODE=”0”
IG_TCP_CPORTS=”21,22,25,53,80,110,143,443,3306”
IG_UDP_CPORTS=”53,67,68,111,5353,48443”
USE_AD=”1”

/etc/init.d/apf restart

Brute Force Detection (BFD)

Brute Force Detection (BFD)

1) Download and Install Brute Force Detection (BFD)
wget -c http://rfxnetworks.com/downloads/bfd-current.tar.gz
tar xvfz bfd-current.tar.gz
cd bfd-*
./install.sh
Backup and Edit BFD Configuration
cp /usr/local/bfd/conf.bfd /usr/local/bfd/conf.bfd.ori
vi /usr/local/bfd/conf.bfd

EMAIL_ALERTS=”0″
EMAIL_ADDRESS=”admin@email.com”
Backup and Edit BFD Ignore Hosts
cp /usr/local/bfd/ignore.hosts /usr/local/bfd/ignore.hosts.ori
vi /usr/local/bfd/ignore.hosts

192.168.1.108
Run BFD
bfd -s

DDoS Deflate

Download and Install DDoS Deflate
wget -c http://www.inetbase.com/scripts/ddos/install.sh

sh install.sh
Backup and Edit DDOS Configuration
cp /usr/local/ddos/ddos.conf /usr/local/ddos/ddos.conf.ori
vi /usr/local/ddos/ddos.conf

EMAIL_TO=”test@email.com”
Run DDOS
/usr/local/ddos/ddos.sh -c

Open a port in apf firewall and add trusted IP

Apf is a policy based iptable firewall which is very useful for blocking DDoS attack on heavily traffic servers.
The issue is when we developrs/testers are using the same server which will deny all the traffic from their static Ip given.
This is a major headache in most cases.

1. Opening port in apf firewall
Edit the file
“/etc/apf/conf.apf”

and find the entry of IG_TCP_CPORTS”

and added the ports to be opened in it.

A sample entry like this, I add the port ’9091? in it
# Common inbound (ingress) TCP ports
IG_TCP_CPORTS=”20,21,22,25,53,80,110,143,443,465,993,995,3306″

Then restart the firewall
[root@host.mydomain.com] ~ >> apf -r

Trusting our ip’s on Apf firewall

Add our ip information on ”
/etc/apf/allow_hosts.rules

“. A sample entry like this
# inbound to destination port 22 from 192.168.2.1
# tcp:in:d=22:s=192.168.2.1#
# outbound to destination port 23 to destination host 192.168.2.1
# out:d=23:d=192.168.2.1#
# inbound to destination port 3306 from 192.168.5.0/24
# d=3306:s=192.168.5.0/24
# my IP ranges
10.0.4.0/24
10.0.5.0/24
10.0.6.0/24
tcp:in:d=22:s=192.168.2.1#
out:d=23:d=192.168.2.1#
d=3306:s=192.168.5.0/24

IPTABLES Firewall on Centos

Firewall on Centos OS

#!/bin/sh
#
#

## Set your IP address
MYIP=”192.168.1.108″
#
## Flush rules & reset counters
/sbin/iptables -F
/sbin/iptables -Z
#
## Set policies
/sbin/iptables -P INPUT DROP
/sbin/iptables -P FORWARD DROP
/sbin/iptables -P OUTPUT DROP
#
## Drop all incoming fragments
/sbin/iptables -A INPUT -i eth0 -f -j DROP
#
## Drop outside packets with local addresses – anti-spoofing measure
/sbin/iptables -A INPUT -s $MYIP -i ! lo -j DROP
/sbin/iptables -A INPUT -s 127.0.0.0/8 -i ! lo -j DROP
/sbin/iptables -A INPUT -s 10.0.0.0/8 -i ! lo -j DROP
/sbin/iptables -A INPUT -s 192.168.0.0/16 -i ! lo -j DROP
/sbin/iptables -A INPUT -s 224.0.0.0/4 -i ! lo -j DROP
/sbin/iptables -A INPUT -s 0.0.0.0/8 -i ! lo -j DROP
/sbin/iptables -A INPUT -s 255.255.255.255 -i ! lo -j DROP
/sbin/iptables -A INPUT -s 169.254.0.0/16 -i ! lo -j DROP
/sbin/iptables -A INPUT -s 221.240.102 -i ! lo -j DROP
/sbin/iptables -A INPUT -s 203.215.94.193 -i ! lo -j DROP
/sbin/iptables -A INPUT -s 218.71.137.68 -i ! lo -j DROP
#
## Pass all locally-originating packets
/sbin/iptables -A INPUT -i lo -j ACCEPT
/sbin/iptables -A OUTPUT -o lo -j ACCEPT
#
## Accept ICMP ping echo requests
## (this allows other people to ping your machine, among other things),
/sbin/iptables -A INPUT -p icmp –icmp-type echo-request -j ACCEPT
#
## Accept all traffic from a specific machine with IP x.x.x.x
## replace x.x.x.x with the desired IP, then uncomment the line.
#/sbin/iptables -A INPUT -p tcp -m tcp –syn -s xxx.xxx.xxx.xxx -j ACCEPT
#
## Accept traffic on port p from a specific machine with IP x.x.x.x
## replace p with the desired port number, and replace x.x.x.x with
## the desired IP, then uncomment the line.
#/sbin/iptables -A INPUT -p tcp -m tcp –syn -s x.x.x.x –dport p -j ACCEPT
#
## Accept ftp-data and ftp (ports 20 & 21)
/sbin/iptables -A INPUT -p tcp -m tcp –syn –dport 20 -j ACCEPT
/sbin/iptables -A INPUT -p tcp -m tcp –syn –dport 21 -j ACCEPT
#
## Accept ssh (port 22)
/sbin/iptables -A INPUT -p tcp -m tcp –syn –dport 22 -j ACCEPT
#
## Accept telnet (port 23)
#/sbin/iptables -A INPUT -p tcp -m tcp –syn –dport 23 -j ACCEPT
#
## Accept smtp (port 25)
#/sbin/iptables -A INPUT -p tcp -m tcp –syn –dport 25 -j ACCEPT
## Accept dns (port 53)
/sbin/iptables -A INPUT -p udp -m udp -s 0/0 –dport 53 -d 0/0 -j ACCEPT
/sbin/iptables -A INPUT -p tcp -m tcp -s 0/0 –dport 53 -d 0/0 -j ACCEPT
#
## Accept http (port 80)
#/sbin/iptables -A INPUT -p tcp -m tcp –syn –dport 80 -j ACCEPT
#
## Accept pop3 (port 110)
#/sbin/iptables -A INPUT -p tcp -m tcp –syn –dport 110 -j ACCEPT
#
## Accept inbound identd (port 113)
#/sbin/iptables -A INPUT -p tcp -m tcp –syn –dport 113 -j ACCEPT
## or you can reject and send back a TCP RST packet instead
#/sbin/iptables -A INPUT -p tcp -m tcp –dport 113 -j REJECT –reject-with tcp-reset
#
## Accept imap (port 143)
#/sbin/iptables -A INPUT -p tcp -m tcp –syn –dport 143 -j ACCEPT
#
## Accept https (port 443)
#/sbin/iptables -A INPUT -p tcp -m tcp –syn –dport 443 -j ACCEPT
#
## Accept smtps (port 465)
#/sbin/iptables -A INPUT -p tcp -m tcp –syn –dport 465 -j ACCEPT
## Accept msp (port 587)
#/sbin/iptables -A INPUT -p tcp -m tcp –syn –dport 587 -j ACCEPT
#
## Accept SpamAssassin (port 783)
#/sbin/iptables -A INPUT -p tcp -m tcp –syn –dport 783 -j ACCEPT
#
## Accept imaps (port 993)
#/sbin/iptables -A INPUT -p tcp -m tcp –syn –dport 993 -j ACCEPT
#
## Accept pop3s (port 995)
#/sbin/iptables -A INPUT -p tcp -m tcp –syn –dport 995 -j ACCEPT
#
## Accept mysql (port 3306)
#/sbin/iptables -A INPUT -p tcp -m tcp –syn –dport 3306 -j ACCEPT
#
## Allow inbound established and related outside communication
/sbin/iptables -A INPUT -m state –state ESTABLISHED,RELATED -j ACCEPT
#
## Drop outside initiated connections
/sbin/iptables -A INPUT -m state –state NEW -j REJECT
#
## Allow all outbound tcp, udp, icmp traffic with state
/sbin/iptables -A OUTPUT -p tcp -m state –state NEW,ESTABLISHED -j ACCEPT
/sbin/iptables -A OUTPUT -p udp -m state –state NEW,ESTABLISHED -j ACCEPT
/sbin/iptables -A OUTPUT -p icmp -m state –state NEW,ESTABLISHED,RELATED -j ACCEPT
#
## Save rules
service /sbin/iptables save
#
#
echo “/sbin/iptables configuration is complete”
echo “”
echo “Check your rules – /sbin/iptables -L -n”
echo “”

Redhat Linux IPTABLES

==============================================================================================
==============================================================================================
# Generated by iptables-save v1.3.5 on Sat Dec 10 05:28:35 2011
*filter
:INPUT DROP [0:0]
:FORWARD DROP [0:0]
:OUTPUT ACCEPT [59:18308]
:RH-Firewall-1-INPUT – [0:0]
:SSH_CHECK – [0:0]
-A INPUT -j RH-Firewall-1-INPUT
-A INPUT -s 10.0.0.0/255.0.0.0 -i eth0 -j LOG –log-prefix “IP DROP SPOOF A: ”
-A INPUT -s 172.16.0.0/255.240.0.0 -i eth0 -j LOG –log-prefix “IP DROP SPOOF B: ”
-A INPUT -s 192.168.0.0/255.255.0.0 -i eth0 -j LOG –log-prefix “IP DROP SPOOF C: ”
-A INPUT -s 224.0.0.0/240.0.0.0 -i eth0 -j LOG –log-prefix “IP DROP MULTICAST D: ”
-A INPUT -s 240.0.0.0/248.0.0.0 -i eth0 -j LOG –log-prefix “IP DROP SPOOF E: ”
-A INPUT -d 127.0.0.0/255.0.0.0 -i eth0 -j LOG –log-prefix “IP DROP LOOPBACK: ”
-A INPUT -p tcp -m tcp –dport 22 -m state –state NEW -j SSH_CHECK
-A FORWARD -j RH-Firewall-1-INPUT
-A RH-Firewall-1-INPUT -i lo -j ACCEPT
-A RH-Firewall-1-INPUT -p icmp -m icmp –icmp-type 0 -j ACCEPT
-A RH-Firewall-1-INPUT -p icmp -m icmp –icmp-type 3 -j ACCEPT
-A RH-Firewall-1-INPUT -p icmp -m icmp –icmp-type 11 -j ACCEPT
-A RH-Firewall-1-INPUT -p icmp -m icmp –icmp-type 8 -j ACCEPT
-A RH-Firewall-1-INPUT -m state –state RELATED,ESTABLISHED -j ACCEPT
-A RH-Firewall-1-INPUT -p tcp -m state –state NEW -m tcp –dport 22 -j ACCEPT
-A RH-Firewall-1-INPUT -p tcp -m state –state NEW -m tcp –dport 80 -j ACCEPT
-A RH-Firewall-1-INPUT -p tcp -m state –state NEW -m tcp –dport 443 -j ACCEPT
-A RH-Firewall-1-INPUT -j LOG
-A RH-Firewall-1-INPUT -j DROP
-A SSH_CHECK -m recent –set –name SSH –rsource
-A SSH_CHECK -m recent –update –seconds 60 –hitcount 4 –name SSH –rsource -j DROP
COMMIT
# Completed on Sat Dec 10 05:28:35 2011
==============================================================================================
==============================================================================================

Block Incomming Port 80 except for IP Address 192.168.3.0/24

# /sbin/iptables -A INPUT -p tcp -i eth0 -s ! 192.168.3.0/24 –dport 80 -j DROP

# Generated by iptables-save v1.3.5 on Sat Dec 10 06:17:00 2011
*filter
:INPUT ACCEPT [80:5760]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [78:12568]
-A INPUT -p tcp -m tcp –dport 80 –tcp-flags FIN,SYN,RST,ACK SYN -j ACCEPT
-A INPUT -p tcp -m tcp –dport 443 –tcp-flags FIN,SYN,RST,ACK SYN -j ACCEPT
-A INPUT -p tcp -m tcp –dport 22 –tcp-flags FIN,SYN,RST,ACK SYN -j ACCEPT
-A INPUT -s ! 192.168.3.0/255.255.255.0 -i eth0 -p tcp -m tcp –dport 80 -j DROP
COMMIT
# Completed on Sat Dec 10 06:17:00 2011
==============================================================================================
==============================================================================================

FTP FIREWALL

# Generated by iptables-save v1.3.5 on Wed Jun 10 21:13:16 2009
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [423:45748]
:RH-Firewall-1-INPUT – [0:0]
-A INPUT -j RH-Firewall-1-INPUT
-A FORWARD -j RH-Firewall-1-INPUT
-A RH-Firewall-1-INPUT -i lo -j ACCEPT
-A RH-Firewall-1-INPUT -p icmp -m icmp –icmp-type any -j ACCEPT
-A RH-Firewall-1-INPUT -p esp -j ACCEPT
-A RH-Firewall-1-INPUT -p ah -j ACCEPT
-A RH-Firewall-1-INPUT -d 224.0.0.251 -p udp -m udp –dport 5353 -j ACCEPT
-A RH-Firewall-1-INPUT -p udp -m udp –dport 631 -j ACCEPT
-A RH-Firewall-1-INPUT -p tcp -m tcp –dport 631 -j ACCEPT
-A RH-Firewall-1-INPUT -m state –state RELATED,ESTABLISHED -j ACCEPT
-A RH-Firewall-1-INPUT -p tcp -m state –state NEW -m tcp –dport 20 -j ACCEPT
-A RH-Firewall-1-INPUT -p tcp -m state –state NEW -m tcp –dport 21 -j ACCEPT
-A RH-Firewall-1-INPUT -p tcp -m state –state NEW -m tcp –dport 22 -j ACCEPT
-A RH-Firewall-1-INPUT -p tcp -m state –state NEW -m tcp –dport 23 -j ACCEPT
-A RH-Firewall-1-INPUT -j REJECT –reject-with icmp-host-prohibited
COMMIT
==============================================================================================
==============================================================================================

Redhat Basic Firewall

# Firewall configuration written by system-config-securitylevel
# Manual customization of this file is not recommended.
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
:RH-Firewall-1-INPUT – [0:0]
-A INPUT -j RH-Firewall-1-INPUT
-A FORWARD -j RH-Firewall-1-INPUT
-A RH-Firewall-1-INPUT -i lo -j ACCEPT
-A RH-Firewall-1-INPUT -p icmp –icmp-type any -j ACCEPT
-A RH-Firewall-1-INPUT -p 50 -j ACCEPT
-A RH-Firewall-1-INPUT -p 51 -j ACCEPT
-A RH-Firewall-1-INPUT -p udp –dport 5353 -d 224.0.0.251 -j ACCEPT
-A RH-Firewall-1-INPUT -p udp -m udp –dport 631 -j ACCEPT
-A RH-Firewall-1-INPUT -p tcp -m tcp –dport 631 -j ACCEPT
-A RH-Firewall-1-INPUT -m state –state ESTABLISHED,RELATED -j ACCEPT
-A RH-Firewall-1-INPUT -m state –state NEW -m tcp -p tcp –dport 8009 -j ACCEPT
-A RH-Firewall-1-INPUT -m state –state NEW -m tcp -p tcp –dport 5902 -j ACCEPT
A RH-Firewall-1-INPUT -m state –state NEW -m tcp -p tcp –dport 8080 -j ACCEPT
-A RH-Firewall-1-INPUT -m state –state NEW -m tcp -p tcp –dport 10050 -j ACCEPT
-A RH-Firewall-1-INPUT -m state –state NEW -m tcp -p tcp –dport 22 -j ACCEPT
-A RH-Firewall-1-INPUT -m state –state NEW -m tcp -p tcp –dport 80 -j ACCEPT
-A RH-Firewall-1-INPUT -m state –state NEW -m tcp -p tcp –dport 443 -j ACCEPT
-A RH-Firewall-1-INPUT -j REJECT –reject-with icmp-host-prohibited
COMMIT

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

SSH Rules

Using iptables to allow only specific hosts to connect

An alternative to TCP wrappers (although you can use both at the same time) is limiting SSH access with iptables. Here’s a simple example of how you can allow only a specific host to connect to your SSH service:

~# iptables -A INPUT -p tcp -m state –state NEW –source 193.180.177.13 –dport 22 -j ACCEPT

And make sure no one else has access to SSH service:

~# iptables -A INPUT -p tcp –dport 22 -j DROP

~# iptables -A INPUT -p tcp -m state –syn –state NEW –dport 22 -m limit –limit 1/minute –limit-burst 1 -j ACCEPT
~# iptables -A INPUT -p tcp -m state –syn –state NEW –dport 22 -j DROP

In a second example, iptables are set to allow only host 193.180.177.13 to connect to the SSH service. After three failed login tries, iptables allows the host only one login try per minute:

~# iptables -A INPUT -p tcp -s 193.180.177.13 -m state –syn –state NEW –dport 22 -m limit –limit 1/minute –limit-burst 1 -j ACCEPT
~# iptables -A INPUT -p tcp -s 193.180.177.13 -m state –syn –state NEW –dport 22 -j DROP

Conclusion

iptables -N SSH_CHECK
iptables -A INPUT -p tcp –dport 22 -m state –state NEW -j SSH_CHECK
iptables -A SSH_CHECK -m recent –set –name SSH
iptables -A SSH_CHECK -m recent –update –seconds 60 –hitcount 4 –name SSH -j DROP

Page 164 of 164« First...102030...160161162163164