BL🅾G News


Actu G33k & admin stuff.

Aucun commentaire

alt

Les forte augmentations de scan à la recherche de serveurs mails mal configurés ("open relays") sont devenu un classique.
Ces serveurs acceptent de transférer des courriels en provenance de n'importe qui (et non uniquement des utilisateurs enregistrés) : une aubaine pour les spammeurs qui peuvent les utiliser pour relayer leurs cochonneries.

Comme vous le savez peut-être, il existe pour chaque bloc d'aresses IP (ou presque) une adresse de contact à qui l'on peut écrire pour se plaindre des manquements à la nétiquette. J'avais commencé par envoyer des mails dits "d'abuse" manuels, mais j'ai vite réalisé que ça me prendrait un temps fou à chaque fois.

Automatisation afin que les fournisseurs d'accès puissent prendre des mesures contre leurs clients belliqueux (s'ils le désirent).
Le script suivant traverse les logs postfix, identifie les lignes suspectes et envoie un joli rapport au contact "abuse" de l'IP identifiée.

postfix.openrelay.sh


#!/bin/bash
# postfix.openrelay.sh ( à placer ou vous voulez, chmod +x )

# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
 
MAIL_HEAD="Hello,\n
\n\
I have received suspicious connections on port 25 from a machine located in your network.\n\
Here are the relevant postfix logs (all timestamps are relative to the `date +"%Z"` timezone):\n"

MAIL_FOOT="\nOne of your computers may have been infected, or it is possible that one of your clients is up to no good.\n\
Could you please look into it?\n\
\n\
Regards,\n\
[Echosystem.fr]"

function check_exit_node {
        dnsel_answer=`host \`echo $1 | perl -ne '/([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})/ && print $4 . "." . $3 . "." . $2 . "." . $1 . ".25.13.200.179.88.ip-port.exitlist.torproject.org"'\` | pe
rl -ne '/has address ([0-9\.]+)/ && print $1'`
        if [[ -z "$dnsel_answer" || "$dnsel_answer" == "127.0.0.1" ]]; then
                return 0
        else
                return 1
        fi
}

for IP in `grep -i "relay access" /var/log/mail.log.1 |perl -ne '/from [A-Za-z0-9.-]+\[([0-9.]+)\]/ && print $1 . "\n"' |sort -u`
do
        if check_exit_node $IP
        then
                ABUSE_MAIL=`whois $IP |egrep -o "[A-Za-z0-9-]*abuse[A-Za-z0-9-]*@[A-Za-z0-9.-]+" |grep -iv "abuse@ripe.net"|sort -u`
                if [[ -n "$ABUSE_MAIL" ]]
                then
                        echo -e $MAIL_HEAD > mail.tmp
                        grep $IP /var/log/mail.log.1 >> mail.tmp
                        echo -e $MAIL_FOOT >> mail.tmp
                        # Add "-b abuse@echosystem.fr" to mutt's arguments if you want to recieve a blind carbon copy of the sent e-mails.
                        mutt -e 'set from=abuse@echosystem.fr realname="[echosystem.fr]" envelope_from="yes" user_agent="no"' -s "SMTP abuse from $IP" $ABUSE_MAIL < mail.tmp
                fi
        fi
done
rm -f mail.tmp



Pour que le script soit appelé tous les jours, il suffit d'éditer le script de rotation des logs de postfix.
Créé un fichier dans /etc/logrotate.d/postfix.


/var/log/mail.log
/var/log/mail.err
/var/log/mail.info
/var/log/mail.warn
{
daily
missingok
rotate 21
compress
delaycompress
notifempty
create 640 root
sharedscripts
postrotate
if [ -f /var/run/postfix.pid ]; then
/etc/init.d/postfix reload > /dev/null
####  appel du script ici 
/home/tools/SH/postfix.openrelay.sh || true
fi
endscript
}



Si vous utilisez un autre front-end, le script à modifier sera différent mais l'esprit reste le même.


Exemple de mail généré :



Hello,

I have received suspicious connections on port 25 from a machine located in your network.
Here are the relevant postfix logs (all timestamps are relative to the CEST timezone):

Jan 31 19:27:02 atria postfix/smtpd[21972]: warning: hostname 88.247.78.4.static.ttnet.com.tr does not resolve to address 88.247.78.4: No address associated with hostname
Jan 31 19:27:02 atria postfix/smtpd[21972]: connect from unknown[88.247.78.4]
Jan 31 19:27:03 atria postfix/smtpd[21972]: NOQUEUE: filter: RCPT from unknown[88.247.78.4]: : Sender address triggers FILTER smtp-amavis:[127.0.0.1]:10026; from= to= proto=ESMTP helo=<[192.168.2.33]>Jan 31 19:27:03 atria postfix/smtpd[21972]: NOQUEUE: filter: RCPT from unknown[88.247.78.4]: : Sender address triggers FILTER smtp-amavis:[127.0.0.1]:10024; from= to= proto=ESMTP helo=<[192.168.2.33]>Jan 31 19:27:03 atria postfix/smtpd[21972]: NOQUEUE: reject: RCPT from unknown[88.247.78.4]: 554 5.7.1 : Relay access denied; from= to= proto=ESMTP helo=<[192.168.2.33]>Jan 31 19:27:03 atria postfix/smtpd[21972]: disconnect from unknown[88.247.78.4]
Jan 31 19:30:23 atria postfix/anvil[21974]: statistics: max connection rate 1/60s for (smtp:88.247.78.4) at Jan 31 19:27:02
Jan 31 19:30:23 atria postfix/anvil[21974]: statistics: max connection count 1 for (smtp:88.247.78.4) at Jan 31 19:27:02
Jan 31 22:15:21 atria postfix/smtpd[3430]: warning: hostname 88.247.78.4.static.ttnet.com.tr does not resolve to address 88.247.78.4: No address associated with hostname
Jan 31 22:15:21 atria postfix/smtpd[3430]: connect from unknown[88.247.78.4]
Jan 31 22:15:21 atria postfix/smtpd[3430]: NOQUEUE: filter: RCPT from unknown[88.247.78.4]: : Sender address triggers FILTER smtp-amavis:[127.0.0.1]:10026; from= to= proto=ESMTP helo=<[192.168.2.33]>Jan 31 22:15:21 atria postfix/smtpd[3430]: NOQUEUE: filter: RCPT from unknown[88.247.78.4]: : Sender address triggers FILTER smtp-amavis:[127.0.0.1]:10024; from= to= proto=ESMTP helo=<[192.168.2.33]>Jan 31 22:15:21 atria postfix/smtpd[3430]: NOQUEUE: reject: RCPT from unknown[88.247.78.4]: 554 5.7.1 : Relay access denied; from= to= proto=ESMTP helo=<[192.168.2.33]>Jan 31 22:15:22 atria postfix/smtpd[3430]: disconnect from unknown[88.247.78.4]
Jan 31 22:18:42 atria postfix/anvil[3432]: statistics: max connection rate 1/60s for (smtp:88.247.78.4) at Jan 31 22:15:21
Jan 31 22:18:42 atria postfix/anvil[3432]: statistics: max connection count 1 for (smtp:88.247.78.4) at Jan 31 22:15:21
Jan 31 22:43:40 atria postfix/smtpd[16701]: warning: hostname 88.247.78.4.static.ttnet.com.tr does not resolve to address 88.247.78.4: No address associated with hostname
Jan 31 22:43:40 atria postfix/smtpd[16701]: connect from unknown[88.247.78.4]
Jan 31 22:43:41 atria postfix/smtpd[16701]: NOQUEUE: filter: RCPT from unknown[88.247.78.4]: : Sender address triggers FILTER smtp-amavis:[127.0.0.1]:10026; from= to= proto=ESMTP helo=<[192.168.2.33]>Jan 31 22:43:41 atria postfix/smtpd[16701]: NOQUEUE: filter: RCPT from unknown[88.247.78.4]: : Sender address triggers FILTER smtp-amavis:[127.0.0.1]:10024; from= to= proto=ESMTP helo=<[192.168.2.33]>Jan 31 22:43:41 atria postfix/smtpd[16701]: NOQUEUE: reject: RCPT from unknown[88.247.78.4]: 554 5.7.1 : Relay access denied; from= to= proto=ESMTP helo=<[192.168.2.33]>Jan 31 22:43:41 atria postfix/smtpd[16701]: disconnect from unknown[88.247.78.4]
Jan 31 22:47:01 atria postfix/anvil[16703]: statistics: max connection rate 1/60s for (smtp:88.247.78.4) at Jan 31 22:43:40
Jan 31 22:47:01 atria postfix/anvil[16703]: statistics: max connection count 1 for (smtp:88.247.78.4) at Jan 31 22:43:40

One of your computers may have been infected, or it is possible that one of your clients is up to no good.
Could you please look into it?

Regards,
YOU




Un petit truc qui ne coûte pas grand chose et qui, avec un volume suffisant de plaintes, pourrait bien faire perdre de précieuses machines aux spammeurs.
N'hésitez pas à modifier le script pour qu'il réagisse à d'autre types de comportements indésirables !

EDIT du 16/05/2014 : Modification du corps du mail pour inclure le fuseau horaire de l'horodatage.
EDIT du 08/08/2015 : Les courriels d'abuse ne sont plus envoyés aux exit nodes Tor, car ils ne peuvent rien faire pour retrouver les expéditeurs des courriels et les plaintes ne font qu'irriter leurs hébergeurs.
site de reference du script : https://blog.kwiatkowski.fr/?q=fr/node/19#comment-118
EDIT du 01/10/2016 : Modification pour postfix by 🅴🆁🆁🅴🆄🆁32.



by 🅴🆁🆁🅴🆄🆁32
Hosted on
🅴🅲🅷🅾🆂🆈🆂🆃🅴🅼



Aucun commentaire

alt

Sous Windows avec Putty

Putty est le client SSH le plus répandu pour Windows

- Télécharger le logiciel puttygen permettant de générer la clé

Sinon si vous avez la dernière version de putty ,

boutton Windows -> Start Menu -> All Programs -> PuTTY -> PuTTYgen

- Exécuter le logiciel de génération de clé

- Au niveau de Number of bits in a generated key, indiquer la valeur 4096

alt

- Cliquer sur Generate (déplacer la souris dans le cadre gris pendant l'opération)

- Indiquer une passphrase pour protéger la clé par un mot de passe

- Enregistrer la clé privée Save private key, donner un nom à ce fichier (key.rsa par exemple)

- Copier la clé publique affichée dans le cadre

alt

- Démarrer Putty

- Dans la liste sur la gauche, cliquer sur Connection puis SSH, puis Auth
A la ligne Private key file for authentification , cliquer sur Browse, sélectionner la clé privée, valider.

alt

Retourner sur Puttygen
Dans le cadre Key, copier la clé publique
La procédure d'importation de la clé publique est identique à Linux/Mac, une fois la copie effectuée, cliquer sur Open dans Putty.

issue key putty

IF ISSUE with PuTTY key format too new when using ppk file for PuTTY SSH key authentication

If you have a key in the new PPK version 3 format, you can use PuTTYgen to export it to the old PPK version 2 format.

I don't know what Operating System you're using PuTTYgen/PuTTY on, but if it's Microsoft Windows you can set PPK Version 2 by default for PuTTYgen selecting in the app menu:

Key->Parameters for saving key files...->PPK file version: 2.

by 🅴🆁🆁🅴🆄🆁32
Hosted on
🅴🅲🅷🅾🆂🆈🆂🆃🅴🅼



Aucun commentaire

i ii
Lancement automatique d'une connection SSH avec fichier Clef avec Keepass et Putty.

Résumé sur Keepass:

Retenir tous ces mots de passe devient impossible, Mais Keepass est la pour ça !
Ultra léger et sécurisé il va nous permettre d'enregistrer et gérer une base de donnée de vos mots de passe.
Ensuite couplé à putty cela devient nettement plus pratique pour se connecter en SSH et envoyer le fichier KEY en 1 clic.
\o/

Pré-requis:

- Keepass
- Putty



Configuration de keepass:

Il est possible de mettre des fichiers attachés dans keepass, pratique surtout pour mettre en pièce jointe un fichier KEY serveur pour s’identifier en SSH.

Crééer une entrée pour votre serveur SSH dasn keepass.




- Dans l'onglet "principal", remplir les champs USER et pass de votre serveur (pas indispensable)

i



- Dans l'onglet "avancé", cliquez sur pièces jointes et y mettre votre fichier KEY. ( indispensable)

i


- Dans l'onglet "propriété", copier cette commande (Modifier PATH, SESSION, user et pass)


cmd://C:\PATH\putty.exe -load "SESSION_PUTTY" -l USER -pw PASSWORD



ialt

PATH: emplacement de putty dans windows
SEESION_PUTTY: Nom de la session sauvegardée dans putty (le nom qui apparait dans saved sessions)
USER: L'user de votre server pour la connection SSH
VOTRE_PASSWORD: Votre PASS

cmd://C:\PATH\putty.exe -load "SESSION_PUTTY" -l USER -pw PASSWORD



Voilà plus qu'a ce connecté en sélectionnant l'entrée dans Keypass (mettre en bleue la ligne) , puis CTRL + la touche U (lance le fichier KEY)

Putty devrait se lancer directement dans votre session SSH (avec le fichier key chargé).


BONUS export data Putty :

Cliquez touche Windows et tapez cmd (enter)
ensuite copier/coller ceci:

regedit /e "%userprofile%\Desktop\putty.reg" HKEY_CURRENT_USER\Software\SimonTatham


Vous pouvez le mettre en pièce jointe dans keepass histoire d'avoir les même settings si vous avez du multi poste (ou un backup)



* Point négatif : on envoie en clair le mot de pass entre keepass et putty ...


by 🅴🆁🆁🅴🆄🆁32
Hosted on
🅴🅲🅷🅾🆂🆈🆂🆃🅴🅼



Aucun commentaire

BANIP

Simple script Debian pour bannir une ip/range avec iptables facilement ;)

banip image

banip.sh

#!/bin/bash
# Script name : Ban/Unban IP with Iptables

function help {
    echo "Syntax: $0 -[L][u] target(s)"
    echo " Parameters come first. Target is expressed as an IP address."
    echo " No specified parameter will ban the IP."
    echo " -L to list currently banned IPs."
    echo " -u to unban IP(s)."
    exit 1
}

# If no arguments are passed, call the "help" function.
if [ -z "$1" ]; then
    help
fi

# Define some variables
ACTION="-A"
txtred=$(tput setaf 1)
txtyel=$(tput setaf 3)
txtcya=$(tput setaf 6)
txtrst=$(tput sgr0)

while getopts "huL" OPTION
do
    case $OPTION in
        h)
            help
            ;;
        u)
            ACTION="-D"
            shift $(($OPTIND - 1))
            ;;
        L)
            ACTION="-L"
            shift $(($OPTIND - 1))
            ;;
        \?)
            help
            ;;
    esac
done

if [ $ACTION == "-L" ]; then
    echo $txtcya"List of Banned IPs:"$txtrst
    iptables -L INPUT -v -n | grep DROP
else
    # ban work loop
    for ZTARGET in "$@"
    do
        echo $txtcya"Applying action $txtred$ACTION$txtcya to $txtyel$ZTARGET"$txtrst
        iptables $ACTION INPUT -s $ZTARGET -j DROP
       # write ip list file in to root 
      echo $txtyel$ZTARGET >> /root/banip-list.txt
    done
fi

by
🅴🆁🆁🅴🆄🆁32



Aucun commentaire
windows10

Désactiver le port 80 sur Windows 10

Par défaut le port 80 est utilisé dans Windows10 par le service "World Wide Web publishing Service"

Pour désactiver ce service:

- appuyez sur la touche windows du clavier et tapez simplement "Services"

- Rechercher dans la fenêtre "World Wide Web publishing Service"

- Mettre sur "Stop"

- ( Optionel) Désactivation permanente : Sélectionner "Manuel"

by 🅴🆁🆁🅴🆄🆁32
Hosted on
🅴🅲🅷🅾🆂🆈🆂🆃🅴🅼