Creare un firewall

Postate qui per tutte le discussioni legate alla sicurezza di Linux/Slackware

Moderatore: Staff

Regole del forum
1) Citare sempre la versione di Slackware usata, la versione del Kernel e magari anche la versione della libreria coinvolta. Questi dati aiutano le persone che possono rispondere.
2) Specificare se discussione/suggerimento o richiesta d'aiuto.
3) Leggere attentamente le risposte ricevute.
4) Scrivere i messaggi con il colore di default, evitare altri colori.
5) Scrivere in Italiano o in Inglese, se possibile grammaticalmente corretto, evitate stili di scrittura poco chiari, quindi nessuna abbreviazione tipo telegramma o scrittura stile SMS o CHAT.
6) Appena registrati è consigliato presentarsi nel forum dedicato.

La non osservanza delle regole porta a provvedimenti di vari tipo da parte dello staff, in particolare la non osservanza della regola 5 porta alla cancellazione del post e alla segnalazione dell'utente. In caso di recidività l'utente rischia il ban temporaneo.
Avatar utente
darkstaring
Linux 3.x
Linux 3.x
Messaggi: 657
Iscritto il: mer 13 ott 2010, 13:55
Nome Cognome: Francesco Achenza
Desktop: KDE
Distribuzione: Arch Linux
Contatta:

Creare un firewall

Messaggio da darkstaring »

Olà, stavo dando un'occhiata al Wiki di Alien ed ho trovato il generatore di
Firewall http://connie.slackware.com/~alien/efg/...
Volevo sapere se è ottimizabile, ho notato molte cose commentate..Questo è il sorgente:

Codice: Seleziona tutto

#!/bin/sh
#
# Generated iptables firewall script for the Linux 2.4 kernel and later.
# Script generated by Easy Firewall Generator for IPTables 1.15
# copyright 2002 Timothy Scott Morizot
# Modified for Slackware Linux by Eric Hameleers <alien@slackware.com>
# 
# This generator is adapted from the original to work on Slackware Linux.
# Basically, I corrected the path name to the iptables* commands
# and re-wrote this comment.
#
# It can be executed with the typical start and stop arguments.
# If used with stop, it will stop after flushing the firewall.
# The save and restore arguments will save or restore the rules
# from the /etc/sysconfig/iptables file.  The save and restore
# arguments are included to preserve compatibility with
# Redhat's or Fedora's init.d script if you prefer to use it.

# You may want to save this script as /etc/rc.d/rc.firewall
# and make it executable, like this:
#   chmod +x /etc/rc.d/rc.firewall
# Slackware Linux will then automatically run this script
# with the "start" parameter.

###############################################################################
# 
# Local Settings
#

# sysctl location.  If set, it will use sysctl to adjust the kernel parameters.
# If this is set to the empty string (or is unset), the use of sysctl
# is disabled.

SYSCTL="/sbin/sysctl -w" 

# To echo the value directly to the /proc file instead
# SYSCTL=""

# IPTables Location - adjust if needed

IPT="/usr/sbin/iptables"
IPTS="/usr/sbin/iptables-save"
IPTR="/usr/sbin/iptables-restore"

# Internet Interface
INET_IFACE="wlan0"

# Localhost Interface

LO_IFACE="lo"
LO_IP="127.0.0.1"

# Save and Restore arguments handled here
if [ "$1" = "save" ]
then
	echo -n "Saving firewall to /etc/sysconfig/iptables ... "
	$IPTS > /etc/sysconfig/iptables
	echo "done"
	exit 0
elif [ "$1" = "restore" ]
then
	echo -n "Restoring firewall from /etc/sysconfig/iptables ... "
	$IPTR < /etc/sysconfig/iptables
	echo "done"
	exit 0
fi

###############################################################################
#
# Load Modules
#

echo "Loading kernel modules ..."

# You should uncomment the line below and run it the first time just to
# ensure all kernel module dependencies are OK.  There is no need to run
# every time, however.

# /sbin/depmod -a

# Unless you have kernel module auto-loading disabled, you should not
# need to manually load each of these modules.  Other than ip_tables,
# ip_conntrack, and some of the optional modules, I've left these
# commented by default.  Uncomment if you have any problems or if
# you have disabled module autoload.  Note that some modules must
# be loaded by another kernel module.

# core netfilter module
/sbin/modprobe ip_tables

# the stateful connection tracking module
/sbin/modprobe ip_conntrack

# filter table module
# /sbin/modprobe iptable_filter

# mangle table module
# /sbin/modprobe iptable_mangle

# nat table module
# /sbin/modprobe iptable_nat

# LOG target module
# /sbin/modprobe ipt_LOG

# This is used to limit the number of packets per sec/min/hr
# /sbin/modprobe ipt_limit

# masquerade target module
# /sbin/modprobe ipt_MASQUERADE

# filter using owner as part of the match
# /sbin/modprobe ipt_owner

# REJECT target drops the packet and returns an ICMP response.
# The response is configurable.  By default, connection refused.
# /sbin/modprobe ipt_REJECT

# This target allows packets to be marked in the mangle table
# /sbin/modprobe ipt_mark

# This target affects the TCP MSS
# /sbin/modprobe ipt_tcpmss

# This match allows multiple ports instead of a single port or range
# /sbin/modprobe multiport

# This match checks against the TCP flags
# /sbin/modprobe ipt_state

# This match catches packets with invalid flags
# /sbin/modprobe ipt_unclean

# The ftp nat module is required for non-PASV ftp support
/sbin/modprobe ip_nat_ftp

# the module for full ftp connection tracking
/sbin/modprobe ip_conntrack_ftp

# the module for full irc connection tracking
/sbin/modprobe ip_conntrack_irc


###############################################################################
#
# Kernel Parameter Configuration
#
# See http://ipsysctl-tutorial.frozentux.net/chunkyhtml/index.html
# for a detailed tutorial on sysctl and the various settings
# available.

# Required to enable IPv4 forwarding.
# Redhat users can try setting FORWARD_IPV4 in /etc/sysconfig/network to true
# Alternatively, it can be set in /etc/sysctl.conf
#if [ "$SYSCTL" = "" ]
#then
#    echo "1" > /proc/sys/net/ipv4/ip_forward
#else
#    $SYSCTL net.ipv4.ip_forward="1"
#fi

# This enables dynamic address hacking.
# This may help if you have a dynamic IP address \(e.g. slip, ppp, dhcp\).
#if [ "$SYSCTL" = "" ]
#then
#    echo "1" > /proc/sys/net/ipv4/ip_dynaddr
#else
#    $SYSCTL net.ipv4.ip_dynaddr="1"
#fi

# This enables SYN flood protection.
# The SYN cookies activation allows your system to accept an unlimited
# number of TCP connections while still trying to give reasonable
# service during a denial of service attack.
if [ "$SYSCTL" = "" ]
then
    echo "1" > /proc/sys/net/ipv4/tcp_syncookies
else
    $SYSCTL net.ipv4.tcp_syncookies="1"
fi

# This enables source validation by reversed path according to RFC1812.
# In other words, did the response packet originate from the same interface
# through which the source packet was sent?  It's recommended for single-homed
# systems and routers on stub networks.  Since those are the configurations
# this firewall is designed to support, I turn it on by default.
# Turn it off if you use multiple NICs connected to the same network.
if [ "$SYSCTL" = "" ]
then
    echo "1" > /proc/sys/net/ipv4/conf/all/rp_filter
else
    $SYSCTL net.ipv4.conf.all.rp_filter="1"
fi

# This option allows a subnet to be firewalled with a single IP address.
# It's used to build a DMZ.  Since that's not a focus of this firewall
# script, it's not enabled by default, but is included for reference.
# See: http://www.sjdjweis.com/linux/proxyarp/ 
#if [ "$SYSCTL" = "" ]
#then
#    echo "1" > /proc/sys/net/ipv4/conf/all/proxy_arp
#else
#    $SYSCTL net.ipv4.conf.all.proxy_arp="1"
#fi

# The following kernel settings were suggested by Alex Weeks. Thanks!

# This kernel parameter instructs the kernel to ignore all ICMP
# echo requests sent to the broadcast address.  This prevents
# a number of smurfs and similar DoS nasty attacks.
if [ "$SYSCTL" = "" ]
then
    echo "1" > /proc/sys/net/ipv4/icmp_echo_ignore_broadcasts
else
    $SYSCTL net.ipv4.icmp_echo_ignore_broadcasts="1"
fi

# This option can be used to accept or refuse source routed
# packets.  It is usually on by default, but is generally
# considered a security risk.  This option turns it off.
if [ "$SYSCTL" = "" ]
then
    echo "0" > /proc/sys/net/ipv4/conf/all/accept_source_route
else
    $SYSCTL net.ipv4.conf.all.accept_source_route="0"
fi

# This option can disable ICMP redirects.  ICMP redirects
# are generally considered a security risk and shouldn't be
# needed by most systems using this generator.
#if [ "$SYSCTL" = "" ]
#then
#    echo "0" > /proc/sys/net/ipv4/conf/all/accept_redirects
#else
#    $SYSCTL net.ipv4.conf.all.accept_redirects="0"
#fi

# However, we'll ensure the secure_redirects option is on instead.
# This option accepts only from gateways in the default gateways list.
if [ "$SYSCTL" = "" ]
then
    echo "1" > /proc/sys/net/ipv4/conf/all/secure_redirects
else
    $SYSCTL net.ipv4.conf.all.secure_redirects="1"
fi

# This option logs packets from impossible addresses.
if [ "$SYSCTL" = "" ]
then
    echo "1" > /proc/sys/net/ipv4/conf/all/log_martians
else
    $SYSCTL net.ipv4.conf.all.log_martians="1"
fi


###############################################################################
#
# Flush Any Existing Rules or Chains
#

echo "Flushing Tables ..."

# Reset Default Policies
$IPT -P INPUT ACCEPT
$IPT -P FORWARD ACCEPT
$IPT -P OUTPUT ACCEPT
$IPT -t nat -P PREROUTING ACCEPT
$IPT -t nat -P POSTROUTING ACCEPT
$IPT -t nat -P OUTPUT ACCEPT
$IPT -t mangle -P PREROUTING ACCEPT
$IPT -t mangle -P OUTPUT ACCEPT

# Flush all rules
$IPT -F
$IPT -t nat -F
$IPT -t mangle -F

# Erase all non-default chains
$IPT -X
$IPT -t nat -X
$IPT -t mangle -X

if [ "$1" = "stop" ]
then
	echo "Firewall completely flushed!  Now running with no firewall."
	exit 0
fi
E se sia possibile aggiungere la porta ethernet così:

# Internet Interface
INET_IFACE="wlan0" "eth0"

o così

# Internet Interface
INET_IFACE="wlan0 eth0"

Grazieee
Ultima modifica di darkstaring il sab 4 dic 2010, 2:13, modificato 1 volta in totale.

Avatar utente
krisis
Linux 4.x
Linux 4.x
Messaggi: 1120
Iscritto il: mar 25 gen 2005, 0:00
Distribuzione: debian
Località: Roma

Re: Easy Firewall AlienBob

Messaggio da krisis »

Non l'ho letto tutto ma mi pare tagliato su misura per una sola scheda di rete , per tanto :

Codice: Seleziona tutto

INET_IFACE="ethX"
è il valore corretto , dove X è l'id relativo alla tua interfaccia ethernet.

Avatar utente
darkstaring
Linux 3.x
Linux 3.x
Messaggi: 657
Iscritto il: mer 13 ott 2010, 13:55
Nome Cognome: Francesco Achenza
Desktop: KDE
Distribuzione: Arch Linux
Contatta:

Re: Easy Firewall AlienBob

Messaggio da darkstaring »

E se voglio usare più periferiche? devo ricopiare il tutto ed aggiungere INET_IFACE2="eth0" e anche tutti i rispettivi INET_IFACE?

Avatar utente
krisis
Linux 4.x
Linux 4.x
Messaggi: 1120
Iscritto il: mar 25 gen 2005, 0:00
Distribuzione: debian
Località: Roma

Re: Easy Firewall AlienBob

Messaggio da krisis »

Se devi fare un firewall per gestire più periferiche devi studiarti iptables e farti il tuo script su misura.

Avatar utente
darkstaring
Linux 3.x
Linux 3.x
Messaggi: 657
Iscritto il: mer 13 ott 2010, 13:55
Nome Cognome: Francesco Achenza
Desktop: KDE
Distribuzione: Arch Linux
Contatta:

Re: Easy Firewall AlienBob

Messaggio da darkstaring »

Ho dato un'occhiata a wikipedia, ma non saprei cosa acettare e cosa no...
Una bella guida???... magari in italiano
Thank's

hashbang
Packager
Packager
Messaggi: 2021
Iscritto il: ven 4 giu 2010, 10:27
Nome Cognome: Luca De Pandis
Distribuzione: macOS/OpenBSD
Località: Lecce/Bergamo

Re: Easy Firewall AlienBob

Messaggio da hashbang »

darkstaring ha scritto:Ho dato un'occhiata a wikipedia, ma non saprei cosa acettare e cosa no...
Una bella guida???... magari in italiano
Thank's
Sito ufficiale
Ubuntu-it wiki

Inoltre, appena Loris aggiorna il repository x86, troverai gtk-iptables che è un frontend grafico scritto in gtk+.

albatross
Linux 0.x
Linux 0.x
Messaggi: 97
Iscritto il: mar 21 ott 2003, 0:00
Contatta:

Re: Creare un firewall

Messaggio da albatross »

un bel po di tempo fa ne abbiamo discusso qui [url]viewtopic.php?f=2&t=165&hilit=albatross[/url] con useless

Avatar utente
DarthSteve
Linux 1.x
Linux 1.x
Messaggi: 127
Iscritto il: mer 1 apr 2009, 10:00
Nome Cognome: Stefano
Slackware: --Current--
Kernel: 5.15..x
Desktop: KDE
Località: Lucca

Re: Creare un firewall

Messaggio da DarthSteve »

Messaggio da darkstaring » 12/02/2010, 10:55 pm
E se voglio usare più periferiche? devo ricopiare il tutto ed aggiungere INET_IFACE2="eth0" e anche
tutti i rispettivi INET_IFACE?
Puoi usare, eg.:

Codice: Seleziona tutto

# External Interface
EXT_IF="eth0 wlan0"

for IF in ${EXT_IF} ; do
     iptables -A INPUT -i ${IF} -p all -m state --state INVALID -j DROP
     ..etc...
 done
or in alternativa:

Codice: Seleziona tutto

for IF in eth0 wlan0 ; do
     iptables -A INPUT -i ${IF} -p all -m state --state INVALID -j DROP
done
- C'e un tutorial di Oskar Andreasson (in inglese) al URL http://www.frozentux.net/documents/iptables-tutorial/
che include alcuni esempi di configurazione per diverse tipologie di firewall.
--- The Jedi Code ---
There is no emotion; there is peace.
There is no ignorance; there is knowledge.
There is no passion; there is serenity.
There is no death; there is the Force

Avatar utente
marlavo
Linux 1.x
Linux 1.x
Messaggi: 180
Iscritto il: ven 2 lug 2010, 16:38
Nome Cognome: Marco Lavorini
Slackware: 15.0 x86_x64
Kernel: 6.6.21
Desktop: XFCE 4.18

Re: Creare un firewall

Messaggio da marlavo »

Oppure, se non ti interessa studiare iptables ma semplicemente vuoi creare un firewall, uno tool che secondo me è molto interessante è Firewall Builder:

Codice: Seleziona tutto

http://www.slacky.eu/aadm/pkgs/index.php?ver=14&pkg=1884
Io l'ho usato per creare un semplice firewall sulla connessione Internet con modem (chiavetta), ma sicuramente fwbuilder ti consente di creare firewall per reti assai più complesse, con il vantaggio di avere un'interfaccia grafica che ti permette di capire "al volo" cosa fa il firewall. Il bello è che alla fine crea uno script che altro non fa che usare iptables, quindi se il risultato non ti soddisfa puoi sempre modificare questo script.

Spero di esserti stato di aiuto.

Avatar utente
boh
Linux 4.x
Linux 4.x
Messaggi: 1027
Iscritto il: ven 16 set 2005, 0:00
Slackware: 14.2 (x64)
Kernel: 4.4.111
Desktop: KDE 4.14.32
Località: Milano
Contatta:

Re: Creare un firewall

Messaggio da boh »

Una guida che potrebbe esserti utile la trovi a questo indirizzo (è in inglese): http://www.thegeekstuff.com/2011/01/ipt ... damentals/
"Be yourself. Everyone else is already taken." ~ Oscar Wilde

leocata
Linux 3.x
Linux 3.x
Messaggi: 598
Iscritto il: mar 5 feb 2008, 22:25
Slackware: 13.1
Desktop: xfce 4.x
Località: Giarre(CT)
Contatta:

Re: Creare un firewall

Messaggio da leocata »

Il problema del firewall me lo sono sempre posto... ma obbiettivamente non ho avuto molto tempo per studiarmi IPtables e quindi da utonto (hihihi) ho preso il file presente in /etc/ppp/firewall-standalone e l'ho modificato cambiando solo una riga (quella in grassetto)... e l'ho copiato in /etc/rc.d/rc.firewall dando ovviamente i seguenti permessi -rwxr-xr-x Avrò fatto bene ??? boh? ma da una prima lettura mi sembra sufficiente.

Codice: Seleziona tutto

#!/bin/sh
#
# firewall-standalone	This script sets up firewall rules for a standalone
#                       machine
#
# Copyright (C) 2005 Roaring Penguin Software Inc.  This software may
# be distributed under the terms of the GNU General Public License, version
# 2 or any later version.
# LIC: GPL
echo "lancio il firewall"
# Interface to Internet
[b]EXTIF=wlan0[/b]

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

iptables -F FORWARD
iptables -F INPUT
iptables -F OUTPUT

# Deny TCP and UDP packets to privileged ports
iptables -A INPUT -p udp -i $EXTIF --dport 0:1023 -j LOG
iptables -A INPUT -p tcp -i $EXTIF --dport 0:1023 -j LOG
iptables -A INPUT -p udp -i $EXTIF --dport 0:1023 -j DROP
iptables -A INPUT -p tcp -i $EXTIF --dport 0:1023 -j DROP

# Deny TCP connection attempts
iptables -A INPUT -i $EXTIF -p tcp --syn -j LOG
iptables -A INPUT -i $EXTIF -p tcp --syn -j DROP

# Deny ICMP echo-requests
iptables -A INPUT -i $EXTIF -p icmp --icmp-type echo-request -j DROP

albatross
Linux 0.x
Linux 0.x
Messaggi: 97
Iscritto il: mar 21 ott 2003, 0:00
Contatta:

Re: Creare un firewall

Messaggio da albatross »

@leocata

quale è il compito di questo firewall?
Dimmi che cosa devi proteggere e quali esigenze di connessione hai.

C'è un'incongruenza tra i comandi -P e - F che hai dato

-P definisce il comportamento predefinito per quella catena mentre -F azzera tutte le regole per quella catena. In pratica con -F hai annullato i comandi dati nelle righe precedenti...

notsafe
Linux 2.x
Linux 2.x
Messaggi: 451
Iscritto il: mar 21 mar 2006, 11:00

Re: Creare un firewall

Messaggio da notsafe »

albatross ha scritto: C'è un'incongruenza tra i comandi -P e - F che hai dato

-P definisce il comportamento predefinito per quella catena mentre -F azzera tutte le regole per quella catena. In pratica con -F hai annullato i comandi dati nelle righe precedenti...
in realtà -F (flush) elimina tutte le rules nella catena,non cambia la policy impostata in precedenza.

ilmich
Master
Master
Messaggi: 1645
Iscritto il: lun 16 lug 2007, 17:39
Slackware: 15.0 64bit
Kernel: 5.15.27
Desktop: kde
Località: Roma

Re: Creare un firewall

Messaggio da ilmich »

Un bel po' di tempo fa diedi un'occhiata a questo qui, molto potente e anche in versione lite.
Ti consente di scrivere regole in modo piu' "umano" che poi lui a runtime converte in comandi iptables.
Non ho controllato qui, ma su SlackBuilds trovi come farti il pacchetto

Comunque se il firewall non ha "grandi" pretese, anche io ti consiglio di studiare iptables, o sistemare quello che hai trovato come ti spiegava DarthSteve.
#LiveSimple and #ProgramThings
https://github.com/ilmich
http://ilmich6502.it/

leocata
Linux 3.x
Linux 3.x
Messaggi: 598
Iscritto il: mar 5 feb 2008, 22:25
Slackware: 13.1
Desktop: xfce 4.x
Località: Giarre(CT)
Contatta:

Re: Creare un firewall

Messaggio da leocata »

Premesso che questi settaggi sono presenti in qualsiasi slakware nel file presente in /etc/ppp/fi**** detto questo, le righe stabiliscono
le politiche INPUT-OUTPUT-FORWARD DEFAULT
iptables -P INPUT ACCEPT
iptables -P OUTPUT ACCEPT
e poi il resto è commentato... tuttavia ripeto l'avevo preso per buono, perchè presente di default e poi ho letto:
# firewall-standalone This script sets up firewall rules for a standalone
# machine

Rispondi