Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Firewall Script
View unanswered posts
View posts from last 24 hours
View posts from last 7 days

 
Reply to topic    Gentoo Forums Forum Index Deutsches Forum (German)
View previous topic :: View next topic  
Author Message
Sourcemaker
n00b
n00b


Joined: 25 Jun 2003
Posts: 44

PostPosted: Sun Aug 15, 2004 6:15 pm    Post subject: Firewall Script Reply with quote

Hallo Zusammen,

ich bin gerade dabei meine erste Linux Firewall zu erstellen,
allerdings stehe ich vor dem großen Rätsel, warum dieses Script
nicht funktioniert. Alle Verbindungen werden geblockt...

Kann mir jemand von euch helfen ??
Danke im vorraus.


Anbei mein Script...


Code:


#!/sbin/runscript

#--------------------------------------------------------------------------------------------------
# Option:        Beschreibung:
# -A          Anhängen
# -D          Löschen
# -I          Einfügen
# -R          Ersetzen
# -L          Auflisten
# -F          Löscht alle Regeln in der Kette oder in allen Ketten
# -Z          Keine Counter in der Kette oder in allen Ketten
# -C          Teste dieses Paket an der Kette
# -N          Erstellen einer neuen benutzerdefinierten Kette
# -X          Löschen einer benutzerdefinierten Kette
# -P          Richtlinie der Kette bezüglich des Ziels ändern
# -E          Ändern des Kettennamens
# -p          Protokoll
# -s          Quelladresse/maske
# -d          Zieladresse/maske
# -i          Eingabename (Ethernetname)
# -o          Ausgabename (Ethernetname)
# -j          Jump (Ziel für Regel)
# -m          Erweiterter Treffer (Kann erweiterung benutzen)
# -n          Numerische Ausgabe von Adressen und Ports
# -t          Zu ändernde Tabelle
# -v          Ausführliche Ausgabe
# -x          Zahlen Erweitern (exakte Werte anzeigen)
# -f          Nur auf die zweiten oder weitere Pakete achten
# -V          Paketversion
# --line-numbers    Zeilennummern mit ausgeben
#--------------------------------------------------------------------------------------------------

#--------------------------------------------------------------------------------------     
IPTABLES=/sbin/iptables
IPTABLESSAVE=/sbin/iptables-save
IPTABLESRESTORE=/sbin/iptables-restore
FIREWALL=/etc/firewall.rules
#inside
IINTERFACE=eth0
#--------------------------------------------------------------------------------------     

#--------------------------------------------------------------------------------------     
opts="${opts} showstatus panic save restore showoptions rules"
#--------------------------------------------------------------------------------------     

#--------------------------------------------------------------------------------------     
depend() {
  need net
}
#--------------------------------------------------------------------------------------     

#--------------------------------------------------------------------------------------     
rules() {

  stop
  #--------------------------------------------------------------------------------------
  ebegin "Setting internal rules"
  #-------------------------------------------------------------------------------------- 
  einfo "Setting default rule to drop"
  $IPTABLES -P FORWARD DROP
  $IPTABLES -P INPUT   DROP
  $IPTABLES -P OUTPUT  DROP
  #--------------------------------------------------------------------------------------
  einfo "Setting kernel security"
  #-------------------------------------------------------------------------------------- 
  #Drop ping packets
  /bin/echo "1" > /proc/sys/net/ipv4/icmp_echo_ignore_all
 
  #Ignore broadcast pings
  /bin/echo "1" > /proc/sys/net/ipv4/icmp_echo_ignore_broadcasts
 
  #Disable source routed packets
  /bin/echo "0" > /proc/sys/net/ipv4/conf/all/accept_source_route
   
  #Disable redirect acceptance
  /bin/echo "0" > /proc/sys/net/ipv4/conf/all/accept_redirects

  #Protect against bad error messages
  /bin/echo "1" > /proc/sys/net/ipv4/icmp_ignore_bogus_error_responses

  #Enable reverse path filtering
  for i in /proc/sys/net/ipv4/conf/*; do
   /bin/echo "1" > $i/rp_filter
  done

  #Log all spoofed, source routed and redirect packets
  /bin/echo "1" > /proc/sys/net/ipv4/conf/all/log_martians

  #Deactivate IP forwarding
  /bin/echo "0" > /proc/sys/net/ipv4/ip_forward
  #--------------------------------------------------------------------------------------
  einfo "Creating states chain"
  #-------------------------------------------------------------------------------------- 
  $IPTABLES -N allowed-connection
  $IPTABLES -F allowed-connection
  $IPTABLES -A allowed-connection -m state --state ESTABLISHED,RELATED -j ACCEPT
  $IPTABLES -A allowed-connection -i $IINTERFACE -m limit -j LOG --log-prefix   "Bad packet from ${IINTERFACE}:"
  $IPTABLES -A allowed-connection -j DROP
  #--------------------------------------------------------------------------------------
  einfo "Creating icmp chain"
  #--------------------------------------------------------------------------------------
  $IPTABLES -N icmp_allowed
  $IPTABLES -F icmp_allowed
  $IPTABLES -A icmp_allowed -m state --state NEW -p icmp --icmp-type time-exceeded -j ACCEPT
  $IPTABLES -A icmp_allowed -m state --state NEW -p icmp --icmp-type destination-unreachable -j ACCEPT
  $IPTABLES -A icmp_allowed -p icmp -j LOG --log-prefix "Bad ICMP traffic:"
  $IPTABLES -A icmp_allowed -p icmp -j DROP
  #--------------------------------------------------------------------------------------
  einfo "Creating outgoing http/https traffic chain"
  #-------------------------------------------------------------------------------------- 
  $IPTABLES -N allow-www-traffic-out
  $IPTABLES -F allow-www-traffic-out
  $IPTABLES -A allow-www-traffic-out -p tcp --dport www -j ACCEPT
  $IPTABLES -A allow-www-traffic-out -p tcp --dport https -j ACCEPT
  #--------------------------------------------------------------------------------------
  einfo "Creating outgoing mail (pop3/smtp) traffic chain"
  #--------------------------------------------------------------------------------------
  $IPTABLES -N allow-mail-traffic-out
  $IPTABLES -F allow-mail-traffic-out
  $IPTABLES -A allow-mail-traffic-out  -p tcp --dport 25 -j ACCEPT
  $IPTABLES -A allow-mail-traffic-out  -p tcp --dport 135 -j ACCEPT
  #--------------------------------------------------------------------------------------   
  einfo "Creating outgoing icq traffic chain"
  #--------------------------------------------------------------------------------------   
  $IPTABLES -N allow-icq-traffic-out
  $IPTABLES -F allow-icq-traffic-out
  $IPTABLES -A allow-icq-traffic-out  -p tcp --dport 4100:4115 -j ACCEPT
  #--------------------------------------------------------------------------------------   
  einfo "Creating squid traffic chain"
  #--------------------------------------------------------------------------------------     
  $IPTABLES -t nat -A PREROUTING -p tcp --dport 80  -j DNAT --to 127.0.0.1:3128
  $IPTABLES -t nat -A PREROUTING -p tcp --dport 443 -j DNAT --to 127.0.0.1:3128
  #--------------------------------------------------------------------------------------     
  einfo "Creating portscan detection chain"
  #--------------------------------------------------------------------------------------     
  $IPTABLES -N check-flags
  $IPTABLES -F check-flags
  $IPTABLES -A check-flags -p tcp --tcp-flags ALL FIN,URG,PSH -m limit --limit 5/minute -j LOG --log-level alert --log-prefix "NMAP-XMAS:"
  $IPTABLES -A check-flags -p tcp --tcp-flags ALL FIN,URG,PSH -j DROP
  $IPTABLES -A check-flags -p tcp --tcp-flags ALL ALL -m limit --limit 5/minute -j LOG --log-level 1 --log-prefix "XMAS:"
  $IPTABLES -A check-flags -p tcp --tcp-flags ALL ALL -j DROP
  $IPTABLES -A check-flags -p tcp --tcp-flags ALL SYN,RST,ACK,FIN,URG  -m limit --limit 5/minute -j LOG --log-level 1 --log-prefix "XMAS-PSH:"
  $IPTABLES -A check-flags -p tcp --tcp-flags ALL SYN,RST,ACK,FIN,URG -j DROP
  $IPTABLES -A check-flags -p tcp --tcp-flags ALL NONE -m limit --limit 5/minute -j LOG --log-level 1 --log-prefix "NULL_SCAN:"
  $IPTABLES -A check-flags -p tcp --tcp-flags ALL NONE -j DROP
  $IPTABLES -A check-flags -p tcp --tcp-flags SYN,RST SYN,RST -m limit --limit 5/minute -j LOG --log-level 5 --log-prefix "SYN/RST:"
  $IPTABLES -A check-flags -p tcp --tcp-flags SYN,RST SYN,RST -j DROP
  $IPTABLES -A check-flags -p tcp --tcp-flags SYN,FIN SYN,FIN -m limit --limit 5/minute -j LOG --log-level 5 --log-prefix "SYN/FIN:"
  $IPTABLES -A check-flags -p tcp --tcp-flags SYN,FIN SYN,FIN -j DROP
  #--------------------------------------------------------------------------------------     
  einfo "Applying chains to INPUT"
  #--------------------------------------------------------------------------------------       
  $IPTABLES -A INPUT -m state --state INVALID -j DROP
  $IPTABLES -A INPUT -j icmp_allowed
  $IPTABLES -A INPUT -j check-flags
  $IPTABLES -A INPUT -i lo -j ACCEPT
  $IPTABLES -A INPUT -j allowed-connection
  #--------------------------------------------------------------------------------------     
  einfo "Applying chains to FORWARD"
  #--------------------------------------------------------------------------------------       
  $IPTABLES -A FORWARD -m state --state INVALID -j DROP
  $IPTABLES -A FORWARD -j icmp_allowed
  $IPTABLES -A FORWARD -j check-flags
  $IPTABLES -A FORWARD -o lo -j ACCEPT
  $IPTABLES -A FORWARD -j allow-www-traffic-out
  $IPTABLES -A FORWARD -j allow-mail-traffic-out
  $IPTABLES -A FORWARD -j allow-icq-traffic-out
  $IPTABLES -A FORWARD -j allowed-connection
  #--------------------------------------------------------------------------------------     
  einfo "Applying chains to OUTPUT"
  #--------------------------------------------------------------------------------------     
  $IPTABLES -A OUTPUT -m state --state INVALID -j DROP
  $IPTABLES -A OUTPUT -j icmp_allowed
  $IPTABLES -A OUTPUT -j check-flags
  $IPTABLES -A OUTPUT -o lo -j ACCEPT
  $IPTABLES -A OUTPUT -j allow-www-traffic-out
  $IPTABLES -A OUTPUT -j allow-mail-traffic-out
  $IPTABLES -A OUTPUT -j allow-icq-traffic-out
  $IPTABLES -A OUTPUT -j allowed-connection
  #--------------------------------------------------------------------------------------     
  einfo "Allow client to route through via NAT (Network Address Translation)"
  #$IPTABLES -t nat -A POSTROUTING -o $IINTERFACE -j MASQUERADE
  #--------------------------------------------------------------------------------------       
  eend $?
}
#--------------------------------------------------------------------------------------       
start() {
  ebegin "Starting firewall"
  if [ -e "${FIREWALL}" ]; then
    restore
  else
    einfo "${FIREWALL} does not exists. Using default rules."
    rules
  fi
  eend $?
}
#--------------------------------------------------------------------------------------       
stop() {
  ebegin "Stopping firewall"
  $IPTABLES -F
  $IPTABLES -t nat -F
  $IPTABLES -X
  $IPTABLES -P FORWARD ACCEPT
  $IPTABLES -P INPUT   ACCEPT
  $IPTABLES -P OUTPUT  ACCEPT
  eend $?
}
#--------------------------------------------------------------------------------------       
showstatus() {
  ebegin "Status"
  $IPTABLES -L -n -v --line-numbers
  einfo "NAT status"
  $IPTABLES -L -n -v --line-numbers -t nat
  eend $?
}
#--------------------------------------------------------------------------------------       
panic() {
  ebegin "Setting panic rules"
  $IPTABLES -F
  $IPTABLES -X
  $IPTABLES -t nat -F
  $IPTABLES -P FORWARD DROP
  $IPTABLES -P INPUT   DROP
  $IPTABLES -P OUTPUT  DROP
  $IPTABLES -A INPUT -i lo -j ACCEPT
  $IPTABLES -A OUTPUT -o lo -j ACCEPT
  eend $?
}
#--------------------------------------------------------------------------------------       
save() {
  ebegin "Saving Firewall rules"
  $IPTABLESSAVE > $FIREWALL
  eend $?
}
#-------------------------------------------------------------------------------------- 
restore() {
  ebegin "Restoring Firewall rules"
  $IPTABLESRESTORE < $FIREWALL
  eend $?
}
#--------------------------------------------------------------------------------------       
restart() {
  svc_stop; svc_start
}
#--------------------------------------------------------------------------------------       
showoptions() {
  echo "Usage: $0 {start|save|restore|panic|stop|restart|showstatus}"
  echo "start)      will restore setting if exists else force rules"
  echo "stop)       delete all rules and set all to accept"
  echo "rules)      force settings of new rules"
  echo "save)       will store settings in ${FIREWALL}"
  echo "restore)    will restore settings from ${FIREWALL}"
  echo "showstatus) Shows the status"
}
#-------------------------------------------------------------------------------------       


EDIT: CAPS -LOCK-Problem beseitigt. --ian!
Back to top
View user's profile Send private message
Gekko
l33t
l33t


Joined: 29 Oct 2002
Posts: 773

PostPosted: Sun Aug 15, 2004 6:26 pm    Post subject: Reply with quote

Ich weis, dass das jetzt nicht die Antwort ist die Du Dir wuenschst, aber viele Leute verwenden Arnos IpTables Skript http://rocky.eld.leidenuniv.nl/
Back to top
View user's profile Send private message
zbled
Apprentice
Apprentice


Joined: 18 Jun 2002
Posts: 216
Location: Bukowski's Piano Bar

PostPosted: Sun Aug 15, 2004 8:11 pm    Post subject: Reply with quote

ich denke mal, dass noch loopback fehlt...

Quote:

#loopback
$IPTABLES -A INPUT -s "127.0.0.1" -i lo -d "127.0.0.1" -j ACCEPT
$IPTABLES -A OUTPUT -d "127.0.0.1" -o lo -s "127.0.0.1" -j ACCEPT
Back to top
View user's profile Send private message
BlinkEye
Veteran
Veteran


Joined: 21 Oct 2003
Posts: 1046
Location: Gentoo Forums

PostPosted: Thu Aug 26, 2004 1:09 pm    Post subject: Reply with quote

andere frage - braucht man nicht 2 NIC's?
_________________
Easily backup up your system? klick
Get rid of SSH Brute Force Attempts / Script Kiddies klick
Back to top
View user's profile Send private message
Haldir
Guru
Guru


Joined: 27 Sep 2002
Posts: 546

PostPosted: Thu Aug 26, 2004 1:30 pm    Post subject: Reply with quote

Naja wenns nen standalone rechner ist wohl nicht, dann dürfte eth0 als "dsl device" reichen.
Dann seh ich aber auch nicht den Sinn in einer komplexen Firewall config, für nen Desktop Rechner reicht dann auch shorewall usw
Back to top
View user's profile Send private message
dannycool
Tux's lil' helper
Tux's lil' helper


Joined: 13 Aug 2004
Posts: 111
Location: Karlsruhe Germany

PostPosted: Thu Aug 26, 2004 1:45 pm    Post subject: Reply with quote

Also, wenn das Deine erste Firewall ist dann solltest Du echt nicht so ein Riesenskript aus dem Internet kopieren... fang nochmal von vorn an und teste nach jedem Schritt.
Back to top
View user's profile Send private message
hotkey
Tux's lil' helper
Tux's lil' helper


Joined: 10 Jul 2003
Posts: 80

PostPosted: Thu Aug 26, 2004 4:39 pm    Post subject: Reply with quote

Ich kenne mich mit IP Tables nicht besonders aus. Deshalb verwende ich Firehol. Dort erstellt man ein wesentlich übersichtlicheres Skript und Firehol baut daraus die IP Tables regeln. Funktioniert bis jetzt eigentlich ganz gut.
Back to top
View user's profile Send private message
DerMojo
Guru
Guru


Joined: 14 Aug 2003
Posts: 395
Location: Germany

PostPosted: Thu Aug 26, 2004 5:49 pm    Post subject: Reply with quote

Hi!

Mit fwbuilder kann man sowas "Umfangreiches" schön grafisch machen ;)
Mir ist eth0 als IINTERFACE suspekt... Hängst du hinter nem Router? Oder direkt DSL? Dann würd ich ppp0 nehmen...

MfG
Daniel
_________________
To err is human, to forgive, beyond the scope of the Operating System.
Back to top
View user's profile Send private message
Deever
Veteran
Veteran


Joined: 06 Jul 2002
Posts: 1354
Location: Zürich / Switzerland

PostPosted: Thu Aug 26, 2004 8:06 pm    Post subject: Reply with quote

Könntet ihr bitte aufhören mit iptables IP zu demolieren? Jeder, der nicht per command line nen Packetfilter aufsetzten kann, soll die Finger davon lassen. Das ist nichts für Leute, die sich nicht damit auskennen. Einen hostbased Packetfilter aufzusetzen ist DAU-like, sorry!

SCNR,
/dev
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Deutsches Forum (German) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum