BL🅾G News


Actu G33k & admin stuff.

Aucun commentaire

alt

Script for dealing with creating Postgres databases that complain with:

PG::InvalidParameterValue: ERROR: encoding UTF8 does not match locale en_US
DETAIL: The chosen LC_CTYPE setting requires encoding LATIN1.

when trying to create the production DB with :

RAILS_ENV=production bundle exec rails db:setup

FIX :


 su  - postgres

psql

update pg_database set datistemplate=false where datname='template1';
drop database Template1;
create database template1 with owner=postgres encoding='UTF-8'
  lc_collate='en_US.utf8' lc_ctype='en_US.utf8' template template0;

update pg_database set datistemplate=true where datname='template1';

screen:

 su - postgres
postgres@echosystem:~$ psql -U postgres
psql (9.4.9)
Type "help" for help.

postgres=# update pg_database set datistemplate=false where datname='template1';
UPDATE 1
postgres=# drop database Template1;
DROP DATABASE
postgres=# create database template1 with owner=postgres encoding='UTF-8'
postgres-#   lc_collate='en_US.utf8' lc_ctype='en_US.utf8' template template0;
CREATE DATABASE
postgres=# update pg_database set datistemplate=true where datname='template1';
UPDATE 1
postgres=#

Enjoy !!

ref: https://gist.github.com/turboladen/6790847

by 🅴🆁🆁🅴🆄🆁32
Hosted on

🅴🅲🅷🔵🆂🆈🆂🆃🅴🅼



Aucun commentaire

alt

UPDATE:
only working on LENNY/JESSIE version Debian 8

When you want to check your LSB in /usr/bin/lsb_release
and you see : No LSB modules are available.

Like this :

/usr/bin/lsb_release --all
No LSB modules are available.
Distributor ID: Debian
Description:    Debian GNU/Linux 8.6 (jessie)
Release:        8
Codename:       jessie

Fix :


$ apt-get install lsb-core

after install lsb-core:

/usr/bin/lsb_release --all
LSB Version:    core-2.0-amd64:core-2.0-noarch:core-3.0-amd64:core-3.0-noarch:core-3.1-amd64:core-3.1-noarch:core-3.2-amd64:core-3.2-noarch:core-4.0-amd64:core-4.0-noarch:core-4.1-amd64:core-4.1-noarch:security-4.0-amd64:security-4.0-noarch:security-4.1-amd64:security-4.1-noarch
Distributor ID: Debian
Description:    Debian GNU/Linux 8.6 (jessie)
Release:        8
Codename:       jessie

Enjoy :)

alt

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



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

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