bar top left
bar top right
left curve
right curve
Welcome, Guest

Can someone share their Firewall script
(1 viewing) (1) Guest
Go to bottom
Post Reply
Post New Topic
Page: 123456
TOPIC: Can someone share their Firewall script
#37827
Can someone share their Firewall script 9 Months, 3 Weeks ago Karma: 0
Hi,

I have installed Elastix server (ISO install) with full yum update

I am no expert, but learning my way thru.

Can someone please share their firewall script ?
It will help me get a head start and then I can modify rules (if needed) for my network.

My Elastix server is on a live IP with 5 extensions from our office (192.168.1.x) and 3 different trunks from different providers. SSh is on non-standard port and FTP port is closed. Postfix relay is blocked (standard install).

Thank you all in advance.

Best regards,
Vai
Enter code here   
Please note: although no board code and smiley buttons are shown, they are still usable.
vaibhavs
Junior Boarder
Posts: 53
graphgraph
User Offline Click here to see the profile of this user
Reply Quote
 
#38253
Re:Can someone share their Firewall script 9 Months, 2 Weeks ago Karma: 10
Firewalling is generally done at the router level, not on the box itself in my experience?
Enter code here   
Please note: although no board code and smiley buttons are shown, they are still usable.
Chilling_Silence
Senior Boarder
Posts: 486
graphgraph
User Offline Click here to see the profile of this user
Gender: Male Location: New Zealand Birthday: 01/27
Before you ask a question, or before you get upset by a response, see here:
Links hidden for unregistered users. Login or register Here
It will help you to know what to ask, how to ask, and what to expect as a response
Reply Quote
 
#39355
Re:Can someone share their Firewall script 8 Months, 4 Weeks ago Karma: 0
I suggest using IPTABLES. It allows you to stick a public IP directly on the box without needing something to NAT or Xlate for you.. ridding NAT traversal.

My approach is simple... allow traffic originated from the box to the WAN. Deny all inbound connections accept the ones I want. Throw this into a file and sh it, the IPTABLE rules should be saved and load upon reboot of the box:

Code:


#!/bin/sh
# chkconfig: 2345 99 99
# description: IPTABLES FIREWALL STARTUP
echo start by flushing the rules..................

/sbin/iptables -F INPUT
/sbin/iptables -F OUTPUT
/sbin/iptables -F FORWARD
/sbin/iptables -F

echo allow packets coming from the machine..................

/sbin/iptables -A INPUT -i lo -j ACCEPT
/sbin/iptables -A OUTPUT -o lo -j ACCEPT

echo allow established traffic
/sbin/iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
/sbin/iptables -A OUTPUT -m state --state ESTABLISHED,RELATED -j ACCEPT


#################################
## What we allow
#################################

# Everything from trusted hosts
echo Accept all from trusted source hosts
# SOME IP ADDRESS
/sbin/iptables -A INPUT -s 0.0.0.0 -i eth0 -j ACCEPT

#################################
## What we DENY
#################################

echo block spoofing..................

/sbin/iptables -A INPUT -s 127.0.0.0/8 -i ! lo -j DROP

echo stop bad packets..................

/sbin/iptables -A INPUT -m state --state INVALID -j DROP

echo NMAP FIN/URG/PSH..................

/sbin/iptables -A INPUT -i eth0 -p tcp --tcp-flags ALL FIN,URG,PSH -j DROP

echo stop Xmas Tree type scanning..................

/sbin/iptables -A INPUT -i eth0 -p tcp --tcp-flags ALL ALL -j DROP
/sbin/iptables -A INPUT -i eth0 -p tcp --tcp-flags ALL SYN,RST,ACK,FIN,URG -j DROP

echo stop null scanning..................

/sbin/iptables -A INPUT -i eth0 -p tcp --tcp-flags ALL NONE -j DROP

echo SYN/RST..................

/sbin/iptables -A INPUT -i eth0 -p tcp --tcp-flags SYN,RST SYN,RST -j DROP

echo SYN/FIN..................

/sbin/iptables -A INPUT -i eth0 -p tcp --tcp-flags SYN,FIN SYN,FIN -j DROP

echo stop sync flood..................
/sbin/iptables -N SYNFLOOD
/sbin/iptables -A SYNFLOOD -p tcp --syn -m limit --limit 1/s -j RETURN
/sbin/iptables -A SYNFLOOD -p tcp -j REJECT --reject-with tcp-reset
/sbin/iptables -A INPUT -p tcp -m state --state NEW -j SYNFLOOD

echo stop ping flood attack..................
/sbin/iptables -N PING
/sbin/iptables -A PING -p icmp --icmp-type echo-request -m limit --limit 1/second -j RETURN
/sbin/iptables -A PING -p icmp -j REJECT
/sbin/iptables -I INPUT -p icmp --icmp-type echo-request -m state --state NEW -j PING

echo finally - drop the rest
/sbin/iptables -A INPUT -j DROP

echo SAVE CONFIG
/sbin/service iptables save

echo STOP IPTABLES
service iptables stop

echo START IPTABLES
service iptables start


Enter code here   
Please note: although no board code and smiley buttons are shown, they are still usable.
Eham
Fresh Boarder
Posts: 42
graphgraph
User Offline Click here to see the profile of this user
Reply Quote
 
#39362
Re:Can someone share their Firewall script 8 Months, 4 Weeks ago Karma: 95
Eham: May I ask if you find that your posted rule is sufficiently restrictive for you?



/sbin/iptables -A INPUT -s 0.0.0.0 -i eth0 -j ACCEPT



rocky.eld.leidenuniv.nl/joomla/

IMHO would be a good starting point, for a robust iptables script (It's what I use, Thank you Arno)
Enter code here   
Please note: although no board code and smiley buttons are shown, they are still usable.
dicko
Did I learn something today? If not, I wasted it.
Moderator
Posts: 2850
graphgraph
User Offline Click here to see the profile of this user
Gender: Male Location: Where my freeway is the same as my latitude Birthday: 01/21
Last Edit: 2009/11/04 19:24 By dicko.
I assume you have downloaded, read and absorbed - Links hidden for unregistered users. Login or register Here, I encourage you all to visit Links hidden for unregistered users. Login or register Here
Dicko
Reply Quote
 
#39374
Re:Can someone share their Firewall script 8 Months, 4 Weeks ago Karma: 0
Dicko, You really don't leave anything unturned

I changed 0.0.0.0 for the purpose of keeping my trusted host ip off of a forum. But yes, anyone wanting to use the above output will need to substitute 0.0.0.0 with a real host IP address. I have several and so far my above IPTABLES example has held up against everything thrown at it. Your mileage may vary, but if you can truly trust the host this will suffice for any VoIP/Web/Hylafax you need to do (at least I've had great success with it).
Enter code here   
Please note: although no board code and smiley buttons are shown, they are still usable.
Eham
Fresh Boarder
Posts: 42
graphgraph
User Offline Click here to see the profile of this user
Reply Quote
 
#39375
Re:Can someone share their Firewall script 8 Months, 4 Weeks ago Karma: 95
Your script only denies a few "well known" exploits and (with respect) even if you had a trusted host plugged in, how then would it accept inbound calls from your various VSP's/external extensions?, or even internal calls as you only have eth0 defined and one trusted IP.

It is necessary to shape the allow bit to actually be a firewall that meets a VOIP server's needs, you need to allow SIP/IAX2, http(s), email (in and out) etc. and only these to your trusted hosts. Arno's script actually does that restrictively and is a template for adding SIP etc. by port (not IP) and then by host/network as appropriate, you need your VSP's and external extensions allowed, and any external management allowed by host/network.

This is why there will likely ever be a definitive script for VOIP/Elastix/all the other stuff you added, as each and everyone has a different set of needs.

regards
dicko
Enter code here   
Please note: although no board code and smiley buttons are shown, they are still usable.
dicko
Did I learn something today? If not, I wasted it.
Moderator
Posts: 2850
graphgraph
User Offline Click here to see the profile of this user
Gender: Male Location: Where my freeway is the same as my latitude Birthday: 01/21
Last Edit: 2009/11/05 01:06 By dicko.
I assume you have downloaded, read and absorbed - Links hidden for unregistered users. Login or register Here, I encourage you all to visit Links hidden for unregistered users. Login or register Here
Dicko
Reply Quote
 
#39376
Re:Can someone share their Firewall script 8 Months, 4 Weeks ago Karma: 0
Dicko, there certainly isn't an all-in-one solution. My profession over the last few years has been engineering enterprise soft switches- such as Metaswitch and Genband. Anything public-facing preferably use Session Border Controllers to the signaling gateway (Elastix in this case). Good SBCs (such as Acmepacket and Covergence) will control DDOS floods and most other criteria considered malicious. Anything web facing (portals, etc) are typically behind DMZs such as Cisco PIX or ASA (..Sonicwall, Patton, m0n0wall, PfSense etc etc). Enterprise-grade VoIP will literally cost hundreds of thousands of $USD some in the Millions.

I posted a request some time ago about OpenSBC integration, in hopes to cover some of the potential abuse from the public internet. Though my IPTABLES example may not be incredibly flexible it is secure. If you can find a way around mine, I will paypal you $5USD personally
Enter code here   
Please note: although no board code and smiley buttons are shown, they are still usable.
Eham
Fresh Boarder
Posts: 42
graphgraph
User Offline Click here to see the profile of this user
Reply Quote
 
#39377
Re:Can someone share their Firewall script 8 Months, 4 Weeks ago Karma: 95
With only one trusted IP allowed through iptables, I still don't understand how people can actually call each other with your script, never mind me making five bucks trying to penetrate an anonymous /32 network that will only accept connections from one other nominated /32 network. Although I must concede that the trusted host can listen to his voicemails to himself and even configure Elastix/FreePBX/Asterisk

I am also a little confused as to why anything "behind DMZs" should be considered particularly secure.
Enter code here   
Please note: although no board code and smiley buttons are shown, they are still usable.
dicko
Did I learn something today? If not, I wasted it.
Moderator
Posts: 2850
graphgraph
User Offline Click here to see the profile of this user
Gender: Male Location: Where my freeway is the same as my latitude Birthday: 01/21
Last Edit: 2009/11/05 02:01 By dicko.
I assume you have downloaded, read and absorbed - Links hidden for unregistered users. Login or register Here, I encourage you all to visit Links hidden for unregistered users. Login or register Here
Dicko
Reply Quote
 
#39387
Re:Can someone share their Firewall script 8 Months, 4 Weeks ago Karma: 0
Following is my IPTables script.
Critical inputs welcome!

Code:

#!/bin/bash

# Clear any existing firewall stuff before we start
/sbin/iptables --flush

# As the default policies, drop all incoming traffic but allow all
# outgoing traffic.  This will allow us to make outgoing connections
# from any port, but will only allow incoming connections on the ports
# specified below.
/sbin/iptables --policy INPUT DROP
/sbin/iptables --policy FORWARD DROP
/sbin/iptables --policy OUTPUT ACCEPT


# Allow all incoming traffic if it is coming from the local loopback device
/sbin/iptables -A INPUT -i lo -j ACCEPT

# Allow returning packets
/sbin/iptables -A INPUT -i eth0 -m state --state RELATED,ESTABLISHED -j ACCEPT

# Allow incoming traffic for web server
/sbin/iptables -A INPUT -p tcp -m tcp --dport 80 -j ACCEPT
/sbin/iptables -A INPUT -p tcp -m tcp --dport 443 -j ACCEPT

# Allow connections to port 2222 - ssh. You can add other ports you need in here
/sbin/iptables -A INPUT -p tcp -i eth0 --dport 2222 -m state --state NEW -j ACCEPT

# Allow icmp input so that people can ping us
/sbin/iptables -A INPUT -p icmp --icmp-type 8 -m state --state NEW -j ACCEPT

# Allow SIP connections
/sbin/iptables -A INPUT -p udp -i eth0 --dport 5060 -j ACCEPT
/sbin/iptables -A INPUT -p tcp -i eth0 --dport 5060 -j ACCEPT
/sbin/iptables -A INPUT -p udp -i eth0 --dport 10000:20000 -j ACCEPT

# Allow connections from my machines
# /sbin/iptables -A INPUT -p tcp -i eth0 -m state --state NEW -s xxxxxxxx -j ACCEPT

# Check new packets are SYN packets for syn-flood protection
/sbin/iptables -A INPUT -p tcp ! --syn -m state --state NEW -j DROP

# Drop fragmented packets
/sbin/iptables -A INPUT -f -j DROP

# Drop malformed XMAS packets
/sbin/iptables -A INPUT -p tcp --tcp-flags ALL ALL -j DROP

# Drop null packets
/sbin/iptables -A INPUT -p tcp --tcp-flags ALL NONE -j DROP

# Log then drop any packets that are not allowed. You will probably want to turn off the logging
#/sbin/iptables -A INPUT -j LOG
/sbin/iptables -A INPUT -j REJECT


Enter code here   
Please note: although no board code and smiley buttons are shown, they are still usable.
vaibhavs
Junior Boarder
Posts: 53
graphgraph
User Offline Click here to see the profile of this user
Reply Quote
 
#39396
Re:Can someone share their Firewall script 8 Months, 4 Weeks ago Karma: 0
dicko wrote:
With only one trusted IP allowed through iptables, I still don't understand how people can actually call each other with your script, never mind me making five bucks trying to penetrate an anonymous /32 network that will only accept connections from one other nominated /32 network. Although I must concede that the trusted host can listen to his voicemails to himself and even configure Elastix/FreePBX/Asterisk

I am also a little confused as to why anything "behind DMZs" should be considered particularly secure.


It's all about convention, and my convention deals with trusted endpoints that have static IPs, with multiple trusted endpoints added to the IPTABLES permit (my example has just one but add as many as you need). My deployment consists of the Elastix box with a SIP trunk to the Class5 softswitch trusted IP and a few other endpoints for the IP phones. I don't trunk to other Elastix boxes or have dynamic users.. I let the softswitch take care of those (the company I work for as invested in it, so why not?) This doesn't help roaming users or users that don't have the luxury of a static IP as you well know.

I used to allow 5060 and RTP ports open everywhere until someone got a hold of a x-lite softphone config file and ended up making fraudulent call campaigns via my Elastix box. Now you know why I lock mine down so tightly The Softswitch vendors recommend DMZ at minimal, I personally use XLATE over a pair of High Availability Cisco Pix. If anyone is interested in a simple Pix xlate config I can post it here. Dicko, I would pay you $5usd for being a great patron of the Elastix community, and as you said there's not much chance for penetration on the above said IPTABLES code, which is exactly my goal (and thus your mileage may vary).

I'm glad this security topic has been brought to life, as it is a tremendous liability. I would like to see additional security measures implemented into Elastix (such as removing root login, OpenSBC or a basic firewall GUI) for the sake of simplicity and wider use.
Enter code here   
Please note: although no board code and smiley buttons are shown, they are still usable.
Eham
Fresh Boarder
Posts: 42
graphgraph
User Offline Click here to see the profile of this user
Reply Quote
 
Go to top
Post Reply
Post New Topic
Page: 123456
Moderators: ramoncio, rafael, Bob, dicko