PDA

Archiv verlassen und diese Seite im Standarddesign anzeigen : Firewall richtig konfiguriert?



Freymuth
28.07.15, 14:39
HeyHo,

ich beschäftige mich gerade mit der Absicherung meines Debian Servers.
Ich habe dazu ein Bash-Script geschrieben. Was haltet ihr davon? :) Anregungen und Verbesserungen erwünscht.



#!/bin/bash

echo "Initializing Firewall ..."

# Load modules
modprobe ip_conntrack_ftp

# Clear all other rules
iptables -F
iptables -X
iptables -P INPUT DROP
iptables -P OUTPUT DROP
iptables -P FORWARD DROP

# Creation of my own chains
iptables -N mydrop

# Configuring our own chains
iptables -A mydrop -j LOG --log-prefix "FW-DROP: "
iptables -A mydrop -j DROP

# Loopback communication
iptables -A INPUT -i lo -j ACCEPT
iptables -A OUTPUT -o lo -j ACCEPT

# Statefull Inspection
iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -A INPUT -m state --state INVALID -j mydrop
iptables -A OUTPUT -m state --state ESTABLISHED,RELATED -j ACCEPT

# SSH
iptables -A INPUT -p tcp --dport 22 -m state --state NEW -j ACCEPT
#iptables -A OUTPUT -p tcp --dport 22 -m state --state NEW -j ACCEPT

# ICMP Ping
iptables -A INPUT -p icmp -m state --state NEW -j ACCEPT
iptables -A OUTPUT -p icmp -m state --state NEW -j ACCEPT

# DNS
#iptables -A INPUT -p udp --dport 53 -m state --state NEW -j ACCEPT
#iptables -A INPUT -p tcp --dport 53 -m state --state NEW -j ACCEPT
#iptables -A OUTPUT -p udp --dport 53 -m state --state NEW -j ACCEPT
#iptables -A OUTPUT -p tcp --dport 53 -m state --state NEW -j ACCEPT

# WWW
#iptables -A INPUT -p tcp --dport 80 -m state --state NEW -j ACCEPT
#iptables -A OUTPUT -p tcp --dport 80 -m state --state NEW -j ACCEPT
#iptables -A INPUT -p tcp --dport 443 -m state --state NEW -j ACCEPT
#iptables -A OUTPUT -p tcp --dport 443 -m state --state NEW -j ACCEPT

# Mail
#iptables -A INPUT -p tcp --dport 25 -m state --state NEW -j ACCEPT
#iptables -A OUTPUT -p tcp --dport 25 -m state --state NEW -j ACCEPT
#iptables -A INPUT -p tcp --dport 110 -m state --state NEW -j ACCEPT
#iptables -A INPUT -p tcp --dport 143 -m state --state NEW -j ACCEPT

# FTP
iptables -A INPUT -p tcp --dport 21 -m state --state NEW -j ACCEPT
iptables -A OUTPUT -p tcp --dport 21 -m state --state NEW -j ACCEPT

# DHCP
#iptacles -A INPUT -p udp --dport 67 -m state --state NEW -j ACCEPT

#Teamspeak 3 Server
iptables -A INPUT -p udp --dport 9987 -m state --state NEW -j ACCEPT
iptables -A INPUT -p tcp --dport 30033 -m state --state NEW -j ACCEPT
iptables -A INPUT -p tcp --dport 10011 -m state --state NEW -j ACCEPT
iptables -A OUTPUT -p udp --dport 2010 -m state --state NEW -j ACCEPT
iptables -A INPUT -p tcp --dport 41144 -m state --state NEW -j ACCEPT
iptables -A OUTPUT -p tcp --dport 2008 -m state --state NEW -j ACCEPT


echo "Firewall is configured and active!"

iptables -A INPUT -j LOG --log-prefix "FW-NOT-MATCHED:"
iptables -A INPUT -j DROP
iptables -A OUTPUT -j LOG --log-prefix "FW-NOT-MATCHED:"
iptables -A OUTPUT -j DROP

exit 0

DrunkenFreak
28.07.15, 15:38
iptables -A INPUT -j DROP
iptables -A OUTPUT -j DROP

Das ist redundant. Du gibts ihm oben schon die Policy DROP.

Prinzipiell dürfte das Absicherung genug sein. Du lässt aber nur alle relevanten Dienste durch, daher kann man sich meiner Meinung nach die Firewall sparen. Denn, wo kein Port offen, kann auch nichts reinkommen. Schalte lieber ungenutzte Dienste ab.

fork
28.07.15, 16:58
Hallo Freymuth,

bitte Doppelposts kennzeichnen. Danke!

https://debianforum.de/forum/viewtopic.php?f=37&t=156512

Grüße,
fork();

Freymuth
28.07.15, 19:43
@Drunkenfreak
Danke. Wie müsste es denn dann heißen? input oder output rausnehmen? O.o

Liebe Grüße

DrunkenFreak
28.07.15, 20:02
Beide. Diese Regeln sind durch die Policy DROP abgegolten.

Freymuth
28.07.15, 20:54
Alles klar, danke. ^^