dimanche 23 mai 2010

IP Filter : PeerGardian Linux (pgl) succède à Moblock - Blockcontrol

IP Filter : PeerGardian Linux (pgl)
PeerGuardian Linux (pgl) est le successeur de Moblock-Blockcontrol un IP filter destiné à blacklister des plages d'IP indésirables  sous P2P (par exemple). Tous les anciens acteurs de Moblock ainsi que des nouveaux se sont mis au travail pour sortir ce 18 mai dernier la dernière mouture : la version 2.0.0 .
Le démon pgld est basé sur l'ancien NFBlock, lui même basé sur MoBlock, pglcmd est lui basé sur blockcontrol, précédemment moblock-control , un pgl-gui, par l'auteur de  mobloquer, est en préparation mais n'est pas encore disponible dans la version 2.0.0.

Si vous ne pouvez pas vous passer de mobloquer alors mieux vaut attendre la sortie de pgl-gui.

Sinon je vous ai fait un petit script en attendant mieux (voir à la fin de ce billet)


Installation:

Le dépôt:

Dans un terminal, modifier le fichier sources.list en ajoutant les dépôts si ils n'y sont pas encore :
$ gksu gedit /etc/apt/sources.list

Ubuntu 10.04 lucid:
deb http://ppa.launchpad.net/jre-phoenix/ppa/ubuntu lucid main
deb-src http://ppa.launchpad.net/jre-phoenix/ppa/ubuntu lucid main

Puis ajouter la clef  si nécessaire

Ubuntu jaunty et suivants

$ gpg --keyserver keyserver.ubuntu.com --recv 9C0042C8
$ gpg --export --armor 9C0042C8 | sudo apt-key add -

Mettre à jour la liste des paquets par la commande suivante

$ sudo apt-get update

Avant de l'installer
Si vous aviez mobloquer et blockcontrol qui étaient installés , il vous faut les désinstaller par :

$ sudo apt-get remove blockcontrol mobloquer
( ne purgez pas tout de suite les fichiers de configurations, ils vous seront surement utiles pour reparamétrer pgl )


Install:

$ sudo apt-get install pgld pglcmd



Les écran de configuration de debconf

Premier écran d'avertissement

Ecran 2 :  Avertissement aux utilisateurs de firewall

Ecran 3 : choix des Blacklists ,
un choix par défaut est proposé auquel j'ai ajouté une partie de ceux issus de Bluetack

Ecran 4 : Lancement automatique au démarrage = oui par défaut
Utilisation:

Ecran 5 : Explication à propos des Liste Blanches (whitelist)

Ecran 6 : Whitelist des ports TCP et UDP
La configuration par défaut ne propose que http et https,
j'y ai ajouté le smtp, l'imap et le pop3 pour les messageries.

Ecran 7 : Choix des options de Whitelisting
Dans mon cas, le LAN et DNS sont whitelistés automatiquement

Un doute ? Vous aimeriez refaire un paramétrage ? Pas de problème !
Faite un :
$ sudo dpkg-reconfigure pglcmd


Ajouter une blacklist personnelle
Normalement : il devrait suffire d'ajouter une ligne dans le fichier /etc/pgl/blocklists.list, ligne commançant par "locallist" suivi du chemin vers la blacklist perso. Mais chez moi , ça ne marche pas.

Petite manip pour contourner ce problème:
En tant que Root:
  1. Copier votre blacklist dans /var/lib/pgl en prenant soin de la renommer en "locallist"
  2. Copier ce même fichier dans /var/spool/pgl/locallist/extracted , si ce répertoire n'existe pas crée le.
  3. Dans le fichier /etc/pgl/blocklists.list , ajouter les lignes suivantes:
    # locallist
    locallist locallist
En attendant mieux...ça fonctionne.


Utilisation: 

(j'ai laissé la version anglaise...flemme ...les commandes sont suffisamment explicites ...)

  • pglcmd start - inserts iptables rules and starts the IP block daemon. If the blocklist configuration changed, rebuild the master blocklist.
  • pglcmd stop - deletes iptables rules and stops the IP block daemon.
  • pglcmd restart - restarts the IP block daemon.
  • pglcmd reload - rebuilds the master blocklist and reloads the IP block daemon if it is running.
  • pglcmd update - updates the blocklists, rebuilds the master blocklist and reloads the IP block daemon.
  • pglcmd status - gives the iptables settings and the status of the IP block daemon.
  • pglcmd test - does a simple test to check if the IP block daemon is working (pings a random IP in the blocklist and checks if this IP was logged in the block daemons logfile and if it answered).
  • pglcmd search PATTERN - outputs the occurences of a keyword and the names of the single blocklists.
  • pglcmd stats - reports daemon's statistics
  • pglcmd reset_stats - resets daemon's statistics
  • pglcmd show_config - shows the current configuration settings.

En attendant un GUI digne de ce nom , ci-dessous un petit script à l'arrache qui reprend les commandes listées ci-dessus.


Nécessite zenity ($ sudo apt-get install zenity)

Créer un fichier bash , par exemple pgl_gui.sh
Recopier les lignes de code ci-dessous, enregistrer puis
le rendre exécutable
$ chmod +x pgl_gui.sh

Pour le lancer,
$ ./pgl_gui.sh


#!/bin/bash
Status="Status PAS MIS A JOUR"
Verification="Vérification pas faite !"
#
foo=`gksudo -u root -k -m "entrer votre mot de passe pour ouvrir Peer Guardian LINUX avec les droit ROOT" /bin/echo "Do you have root access?"`
#
pidof pgld && a=$?
if [ $a = 0 ]
    then texte1="Peer Guardian LINUX en FONCTION"
    else texte1="Peer Guardian LINUX Arrêté "
fi
zenity --info --title="Peer Guardian LINUX" --text="$texte1"
#
while true ; do

choix=`zenity --list --width=850 --height=450 --title=" Peer Guardian LINUX $texte1 - les options -"  --column="." --column="Choisissez la commande"  \
    0 "fichiers de config" \
    1 "START    : inserts iptables rules and starts the IP block daemon." \
    2 "STOP    : deletes iptables rules and stops the IP block daemon." \
      3 "RESTART    : restarts the IP block daemon." \
      4 "RELOAD    : rebuilds the master blocklist and reloads the IP block daemon if it is running." \
      5 "UPDATE    : updates the blocklists, rebuilds the master blocklist and reloads the IP block daemon." \
    6 "STATUS    : gives the iptables settings and the status of the IP block daemon." \
    7 "TEST    : does a simple test to check if the IP block daemon is working. " \
    9 "STATS    : reports daemon's statistics." \
    10 "RESET    : resets daemon's statistics." \
    11 "SEARCH    : outputs the occurences of a keyword and the names of the single blocklists." \
    12 "Setting    : shows the current configuration settings." \
    13 "Sortie - EXIT." `
#
if [ ! "$choix" ] ; then sudo -k && exit 10 ; fi
#
case $choix in
  0 ) zenity --info --title="Peer Guardian LINUX" \
    --text="Configuration:

Vous pouvez spécifier les blocklist à utiliser dans blocklists.list (/etc/pgl/blocklists.list).

The allow list for IP ranges is allow.p2p (/etc/pgl/allow.p2p) ou  . Per default, the allowlist is used for incoming and outgoing connections. If desired different allow lists for incoming, outgoing and forward connections may be used.

Tous le reste (automatic start and update, iptables handling, IP and port whitelisting)) est configuré dans pgl.conf (/etc/pgl/pglcmd.conf).
Refer to pglcmd.defaults (/usr/lib/pgl/pglcmd.defaults) for the complete set of possible configuration variables with comments." ;;
  1 ) sudo pglcmd start && zenity --info --text="Peer Guardian LINUX démarré."  ;;
  2 ) sudo pglcmd stop && zenity --warning --text="Peer Guardian LINUX stoppé."  ;;
  3 ) sudo pglcmd restart && zenity --info --text="Peer Guardian LINUX Re-démarré" ;;
  4 ) sudo pglcmd reload | zenity --progress \
    --title="Reload Peer Guardian LINUX" \
    --text="Reload en cours..." \
    --pulsate && zenity --info --text="Peer Guardian LINUX reloadé" ;;
  5 ) sudo pglcmd update | zenity --progress \
    --title="Màj des Blocklists" \
    --text="mise à jour en cours..." \
    --pulsate  && zenity --info -- no-wrap --text="Mise à Jour faite et Peer Guardian LINUX reloadé." ;;
  6 ) sudo pglcmd status | zenity --text-info  --title="Etat de Peer Guardian LINUX" \
    --width=850 --height=480 ;;
  7 ) Verification=` sudo pglcmd test ` && zenity --warning --title="Test par ping de Peer Guardian LINUX" \
     --no-wrap --text="$Verification";;
  9 ) der_stat=`sudo pglcmd stats ` && zenity --warning --title="Dernières Stats du jour de Peer Guardian LINUX" \
     --no-wrap --text="$der_stat";;
  10 ) sudo pglcmd reset stats && zenity --warning --text="Statistiques de Peer Guardian LINUX remise à zéro."  ;;
  11 ) keyword=`zenity --entry --title="Choisir un mot clef" --text="Choisir un mot clef à chercher dans les blocklists :'mot1 mot2'"` && sudo xterm -title "recherche mot-clef" -e "sudo pglcmd search $keyword && echo 'Taper sur une touche pour Quitter .' && read mot" ;;
  12) sudo pglcmd show_config | zenity --text-info --title="Config de Peer Guardian LINUX" --width=530 --height=380 ;;
  13) sudo -k && exit ;;

esac

done
echo "sudo arreté"
sudo -k
exit


Info butinée ICI

4 commentaires:

  1. Bonjour, m'autoriseriez-vous à exploiter votre article pour l'édition d'un article sur le site doc.ubuntu-fr.org?
    Merci par avance pour votre réponse (par mail si possible)

    RépondreSupprimer
  2. @lildadou
    Pas de problème, mais ce billet date un peu maintenant.
    Désolé pas trouvé ton e-mail

    RépondreSupprimer
  3. Merci, vous pourrez trouver l'exploitation de votre article sur cette page (en cours de rédaction) : http://doc.ubuntu-fr.org/utilisateurs/lildadou/mediabunker#installation_des_services_mediacenter

    RépondreSupprimer