2002-05-01 01:13:15 +02:00
|
|
|
#!/bin/sh
|
|
|
|
#
|
2002-05-18 15:45:23 +02:00
|
|
|
# Shorewall Packet Filtering Firewall Control Program - V1.3 - 6/14/2002
|
2002-05-01 01:13:15 +02:00
|
|
|
#
|
2002-07-06 00:24:40 +02:00
|
|
|
# This program is under GPL [http://www.gnu.org/copyleft/gpl.htm]
|
2002-05-01 01:13:15 +02:00
|
|
|
#
|
|
|
|
# (c) 1999,2000,2001,2002 - Tom Eastep (teastep@shorewall.net)
|
|
|
|
#
|
|
|
|
#
|
2002-07-06 00:24:40 +02:00
|
|
|
# This file should be placed in /sbin/shorewall.
|
2002-05-01 01:13:15 +02:00
|
|
|
#
|
2002-07-06 00:24:40 +02:00
|
|
|
# Shorewall documentation is available at http://shorewall.sourceforge.net
|
2002-05-01 01:13:15 +02:00
|
|
|
#
|
2002-07-06 00:24:40 +02:00
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of Version 2 of the GNU General Public License
|
|
|
|
# as published by the Free Software Foundation.
|
2002-05-01 01:13:15 +02:00
|
|
|
#
|
2002-07-06 00:24:40 +02:00
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
2002-05-01 01:13:15 +02:00
|
|
|
#
|
2002-07-06 00:24:40 +02:00
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program; if not, write to the Free Software
|
|
|
|
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA
|
|
|
|
#
|
|
|
|
# If an error occurs while starting or restarting the firewall, the
|
|
|
|
# firewall is automatically stopped.
|
2002-05-01 01:13:15 +02:00
|
|
|
#
|
2002-07-06 00:24:40 +02:00
|
|
|
# The firewall uses configuration files in /etc/shorewall/ - skeleton
|
|
|
|
# files is included with the firewall.
|
2002-05-01 01:13:15 +02:00
|
|
|
#
|
2002-07-06 00:24:40 +02:00
|
|
|
# Commands are:
|
2002-05-01 01:13:15 +02:00
|
|
|
#
|
2002-10-01 22:54:42 +02:00
|
|
|
# shorewall add <iface>[:<host>] zone Adds a host or subnet to a zone
|
|
|
|
# shorewall delete <iface>[:<host>] zone Deletes a host or subnet from a zone
|
2002-07-06 00:24:40 +02:00
|
|
|
# shorewall start Starts the firewall
|
|
|
|
# shorewall restart Restarts the firewall
|
|
|
|
# shorewall stop Stops the firewall
|
|
|
|
# shorewall monitor [ refresh-interval ] Repeatedly Displays firewall status
|
|
|
|
# plus the last 20 "interesting"
|
|
|
|
# packets
|
|
|
|
# shorewall status Displays firewall status
|
|
|
|
# shorewall reset Resets iptables packet and
|
|
|
|
# byte counts
|
|
|
|
# shorewall clear Open the floodgates by
|
|
|
|
# removing all iptables rules
|
|
|
|
# and setting the three permanent
|
|
|
|
# chain policies to ACCEPT
|
2002-05-01 01:13:15 +02:00
|
|
|
# shorewall refresh Rebuild the common chain to
|
|
|
|
# compensate for a change of
|
|
|
|
# broadcast address on any "detect"
|
|
|
|
# interface.
|
2002-07-06 00:24:40 +02:00
|
|
|
# shorewall show <chain> Display the rules in a <chain>
|
|
|
|
# shorewall show log Print the last 20 log messages
|
|
|
|
# shorewall show connections Show the kernel's connection
|
|
|
|
# tracking table
|
|
|
|
# shorewall show nat Display the rules in the nat table
|
|
|
|
# shorewall show {mangle|tos} Display the rules in the mangle table
|
|
|
|
# shorewall show tc Display traffic control info
|
2002-12-10 21:42:19 +01:00
|
|
|
# shorewall show classifiers Display classifiers
|
2002-05-01 01:13:15 +02:00
|
|
|
# shorewall version Display the installed version id
|
2002-07-06 00:24:40 +02:00
|
|
|
# shorewall check Verify the more heavily-used
|
|
|
|
# configuration files.
|
|
|
|
# shorewall try <directory> [ <timeout> ] Try a new configuration and if
|
|
|
|
# it doesn't work, revert to the
|
|
|
|
# standard one. If a timeout is supplied
|
2002-05-01 01:13:15 +02:00
|
|
|
# the command reverts back to the
|
|
|
|
# standard configuration after that many
|
|
|
|
# seconds have elapsed after successfully
|
|
|
|
# starting the new configuration.
|
2002-06-04 17:08:50 +02:00
|
|
|
# shorewall logwatch [ refresh-interval ] Monitor the local log for Shorewall
|
|
|
|
# messages.
|
2002-07-06 00:24:40 +02:00
|
|
|
# shorewall drop <address> ... Temporarily drop all packets from the
|
2002-06-04 22:17:46 +02:00
|
|
|
# listed address(es)
|
2002-07-06 00:24:40 +02:00
|
|
|
# shorewall reject <address> ... Temporarily reject all packets from the
|
2002-06-04 22:17:46 +02:00
|
|
|
# listed address(es)
|
2002-06-04 22:58:53 +02:00
|
|
|
# shorewall allow <address> ... Reenable address(es) previously
|
|
|
|
# disabled with "drop" or "reject"
|
|
|
|
# shorewall save Save the list of "rejected" and
|
|
|
|
# "dropped" addresses so that it will
|
|
|
|
# be automatically reinstated the
|
2002-06-11 22:14:58 +02:00
|
|
|
# next time that Shorewall starts.
|
2002-05-01 01:13:15 +02:00
|
|
|
#
|
|
|
|
# Display a chain if it exists
|
|
|
|
#
|
|
|
|
showfirstchain() # $1 = name of chain
|
|
|
|
{
|
|
|
|
awk \
|
2002-07-06 00:24:40 +02:00
|
|
|
'BEGIN {prnt=0; rslt=1; }; \
|
|
|
|
/^$/ { next; };\
|
|
|
|
/^Chain/ {if ( prnt == 1 ) { rslt=0; exit 0; }; };\
|
2002-05-01 01:13:15 +02:00
|
|
|
/Chain '$1'/ { prnt=1; }; \
|
2002-07-06 00:24:40 +02:00
|
|
|
{ if (prnt == 1) print; };\
|
2002-05-30 14:55:47 +02:00
|
|
|
END { exit rslt; }' /tmp/chains-$$
|
2002-05-01 01:13:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
showchain() # $1 = name of chain
|
|
|
|
{
|
|
|
|
if [ "$firstchain" = "Yes" ]; then
|
2002-05-30 14:55:47 +02:00
|
|
|
if showfirstchain $1; then
|
|
|
|
firstchain=
|
|
|
|
fi
|
2002-05-01 01:13:15 +02:00
|
|
|
else
|
|
|
|
awk \
|
2002-07-06 00:24:40 +02:00
|
|
|
'BEGIN {prnt=0;};\
|
|
|
|
/^$|^ pkts/ { next; };\
|
|
|
|
/^Chain/ {if ( prnt == 1 ) exit; };\
|
|
|
|
/Chain '$1'/ { prnt=1; };\
|
|
|
|
{ if (prnt == 1) print; }' /tmp/chains-$$
|
2002-05-01 01:13:15 +02:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2002-10-23 18:48:40 +02:00
|
|
|
#
|
|
|
|
# Set the configuration variables from shorewall.conf
|
|
|
|
#
|
2002-05-01 01:13:15 +02:00
|
|
|
get_config() {
|
|
|
|
|
|
|
|
[ -z "$LOGFILE" ] && LOGFILE=/var/log/messages
|
|
|
|
|
|
|
|
if [ ! -f $LOGFILE ]; then
|
|
|
|
echo "LOGFILE ($LOGFILE) does not exist!" >&2
|
|
|
|
exit 2
|
|
|
|
fi
|
|
|
|
#
|
|
|
|
# See if we have a real version of "tail" -- use separate redirection so
|
|
|
|
# that ash (aka /bin/sh on LRP) doesn't crap
|
|
|
|
#
|
|
|
|
if ( tail -n5 $LOGFILE > /dev/null 2> /dev/null ) ; then
|
2002-07-06 00:24:40 +02:00
|
|
|
realtail="Yes"
|
2002-05-01 01:13:15 +02:00
|
|
|
else
|
2002-07-06 00:24:40 +02:00
|
|
|
realtail=""
|
2002-05-01 01:13:15 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
[ -n "$FW" ] || FW=fw
|
|
|
|
}
|
|
|
|
|
2002-10-23 18:48:40 +02:00
|
|
|
#
|
|
|
|
# Display IPTABLES rules -- we used to store them in a variable but ash
|
|
|
|
# dies when trying to display large sets of rules
|
|
|
|
#
|
2002-05-01 01:13:15 +02:00
|
|
|
display_chains()
|
|
|
|
{
|
|
|
|
trap "rm -f /tmp/chains-$$; exit 1" 1 2 3 4 5 6 9
|
|
|
|
|
|
|
|
if [ "$haveawk" = "Yes" ]; then
|
|
|
|
#
|
|
|
|
# Send the output to a temporary file since ash craps if we try to store
|
|
|
|
# the output in a variable.
|
|
|
|
#
|
|
|
|
iptables -L -n -v > /tmp/chains-$$
|
|
|
|
|
|
|
|
clear
|
2002-11-11 00:15:53 +01:00
|
|
|
echo "$banner `date`"
|
|
|
|
echo
|
|
|
|
echo "Standard Chains"
|
|
|
|
echo
|
2002-05-01 01:13:15 +02:00
|
|
|
firstchain="Yes"
|
|
|
|
showchain INPUT
|
|
|
|
showchain OUTPUT
|
|
|
|
showchain FORWARD
|
|
|
|
|
|
|
|
timed_read
|
|
|
|
|
2002-05-18 15:45:23 +02:00
|
|
|
clear
|
2002-11-11 00:15:53 +01:00
|
|
|
echo "$banner `date`"
|
|
|
|
echo
|
2002-05-30 14:55:47 +02:00
|
|
|
firstchain=Yes
|
2002-11-11 00:15:53 +01:00
|
|
|
echo "Input Chains"
|
|
|
|
echo
|
2002-05-18 15:45:23 +02:00
|
|
|
|
|
|
|
chains=`grep '^Chain.*_[in|fwd]' /tmp/chains-$$ | cut -d' ' -f 2`
|
|
|
|
|
|
|
|
for chain in $chains; do
|
|
|
|
showchain $chain
|
|
|
|
done
|
|
|
|
|
|
|
|
timed_read
|
|
|
|
|
2002-05-18 21:04:45 +02:00
|
|
|
for zone in $zones; do
|
2002-05-18 15:45:23 +02:00
|
|
|
|
2002-05-01 01:13:15 +02:00
|
|
|
if [ -n "`grep "^Chain \.*${zone}" /tmp/chains-$$`" ] ; then
|
|
|
|
clear
|
2002-11-11 00:15:53 +01:00
|
|
|
echo "$banner `date`"
|
|
|
|
echo
|
2002-05-01 01:13:15 +02:00
|
|
|
firstchain=Yes
|
|
|
|
eval display=\$${zone}_display
|
2002-11-11 00:15:53 +01:00
|
|
|
echo "$display Chains"
|
|
|
|
echo
|
2002-05-01 01:13:15 +02:00
|
|
|
for zone1 in $FW $zones; do
|
|
|
|
showchain ${zone}2$zone1
|
|
|
|
showchain @${zone}2$zone1
|
|
|
|
[ "$zone" != "$zone1" ] && \
|
2002-07-06 00:24:40 +02:00
|
|
|
showchain ${zone1}2${zone} && \
|
2002-05-01 01:13:15 +02:00
|
|
|
showchain @${zone1}2${zone}
|
|
|
|
done
|
|
|
|
|
|
|
|
timed_read
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
clear
|
2002-11-11 00:15:53 +01:00
|
|
|
echo "$banner `date`"
|
|
|
|
echo
|
2002-05-01 01:13:15 +02:00
|
|
|
firstchain=Yes
|
2002-11-11 00:15:53 +01:00
|
|
|
echo "Policy Chains"
|
|
|
|
echo
|
2002-05-01 01:13:15 +02:00
|
|
|
showchain common
|
2002-07-06 00:24:40 +02:00
|
|
|
showchain badpkt
|
2002-05-01 01:13:15 +02:00
|
|
|
showchain icmpdef
|
|
|
|
showchain rfc1918
|
|
|
|
showchain blacklst
|
|
|
|
showchain reject
|
2002-08-06 20:45:13 +02:00
|
|
|
showchain newnotsyn
|
2002-05-01 01:13:15 +02:00
|
|
|
for zone in $zones all; do
|
|
|
|
showchain ${zone}2all
|
|
|
|
showchain @${zone}2all
|
|
|
|
[ "$zone" = "all" ] || { showchain all2${zone}; showchain @all2${zone}; }
|
2002-07-06 00:24:40 +02:00
|
|
|
done
|
2002-05-01 01:13:15 +02:00
|
|
|
|
|
|
|
timed_read
|
|
|
|
|
2002-06-04 23:08:44 +02:00
|
|
|
clear
|
2002-11-11 00:15:53 +01:00
|
|
|
echo "$banner `date`"
|
|
|
|
echo
|
2002-06-04 23:08:44 +02:00
|
|
|
firstchain=Yes
|
2002-11-11 00:15:53 +01:00
|
|
|
echo "Dynamic Chain"
|
|
|
|
echo
|
2002-06-04 23:08:44 +02:00
|
|
|
showchain dynamic
|
|
|
|
timed_read
|
|
|
|
|
2002-05-01 01:13:15 +02:00
|
|
|
qt rm -f /tmp/chains-$$
|
|
|
|
else
|
|
|
|
iptables -L -n -v
|
|
|
|
timed_read
|
|
|
|
fi
|
|
|
|
trap - 1 2 3 4 5 6 9
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2002-10-23 18:48:40 +02:00
|
|
|
#
|
|
|
|
# Delay $timeout seconds -- if we're running on a recent bash2 then allow
|
|
|
|
# <enter> to terminate the delay
|
|
|
|
#
|
2002-05-01 01:13:15 +02:00
|
|
|
timed_read ()
|
|
|
|
{
|
|
|
|
read -t $timeout foo 2> /dev/null
|
|
|
|
|
|
|
|
test $? -eq 2 && sleep $timeout
|
|
|
|
}
|
|
|
|
|
2002-10-23 18:48:40 +02:00
|
|
|
#
|
|
|
|
# Display the last $1 packets logged
|
|
|
|
#
|
2002-06-02 19:05:51 +02:00
|
|
|
packet_log() # $1 = number of messages
|
2002-05-01 01:13:15 +02:00
|
|
|
{
|
|
|
|
local options
|
|
|
|
|
2002-06-02 19:05:51 +02:00
|
|
|
[ -n "$realtail" ] && options="-n$1"
|
2002-05-01 01:13:15 +02:00
|
|
|
|
|
|
|
grep 'Shorewall:\|ipt_unclean' $LOGFILE | \
|
2002-12-13 05:06:24 +01:00
|
|
|
sed s/" kernel:"// | \
|
|
|
|
sed s/" $host Shorewall:"/" "/ | \
|
2002-07-06 00:24:40 +02:00
|
|
|
sed s/" $host kernel: ipt_unclean: "/" "/ | \
|
|
|
|
sed 's/MAC=.*SRC=/SRC=/' | \
|
|
|
|
tail $options
|
2002-05-01 01:13:15 +02:00
|
|
|
}
|
|
|
|
|
2002-10-23 18:48:40 +02:00
|
|
|
#
|
|
|
|
# Show traffic control information
|
|
|
|
#
|
2002-05-01 01:13:15 +02:00
|
|
|
show_tc() {
|
|
|
|
|
|
|
|
show_one_tc() {
|
2002-07-06 00:24:40 +02:00
|
|
|
local device=${1%@*}
|
|
|
|
qdisc=`tc qdisc list dev $device`
|
2002-05-01 01:13:15 +02:00
|
|
|
|
|
|
|
if [ -n "$qdisc" ]; then
|
|
|
|
echo Device $device:
|
|
|
|
tc -s -d qdisc show dev $device
|
|
|
|
tc -s -d class show dev $device
|
|
|
|
echo
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
ip link list | \
|
|
|
|
while read inx interface details; do
|
|
|
|
case $inx in
|
|
|
|
[0-9]*)
|
|
|
|
show_one_tc ${interface%:}
|
2002-07-06 00:24:40 +02:00
|
|
|
;;
|
2002-05-01 01:13:15 +02:00
|
|
|
*)
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2002-12-10 21:42:19 +01:00
|
|
|
#
|
|
|
|
# Show classifier information
|
|
|
|
#
|
|
|
|
show_classifiers() {
|
|
|
|
|
|
|
|
show_one_classifier() {
|
|
|
|
local device=${1%@*}
|
|
|
|
qdisc=`tc qdisc list dev $device`
|
|
|
|
|
|
|
|
if [ -n "$qdisc" ]; then
|
|
|
|
echo Device $device:
|
|
|
|
tc -s filter ls dev $device
|
|
|
|
echo
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
ip link list | \
|
|
|
|
while read inx interface details; do
|
|
|
|
case $inx in
|
|
|
|
[0-9]*)
|
|
|
|
show_one_classifier ${interface%:}
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
|
|
|
}
|
2002-10-23 18:48:40 +02:00
|
|
|
#
|
|
|
|
# Monitor the Firewall
|
|
|
|
#
|
2002-05-01 01:13:15 +02:00
|
|
|
monitor_firewall() # $1 = timeout -- if negative, prompt each time that
|
2002-07-06 00:24:40 +02:00
|
|
|
# an 'interesting' packet count changes
|
2002-05-01 01:13:15 +02:00
|
|
|
{
|
|
|
|
|
|
|
|
get_config
|
|
|
|
host=`echo $HOSTNAME | sed 's/\..*$//'`
|
|
|
|
oldrejects=`iptables -L -v -n | grep 'LOG'`
|
|
|
|
|
|
|
|
if [ $1 -lt 0 ]; then
|
|
|
|
let "timeout=- $1"
|
|
|
|
pause="Yes"
|
|
|
|
else
|
|
|
|
pause="No"
|
|
|
|
timeout=$1
|
|
|
|
fi
|
|
|
|
|
|
|
|
qt which awk && { haveawk=Yes; determine_zones; } || haveawk=
|
|
|
|
|
|
|
|
while true; do
|
|
|
|
display_chains
|
|
|
|
|
|
|
|
clear
|
2002-11-11 00:15:53 +01:00
|
|
|
echo "$banner `date`"
|
|
|
|
echo
|
2002-05-01 01:13:15 +02:00
|
|
|
|
2002-11-11 00:15:53 +01:00
|
|
|
echo "Dropped/Rejected Packet Log"
|
|
|
|
echo
|
2002-05-01 01:13:15 +02:00
|
|
|
|
2002-09-18 01:53:46 +02:00
|
|
|
show_reset
|
|
|
|
|
2002-05-01 01:13:15 +02:00
|
|
|
rejects=`iptables -L -v -n | grep 'LOG'`
|
|
|
|
|
|
|
|
if [ "$rejects" != "$oldrejects" ]; then
|
|
|
|
oldrejects="$rejects"
|
2002-11-11 00:15:53 +01:00
|
|
|
|
2002-11-11 17:46:50 +01:00
|
|
|
$RING_BELL
|
2002-11-11 00:15:53 +01:00
|
|
|
|
2002-06-02 19:05:51 +02:00
|
|
|
packet_log 20
|
|
|
|
|
2002-05-01 01:13:15 +02:00
|
|
|
if [ "$pause" = "Yes" ]; then
|
2002-11-11 00:15:53 +01:00
|
|
|
echo
|
2002-11-11 17:46:50 +01:00
|
|
|
echo $ECHO_N 'Enter any character to continue: '
|
2002-05-01 01:13:15 +02:00
|
|
|
read foo
|
|
|
|
else
|
2002-06-02 19:05:51 +02:00
|
|
|
timed_read
|
2002-05-01 01:13:15 +02:00
|
|
|
fi
|
|
|
|
else
|
2002-06-02 19:05:51 +02:00
|
|
|
echo
|
|
|
|
packet_log 20
|
2002-05-01 01:13:15 +02:00
|
|
|
timed_read
|
|
|
|
fi
|
2002-06-02 19:05:51 +02:00
|
|
|
|
2002-05-01 01:13:15 +02:00
|
|
|
clear
|
2002-11-11 00:15:53 +01:00
|
|
|
echo "$banner `date`"
|
|
|
|
echo
|
|
|
|
echo "NAT Status"
|
|
|
|
echo
|
2002-05-01 01:13:15 +02:00
|
|
|
iptables -t nat -L -n -v
|
2002-06-04 23:08:44 +02:00
|
|
|
timed_read
|
|
|
|
|
|
|
|
clear
|
2002-11-11 00:15:53 +01:00
|
|
|
echo "$banner `date`"
|
|
|
|
echo
|
|
|
|
echo
|
|
|
|
echo "TOS/MARK Status"
|
|
|
|
echo
|
2002-05-01 01:13:15 +02:00
|
|
|
iptables -t mangle -L -n -v
|
|
|
|
timed_read
|
|
|
|
|
|
|
|
clear
|
2002-11-11 00:15:53 +01:00
|
|
|
echo "$banner `date`"
|
|
|
|
echo
|
|
|
|
echo
|
|
|
|
echo "Tracked Connections"
|
|
|
|
echo
|
2002-05-01 01:13:15 +02:00
|
|
|
cat /proc/net/ip_conntrack
|
|
|
|
timed_read
|
|
|
|
|
|
|
|
clear
|
2002-11-11 00:15:53 +01:00
|
|
|
echo "$banner `date`"
|
|
|
|
echo
|
|
|
|
echo
|
|
|
|
echo "Traffic Shaping/Control"
|
|
|
|
echo
|
2002-05-01 01:13:15 +02:00
|
|
|
show_tc
|
|
|
|
timed_read
|
2002-12-10 21:42:19 +01:00
|
|
|
|
|
|
|
clear
|
|
|
|
echo "$banner `date`"
|
|
|
|
echo
|
|
|
|
echo
|
|
|
|
echo "Packet Classifiers"
|
|
|
|
echo
|
|
|
|
show_classifiers
|
|
|
|
timed_read
|
2002-05-01 01:13:15 +02:00
|
|
|
done
|
|
|
|
}
|
|
|
|
|
2002-10-23 18:48:40 +02:00
|
|
|
#
|
|
|
|
# Watch the Firewall Log
|
|
|
|
#
|
2002-06-02 19:05:51 +02:00
|
|
|
logwatch() # $1 = timeout -- if negative, prompt each time that
|
2002-07-06 00:24:40 +02:00
|
|
|
# an 'interesting' packet count changes
|
2002-06-02 19:05:51 +02:00
|
|
|
{
|
|
|
|
|
|
|
|
get_config
|
|
|
|
host=`echo $HOSTNAME | sed 's/\..*$//'`
|
|
|
|
oldrejects=`iptables -L -v -n | grep 'LOG'`
|
|
|
|
|
|
|
|
if [ $1 -lt 0 ]; then
|
|
|
|
timeout=$((- $1))
|
|
|
|
pause="Yes"
|
|
|
|
else
|
|
|
|
pause="No"
|
|
|
|
timeout=$1
|
|
|
|
fi
|
|
|
|
|
|
|
|
qt which awk && haveawk=Yes || haveawk=
|
|
|
|
|
|
|
|
while true; do
|
|
|
|
clear
|
2002-11-11 00:15:53 +01:00
|
|
|
echo "$banner `date`"
|
|
|
|
echo
|
2002-06-02 19:05:51 +02:00
|
|
|
|
2002-11-11 00:15:53 +01:00
|
|
|
echo "Dropped/Rejected Packet Log"
|
|
|
|
echo
|
2002-06-02 19:05:51 +02:00
|
|
|
|
2002-09-18 01:53:46 +02:00
|
|
|
show_reset
|
|
|
|
|
2002-06-02 19:05:51 +02:00
|
|
|
rejects=`iptables -L -v -n | grep 'LOG'`
|
|
|
|
|
|
|
|
if [ "$rejects" != "$oldrejects" ]; then
|
|
|
|
oldrejects="$rejects"
|
2002-11-11 00:15:53 +01:00
|
|
|
|
2002-11-11 17:46:50 +01:00
|
|
|
$RING_BELL
|
2002-11-11 00:15:53 +01:00
|
|
|
|
2002-06-02 19:05:51 +02:00
|
|
|
packet_log 40
|
|
|
|
|
|
|
|
if [ "$pause" = "Yes" ]; then
|
2002-11-11 00:15:53 +01:00
|
|
|
echo
|
2002-11-11 17:46:50 +01:00
|
|
|
echo $ECHO_N 'Enter any character to continue: '
|
2002-06-02 19:05:51 +02:00
|
|
|
read foo
|
|
|
|
else
|
|
|
|
timed_read
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
echo
|
|
|
|
packet_log 40
|
|
|
|
timed_read
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
2002-10-23 18:48:40 +02:00
|
|
|
#
|
|
|
|
# Give Usage Information
|
|
|
|
#
|
2002-05-01 01:13:15 +02:00
|
|
|
usage() # $1 = exit status
|
|
|
|
{
|
|
|
|
echo "Usage: `basename $0` [debug] [nolock] [-c <directory>] <command>"
|
|
|
|
echo "where <command> is one of:"
|
2002-10-01 22:54:42 +02:00
|
|
|
echo " add <interface>[:<host>] <zone>"
|
|
|
|
echo " delete <interface>[:<host>] <zone>"
|
2002-12-10 21:42:19 +01:00
|
|
|
echo " show [<chain>|classifiers|connections|log|nat|tc|tos]"
|
2002-05-01 01:13:15 +02:00
|
|
|
echo " start"
|
|
|
|
echo " stop"
|
|
|
|
echo " reset"
|
|
|
|
echo " restart"
|
|
|
|
echo " status"
|
|
|
|
echo " clear"
|
|
|
|
echo " refresh"
|
|
|
|
echo " hits"
|
|
|
|
echo " monitor [<refresh interval>]"
|
|
|
|
echo " version"
|
|
|
|
echo " check"
|
|
|
|
echo " try <directory> [ <timeout> ]"
|
2002-06-02 19:05:51 +02:00
|
|
|
echo " logwatch [<refresh interval>]"
|
2002-06-04 22:17:46 +02:00
|
|
|
echo " drop <address> ..."
|
|
|
|
echo " reject <address> ..."
|
|
|
|
echo " allow <address> ..."
|
|
|
|
echo " save"
|
2002-05-01 01:13:15 +02:00
|
|
|
exit $1
|
|
|
|
}
|
|
|
|
|
2002-10-23 18:48:40 +02:00
|
|
|
#
|
|
|
|
# Display the time that the counters were last reset
|
|
|
|
#
|
2002-07-23 00:31:07 +02:00
|
|
|
show_reset() {
|
2002-09-29 23:08:25 +02:00
|
|
|
[ -f $STATEDIR/restarted ] && \
|
2002-11-11 00:15:53 +01:00
|
|
|
echo "Counters reset `cat $STATEDIR/restarted`" && \
|
|
|
|
echo
|
2002-07-23 00:31:07 +02:00
|
|
|
}
|
|
|
|
|
2002-10-23 18:48:40 +02:00
|
|
|
#
|
|
|
|
# Execution begins here
|
|
|
|
#
|
2002-05-01 01:13:15 +02:00
|
|
|
debugging=
|
|
|
|
|
|
|
|
if [ $# -gt 0 ] && [ "$1" = "debug" ]; then
|
|
|
|
debugging=debug
|
|
|
|
shift
|
|
|
|
fi
|
|
|
|
|
|
|
|
nolock=
|
|
|
|
|
|
|
|
if [ $# -gt 0 ] && [ "$1" = "nolock" ]; then
|
|
|
|
nolock=nolock
|
|
|
|
shift
|
|
|
|
fi
|
|
|
|
|
|
|
|
SHOREWALL_DIR=
|
|
|
|
done=0
|
|
|
|
|
|
|
|
while [ $done -eq 0 ]; do
|
|
|
|
[ $# -eq 0 ] && usage 1
|
|
|
|
case $1 in
|
|
|
|
-c)
|
2002-07-06 00:24:40 +02:00
|
|
|
[ $# -eq 1 ] && usage 1
|
2002-05-01 01:13:15 +02:00
|
|
|
|
|
|
|
if [ ! -d $2 ]; then
|
|
|
|
if [ -e $2 ]; then
|
2002-07-06 00:24:40 +02:00
|
|
|
echo "$2 is not a directory" >&2 && exit 2
|
2002-05-01 01:13:15 +02:00
|
|
|
else
|
2002-07-06 00:24:40 +02:00
|
|
|
echo "Directory $2 does not exist" >&2 && exit 2
|
|
|
|
fi
|
|
|
|
fi
|
2002-05-01 01:13:15 +02:00
|
|
|
|
|
|
|
SHOREWALL_DIR=$2
|
|
|
|
shift
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
*)
|
2002-07-06 00:24:40 +02:00
|
|
|
done=1
|
|
|
|
;;
|
2002-05-01 01:13:15 +02:00
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
2002-06-04 17:08:50 +02:00
|
|
|
if [ $# -eq 0 ]; then
|
2002-05-01 01:13:15 +02:00
|
|
|
usage 1
|
|
|
|
fi
|
|
|
|
|
2002-06-15 19:27:41 +02:00
|
|
|
[ -n "$SHOREWALL_DIR" ] && export SHOREWALL_DIR
|
2002-05-01 01:13:15 +02:00
|
|
|
|
2003-01-07 00:01:23 +01:00
|
|
|
PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin:/usr/local/sbin
|
|
|
|
SHARED_DIR=/usr/lib/shorewall
|
|
|
|
MUTEX_TIMEOUT=
|
|
|
|
|
|
|
|
if [ -n "$SHOREWALL_DIR" -a -f $SHOREWALL_DIR/shorewall.conf ]; then
|
|
|
|
config=$SHOREWALL_DIR/shorewall.conf
|
|
|
|
else
|
|
|
|
config=/etc/shorewall/shorewall.conf
|
|
|
|
fi
|
2002-05-01 01:13:15 +02:00
|
|
|
|
2003-01-07 00:01:23 +01:00
|
|
|
if [ -f $config ]; then
|
|
|
|
. $config
|
2002-05-01 01:13:15 +02:00
|
|
|
else
|
2003-01-07 00:01:23 +01:00
|
|
|
echo "$config does not exist!" >&2
|
2002-05-01 01:13:15 +02:00
|
|
|
exit 2
|
|
|
|
fi
|
|
|
|
|
2003-01-07 00:01:23 +01:00
|
|
|
[ -z "${STATEDIR}" ] && STATEDIR=/var/state/shorewall
|
|
|
|
|
|
|
|
FIREWALL=$SHARED_DIR/firewall
|
|
|
|
FUNCTIONS=$SHARED_DIR/functions
|
|
|
|
VERSION_FILE=$SHARED_DIR/version
|
|
|
|
|
|
|
|
if [ -f $FUNCTIONS ]; then
|
|
|
|
. $FUNCTIONS
|
|
|
|
else
|
|
|
|
echo "$FUNCTIONS does not exist!" >&2
|
|
|
|
exit 2
|
|
|
|
fi
|
2002-05-01 01:13:15 +02:00
|
|
|
|
2003-01-07 00:01:23 +01:00
|
|
|
if [ ! -f $FIREWALL ]; then
|
2002-05-01 01:13:15 +02:00
|
|
|
echo "ERROR: Shorewall is not properly installed"
|
2003-01-07 00:01:23 +01:00
|
|
|
if [ -L $FIREWALL ]; then
|
|
|
|
echo " $FIREWALL is a symbolic link to a"
|
2002-07-06 00:24:40 +02:00
|
|
|
echo " non-existant file"
|
2002-05-01 01:13:15 +02:00
|
|
|
else
|
2003-01-07 00:01:23 +01:00
|
|
|
echo " The file $FIREWALL does not exist"
|
2002-05-01 01:13:15 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
exit 2
|
|
|
|
fi
|
|
|
|
|
2003-01-07 00:01:23 +01:00
|
|
|
if [ -f $VERSION_FILE ]; then
|
|
|
|
version=`cat $VERSION_FILE`
|
2002-05-01 01:13:15 +02:00
|
|
|
else
|
2002-06-15 19:27:41 +02:00
|
|
|
echo "ERROR: Shorewall is not properly installed"
|
2003-01-07 00:01:23 +01:00
|
|
|
echo " The file $VERSION_FILE does not exist"
|
2002-05-01 01:13:15 +02:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
banner="Shorewall-$version Status at $HOSTNAME -"
|
|
|
|
|
2002-10-03 18:10:25 +02:00
|
|
|
|
2002-11-11 17:46:50 +01:00
|
|
|
case `echo -e` in
|
|
|
|
-e*)
|
2003-01-06 20:54:50 +01:00
|
|
|
RING_BELL="echo \a"
|
2002-11-11 17:46:50 +01:00
|
|
|
;;
|
|
|
|
*)
|
2003-01-06 20:54:50 +01:00
|
|
|
RING_BELL="echo -e \a"
|
2002-11-11 17:46:50 +01:00
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
case `echo -n "Testing"` in
|
|
|
|
-n*)
|
|
|
|
ECHO_N=
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
ECHO_N=-n
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
2002-05-01 01:13:15 +02:00
|
|
|
case "$1" in
|
|
|
|
start|stop|restart|reset|clear|refresh|check)
|
|
|
|
[ $# -ne 1 ] && usage 1
|
2003-01-07 00:01:23 +01:00
|
|
|
exec $FIREWALL $debugging $nolock $1
|
2002-05-01 01:13:15 +02:00
|
|
|
;;
|
2002-10-01 22:54:42 +02:00
|
|
|
add|delete)
|
|
|
|
[ $# -ne 3 ] && usage 1
|
2003-01-07 00:01:23 +01:00
|
|
|
exec $FIREWALL $debugging $nolock $1 $2 $3
|
2002-10-01 22:54:42 +02:00
|
|
|
;;
|
2002-05-01 01:13:15 +02:00
|
|
|
show)
|
2002-07-06 00:24:40 +02:00
|
|
|
[ $# -gt 2 ] && usage 1
|
2002-05-01 01:13:15 +02:00
|
|
|
case "$2" in
|
|
|
|
connections)
|
2002-11-11 00:15:53 +01:00
|
|
|
echo "Shorewall-$version Connections at $HOSTNAME - `date`"
|
|
|
|
echo
|
2002-05-01 01:13:15 +02:00
|
|
|
cat /proc/net/ip_conntrack
|
|
|
|
;;
|
|
|
|
nat)
|
2002-11-11 00:15:53 +01:00
|
|
|
echo "Shorewall-$version NAT at $HOSTNAME - `date`"
|
|
|
|
echo
|
2002-07-23 00:31:07 +02:00
|
|
|
show_reset
|
2002-05-01 01:13:15 +02:00
|
|
|
iptables -t nat -L -n -v
|
|
|
|
;;
|
|
|
|
tos|mangle)
|
2002-11-11 00:15:53 +01:00
|
|
|
echo "Shorewall-$version TOS at $HOSTNAME - `date`"
|
|
|
|
echo
|
2002-07-23 00:31:07 +02:00
|
|
|
show_reset
|
2002-05-01 01:13:15 +02:00
|
|
|
iptables -t mangle -L -n -v
|
|
|
|
;;
|
|
|
|
log)
|
2002-07-06 00:24:40 +02:00
|
|
|
get_config
|
2002-11-11 00:15:53 +01:00
|
|
|
echo "Shorewall-$version Log at $HOSTNAME - `date`"
|
|
|
|
echo
|
2002-09-18 01:53:46 +02:00
|
|
|
show_reset
|
2002-05-01 01:13:15 +02:00
|
|
|
host=`echo $HOSTNAME | sed 's/\..*$//'`
|
2002-06-02 19:05:51 +02:00
|
|
|
packet_log 20
|
2002-05-01 01:13:15 +02:00
|
|
|
;;
|
|
|
|
tc)
|
2002-11-11 00:15:53 +01:00
|
|
|
echo "Shorewall-$version Traffic Control at $HOSTNAME - `date`"
|
|
|
|
echo
|
2002-05-01 01:13:15 +02:00
|
|
|
show_tc
|
|
|
|
;;
|
2002-12-10 21:42:19 +01:00
|
|
|
classifiers)
|
|
|
|
echo "Shorewall-$version Clasifiers at $HOSTNAME - `date`"
|
|
|
|
echo
|
|
|
|
show_classifiers
|
|
|
|
;;
|
2002-07-06 00:24:40 +02:00
|
|
|
*)
|
2002-11-11 00:15:53 +01:00
|
|
|
echo "Shorewall-$version Chain $2 at $HOSTNAME - `date`"
|
|
|
|
echo
|
2002-07-23 00:31:07 +02:00
|
|
|
show_reset
|
2002-05-01 01:13:15 +02:00
|
|
|
iptables -L $2 -n -v
|
|
|
|
;;
|
2002-07-06 00:24:40 +02:00
|
|
|
esac
|
2002-05-01 01:13:15 +02:00
|
|
|
;;
|
|
|
|
monitor)
|
|
|
|
if [ $# -eq 2 ]; then
|
|
|
|
monitor_firewall $2
|
|
|
|
elif [ $# -eq 1 ]; then
|
|
|
|
monitor_firewall 30
|
|
|
|
else
|
|
|
|
usage 1
|
|
|
|
fi
|
2002-07-06 00:24:40 +02:00
|
|
|
;;
|
2002-05-01 01:13:15 +02:00
|
|
|
status)
|
2002-07-06 00:24:40 +02:00
|
|
|
[ $# -eq 1 ] || usage 1
|
2002-05-01 01:13:15 +02:00
|
|
|
get_config
|
|
|
|
clear
|
2002-11-11 00:15:53 +01:00
|
|
|
echo "Shorewall-$version Status at $HOSTNAME - `date`"
|
|
|
|
echo
|
2002-07-23 00:31:07 +02:00
|
|
|
show_reset
|
2002-05-01 01:13:15 +02:00
|
|
|
host=`echo $HOSTNAME | sed 's/\..*$//'`
|
|
|
|
iptables -L -n -v
|
|
|
|
echo
|
2002-06-10 18:53:18 +02:00
|
|
|
packet_log 20
|
2002-05-01 01:13:15 +02:00
|
|
|
echo
|
2002-12-20 00:35:21 +01:00
|
|
|
echo "NAT Table"
|
|
|
|
echo
|
2002-05-01 01:13:15 +02:00
|
|
|
iptables -t nat -L -n -v
|
|
|
|
echo
|
2002-12-20 00:35:21 +01:00
|
|
|
echo "Mangle Table"
|
|
|
|
echo
|
2002-05-01 01:13:15 +02:00
|
|
|
iptables -t mangle -L -n -v
|
|
|
|
echo
|
|
|
|
cat /proc/net/ip_conntrack
|
|
|
|
;;
|
|
|
|
hits)
|
2002-07-06 00:24:40 +02:00
|
|
|
[ $# -eq 1 ] || usage 1
|
2002-05-01 01:13:15 +02:00
|
|
|
get_config
|
2002-07-06 00:24:40 +02:00
|
|
|
clear
|
2002-11-11 00:15:53 +01:00
|
|
|
echo "Shorewall-$version Hits at $HOSTNAME - `date`"
|
|
|
|
echo
|
|
|
|
|
2002-05-01 01:13:15 +02:00
|
|
|
timeout=30
|
|
|
|
|
2002-07-06 00:24:40 +02:00
|
|
|
if [ `grep -c "Shorewall:" $LOGFILE ` -gt 0 ] ; then
|
|
|
|
echo " HITS IP DATE"
|
|
|
|
echo " ---- --------------- ------"
|
|
|
|
grep "Shorewall:" $LOGFILE | sed 's/\(.\{6\}\)\(.*SRC=\)\(.*\)\( DST=.*\)/\3 \1/' | sort | uniq -c | sort -rn
|
|
|
|
echo ""
|
2002-05-01 01:13:15 +02:00
|
|
|
|
2002-07-06 00:24:40 +02:00
|
|
|
echo " HITS IP PORT"
|
|
|
|
echo " ---- --------------- -----"
|
|
|
|
grep "Shorewall:" $LOGFILE | sed 's/\(.*SRC=\)\(.*\)\( DST=.*DPT=\)\([0-9]\{1,5\}\)\(.*\)/\2 \4/
|
2002-06-30 00:41:30 +02:00
|
|
|
t
|
|
|
|
s/\(.*SRC=\)\(.*\)\( DST=.*\)/\2/' | sort | uniq -c | sort -rn
|
2002-07-06 00:24:40 +02:00
|
|
|
echo ""
|
|
|
|
|
|
|
|
echo " HITS DATE"
|
|
|
|
echo " ---- ------"
|
|
|
|
grep "Shorewall:" $LOGFILE | sed 's/\(.\{6\}\)\(.*\)/\1/' | sort | uniq -c | sort -rn
|
|
|
|
echo ""
|
|
|
|
|
|
|
|
echo " HITS PORT SERVICE(S)"
|
|
|
|
echo " ---- ----- ----------"
|
|
|
|
grep 'Shorewall:.*DPT' $LOGFILE | sed 's/\(.*DPT=\)\([0-9]\{1,5\}\)\(.*\)/\2/' | sort | uniq -c | sort -rn | \
|
|
|
|
while read count port ; do
|
|
|
|
# List all services defined for the given port
|
|
|
|
srv=`grep "^[^#].*\\b$port/" /etc/services | cut -f 1 | sort -u`
|
|
|
|
srv=`echo $srv | sed 's/ /,/g'`
|
|
|
|
|
|
|
|
if [ -n "$srv" ] ; then
|
|
|
|
printf '%7d %5d %s\n' $count $port $srv
|
|
|
|
else
|
|
|
|
printf '%7d %5d\n' $count $port
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
fi
|
|
|
|
;;
|
2002-05-01 01:13:15 +02:00
|
|
|
version)
|
|
|
|
echo $version
|
|
|
|
;;
|
|
|
|
try)
|
|
|
|
[ -n "$SHOREWALL_DIR" ] && startup_error "Error: -c option may not be used with \"try\""
|
|
|
|
[ $# -lt 2 -o $# -gt 3 ] && usage 1
|
2002-06-04 17:08:50 +02:00
|
|
|
if ! $0 -c $2 restart; then
|
|
|
|
if ! iptables -L shorewall > /dev/null 2> /dev/null; then
|
|
|
|
$0 start
|
|
|
|
fi
|
|
|
|
elif ! iptables -L shorewall > /dev/null 2> /dev/null; then
|
2002-05-01 01:13:15 +02:00
|
|
|
$0 start
|
|
|
|
elif [ $# -eq 3 ]; then
|
|
|
|
sleep $3
|
|
|
|
$0 restart
|
2002-07-06 00:24:40 +02:00
|
|
|
fi
|
2002-05-01 01:13:15 +02:00
|
|
|
;;
|
2002-06-02 19:05:51 +02:00
|
|
|
logwatch)
|
|
|
|
if [ $# -eq 2 ]; then
|
|
|
|
logwatch $2
|
|
|
|
elif [ $# -eq 1 ]; then
|
|
|
|
logwatch 30
|
|
|
|
else
|
|
|
|
usage 1
|
|
|
|
fi
|
2002-07-06 00:24:40 +02:00
|
|
|
;;
|
2002-06-04 22:17:46 +02:00
|
|
|
drop)
|
2002-07-06 00:24:40 +02:00
|
|
|
[ $# -eq 1 ] && usage 1
|
2002-06-04 17:08:50 +02:00
|
|
|
mutex_on
|
|
|
|
while [ $# -gt 1 ]; do
|
|
|
|
shift
|
2002-06-04 22:17:46 +02:00
|
|
|
iptables -A dynamic -s $1 -j DROP || break 1
|
|
|
|
echo "$1 Dropped"
|
2002-06-04 17:08:50 +02:00
|
|
|
done
|
|
|
|
mutex_off
|
|
|
|
;;
|
2002-06-04 22:17:46 +02:00
|
|
|
reject)
|
2002-07-06 00:24:40 +02:00
|
|
|
[ $# -eq 1 ] && usage 1
|
2002-06-04 22:17:46 +02:00
|
|
|
mutex_on
|
|
|
|
while [ $# -gt 1 ]; do
|
|
|
|
shift
|
|
|
|
iptables -A dynamic -s $1 -j reject || break 1
|
|
|
|
echo "$1 Rejected"
|
|
|
|
done
|
|
|
|
mutex_off
|
|
|
|
;;
|
|
|
|
allow)
|
2002-07-06 00:24:40 +02:00
|
|
|
[ $# -eq 1 ] && usage 1
|
2002-06-04 22:17:46 +02:00
|
|
|
mutex_on
|
|
|
|
while [ $# -gt 1 ]; do
|
|
|
|
shift
|
2002-07-06 00:24:40 +02:00
|
|
|
if qt iptables -D dynamic -s $1 -j reject; then
|
|
|
|
#
|
|
|
|
# Address was rejected -- silently remove any drop as well
|
2002-06-04 22:39:00 +02:00
|
|
|
#
|
|
|
|
qt iptables -D dynamic -s $1 -j DROP
|
|
|
|
echo "$1 Allowed"
|
2002-06-04 23:08:44 +02:00
|
|
|
elif qt iptables -D dynamic -s $1 -j DROP; then
|
2002-07-06 00:24:40 +02:00
|
|
|
echo "$1 Allowed"
|
2002-06-04 22:17:46 +02:00
|
|
|
else
|
2002-06-04 22:39:00 +02:00
|
|
|
echo "$1 Not Dropped or Rejected"
|
2002-06-04 22:17:46 +02:00
|
|
|
fi
|
|
|
|
done
|
|
|
|
mutex_off
|
|
|
|
;;
|
|
|
|
save)
|
2002-07-06 00:24:40 +02:00
|
|
|
[ $# -ne 1 ] && usage 1
|
|
|
|
mutex_on
|
2002-06-04 22:39:00 +02:00
|
|
|
if qt iptables -L shorewall -n; then
|
2002-10-29 04:24:38 +01:00
|
|
|
[ -d /var/lib/shorewall ] || mkdir /var/lib/shorewall
|
|
|
|
|
2002-06-16 19:56:45 +02:00
|
|
|
if iptables -L dynamic -n > /var/lib/shorewall/save; then
|
2002-06-04 22:39:00 +02:00
|
|
|
echo "Dynamic Rules Saved"
|
|
|
|
else
|
2002-07-06 00:24:40 +02:00
|
|
|
echo "Error Saving the Dynamic Rules"
|
2002-06-04 22:39:00 +02:00
|
|
|
fi
|
|
|
|
else
|
|
|
|
echo "Shorewall isn't started"
|
2002-06-04 22:17:46 +02:00
|
|
|
fi
|
2002-06-04 22:39:00 +02:00
|
|
|
mutex_off
|
2002-06-04 22:17:46 +02:00
|
|
|
;;
|
2002-05-01 01:13:15 +02:00
|
|
|
*)
|
|
|
|
usage 1
|
|
|
|
;;
|
|
|
|
esac
|