View previous topic :: View next topic |
Author |
Message |
Cazzantonio Bodhisattva


Joined: 20 Mar 2004 Posts: 4514 Location: Somewere around the world
|
Posted: Sat Mar 18, 2006 1:14 am Post subject: |
|
|
basta aprire le porte usate dal servizio richiesto... _________________ Any mans death diminishes me, because I am involved in Mankinde; and therefore never send to know for whom the bell tolls; It tolls for thee.
-John Donne |
|
Back to top |
|
 |
quantumwire Guru


Joined: 15 Oct 2003 Posts: 403 Location: Lausanne
|
Posted: Mon Mar 20, 2006 10:15 am Post subject: |
|
|
Cazzantonio wrote: | basta aprire le porte usate dal servizio richiesto... |
Scusa la mia ignoranza in materia ma delle regole cosi vanno bene?
Code: | iptables -A INPUT -p tcp -s 0/0 -d 0/0 -i eth0 --dport 111 -j ACCEPT
iptables -A INPUT -p udp -s 0/0 -d 0/0 -i eth0 --dport 111 -j ACCEPT
iptables -A INPUT -p tcp -s 0/0 -d 0/0 -i eth0 --dport 2049 -j ACCEPT
iptables -A INPUT -p udp -s 0/0 -d 0/0 -i eth0 --dport 2049 -j ACCEPT
iptables -A INPUT -p tcp -s 0/0 -d 0/0 -i eth0 --dport 4001 -j ACCEPT
iptables -A INPUT -p udp -s 0/0 -d 0/0 -i eth0 --dport 4001 -j ACCEPT
iptables -A INPUT -p tcp -s 0/0 -d 0/0 -i eth0 --dport 32764:32767 -j ACCEPT
iptables -A INPUT -p udp -s 0/0 -d 0/0 -i eth0 --dport 32764:32767 -j ACCEPT |
pero' non so dove metterle nel tuo script.
PS: in realta' i due teraserver che esportano i fs hanno indirizzi rispettivamente 128.178.54.117 e 128.178.54.119.
Dovrei dunque cambiare la regola in questo modo?
iptables -A INPUT -p tcp -s 128.178.54.117 -d 0/0 -i eth0 --dport 2049 -j ACCEPT
Grazie. _________________ HOWTO 1: Spegnere il laptop!
HOWTO 2: Comprimere i DVDs! |
|
Back to top |
|
 |
Cazzantonio Bodhisattva


Joined: 20 Mar 2004 Posts: 4514 Location: Somewere around the world
|
Posted: Mon Mar 20, 2006 8:56 pm Post subject: |
|
|
beh il modo corretto è creare delle catene come quelle del mio script e poi caricarle nella sezione apposita... comunque il modo migliore per vedere se funzionano è provare e vedere  _________________ Any mans death diminishes me, because I am involved in Mankinde; and therefore never send to know for whom the bell tolls; It tolls for thee.
-John Donne |
|
Back to top |
|
 |
mack1 Guru


Joined: 18 Mar 2006 Posts: 315
|
Posted: Wed Aug 02, 2006 3:22 pm Post subject: |
|
|
Ciao ragazzi mi sono accorto solo adesso che collegandomi ad internet (pppoe-start) vengono modificate alcune regole dello script di Cazzantonio:premessa uso integralmente lo script di Cazzantonio avendo però modificato(decommentato) i servizi che non uso tipo ssh o bittorrent; non faccio partire la connessione al boot ma manualmente.
Dopo il boot (eseguito senza che lo script dia errori) digitando iptables -L ho queste regole:
Code: | Chain INPUT (policy DROP)
target prot opt source destination
portscan all -- anywhere anywhere
DROP all -- anywhere anywhere state INVALID
icmp_in all -- anywhere anywhere
ACCEPT all -- anywhere anywhere
connessioni_avviate all -- anywhere anywhere
Chain FORWARD (policy DROP)
target prot opt source destination
DROP all -- anywhere anywhere state INVALID
ACCEPT all -- anywhere anywhere
connessioni_avviate all -- anywhere anywhere
Chain OUTPUT (policy ACCEPT)
target prot opt source destination
Chain connessioni_avviate (2 references)
target prot opt source destination
ACCEPT all -- anywhere anywhere state RELATED,ESTABLISHED
LOG all -- anywhere anywhere limit: avg 3/hour burst 5 LOG level warning prefix `FW:Bad packet from eth0:'
DROP all -- anywhere anywhere
Chain icmp_in (1 references)
target prot opt source destination
ACCEPT icmp -- anywhere anywhere icmp time-exceeded
ACCEPT icmp -- anywhere anywhere icmp destination-unreachable
Chain portscan (1 references)
target prot opt source destination
LOG tcp -- anywhere anywhere tcp flags:FIN,SYN,RST,PSH,ACK,URG/FIN,PSH,URG limit: avg 5/min burst 5 LOG level alert prefix `FW:SCAN:NMAP-XMAS:'
DROP tcp -- anywhere anywhere tcp flags:FIN,SYN,RST,PSH,ACK,URG/FIN,PSH,URG
LOG tcp -- anywhere anywhere tcp flags:FIN,SYN,RST,PSH,ACK,URG/FIN,SYN,RST,PSH,ACK,URG limit: avg 5/min burst 5 LOG level alert prefix `FW:SCAN:XMAS:'
DROP tcp -- anywhere anywhere tcp flags:FIN,SYN,RST,PSH,ACK,URG/FIN,SYN,RST,PSH,ACK,URG
LOG tcp -- anywhere anywhere tcp flags:FIN,SYN,RST,PSH,ACK,URG/FIN,SYN,RST,ACK,URG limit: avg 5/min burst 5 LOG level alert prefix `FW:SCAN:XMAS-PSH:'
DROP tcp -- anywhere anywhere tcp flags:FIN,SYN,RST,PSH,ACK,URG/FIN,SYN,RST,ACK,URG
LOG tcp -- anywhere anywhere tcp flags:FIN,SYN,RST,PSH,ACK,URG/NONE limit: avg 5/min burst 5 LOG level alert prefix `FW:SCAN:NULL_SCAN:'
DROP tcp -- anywhere anywhere tcp flags:FIN,SYN,RST,PSH,ACK,URG/NONE
LOG tcp -- anywhere anywhere tcp flags:SYN,RST/SYN,RST limit: avg 5/min burst 5 LOG level notice prefix `FW:SCAN:SYN/RST:'
DROP tcp -- anywhere anywhere tcp flags:SYN,RST/SYN,RST
LOG tcp -- anywhere anywhere tcp flags:FIN,SYN/FIN,SYN limit: avg 5/min burst 5 LOG level notice prefix `FW:SCAN:SYN/FIN:'
DROP tcp -- anywhere anywhere tcp flags:FIN,SYN/FIN,SYN
|
Mentre dopo la connessione le catene input e forward vengono modificate:
Code: | iptables -L
Chain INPUT (policy ACCEPT)
target prot opt source destination
LOG udp -- anywhere anywhere udp dpts:0:1023 LOG level warning
LOG tcp -- anywhere anywhere tcp dpts:0:1023 LOG level warning
DROP udp -- anywhere anywhere udp dpts:0:1023
DROP tcp -- anywhere anywhere tcp dpts:0:1023
LOG tcp -- anywhere anywhere tcp flags:FIN,SYN,RST,ACK/SYN LOG level warning
DROP tcp -- anywhere anywhere tcp flags:FIN,SYN,RST,ACK/SYN
DROP icmp -- anywhere anywhere icmp echo-request
Chain FORWARD (policy DROP)
target prot opt source destination
Chain OUTPUT (policy ACCEPT)
target prot opt source destination
Chain connessioni_avviate (0 references)
target prot opt source destination
ACCEPT all -- anywhere anywhere state RELATED,ESTABLISHED
LOG all -- anywhere anywhere limit: avg 3/hour burst 5 LOG level warning prefix `FW:Bad packet from eth0:'
DROP all -- anywhere anywhere
Chain icmp_in (0 references)
target prot opt source destination
ACCEPT icmp -- anywhere anywhere icmp time-exceeded
ACCEPT icmp -- anywhere anywhere icmp destination-unreachable
Chain portscan (0 references)
target prot opt source destination
LOG tcp -- anywhere anywhere tcp flags:FIN,SYN,RST,PSH,ACK,URG/FIN,PSH,URG limit: avg 5/min burst 5 LOG level alert prefix `FW:SCAN:NMAP-XMAS:'
DROP tcp -- anywhere anywhere tcp flags:FIN,SYN,RST,PSH,ACK,URG/FIN,PSH,URG
LOG tcp -- anywhere anywhere tcp flags:FIN,SYN,RST,PSH,ACK,URG/FIN,SYN,RST,PSH,ACK,URG limit: avg 5/min burst 5 LOG level alert prefix `FW:SCAN:XMAS:'
DROP tcp -- anywhere anywhere tcp flags:FIN,SYN,RST,PSH,ACK,URG/FIN,SYN,RST,PSH,ACK,URG
LOG tcp -- anywhere anywhere tcp flags:FIN,SYN,RST,PSH,ACK,URG/FIN,SYN,RST,ACK,URG limit: avg 5/min burst 5 LOG level alert prefix `FW:SCAN:XMAS-PSH:'
DROP tcp -- anywhere anywhere tcp flags:FIN,SYN,RST,PSH,ACK,URG/FIN,SYN,RST,ACK,URG
LOG tcp -- anywhere anywhere tcp flags:FIN,SYN,RST,PSH,ACK,URG/NONE limit: avg 5/min burst 5 LOG level alert prefix `FW:SCAN:NULL_SCAN:'
DROP tcp -- anywhere anywhere tcp flags:FIN,SYN,RST,PSH,ACK,URG/NONE
LOG tcp -- anywhere anywhere tcp flags:SYN,RST/SYN,RST limit: avg 5/min burst 5 LOG level notice prefix `FW:SCAN:SYN/RST:'
DROP tcp -- anywhere anywhere tcp flags:SYN,RST/SYN,RST
LOG tcp -- anywhere anywhere tcp flags:FIN,SYN/FIN,SYN limit: avg 5/min burst 5 LOG level notice prefix `FW:SCAN:SYN/FIN:'
DROP tcp -- anywhere anywhere tcp flags:FIN,SYN/FIN,SYN
|
Facendo ripartire il servizio "muro-di-fuoco" le regole dello script vengono ricaricate senza errori!La cosa per un niubbo come me è un mistero... come posso risolvere l'inconveniente?
Ciao Mack1 |
|
Back to top |
|
 |
mack1 Guru


Joined: 18 Mar 2006 Posts: 315
|
Posted: Thu Aug 03, 2006 12:58 pm Post subject: |
|
|
Risolto: stupidamente avevo lasciato attivo lo script che viene caricato eseguendo pppoe-start (stanalone invece di none) così caricava quelle regole.
Scusate
Ciao |
|
Back to top |
|
 |
lucapost Veteran


Joined: 24 Nov 2005 Posts: 1419 Location: <ud|me|ts> - Italy
|
Posted: Wed Oct 18, 2006 10:38 pm Post subject: Re: [Tip] Uno script di init per iptables |
|
|
Questo è il mio kernel: Code: | jarod iptables # uname -a
Linux jarod 2.6.18-gentoo-r1 #7 SMP Wed Oct 18 21:19:13 CEST 2006 x86_64 AMD Turion(tm) 64 X2 Mobile Technology TL-50 AuthenticAMD GNU/Linux |
Inoltre nel make.conf:
Code: | jarod iptables # cat /etc/make.conf | grep KEYWORDS
ACCEPT_KEYWORDS="~amd64" |
Sto cercando di imparare ad utilizzare iptables, come punto di partenza uso lo script di cazzantonio.
Preferisco comunque creare un nuovo script (non init), che ho scopiazzato dall'/etc/conf.d/muro_di_fuoco, e poi gestire il firewall con /etc/init.d/iptables e le sue opzioni.
Ora avrei qualche domanda.
Riferendomi all'inizio di questo thread:
Cazzantonio wrote: |
[b]Di default setta INPUT e FORWARD su DROP e OUTPUT su ACCEPT |
Ho mantenuto queste opzioni pure io,infatti il mio script inizia con:
Code: | $IPTABLES -F
$IPTABLES -F -t mangle
$IPTABLES -F -t nat
$IPTABLES -X
$IPTABLES -X -t mangle
$IPTABLES -X -t nat
$IPTABLES -P INPUT DROP
$IPTABLES -P OUTPUT ACCEPT
$IPTABLES -P FORWARD DROP |
ma allora è necessario definire le catene di out, come icmp in uscita, ssh in uscita, ftp in uscita, rsync in uscita, ecc?
Cazzantonio wrote: |
Per poter loggare meglio gli eventi del vostro firewall (specialmente i portscan) potete impostare dei filtri in modo da catturare gli eventi del kernel relativi a queste stringhe:
Se usate syslog-ng e avete in /etc/syslog-ng/syslog-ng.conf questa riga:
Code: | source kernsrc { file("/proc/kmsg"); }; |
allora aggiungete anche queste:
Code: | destination firewall { file("/var/log/firewall.log"); };
filter f_firewall { match ("FW:"); };
log { source(kernsrc); filter(f_firewall); destination(firewall); }; |
in modo da destinare tutti gli eventi del firewall nel file /var/log/firewall.log
|
Nel mio syslog-ng.conf c'è questa riga:
Code: | jarod iptables # cat /etc/syslog-ng/syslog-ng.conf | grep /proc/kmsg
source src { unix-stream("/dev/log"); internal(); pipe("/proc/kmsg"); }; |
Non è che me ne intendo molto, anzi, aggiungo anche io le righe consigliate?
Luca. |
|
Back to top |
|
 |
Cazzantonio Bodhisattva


Joined: 20 Mar 2004 Posts: 4514 Location: Somewere around the world
|
Posted: Thu Oct 19, 2006 8:44 am Post subject: Re: [Tip] Uno script di init per iptables |
|
|
lucapost wrote: | ma allora è necessario definire le catene di out, come icmp in uscita, ssh in uscita, ftp in uscita, rsync in uscita, ecc? |
Perché scusa? se metti out in accept?
Quote: | Nel mio syslog-ng.conf c'è questa riga:
Code: | jarod iptables # cat /etc/syslog-ng/syslog-ng.conf | grep /proc/kmsg
source src { unix-stream("/dev/log"); internal(); pipe("/proc/kmsg"); }; |
Non è che me ne intendo molto, anzi, aggiungo anche io le righe consigliate?
Luca. |
beh in quel modo definisci una sorgente "src"... io avevo fatto una cosa un pochino più specifica...
E' semplice: definisci un source, un filter, una destination e con log unisci queste tre cose
comunque non mi sembra questo il posto per mettersi a discutere in dettaglio di syslog  _________________ Any mans death diminishes me, because I am involved in Mankinde; and therefore never send to know for whom the bell tolls; It tolls for thee.
-John Donne |
|
Back to top |
|
 |
lucapost Veteran


Joined: 24 Nov 2005 Posts: 1419 Location: <ud|me|ts> - Italy
|
Posted: Thu Oct 19, 2006 9:21 am Post subject: |
|
|
non capisco, quindi nel tuo /etc/conf.d/muro_di_fuoco non è necessario definite le catene icmp_out, ssh_out, http_out, ftp_out,...
in fondo non le applichi nemmeno alla catena di OUTPUT, giusto?
Luca |
|
Back to top |
|
 |
Cazzantonio Bodhisattva


Joined: 20 Mar 2004 Posts: 4514 Location: Somewere around the world
|
Posted: Thu Oct 19, 2006 12:30 pm Post subject: |
|
|
no sono lì solo come esempio _________________ Any mans death diminishes me, because I am involved in Mankinde; and therefore never send to know for whom the bell tolls; It tolls for thee.
-John Donne |
|
Back to top |
|
 |
Cazzantonio Bodhisattva


Joined: 20 Mar 2004 Posts: 4514 Location: Somewere around the world
|
Posted: Tue May 01, 2007 3:09 pm Post subject: |
|
|
[AGGIORNAMENTO IMPORTANTE]
Ho modificato sia lo script di init che quello per il caricamento delle regole. nel primo post trovate tutti i dettagli _________________ Any mans death diminishes me, because I am involved in Mankinde; and therefore never send to know for whom the bell tolls; It tolls for thee.
-John Donne |
|
Back to top |
|
 |
Luca89 Advocate


Joined: 27 Apr 2005 Posts: 2107 Location: Agrigento (Italy)
|
Posted: Thu May 03, 2007 7:15 pm Post subject: |
|
|
Cazzantonio wrote: | [AGGIORNAMENTO IMPORTANTE]
Ho modificato sia lo script di init che quello per il caricamento delle regole. nel primo post trovate tutti i dettagli |
Tanto vale allora utilizzare lo script in /etc/firewall per creare le regole e poi lo script di avvio di iptables per caricarle, salvarle, ricaricarle all'avvio etc. _________________ Running Fast! |
|
Back to top |
|
 |
Cazzantonio Bodhisattva


Joined: 20 Mar 2004 Posts: 4514 Location: Somewere around the world
|
Posted: Thu May 03, 2007 10:16 pm Post subject: |
|
|
Ah si... anche se non mi pare che lo script di iptables possa fare molto a parte "save" e "restore" delle regole impostate. Sarò diffidente io ma non mi piace usare "save" e "restore".
In realtà basterebbe mettere in local.start lo script del firewall...
Questo script era nato in un epoca in cui lo script di iptables non esisteva. L'aggiornamento attuale infatti è nell'ottica che lo script di init ha una utilità relativa... _________________ Any mans death diminishes me, because I am involved in Mankinde; and therefore never send to know for whom the bell tolls; It tolls for thee.
-John Donne |
|
Back to top |
|
 |
alegioit Tux's lil' helper

Joined: 13 Jul 2007 Posts: 78
|
Posted: Tue Sep 18, 2007 12:17 pm Post subject: |
|
|
Ciao ragazzi, ho un piccolo problema: sono un noob assurdo di linux, ma sono deciso a cercare di imparare il più possibile!
Ho installato gentoo su vari computer ed è andato tutto bene, ma quando tento di configurare iptables sul mio serverino-gateway non riesco a farlo partire!
Vi spiego la situazione: ho 3 computer collegati su una lan interna con ip fissi 192.168.0.2-3-4 netmask 255.255.255.0 e un server che natta la lan interna sulla rete esterna ( ho fastweb 2.244.x.x ).
Ho aperto un topic a riguardo, ma cazzantonio mi ha suggerito di scrivere in questo perchè accorpa tutti i messaggi su iptables!
Dunque ho provato lo script di inizializzazione sia di cazzantonio sia di MonsterMord, ma non mi funzionano: li faccio partire e non rieso a pingare ne la rete interna, ne l'esterna, ne andare su internet con il server, la connessione ssh salta e non posso più connettermi ( ne passando dalla rete esterna ne da quella interna ); per poter nuovamente connettermi devo stoppare iptables.
Lo script che sto usando adesso è quello di MonsterMord con alcune variazioni che spero siano giuste!
Code: |
# Interfacce
IFACE=eth1 # Interfaccia interna LAN
EFACE=eth0 # Interfaccia esterna INTERNET
LAN=192.168.0.0/24
# Nameservers
NAMESERVER_1=213.140.2.12
NAMESERVER_2=213.140.2.21
|
Non so cosa possa essere, ma è come se quando faccio partire iptables e gli faccio caricare queste regole chiuda tutto e non possa passare più nulla!!
Non può essere qualche errore di compilazione del kernel ( come ho letto su una guida ho compilato tutto quello che c'era in netfilter come modulo quando possibile e built-in quando non lo era! Magari devo compilare solo alcune cose o le devo compilare come built-in? )
Di sicuro avrò fatto qualche errore, quindi ringrazio in anticipo chiunque mi risponda per la sua disponibilità!
NB: mi sono dimenticato di dirvi che ogni volta che la scheda di rete collegata all'hag parte mi dice che il valora di mtu ( 64 ) che trova è troppo basso e allora lo mette a default 512 ( o 536, nn mi ricordo ! ) può essere questo?
Last edited by alegioit on Wed Sep 19, 2007 10:22 am; edited 1 time in total |
|
Back to top |
|
 |
Cazzantonio Bodhisattva


Joined: 20 Mar 2004 Posts: 4514 Location: Somewere around the world
|
Posted: Wed Sep 19, 2007 9:16 am Post subject: |
|
|
alegioit wrote: | Ciao ragazzi, ho un piccolo problema: sono un noob assurdo di linux, ma sono deciso a cercare di imparare il più possibile! | Benissimo però forse l'argomento firewall necessiterebbe un'attimo di studio sopra...
Intanto i firewall, come concetto funzionano allo stesso modo su tutti i S.O.
In pratica devi domandarti "a che mi serve?" e "cosa ci voglio fare?". Devi capire quali servizi di rete vuoi offrire dal tuo pc, qual'è l'utilizzo del tuo pc (server, server con assolute necessità di sicurezza, desktop) e infine quali sono le porte utilizzate dai tuoi servizi.
Intanto risponditi a questo e poi ti do una mano con lo script.
Contattami via pm per non intasare questo thread.
P.S. potresti editare il tuo post, rimuovere lo script e postare solo le parti che hai modificato? E' molto lungo e intasa un po' il thread.
Solo se non è indispensabile (dici che hai modificato solo poche cose). _________________ Any mans death diminishes me, because I am involved in Mankinde; and therefore never send to know for whom the bell tolls; It tolls for thee.
-John Donne |
|
Back to top |
|
 |
mack1 Guru


Joined: 18 Mar 2006 Posts: 315
|
Posted: Mon Nov 02, 2009 9:53 am Post subject: |
|
|
Ciao, syslog-ng è stato aggiornato alla versione 3 e c'è stata una modifica all'uso di "match":
Code: |
destination firewall { file("/var/log/firewall.log"); };
filter f_firewall { match ("FW:"); };
log { source(kernsrc); filter(f_firewall); destination(firewall); };
|
Riavviando syslog-ng ottengo il seguente messaggio:
Code: |
WARNING: the match() filter without the use of the value() option is deprecated and hinders performance, please update your configuration;
|
Allora "match()" cerca, non solo nel testo del messaggio d'errore, ma anche nel payload (es. il programma/demone che ha generato l'errore), mentre "message()" controlla solo il testo del messaggio.
http://www.balabit.com/dl/html/syslog-ng-v3.0-guide-admin-en.html/ch08s04.html
Anche qui si discute del "problema":
https://bugs.gentoo.org/show_bug.cgi?id=291259
Seguendo la guida va modificato il file di configurazione di syslog-ng:
Code: |
filter f_firewall { message("FW"); };
|
O usando match():
Code: |
match("<some regexp>" value("<a macro name>"))
|
Sono ancora in fase di test perchè i log del firewall vengono scritti sempre in /var/log/debug, ma a singhiozzo in firewall.log, non riesco a capire se sia un problema di sintassi si syslog-ng, o di caratteri speciali all'interno della stringa di ricerca .
Edit 1:
Ok adesso logga correttamente(mi mancava una sorgente all'interno del file di syslog-ng ), usate "message()" che appesantisce meno l'attività di logging.
Ciao |
|
Back to top |
|
 |
|
|
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
|
|