Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
iptable-Rules? Welche feuert?
View unanswered posts
View posts from last 24 hours
View posts from last 7 days

Goto page 1, 2  Next  
Reply to topic    Gentoo Forums Forum Index Deutsches Forum (German)
View previous topic :: View next topic  
Author Message
SNo0py
Apprentice
Apprentice


Joined: 12 Jul 2002
Posts: 270
Location: Vienna, Austria

PostPosted: Thu Jul 18, 2002 6:35 am    Post subject: iptable-Rules? Welche feuert? Reply with quote

Beim Lesen des Gentoo-Security-HowTos (http://www.gentoo.org/doc/gentoo-security.html#doc_chap6) ist mir folgendes aufgefallen:

Code:
panic() {
  ebegin "Setting panic rules"
  $IPTABLES -F
  $IPTABLES -X
  $IPTABLES -t nat -F
  $IPTABLES -P FORWARD DROP
  $IPTABLES -P INPUT   DROP                    <== 1.)
  $IPTABLES -P OUTPUT  DROP
  $IPTABLES -A INPUT -i lo -j ACCEPT        <== 2.)
  $IPTABLES -A OUTPUT -o lo -j ACCEPT
  eend $?
}


Wie kann die 2. Regel jemals feuern, wenn ich bei 1.) jeglichen Traffic DROPpe ? Es feuert doch die erste Regel, dann wird abgebrochen, oder etwa nicht?

thx,
Mike
_________________
Sex is like hacking. You get in, you get out, and you hope you didnt leave something behind that can be traced back to you.
Back to top
View user's profile Send private message
sulu
Guru
Guru


Joined: 21 May 2002
Posts: 399
Location: Dornbirn/Austria

PostPosted: Thu Jul 18, 2002 7:22 am    Post subject: Reply with quote

Seavas !

Die Policy (iptables -P ....) legt das Default-Verhalten fest.
Wenn also keine Rule gefunden wird dann greift in deinem Beispiel der DROP. Das Loopback-Netzwerkinterface ist in deinem Beispiel vom DROP ausgenommen. Der Sinn dieser Panic-Regeln ist also: "Sperre alles ausser dem Loopback-Interface".

Gruss
Sulu
Back to top
View user's profile Send private message
SNo0py
Apprentice
Apprentice


Joined: 12 Jul 2002
Posts: 270
Location: Vienna, Austria

PostPosted: Thu Jul 18, 2002 7:30 am    Post subject: Reply with quote

Aha... das erklärt einiges. (Was dieses Fragment macht, war mir klar, aber warum? ;))

Aber ansonsten werden die Regeln hintereinander abgearbeitet und wenn die 1. passt, wird beendet, d.h. die Reihenfolge ist wichtig?

mfg
_________________
Sex is like hacking. You get in, you get out, and you hope you didnt leave something behind that can be traced back to you.
Back to top
View user's profile Send private message
citizen428
Retired Dev
Retired Dev


Joined: 10 Jun 2002
Posts: 317
Location: Vienna, Austria

PostPosted: Thu Jul 18, 2002 10:36 am    Post subject: Reply with quote

SNo0py wrote:
Aber ansonsten werden die Regeln hintereinander abgearbeitet und wenn die 1. passt, wird beendet, d.h. die Reihenfolge ist wichtig?

Denke schon, AFAIK geht iptables nach "first match".
Back to top
View user's profile Send private message
sulu
Guru
Guru


Joined: 21 May 2002
Posts: 399
Location: Dornbirn/Austria

PostPosted: Thu Jul 18, 2002 11:04 am    Post subject: Reply with quote

Yep. Man setzt den default und danach die Special-cases.
Aber ein grosser Meister mit netfilter bin ich auch nicht. Im Moment versuche ich mein eigenes (eigenhändig downgeloadetes) Firewall-Script zu verstehen.
Man kann mit iptables fürchterlich viel machen. Das muss man anscheinend auch, da es doch einige verschiedene Arten von Netzatacken gibt.

cya
Sulu
Back to top
View user's profile Send private message
SNo0py
Apprentice
Apprentice


Joined: 12 Jul 2002
Posts: 270
Location: Vienna, Austria

PostPosted: Thu Jul 18, 2002 11:18 am    Post subject: Reply with quote

citizen428 wrote:
..., AFAIK ...


??? Was ist das für eine Abkürzung, die kenn ich net :?:
_________________
Sex is like hacking. You get in, you get out, and you hope you didnt leave something behind that can be traced back to you.
Back to top
View user's profile Send private message
SNo0py
Apprentice
Apprentice


Joined: 12 Jul 2002
Posts: 270
Location: Vienna, Austria

PostPosted: Thu Jul 18, 2002 11:20 am    Post subject: Reply with quote

sulu wrote:
Im Moment versuche ich mein eigenes (eigenhändig downgeloadetes) Firewall-Script zu verstehen.

Welches denn? Ich hab mir das vom Gentoo-Security-HowTo gesaugt und versuche es anzupassen. Das ist recht übersichtlich gemacht - jetzt muss nur noch der Kernel mitmachen :(
Eigentlich wäre die Regel ja einfach - extern alles blockieren und intern alles zulassen - leider ist das ja nicht so einfach, weil man ja dann die Antworten von fremden Servern auch blockiert :(

Wird schon werden...
_________________
Sex is like hacking. You get in, you get out, and you hope you didnt leave something behind that can be traced back to you.
Back to top
View user's profile Send private message
ElCondor
Guru
Guru


Joined: 10 Apr 2002
Posts: 520
Location: Vienna, Austria, Europe

PostPosted: Thu Jul 18, 2002 11:30 am    Post subject: Reply with quote

SNo0py wrote:
citizen428 wrote:
..., AFAIK ...

??? Was ist das für eine Abkürzung, die kenn ich net :?:

soviel ich weiss = As Far As I Know :)

ad firewall: ich hab mir vor langem mal gShield runtergeladen und heftig umgebaut, die config vereinfacht und vor allem für netze mit mehreren subnetzen mit unterschiedlichen rechten angepasst. falls wer interesse daran hat, stell ichs auf meinen server zum download.

* ElCondor pasa *
_________________
Here I am the victim of my own choices and I'm just starting!
Back to top
View user's profile Send private message
citizen428
Retired Dev
Retired Dev


Joined: 10 Jun 2002
Posts: 317
Location: Vienna, Austria

PostPosted: Thu Jul 18, 2002 11:41 am    Post subject: Reply with quote

SNo0py wrote:
citizen428 wrote:
..., AFAIK ...

??? Was ist das für eine Abkürzung, die kenn ich net :?:

Sorry, ich benutz ständig so Abkürzungen, kommt wohl noch aus meiner recht aktiven Usenet Zeit... ;)

Eine gute Anlaufstelle für sowas ist das Jargonlexikon von Eric S. Raymonds:

http://www.tuxedo.org/~esr/jargon/html/The-Jargon-Lexicon-framed.html

Quote:

AFAIK // n.

[Usenet] Abbrev. for "As Far As I Know".
Back to top
View user's profile Send private message
Larde
Guru
Guru


Joined: 07 Jun 2002
Posts: 313
Location: Duesseldorf, Germany

PostPosted: Thu Jul 18, 2002 1:35 pm    Post subject: Reply with quote

[quote="SNo0py"]
sulu wrote:

Eigentlich wäre die Regel ja einfach - extern alles blockieren und intern alles zulassen - leider ist das ja nicht so einfach, weil man ja dann die Antworten von fremden Servern auch blockiert :(

Wird schon werden...


Hmm, wenn Du nur sowas willst, ist es doch einfach. Die Antworten fallen in die Kategorie "established", weil sie zu einer aufgebauten Verbindung gehören, also brauchst Du sowas:

Code:

iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT


Je nach Bedarf auch in die FORWARD chain. Dann klappt's auch mit den Antworten... :-)
Back to top
View user's profile Send private message
SNo0py
Apprentice
Apprentice


Joined: 12 Jul 2002
Posts: 270
Location: Vienna, Austria

PostPosted: Thu Jul 18, 2002 3:02 pm    Post subject: Reply with quote

Danke!

Aber ich werd mich noch ein wenig einlesen, weil ich hab ja mehr vor -> http://www.wcm.at/vb2/showthread.php?threadid=63688 -> leider noch keine Antwort erhalten :(
_________________
Sex is like hacking. You get in, you get out, and you hope you didnt leave something behind that can be traced back to you.
Back to top
View user's profile Send private message
Larde
Guru
Guru


Joined: 07 Jun 2002
Posts: 313
Location: Duesseldorf, Germany

PostPosted: Thu Jul 18, 2002 3:23 pm    Post subject: Reply with quote

SNo0py wrote:
Danke!

Aber ich werd mich noch ein wenig einlesen, weil ich hab ja mehr vor -> http://www.wcm.at/vb2/showthread.php?threadid=63688 -> leider noch keine Antwort erhalten :(


Oh, ich schreib Dir nachher mal ein Regelfile dafür. Im Moment muß ich mich mal hinlegen und wenig die Augen zu machen... Aber nachher schnipsel ich Dir was passendes hin. :-)

Ich würde aber ping und einige andere ICMPs nicht blocken, glaub mir, das tut man nicht. Bringt mehr Ärger als Nutzen.

Und Du willst einen Samba ins externe Netz pusten? *staun*
Ah, ich sehe gerade, eth0 geht nach "LAN"? Ich hätte jetzt gedacht, über ppp (DSL) ins Internet...

Noch eine Nachfrage, um präzise zu sein: eth1 und eth2 gehen auch in Zunkunft nur zu jeweils einem Rechner, und nicht in Subnetze? Ansonsten wäre es schlauer, gleich vernünftige Subnetze zu vergeben, und nicht über die Host-IPs zu routen.
Back to top
View user's profile Send private message
Larde
Guru
Guru


Joined: 07 Jun 2002
Posts: 313
Location: Duesseldorf, Germany

PostPosted: Thu Jul 18, 2002 4:04 pm    Post subject: Reply with quote

Ok, hab mich doch gleich rangesetzt. Mein erster Entwurf:

Code:

#!/bin/bash
#

echo "Initializing Firewall"

LAN_DEV="eth0"
LAN_NET="172.16.1.0/24"
LAPTOP_DEV="eth2"
DESKTOP_DEV="eth1"

/sbin/modprobe ip_conntrack_ftp
/sbin/modprobe ip_nat_ftp

iptables -F
iptables -t nat -F
iptables -X

#IP forwarding ist standardmäßig aus
#
echo "1" > /proc/sys/net/ipv4/ip_forward

# Für Dynamische IP Nutzung (DHCP?)
#
echo "1" > /proc/sys/net/ipv4/ip_dynaddr

#
# default policies
# (wenn du netter sein willst, nimmst Du REJECT statt DROP)

iptables -P INPUT DROP
iptables -P OUTPUT DROP
iptables -P FORWARD DROP

#
# Ein paar Hilfs-Chains
# (He, ich will wenigstens etwas Struktur)
#

iptables -N icmps
iptables -N out
iptables -N in

#
# ICMP
# (die sind ok)

iptables -A icmp_packets -p ICMP -s 0/0 --icmp-type 0 -j ACCEPT
iptables -A icmp_packets -p ICMP -s 0/0 --icmp-type 3 -j ACCEPT
iptables -A icmp_packets -p ICMP -s 0/0 --icmp-type 4 -j ACCEPT
iptables -A icmp_packets -p ICMP -s 0/0 --icmp-type 8 -j ACCEPT
iptables -A icmp_packets -p ICMP -s 0/0 --icmp-type 10 -j ACCEPT
iptables -A icmp_packets -p ICMP -s 0/0 --icmp-type 11 -j ACCEPT
iptables -A icmp_packets -p ICMP -s 0/0 --icmp-type 12 -j ACCEPT

#nicht wieder zurück zum aufrufenden Rule springen sondern denien
iptables -A icmp_packets -j DROP

#
# OUTGOING
# (ist ja recht leer für Dich, ich hätte da mehr Policies ;-)
#
iptables -A out -s 127.0.0.1 -j ACCEPT
iptables -A out -i ! $LAN_DEV -j ACCEPT

#
# INCOMING
#
iptables -A in -s 127.0.0.1 -j ACCEPT
iptables -A in -i !$LAN_DEV -j ACCEPT
# wenn Du meinen Rat annimmst ;-)
iptables -A in -p ICMP -j icmps
iptables -A in -s $LAN_NET -p TCP --dport 80 -j ACCEPT
iptables -A in -s $LAN_NET -p UDP --dport 137:139 -j ACCEPT
iptables -A in -s $LAN_NET -p TCP --dport 137:139 -j ACCEPT



#
# PREROUTING chain.
#
# einige spoofed IPs abfangen :-)
#

iptables -t nat -A PREROUTING -i $LAN_DEV -s 192.168.1.0/24 -j DROP


#
# INPUT chain
#
#

iptables -A INPUT -j in
iptables -A INPUT -p ALL -m state --state ESTABLISHED,RELATED -j ACCEPT
# wenn Du logging willst:
#iptables -A INPUT -m limit --limit 3/minute --limit-burst 3 -j LOG --log-prefix "INPUT denied: "


#
# FORWARD CHAIN
#

# dito
iptables -A FORWARD -p ICMP -j icmps
iptables -A FORWARD -j out
iptables -A FORWARD -m state --state ESTABLISHED,RELATED -j ACCEPT
# logging?
#iptables -A FORWARD -m limit --limit 3/minute --limit-burst 3 -j LOG --log-prefix "FORWARD denied: "

#
# OUTPUT chain
#

iptables -A OUTPUT -p ICMP -j icmps
iptables -A OUTPUT -j out
iptables -A OUTPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
#iptables -A OUTPUT -m limit --limit 3/minute --limit-burst 3 -j LOG --log-prefix "OUTPUT denied: "

#
# POSTROUTING CHAIN
#

iptables -t nat -A POSTROUTING -o $LAN_DEV -j MASQUERADE


Hoffentlich hältst du meine Lösung nicht für Overkill. :-) Oh, ist natürlich nicht getestet, da ich zu Hause nur nen 2-Port-Rechner habe. Aber ich bin gerne bereit, zu diskutieren - ich schließlich Beruf *und* Hobby. ;-)
edit: Argh, ich kenne das LAN nicht. Ich mußte daher den Bereich für potentiell gespoofte IPs eingrenzen.
edit2: lol - Da ich die beiden Windowsrechner über "Nicht-LAN-Device" abdecke, könnte ich das ja doch mit nur 2 Ports testen. *smiles*
Back to top
View user's profile Send private message
SNo0py
Apprentice
Apprentice


Joined: 12 Jul 2002
Posts: 270
Location: Vienna, Austria

PostPosted: Fri Jul 19, 2002 7:50 am    Post subject: Reply with quote

Poi eh, danke für die Arbeit! Ich werd's nach dem Wochenende so schnell wie möglich ausprobieren!

Ein paar Fragen noch:
Welchen Ärger meinst du (bezüglich ICMP?)

Code:
# Für Dynamische IP Nutzung (DHCP?)
#
echo "1" > /proc/sys/net/ipv4/ip_dynaddr

Wozu ist das?

Code:
#
# OUTGOING
# (ist ja recht leer für Dich, ich hätte da mehr Policies ;-)
#

z.B.??
_________________
Sex is like hacking. You get in, you get out, and you hope you didnt leave something behind that can be traced back to you.
Back to top
View user's profile Send private message
SNo0py
Apprentice
Apprentice


Joined: 12 Jul 2002
Posts: 270
Location: Vienna, Austria

PostPosted: Fri Jul 19, 2002 7:51 am    Post subject: Reply with quote

Zu Samba: ja, das geht ins LAN; und an eth1/2 hängt jeweils nur ein Rechner (vorraussichtlich) und die sollten sich gegenseitig "sehen" können!

mfg
_________________
Sex is like hacking. You get in, you get out, and you hope you didnt leave something behind that can be traced back to you.
Back to top
View user's profile Send private message
Larde
Guru
Guru


Joined: 07 Jun 2002
Posts: 313
Location: Duesseldorf, Germany

PostPosted: Fri Jul 19, 2002 8:21 am    Post subject: Reply with quote

Moin!

Zu ICMP: Man will einfach seinen Rechner von woanders auch mal anpingen können. Außerdem wird über ICMP teilweise ja auch sowas wie Paket-Timeouts etc gehandlet.
Hmm, naja, bei zweiter Überlegung: Wenns "extremely hardened" sein soll, schmeiss die ICMP 3 und 4 doch weg, als zusätzlichen Schutz gegen DOS. Frag 3 Admins und krieg 4 Meinungen. :-)

/proc/sys/net/ipv4/ip_dynaddr: Ist eher wie Leute wie mich deren äußere IP schon mal häufiger wechseln kann. Deine DHCP Adresse wird ja eher statisch sein, nehme ich an. Ich müßte die exakte Erklärung noch mal nachlesen, aber im Groben: iptables bietet ja eine stateful firewall an, und Leute mit dynamischer IP haben dadurch die Möglichkeit, daß der Zustand einer Verbindung trotz wechselnder IP bestehen bleibt. (Wenn ich mich jetzt recht erinnere ;-))

eth1/eth2 können sich mit den Regeln von mir problemlos sehen, da in der FORWARD chain in die "out" chain gesprungen wird, wo alles was nicht über eth0 kommt erlaubt wird.

Ich bin mit meinem outgoing insofern restriktiver, als daß ich wirklich auch nur die Ports erlaube, die ich benötige. Naja, da hab ich mich wohl dran gewöhnt da es bei uns in der Firma auch so ist. :-)

Gruß,
Larde.
_________________
Someday this will be my home... http://moonage.net/
I'll make you a deal
I'll say I came from Earth and my tongue is taped
Back to top
View user's profile Send private message
SNo0py
Apprentice
Apprentice


Joined: 12 Jul 2002
Posts: 270
Location: Vienna, Austria

PostPosted: Fri Jul 19, 2002 8:33 am    Post subject: Reply with quote

Na ja, die externe IP wird via DHCP zugewiesen und wechselt eigentlich ehr selten. Aber anpingen will ich meinen Rechner trotzdem nicht, ich will ihn einfach nur gegen das Wohnhaus-LAN sicher nachen (Rekord laut Norton Firewall: >3000 Portscans in einer Stunde!)

@outgoing: das is egal, die 3 Rechner (Linux, Desktop, Notebook) stehen bei mir im Zimmer und sollten problemlos mit jeder Software ins Internet kommen. Da is es mir (noch) zu blöd für FTP, http, Mail, ... die einzelnen Ports zu öffnen!

btw, gibt es eine Möglichkeit, am Desktop die Rechner vom LAN zu sehen (wg. Freigaben) oder geht das nur mit IPs?

thx
_________________
Sex is like hacking. You get in, you get out, and you hope you didnt leave something behind that can be traced back to you.
Back to top
View user's profile Send private message
Larde
Guru
Guru


Joined: 07 Jun 2002
Posts: 313
Location: Duesseldorf, Germany

PostPosted: Fri Jul 19, 2002 8:58 am    Post subject: Reply with quote

Quote:
btw, gibt es eine Möglichkeit, am Desktop die Rechner vom LAN zu sehen (wg. Freigaben) oder geht das nur mit IPs?


Das geht, aber frag mich jetzt nicht nach der passenden Kommandozeile. Ich habe immer gnomba genommen um zu browsen, das ist aber schon etwas antik. Es gibt so einige Frontends. *mit den Schultern zuck*

Gruß,
Larde.
_________________
Someday this will be my home... http://moonage.net/
I'll make you a deal
I'll say I came from Earth and my tongue is taped
Back to top
View user's profile Send private message
SNo0py
Apprentice
Apprentice


Joined: 12 Jul 2002
Posts: 270
Location: Vienna, Austria

PostPosted: Mon Jul 22, 2002 2:12 pm    Post subject: Reply with quote

Hi!

Ich hab das unten angefügte Script verbrochen, fallen wem Fehler auf, was sollte ich anders machen?

Extern soll auf den Rechner nur per www/ssh/samba zugegriffen werden können, Intern ist alles erlaubt und soll geroutet werden.

mfg
Mike

Code:

#!/sbin/runscript

# executeables
IPTABLES=/sbin/iptables
IPTABLESSAVE=/sbin/iptables-save
IPTABLESRESTORE=/sbin/iptables-restore

# file for storing firewall-rules
FIREWALL=/etc/firewall.rules

# DNS-Servers
DNS1=195.61
DNS2=195.62

# internal interfaces
INT1_IP=192.168.1.1
INT1_INTERFACE=eth1
INT2_IP=192.168.1.10
INT2_INTERFACE=eth2
INT_NET=192.168.1.0/24

# external interfaces
#OIP= ?dhcp?
EXT_INTERFACE=eth0
EXT_NET=172.16.1.0/24

# all known parameters
opts="${opts} showstatus panic save restore showoptions"

# dependencies
depend() {
   need net
}

# set the default-rules
rules() {
    stop
    ebegin "Setting internal rules"

    # Only SSH and HTTP is allowed from the external interface
    # The local network should have full access to the firewall and to the external network
    # ICMP traffic can contain payload as should not be allowed (except needed ones)
    # Port scan should be detected and logged
    # SYN attack should avoided
    # All other traffic should be dropped (and logged)

    einfo "Setting default rule to drop"
    $IPTABLES -P FORWARD DROP
    $IPTABLES -P INPUT   DROP
    $IPTABLES -P OUTPUT  DROP

    # default rule
    einfo "Creating states chain"
    $IPTABLES -N allowed-state
    $IPTABLES -F allowed-state
    $IPTABLES -A allowed-state -m state --state ESTABLISHED,RELATED -j ACCEPT
    $IPTABLES -A allowed-state -i $EXT_INTERFACE -m limit -j LOG --log-prefix "Bad packet from ${EXT_INTERFACE}:    "
    $IPTABLES -A allowed-state -j DROP

    # ICMP traffic
    einfo "Creating icmp chain"
    $IPTABLES -N allowed-icmp
    $IPTABLES -F allowed-icmp
    $IPTABLES -A allowed-icmp -m state --state NEW -p icmp --icmp-type time-exceeded -j ACCEPT
    $IPTABLES -A allowed-icmp -m state --state NEW -p icmp --icmp-type destination-unreachable -j ACCEPT
    # allow everything internal
    $IPTABLES -A allowed-icmp -i !$EXT_INTERFACE -p icmp -j ACCEPT
    # log & drop
    $IPTABLES -A allowed-icmp -p icmp -j LOG --log-prefix "Bad ICMP traffic:        "
    $IPTABLES -A allowed-icmp -p icmp -j DROP

    # Incomming traffic
    einfo "Creating incomming traffic chain"
    $IPTABLES -N allow-traffic-in
    $IPTABLES -F allow-traffic-in
    # allow SSH
    $IPTABLES -A allow-traffic-in -p tcp -i $EXT_INTERFACE --dport ssh -j ACCEPT
    # allow WWW/apache
    $IPTABLES -A allow-traffic-in -p tcp -i $EXT_INTERFACE --dport www -j ACCEPT
    # allow Samba
    $IPTABLES -A allow-traffic-in -p tcp -i $EXT_INTERFACE --dport 137:139 -j ACCEPT
    $IPTABLES -A allow-traffic-in -p udp -i $EXT_INTERFACE --dport 137:139 -j ACCEPT
   
    # outgoing traffic
    einfo "Creating outcomming traffic chain"
    $IPTABLES -N allow-traffic-out
    $IPTABLES -F allow-traffic-out
    # allow * from this machine to everywhere
    $IPTABLES -A allow-traffic-out -p tcp -j ACCEPT
    $IPTABLES -A allow-traffic-out -p udp -j ACCEPT
   
#    $IPTABLES -A allow-traffic-out -p tcp --dport ssh -j ACCEPT
#    # allow WWW/apache
#    $IPTABLES -A allow-traffic-out -p tcp --dport www -j ACCEPT
#    $IPTABLES -A allow-traffic-out -p tcp --dport https -j ACCEPT
#    # allow DNS
#    $IPTABLES -A allow-traffic-out -p udp -d $DNS1 --dport domain -j ACCEPT
#    $IPTABLES -A allow-traffic-out -p udp -d $DNS2 --dport domain -j ACCEPT

    # Catch portscanners
    einfo "Creating portscan detection chain"
    $IPTABLES -N portscan-chain
    $IPTABLES -F portscan-chain
    $IPTABLES -A portscan-chain -p tcp --tcp-flags ALL FIN,URG,PSH -m limit --limit 5/minute -j LOG --log-level alert --log-prefix "NMAP-XMAS:               "
    $IPTABLES -A portscan-chain -p tcp --tcp-flags ALL FIN,URG,PSH -j DROP
    $IPTABLES -A portscan-chain -p tcp --tcp-flags ALL ALL -m limit --limit 5/minute -j LOG --log-level 1 --log-prefix "XMAS:                    "
    $IPTABLES -A portscan-chain -p tcp --tcp-flags ALL ALL -j DROP
    $IPTABLES -A portscan-chain -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 portscan-chain -p tcp --tcp-flags ALL SYN,RST,ACK,FIN,URG -j DROP
    $IPTABLES -A portscan-chain -p tcp --tcp-flags ALL NONE -m limit --limit 5/minute -j LOG --log-level 1 --log-prefix "NULL_SCAN:               "
    $IPTABLES -A portscan-chain -p tcp --tcp-flags ALL NONE -j DROP
    $IPTABLES -A portscan-chain -p tcp --tcp-flags SYN,RST SYN,RST -m limit --limit 5/minute -j LOG --log-level 5 --log-prefix "SYN/RST:                 "
    $IPTABLES -A portscan-chain -p tcp --tcp-flags SYN,RST SYN,RST -j DROP
    $IPTABLES -A portscan-chain -p tcp --tcp-flags SYN,FIN SYN,FIN -m limit --limit 5/minute -j LOG --log-level 5 --log-prefix "SYN/FIN:                 "
    $IPTABLES -A portscan-chain -p tcp --tcp-flags SYN,FIN SYN,FIN -j DROP

    einfo "Creating delay chains"
    $IPTABLES -N delay-chain
    $IPTABLES -F delay-chain
    $IPTABLES -A delay-chain -m limit --limit 1/second -p tcp --tcp-flags ALL RST -j ACCEPT
    $IPTABLES -A delay-chain -m limit --limit 1/second -p tcp --tcp-flags ALL FIN -j ACCEPT
    $IPTABLES -A delay-chain -m limit --limit 1/second -p tcp --tcp-flags ALL SYN -j ACCEPT

    # Apply and add invalid states to the chains
    einfo "Applying chains to INPUT"
    $IPTABLES -A INPUT -M state --state INVALID -j DROP
    $IPTABLES -A INPUT -j allowed-icmp
    $IPTABLES -A INPUT -j portscan-chain
    $IPTABLES -A INPUT -j delay-chain
    $IPTABLES -A INPUT -i lo -j ACCEPT
    $IPTABLES -A INPUT -j allow-traffic-in
    $IPTABLES -A INPUT -j allowed-state

    einfo "Applying chains to OUTPUT"
    $IPTABLES -A OUTPUT -m state --state INVALID -j DROP
    $IPTABLES -A OUTPUT -j allowed-icmp
    $IPTABLES -A OUTPUT -j portscan-chain
    $IPTABLES -A OUTPUT -o lo -j ACCEPT
    $IPTABLES -A OUTPUT -j allow-traffic-out
    $IPTABLES -A OUTPUT -j allowed-state

    einfo "Applying chains to FORWARD"
    $IPTABLES -A FORWARD -m state --state INVALID -j DROP
    $IPTABLES -A FORWARD -j allowed-icmp
    $IPTABLES -A FORWARD -j portscan-chain
    $IPTABLES -A FORWARD -o lo -j ACCEPT
    $IPTABLES -A FORWARD -j allow-traffic-in
    $IPTABLES -A FORWARD -j allow-traffic-out
    $IPTABLES -A FORWARD -j allowed-state

    # NAT
    einfo "Setting up NAT"
    # no spoofed IPs
    $IPTABLES -t nat -A PREROUTING -i $EXT_INTERFACE -s INT_NET -j DROP
    # add routing
    $IPTABLES -t nat -A POSTROUTING -o $EXT_INTERFACE -j MASQUERADE

    eend $?
}

# startup the firewall
start() {
    ebegin "Starting firewall"
    if [ -e "${FIREWALL}" ]; then
   restore
    else
        einfo "${FIREWALL} does not exists. Using default rules."
   rules
    fi
    eend $?
}

# stop the firewall
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 $?
}

# show the status
showstatus() {
    ebegin "Status"
    $IPTABLES -L -n -v --line-numbers
    einfo "NAT status"
    $IPTABLES -L -n -v --line-numbers -t nat
    eend $?
}

# stop any traffic!
panic() {
    ebegin "Setting panic rules"
    $IPTABLES -F
    $IPTABLES -X
    $IPTABLES -t nat -F
    # drop everything
    $IPTABLES -P FORWARD DROP
    $IPTABLES -P INPUT   DROP
    $IPTABLES -P OUTPUT  DROP
    # only loopback allowed - INT1?
    $IPTABLES -A INPUT -i lo -j ACCEPT
    $IPTABLES -A OUTPUT -o lo -j ACCEPT
    eend $?
}

# save the rules
save() {
    ebegin "Saving Firewall rules"
    $IPTABLESSAVE > $FIREWALL
    eend $?
}

# load the rules
restore() {
    ebegin "Restoring Firewall rules"
    $IPTABLESRESTORE < $FIREWALL
    eend $?
}

# restart the firewall
restart() {
    svc_stop; svc_start
}

# show all available options
showoptions() {
    echo "Usage: $0 {start|save|restore|panic|stop|restart|showstatus}"
    echo "start)      will restore setting if exists else force rule settings"
    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"

}


_________________
Sex is like hacking. You get in, you get out, and you hope you didnt leave something behind that can be traced back to you.
Back to top
View user's profile Send private message
Larde
Guru
Guru


Joined: 07 Jun 2002
Posts: 313
Location: Duesseldorf, Germany

PostPosted: Mon Jul 22, 2002 4:53 pm    Post subject: Reply with quote

Oh, hier auch :-). Es ging jetzt per private Mail mit ner langen Erläuterungs-Mail raus. Soll ich das so wie ich denke editierte Skript mit meinen Gedanken dazu veröffentlichen? Ist recht lang, und ich weiß auch nicht, ob meine Hinweise wirklich alle richtig und für andere interessant sind....

Gruß,
Larde.
_________________
Someday this will be my home... http://moonage.net/
I'll make you a deal
I'll say I came from Earth and my tongue is taped
Back to top
View user's profile Send private message
SNo0py
Apprentice
Apprentice


Joined: 12 Jul 2002
Posts: 270
Location: Vienna, Austria

PostPosted: Tue Jul 23, 2002 8:14 am    Post subject: Reply with quote

Ne, danke, ich wollt nur meine Erkenntnisse veröffentlichen.

Wenn also jemand Interesse an einem Firewallscript hat, bei mir oder larde melden!

mfg
_________________
Sex is like hacking. You get in, you get out, and you hope you didnt leave something behind that can be traced back to you.
Back to top
View user's profile Send private message
dek
l33t
l33t


Joined: 16 May 2002
Posts: 657
Location: Germany

PostPosted: Tue Jul 23, 2002 3:09 pm    Post subject: Reply with quote

Also ich wäre an etwas Hilfe interessiert. Habe leider so gut wie keine Ahnung von iptables. Aber langsam wirds mal Zeit, dass ich das lerne. Habe bisher nur vorgefertigte Lösungen benutzt.

Meine rules beschränken sich derzeit auf das folgende:
Code:

echo 1 > /proc/sys/net/ipv4/ip_forward
iptables -P FORWARD ACCEPT
iptables -t nat -A POSTROUTING -o ppp0 -j MASQUERADE

Also gerade mal routing mit masquerade.

Zu meinen Netzwerk: Ein Gentoo gateway mit zwei Netzwerkkarten und TDSL. eth0 ist das interne Netz (geht an ein switch), eth1 ist mit dem DSL-Modem verbunden und baut die Verbindung auf, wird dann ppp0.
IPs sind wie folgt vergeben:
workstation1: 192.168.10.1
gateway: 192.168.10.2
andere workstations: 192.168.10.3, 192.168.10.4, ...
Im internen Netz soll alles erlaubt sein. Von aussen evtl. ftp, sowie irc und icq sollen möglich sein. onlinegames und filesharing eigentlich auch. Ich weis viele sagen, dann brauch man auch keine firewall.. was meint ihr dazu?

Damit ich mal einen Einstieg bekomme: Was für Variablen sollte ich setzen? Wenn ich mir das hier gepostete Skript anschaue, werfen sich mir einige fragen auf.
INT1_IP=192.168.10.2 <== für welchen Rechner steht die, für die firewall?
INT1_INTERFACE=eth0
INT_NET=192.168.10.0/24
EXT_INTERFACE=ppp0
EXT_NET=? <== ist bei mir dynamisch oder?
Back to top
View user's profile Send private message
SNo0py
Apprentice
Apprentice


Joined: 12 Jul 2002
Posts: 270
Location: Vienna, Austria

PostPosted: Wed Jul 24, 2002 8:45 am    Post subject: Reply with quote

VORSICHT!

Ich hab gestern das Firewall-Script ausprobiert und bin nachher nicht mehr ins Netz gekommen (vom lokalen Rechner aus) -> da hat's noch was!!!
_________________
Sex is like hacking. You get in, you get out, and you hope you didnt leave something behind that can be traced back to you.
Back to top
View user's profile Send private message
Larde
Guru
Guru


Joined: 07 Jun 2002
Posts: 313
Location: Duesseldorf, Germany

PostPosted: Wed Jul 24, 2002 12:16 pm    Post subject: Reply with quote

Die Version die hier liegt oder die geänderte? Wenn die geänderte, oops. :-)
Was sagen denn dann die Logfiles dazu?

Naja, ich schätze mal, inzwischen kannst Du es selbst sehr gut nachvollziehen, welche Regel was macht. Ich verwirr wahrscheinlich nur mit meinen vermeintlichen Optimierungen. ;-)
_________________
Someday this will be my home... http://moonage.net/
I'll make you a deal
I'll say I came from Earth and my tongue is taped
Back to top
View user's profile Send private message
SNo0py
Apprentice
Apprentice


Joined: 12 Jul 2002
Posts: 270
Location: Vienna, Austria

PostPosted: Wed Jul 24, 2002 12:33 pm    Post subject: Reply with quote

Das geänderte File :evil:

Aber macht nix, ich glaub ich hab den Fehler schon und ich muss mir mal in aller Ruhe die Logs ansehen (war gestern schon zu spät!)

Inzwischen hab ich das System glaub ich kapiert - es is eigentlich eh nicht schwer, der Teufel liegt im Detail (oder kannst du mir den Portscan-Chain erklärten? :))

mfg
_________________
Sex is like hacking. You get in, you get out, and you hope you didnt leave something behind that can be traced back to you.
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
Goto page 1, 2  Next
Page 1 of 2

 
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