chiark / gitweb /
Merge branch 'master' of metalzone:public-git/firewall
authorMark Wooding <mdw@distorted.org.uk>
Sat, 17 Apr 2010 15:37:28 +0000 (16:37 +0100)
committerMark Wooding <mdw@distorted.org.uk>
Sat, 17 Apr 2010 15:37:28 +0000 (16:37 +0100)
* 'master' of metalzone:public-git/firewall:
  functions.m4, local.m4: Handle fragments in a useful way.
  classify.m4: Correct summary line at the top.
  vampire.m4: Remove the magical DNS DDoS hack.

classify.m4
functions.m4
local.m4
local.mk
logtrawl [deleted file]
vampire.m4

index c1365b6b048881e2608d78a2667e4b335b38c256..148a72f21b9896f787c79b4c565a8fc25c6bac75 100644 (file)
@@ -1,6 +1,6 @@
 ### -*-m4-*-
 ###
-### Initialization and finishing touches for firewall scripts
+### Classify packets according to source and destination networks.
 ###
 ### (c) 2008 Mark Wooding
 ###
index 80caf1db05a92502ea3fb49c4d79590ab73d0a97..85afc1083848a65b9f26bf63779d87f9ab751237 100644 (file)
@@ -126,6 +126,20 @@ conntrack () {
   run iptables -A $chain -p tcp ! --syn -g bad-tcp
 }
 
+## commonrules CHAIN
+##
+## Add standard IP filtering rules to the CHAIN.
+commonrules () {
+  set -e
+  chain=$1
+
+  ## Pass fragments through, assuming that the eventual destination will sort
+  ## things out properly.  Except for TCP, that is, which should never be
+  ## fragmented.
+  run iptables -A $chain -p tcp -f -g tcp-fragment
+  run iptables -A $chain -f -j ACCEPT
+}
+
 ## allowservices CHAIN PROTO SERVICE ...
 ##
 ## Add rules to allow the SERVICES on the CHAIN.
index 52dc94ce13d0a1fe1b234672f95cce10fc65ffe7..b321cde9f86d341fda8be5f657ef4823d52e6a32 100644 (file)
--- a/local.m4
+++ b/local.m4
@@ -56,19 +56,19 @@ m4_divert(60)m4_dnl
 
 ## Allow ping from safe/noloop to untrusted networks.
 run iptables -A FORWARD -j ACCEPT \
-       -p icmp --icmp-type echo-request \
+       -p icmp ! -f --icmp-type echo-request \
        -m mark --mark $to_untrusted/$MASK_TO
 run iptables -A FORWARD -j ACCEPT \
-       -p icmp --icmp-type echo-reply \
+       -p icmp ! -f --icmp-type echo-reply \
        -m mark --mark $from_untrusted/$MASK_FROM \
        -m state --state ESTABLISHED
 
 ## Allow SSH from safe/noloop to untrusted networks.
 run iptables -A FORWARD -j ACCEPT \
-       -p tcp --destination-port $port_ssh \
+       -p tcp ! -f --destination-port $port_ssh \
        -m mark --mark $to_untrusted/$MASK_TO
 run iptables -A FORWARD -j ACCEPT \
-       -p tcp --source-port $port_ssh \
+       -p tcp ! -f --source-port $port_ssh \
        -m mark --mark $from_untrusted/$MASK_FROM \
        -m state --state ESTABLISHED
 
@@ -79,6 +79,7 @@ m4_divert(80)m4_dnl
 clearchain inbound
 
 ## Track connections.
+commonrules inbound
 conntrack inbound
 
 ## Allow incoming bootp.  Bootp won't be forwarded, so this is obviously a
index 8294782ca8a2ef1b5868ff677eae78c19774027c..308f22c86bb3390192e7fa19f9fbd557ca5ed423 100644 (file)
--- a/local.mk
+++ b/local.mk
@@ -7,8 +7,6 @@ HOSTS                   += vampire
 
 ROOT                    = become root
 
-SCRIPTS                        += logtrawl
-
 ## Installation.
 install: all
        firewall_script=./`hostname`.sh && \
@@ -17,7 +15,7 @@ install: all
        $(ROOT) ./$$firewall_script
        for i in $(HOSTS); do \
          $(ROOT) scp $$i.sh $$i:/etc/init.d/firewall; \
-         for j in $(SCRIPTS); do \
+         [ "$(SCRIPTS)" ] && for j in $(SCRIPTS); do \
            $(ROOT) ssh $$i <$$j " \
                cd /usr/local/sbin && \
                rm -f $$j.new && \
diff --git a/logtrawl b/logtrawl
deleted file mode 100755 (executable)
index 8153acc..0000000
--- a/logtrawl
+++ /dev/null
@@ -1,27 +0,0 @@
-#! /bin/bash
-
-set -e
-
-## DNS DDOS victims.
-dns_victims=$(
-  sed -n '
-    /^.*named.*client \([0-9]\+\.[0-9]\+\.[0-9]\+\.[0-9]\+\)#.*:.*view inet.*NS\/IN.*denied.*$/ s//\1/p
-  ' /var/log/daemon.log |
-  sort -u |
-  while read addr; do
-    if ! ipset -qT ddos-evil-dns "$addr"; then
-      echo "$addr"
-    fi
-  done
-)
-case "$dns_victims" in
-  "") ;;
-  *)
-    echo 'DNS DDOS victim addresses:'
-    ipset -N ddos-evil-dns iphash >/dev/null 2>&1 || :
-    for addr in $dns_victims; do
-      echo "  $addr"
-      ipset -A ddos-evil-dns "$addr" || :
-    done
-    ;;
-esac
index e5ab346c1f6f1fb68ef0ad7311c9926c0955dde0..2f8c105c28743befd910824b679845de866f3ed4 100644 (file)
@@ -37,18 +37,7 @@ m4_divert(-1)
 ###--------------------------------------------------------------------------
 ### vampire-specific rules.
 
-m4_divert(35)m4_dnl
-errorchain ddos-evil-dns DROP
-## Invalid DNS request with probably-forged sender address, with intent to
-## cause DDOS.
-
 m4_divert(82)m4_dnl
-## Repelling evil DDos attack.
-run ipset -N ddos-evil-dns iphash 2>/dev/null || :
-run iptables -A inbound -g ddos-evil-dns \
-       -m set --set ddos-evil-dns src \
-       -p udp --destination-port $port_dns
-
 ## Externally visible services.
 allowservices inbound tcp \
        finger ident \