Zum Inhalt springen
View in the app

A better way to browse. Learn more.

Fachinformatiker.de

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Linux Server absichern

Empfohlene Antworten

Veröffentlicht

Hi

Ich habe nen Linux Rootserver, auf diesem möchte ich nun nur noch die Ports freigeben, die ich auch wirklich brauche. Alle anderen Anfragen (ob von innen oder aussen) soll er "verschlucken"

Hierzu habe ich das folgende Script:

# iptables-Modul

    modprobe ip_tables

    # Connection-Tracking-Module

    modprobe ip_conntrack

    # Das Modul ip_conntrack_irc ist erst bei Kerneln >= 2.4.19 verfuegbar

    modprobe ip_conntrack_irc

    modprobe ip_conntrack_ftp


    # Tabelle flushen

    iptables -F

    iptables -t nat -F

    iptables -t mangle -F

    iptables -X

    iptables -t nat -X

    iptables -t mangle -X


    # Default-Policies setzen

    iptables -P INPUT DROP

    iptables -P OUTPUT DROP

    iptables -P FORWARD DROP


    # MY_REJECT-Chain

    iptables -N MY_REJECT


    # MY_REJECT fuellen

    iptables -A MY_REJECT -p tcp -m limit --limit 7200/h -j LOG --log-prefix "REJECT TCP "

    iptables -A MY_REJECT -p tcp -j REJECT --reject-with tcp-reset

    iptables -A MY_REJECT -p udp -m limit --limit 7200/h -j LOG --log-prefix "REJECT UDP "

    iptables -A MY_REJECT -p udp -j REJECT --reject-with icmp-port-unreachable

    iptables -A MY_REJECT -p icmp -m limit --limit 7200/h -j LOG --log-prefix "DROP ICMP "

    iptables -A MY_REJECT -p icmp -j DROP

    iptables -A MY_REJECT -m limit --limit 7200/h -j LOG --log-prefix "REJECT OTHER "

    iptables -A MY_REJECT -j REJECT --reject-with icmp-proto-unreachable


    # MY_DROP-Chain

    iptables -N MY_DROP

    iptables -A MY_DROP -m limit --limit 7200/h -j LOG --log-prefix "PORTSCAN DROP "

    iptables -A MY_DROP -j DROP


    # Alle verworfenen Pakete protokollieren

    iptables -A INPUT -m state --state INVALID -m limit --limit 7200/h -j LOG --log-prefix "INPUT INVALID "

    iptables -A OUTPUT -m state --state INVALID -m limit --limit 7200/h -j LOG --log-prefix "OUTPUT INVALID "


    # Korrupte Pakete zurueckweisen

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

    iptables -A OUTPUT -m state --state INVALID -j DROP


    # Stealth Scans etc. DROPpen

    # Keine Flags gesetzt

    iptables -A INPUT -p tcp --tcp-flags ALL NONE -j MY_DROP


    # SYN und FIN gesetzt

    iptables -A INPUT -p tcp --tcp-flags SYN,FIN SYN,FIN -j MY_DROP


    # SYN und RST gleichzeitig gesetzt

    iptables -A INPUT -p tcp --tcp-flags SYN,RST SYN,RST -j MY_DROP


    # FIN und RST gleichzeitig gesetzt

    iptables -A INPUT -p tcp --tcp-flags FIN,RST FIN,RST -j MY_DROP


    # FIN ohne ACK

    iptables -A INPUT -p tcp --tcp-flags ACK,FIN FIN -j MY_DROP


    # PSH ohne ACK

    iptables -A INPUT -p tcp --tcp-flags ACK,PSH PSH -j MY_DROP


    # URG ohne ACK

    iptables -A INPUT -p tcp --tcp-flags ACK,URG URG -j MY_DROP


    # Loopback-Netzwerk-Kommunikation zulassen

    iptables -A INPUT -i lo -j ACCEPT

    iptables -A OUTPUT -o lo -j ACCEPT


    # Connection-Tracking aktivieren

    iptables -A OUTPUT -m state --state NEW,ESTABLISHED,RELATED -j ACCEPT

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


    # HTTP

    iptables -A INPUT -i ppp0 -m state --state NEW -p tcp --dport 80 -j ACCEPT


    # HTTPS

    iptables -A INPUT -i ppp0 -m state --state NEW -p tcp --dport 443 -j ACCEPT


    # SMTP

    iptables -A INPUT -i ppp0 -m state --state NEW -p tcp --dport 25 -j ACCEPT


    # POP3

    iptables -A INPUT -i ppp0 -m state --state NEW -p tcp --dport 110 -j ACCEPT


    # POP3S

    iptables -A INPUT -i ppp0 -m state --state NEW -p tcp --dport 995 -j ACCEPT


    # NNTP

    iptables -A INPUT -i ppp0 -m state --state NEW -p tcp --dport 119 -j ACCEPT


    # DNS

    iptables -A INPUT -i ppp0 -m state --state NEW -p tcp --dport 53 -j ACCEPT

    iptables -A INPUT -i ppp0 -m state --state NEW -p udp --dport 53 -j ACCEPT


    # FTP

    iptables -A INPUT -i ppp0 -m state --state NEW -p tcp --dport 21 -j ACCEPT


    # SSH

    iptables -A INPUT -i ppp0 -m state --state NEW -p tcp --dport 22 -j ACCEPT


    # MYSQL

    iptables -A INPUT -i ppp0 -m state --state NEW -p tcp --dport 3306 -j ACCEPT


    # NTP

    iptables -A INPUT -i ppp0 -m state --state NEW -p udp --dport 123 -j ACCEPT


    # Default-Policies mit REJECT

    iptables -A INPUT -j MY_REJECT

    iptables -A OUTPUT -j MY_REJECT


    # Max. 500/Sekunde (5/Jiffie) senden

    echo 5 > /proc/sys/net/ipv4/icmp_ratelimit


    # Speicherallozierung und -timing für IP-De/-Fragmentierung

    echo 262144 > /proc/sys/net/ipv4/ipfrag_high_thresh

    echo 196608 > /proc/sys/net/ipv4/ipfrag_low_thresh

    echo 30 > /proc/sys/net/ipv4/ipfrag_time


    # TCP-FIN-Timeout zum Schutz vor DoS-Attacken setzen

    echo 30 > /proc/sys/net/ipv4/tcp_fin_timeout


    # Maximal 3 Antworten auf ein TCP-SYN

    echo 3 > /proc/sys/net/ipv4/tcp_retries1


    # TCP-Pakete maximal 15x wiederholen

    echo 15 > /proc/sys/net/ipv4/tcp_retries2

Meine Frage nun:

Kann es sein, dass mein Server hiermit zwar alle Anfragen (beispielsweise SMTP) von aussen annimmt, aber nix versenden kann ?

Funktioniert das nun auch, dass wenn beispieslweise auf dem Server selbst ein Dienst laufen würde der über bestimmte Ports etwas tun möchte, dies nicht mehr möglich ist (Beispiel, jemand installiert über ne Shell einen Eggdrop - das soll nicht funzen)

Gruß Thomas

ich würde da mal sagen ja. weil du ja auch alles was nach draussen geht blockst. du hast dich quasi eingemauert.

ich würde auch nicht unbedingt droppen, da sonst ein etwas schlauer bösewicht merkt das da wer ist der sich versteckt, da er keine antowrt bekommt. ich empfehle dir anstatt DROP REJECT zu benutzen dann sendet dein rechner das da keiner ist. also ein destynation host unreachable o.ä. und nicht einfach nix

  • Autor

Hallo

Nochmal ich.

Ich habe nun dieses Script hier aktiviert, von aussen scheint alles wunderbar dicht zu sein, sogar den Ping lehnt er ab. Wie kann ich nun testen ob ich auch die Anfragen von Innen nach Aussen geschlossen habe ?

Pings nach aussen funzen

    echo "Starte IP-Paketfilter"


    # iptables-Modul

    modprobe ip_tables

    # Connection-Tracking-Module

    modprobe ip_conntrack

    # Das Modul ip_conntrack_irc ist erst bei Kerneln >= 2.4.19 verfuegbar

    modprobe ip_conntrack_irc

    modprobe ip_conntrack_ftp


    # Tabelle flushen

    iptables -F

    iptables -t nat -F

    iptables -t mangle -F

    iptables -X

    iptables -t nat -X

    iptables -t mangle -X


    # Default-Policies setzen

    iptables -P INPUT REJECT 

    iptables -P OUTPUT REJECT

    iptables -P FORWARD REJECT


    # MY_REJECT-Chain

    iptables -N MY_REJECT


    # MY_REJECT fuellen

    iptables -A MY_REJECT -p tcp -m limit --limit 7200/h -j LOG --log-prefix "REJECT TCP "

    iptables -A MY_REJECT -p tcp -j REJECT --reject-with tcp-reset

    iptables -A MY_REJECT -p udp -m limit --limit 7200/h -j LOG --log-prefix "REJECT UDP "

    iptables -A MY_REJECT -p udp -j REJECT --reject-with icmp-port-unreachable

    iptables -A MY_REJECT -p icmp -m limit --limit 7200/h -j LOG --log-prefix "REJECT ICMP "

    iptables -A MY_REJECT -p icmp -j REJECT

    iptables -A MY_REJECT -m limit --limit 7200/h -j LOG --log-prefix "REJECT OTHER "

    iptables -A MY_REJECT -j REJECT --reject-with icmp-proto-unreachable


    # MY_REJECT-Chain

    iptables -N MY_REJECT

    iptables -A MY_REJECT -m limit --limit 7200/h -j LOG --log-prefix "PORTSCAN REJECT "

    iptables -A MY_REJECT -j REJECT


    # Alle verworfenen Pakete protokollieren

    iptables -A INPUT -m state --state INVALID -m limit --limit 7200/h -j LOG --log-prefix "INPUT INVALID "

    iptables -A OUTPUT -m state --state INVALID -m limit --limit 7200/h -j LOG --log-prefix "OUTPUT INVALID "


    # Korrupte Pakete zurueckweisen

    iptables -A INPUT -m state --state INVALID -j REJECT

    iptables -A OUTPUT -m state --state INVALID -j REJECT


    # Stealth Scans etc. REJECTpen

    # Keine Flags gesetzt

    iptables -A INPUT -p tcp --tcp-flags ALL NONE -j MY_REJECT


    # SYN und FIN gesetzt

    iptables -A INPUT -p tcp --tcp-flags SYN,FIN SYN,FIN -j MY_REJECT


    # SYN und RST gleichzeitig gesetzt

    iptables -A INPUT -p tcp --tcp-flags SYN,RST SYN,RST -j MY_REJECT


    # FIN und RST gleichzeitig gesetzt

    iptables -A INPUT -p tcp --tcp-flags FIN,RST FIN,RST -j MY_REJECT


    # FIN ohne ACK

    iptables -A INPUT -p tcp --tcp-flags ACK,FIN FIN -j MY_REJECT


    # PSH ohne ACK

    iptables -A INPUT -p tcp --tcp-flags ACK,PSH PSH -j MY_REJECT


    # URG ohne ACK

    iptables -A INPUT -p tcp --tcp-flags ACK,URG URG -j MY_REJECT


    # Loopback-Netzwerk-Kommunikation zulassen

    iptables -A INPUT -i lo -j ACCEPT

    iptables -A OUTPUT -o lo -j ACCEPT


    # Connection-Tracking aktivieren

    iptables -A OUTPUT -m state --state NEW,ESTABLISHED,RELATED -j ACCEPT

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


    # HTTP

    iptables -A INPUT -i eth0 -m state --state NEW -p tcp --dport 80 -j ACCEPT


    # HTTPS

    iptables -A INPUT -i eth0 -m state --state NEW -p tcp --dport 443 -j ACCEPT


    # SMTP

    iptables -A INPUT -i eth0 -m state --state NEW -p tcp --dport 25 -j ACCEPT


    # POP3

    iptables -A INPUT -i eth0 -m state --state NEW -p tcp --dport 110 -j ACCEPT


    # POP3S

    iptables -A INPUT -i eth0 -m state --state NEW -p tcp --dport 995 -j ACCEPT


    # NNTP

    iptables -A INPUT -i eth0 -m state --state NEW -p tcp --dport 119 -j ACCEPT


    # DNS

    iptables -A INPUT -i eth0 -m state --state NEW -p tcp --dport 53 -j ACCEPT

    iptables -A INPUT -i eth0 -m state --state NEW -p udp --dport 53 -j ACCEPT


    # FTP

    iptables -A INPUT -i eth0 -m state --state NEW -p tcp --dport 21 -j ACCEPT


    # SSH

    iptables -A INPUT -i eth0 -m state --state NEW -p tcp --dport 22 -j ACCEPT


    # MYSQL

    # iptables -A INPUT -i eth0 -m state --state NEW -p tcp --dport 3306 -j ACCEPT


    # NTP

    iptables -A INPUT -i eth0 -m state --state NEW -p udp --dport 123 -j ACCEPT


    # Default-Policies mit REJECT

    iptables -A INPUT -j MY_REJECT

    iptables -A OUTPUT -j MY_REJECT


    # Max. 500/Sekunde (5/Jiffie) senden

    echo 5 > /proc/sys/net/ipv4/icmp_ratelimit


    # Speicherallozierung und -timing für IP-De/-Fragmentierung

    echo 262144 > /proc/sys/net/ipv4/ipfrag_high_thresh

    echo 196608 > /proc/sys/net/ipv4/ipfrag_low_thresh

    echo 30 > /proc/sys/net/ipv4/ipfrag_time


    # TCP-FIN-Timeout zum Schutz vor DoS-Attacken setzen

    echo 30 > /proc/sys/net/ipv4/tcp_fin_timeout


    # Maximal 3 Antworten auf ein TCP-SYN

    echo 3 > /proc/sys/net/ipv4/tcp_retries1


    # TCP-Pakete maximal 15x wiederholen

    echo 15 > /proc/sys/net/ipv4/tcp_retries2

Gruß Thomas

ich würd einfach mal versuchen was von inner nach aussen zu machen. also über den server aufn anderen ftp oder so.

wenn du das noch mit rein nimmst

# SMTP

iptables -A OUTPUT -i eth0 -m state --state NEW -p tcp --dport 25 -j ACCEPT

müsste es eigentlich auf jedenfall gehen.

Alle angeben ohne Gewähr ;-)

  • Autor

Ich habe nun mal ohne die obigen regeln zu ändern getestet, allerdings komme ich von innen auf alles nach draussen wsa auch von aussen zu ist

wenn ich also den ftp port zu lasse komme ich vom server mit ftp <beliebier adresse> bis zum login, von aussen aber nicht drauf

demnach funzt die regel nur von aussen nach innen, wie kann ich das nun drehen ?

Funktioniert das nun auch, dass wenn beispieslweise auf dem Server selbst ein Dienst laufen würde der über bestimmte Ports etwas tun möchte, dies nicht mehr möglich ist (Beispiel, jemand installiert über ne Shell einen Eggdrop - das soll nicht funzen)

Hi,

eine Firewall hat auf einem Server nix zu suchen...

Wenn jemand was installieren kann, kann er höchst wahrscheinlich auch die Firewall manipulieren.

Dienste die man nicht benötigt schaltet man ab oder konfiguriert sie so, das sie nur das machen was man will. Ansonsten hilft nur Security Listen zu verfolgen und bei aufkommenden exploits zu patchen.

Wenn du auf Nummer sicher gehen willst, muss die Firewall zwischen web und Rechner stehen.

Gruß Jaraz

...

eine Firewall hat auf einem Server nix zu suchen...

...

Wenn du auf Nummer sicher gehen willst, muss die Firewall zwischen web und Rechner stehen.

...

So pauschal würde ich das nicht unterschreiben.

Was wenn Du z.B. nur eingehende Pakete von bestimmten IP-Adressen im LAN annehmen willst?

Oder nur bestimmte Zieladressen im selben LAN zulassen willst?

Was ich Dir unterschreiben würde wäre dass ein Rechner, auf den über ein öffentliches Netz zugegriffen wird,

in eine DMZ mit dedizierter FireWall gehört.

Bye

SystemError

PS: Ähhh... Sorry das OffTopic Gesülze.

Archiv

Dieses Thema wurde archiviert und kann nicht mehr beantwortet werden.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.