iptables non funziona come vorrei

Sicurezza del sistema: firewall, antispam, antivirus, ssh, patch, bug, eccetera.
snt
Prode Principiante
Messaggi: 42
Iscrizione: lunedì 16 ottobre 2006, 20:34

iptables non funziona come vorrei

Messaggio da snt »

ovviamente perchè sbaglio qualcosa io, ma con l'aiuto di qualche utente più esperto vorrei capire dove sbaglio.


su questo forum ho trovato uno script per settare iptables secondo le occorrenze di ognuno, l'ho quindi copiato e modificato per le mie esigenze:

Codice: Seleziona tutto

#!/bin/bash
#
# Firewall
############################################

#########################
# Definizione Variabili #
#########################
IPTABLES="/sbin/iptables"
IFLO="lo"
IFEXT="eth0"                    # Da sostituire con la propria interfaccia: eth0, eth1, ppp0, etc

case "$1" in
  start)
        ########################
        # Attivazione Firewall #
        ########################
        echo -n "Attivazione Firewall:    "

        #################################
        # Caricamento Moduli del Kernel #
        #################################
        modprobe ip_tables
        modprobe iptable_nat
        modprobe ip_conntrack
        modprobe ip_conntrack_ftp
        modprobe ip_nat_ftp
        modprobe ipt_LOG
        modprobe ipt_MARK
        modprobe ipt_MASQUERADE
        modprobe ipt_REDIRECT
        modprobe ipt_REJECT
        modprobe ipt_TOS
        modprobe ipt_limit
        modprobe ipt_mac
        modprobe ipt_mark
        modprobe ipt_multiport
        modprobe ipt_state
        modprobe ipt_tos
        modprobe iptable_mangle

        ############################
        # Reset delle impostazioni #
        ############################
        $IPTABLES -F
        $IPTABLES -F -t nat
        $IPTABLES -F -t mangle
        $IPTABLES -X
        $IPTABLES -X -t nat
        $IPTABLES -X -t mangle

        ################################
        # Impostazione Policy standard #
        ################################
        $IPTABLES -P INPUT   DROP
        $IPTABLES -P FORWARD DROP
        $IPTABLES -P OUTPUT  ACCEPT

        #################################
        # Abilitazione traffico interno #
        #################################
        $IPTABLES -A INPUT  -i $IFLO -j ACCEPT
        $IPTABLES -A OUTPUT -o $IFLO -j ACCEPT

        #############################################################################
        # Regole                                                                    #
        #############################################################################
        $IPTABLES -A INPUT -p  tcp -i $IFEXT -m state -s 0/0 --state ESTABLISHED,RELATED -j ACCEPT
        $IPTABLES -A INPUT -p icmp -i $IFEXT -m state -s 0/0 --state ESTABLISHED,RELATED -j ACCEPT
        $IPTABLES -A INPUT -p  udp -i $IFEXT -m state -s 0/0 --state ESTABLISHED,RELATED -j ACCEPT
        $IPTABLES -A INPUT -p tcp -i $IFEXT --dport 80 -j ACCEPT
        $IPTABLES -A INPUT -p tcp -i $IFEXT --dport 22 -j ACCEPT
        $IPTABLES -A INPUT -p tcp  -i $IFEXT --dport 20:21 -j ACCEPT
        $IPTABLES -A INPUT -p tcp -i $IFEXT --dport 60000:60050 -j ACCEPT
        $IPTABLES -A OUTPUT -p  tcp -m state -s 0/0 --state ESTABLISHED,RELATED -j ACCEPT
        $IPTABLES -A OUTPUT -p icmp -m state -s 0/0 --state ESTABLISHED,RELATED -j ACCEPT
        $IPTABLES -A OUTPUT -p  udp -m state -s 0/0 --state ESTABLISHED,RELATED -j ACCEPT
        $IPTABLES -A OUTPUT -p icmp --icmp-type echo-request -j ACCEPT
        $IPTABLES -A OUTPUT -p tcp --dport 80 -j ACCEPT
        $IPTABLES -A OUTPUT -p tcp --dport 443 -j ACCEPT
        $IPTABLES -A OUTPUT -p tcp --dport 20:21 -j ACCEPT
        $IPTABLES -A OUTPUT -p tcp --dport 43 -j ACCEPT
        $IPTABLES -A OUTPUT -p tcp --dport 123 -j ACCEPT
        $IPTABLES -A OUTPUT -p tcp -j REJECT --reject-with tcp-reset

        echo "ok"
        ;;

  stop)
        ###########################
        # Disattivazione Firewall #
        ###########################
        echo -n "Disattivazione Firewall: "

        $IPTABLES -F
        $IPTABLES -F -t nat
        $IPTABLES -F -t mangle
        $IPTABLES -X
        $IPTABLES -X -t nat
        $IPTABLES -X -t mangle

        $IPTABLES -P INPUT   ACCEPT
        $IPTABLES -P FORWARD ACCEPT
        $IPTABLES -P OUTPUT  ACCEPT

        echo "ok"
        ;;

  status)
        ##############################
        # Display stato del Firewall #
        ##############################
        echo -n "Regole attuali nel Firewall: "

        $IPTABLES -L
        ;;

  restart|reload)
        $0 stop
        $0 start
        ;;

  *)
        echo "Utilizzo: firewall {start|stop|restart|reload|status}" >&2
        exit 1
        ;;

esac

exit 0
il mio server fa da webserver, da server ssh e da server ftp.
quello che non mi torna è perchè così come è impostato il firewall tutto funziona, ma se cambio la policy standard
$IPTABLES -P OUTPUT  ACCEPT
droppandola
$IPTABLES -P OUTPUT  DROP

ftp non funziona più (mentre ssh si per esempio).
eppure le porte 20 e 21 le ho aperte sia in input che in output, perciò dovrebbe comunque funzionare...
chi mi spiega dove sbaglio?
Avatar utente
fortran77
Entusiasta Emergente
Entusiasta Emergente
Messaggi: 1385
Iscrizione: sabato 29 dicembre 2007, 9:44
Desktop: Xfce, iconoclasta
Distribuzione: Gentoo o Xubuntu, dipende
Località: Firenze (collina)

Re: iptables non funziona come vorrei

Messaggio da fortran77 »

Ftp non si appoggia solo alle porte 20 e 21.
Ftp è un bel casino perché apre delle porte random da cui parte il trasferimento file, serve un metodo dinamico per aprire/chiudere le porte se vuoi firewallare iptables anche in uscita.

P.S. Sei sicuro di voler chiudere le porte anche in uscita? Non ti fidi degli utenti della tua rete?
any man's death diminishes me, because I am involved in mankind, and therefore never send to know for whom the bell tolls; it tolls for thee.    --- John Donne
snt
Prode Principiante
Messaggi: 42
Iscrizione: lunedì 16 ottobre 2006, 20:34

Re: iptables non funziona come vorrei

Messaggio da snt »

fortran77 ha scritto: Ftp non si appoggia solo alle porte 20 e 21.
Ftp è un bel casino perché apre delle porte random da cui parte il trasferimento file, serve un metodo dinamico per aprire/chiudere le porte se vuoi firewallare iptables anche in uscita.

P.S. Sei sicuro di voler chiudere le porte anche in uscita? Non ti fidi degli utenti della tua rete?
esattamente, voglio bloccare qualsiasi possibilità di uscita.
anche perchè se viene compromesso il server web/ftp avendolo per altre ragioni dovuto mettere in rete con gli altri server, ne andrebbe della sicurezza degli altri server.
per questo vorrei blindarlo il più possibile.

so che ftp usa delle porte randomiche per la modalità passiva, infatti le ho aperte in input:
        $IPTABLES -A INPUT -p tcp -i $IFEXT --dport 60000:60050 -j ACCEPT

e lato ftp server ho forzato pure-ftpd ad usare quel range di porte.

però non funziona ugualmente se droppo di default il traffico in output
Avatar utente
fortran77
Entusiasta Emergente
Entusiasta Emergente
Messaggi: 1385
Iscrizione: sabato 29 dicembre 2007, 9:44
Desktop: Xfce, iconoclasta
Distribuzione: Gentoo o Xubuntu, dipende
Località: Firenze (collina)

Re: iptables non funziona come vorrei

Messaggio da fortran77 »

Ma le usa solo in entrata?
Prova ad aprirle anche in uscita.
any man's death diminishes me, because I am involved in mankind, and therefore never send to know for whom the bell tolls; it tolls for thee.    --- John Donne
snt
Prode Principiante
Messaggi: 42
Iscrizione: lunedì 16 ottobre 2006, 20:34

Re: iptables non funziona come vorrei

Messaggio da snt »

fatto.
non cambia nulla. :-\
snt
Prode Principiante
Messaggi: 42
Iscrizione: lunedì 16 ottobre 2006, 20:34

Re: iptables non funziona come vorrei

Messaggio da snt »

riporto su nella speranza che qualcuno legga e mi sappia dare una mano...
Scrivi risposta

Ritorna a “Sicurezza”

Chi c’è in linea

Visualizzano questa sezione: 0 utenti iscritti e 2 ospiti