POSTFIX AUTOMÁTICO COM MYSQL E IPTABLES - FILTRO PARA CMAMAR O CLAMAV DIRETAMENTE DO POSTFIX
Publicado por Alessandro Dias 17/05/2005
[ Hits: 4.201 ]
Script adaptado de um script baixado, que controla o Clamav diretamente sem precisar usar o AMAVIS. Adaptado para registrar o IP do remetente de msgs com vírus, bloqueá-lo e Registrar em Relatorios/RESUMOS. Verifique no próprio script como intalá-lo.
#!/bin/sh
# ClamAV script; set a opcao ScanMail no clamav.conf
# by Deives Michellis "thefallen" - dmichellis@yahoo.com | thefallen@unitednerds.org
#
# Crie uma linha no master.cf com o formato:
#clamav unix - n n - - pipe
# flags=Rq user=clamav argv=/usr/libexec/postfix/clamav-filter.sh -f ${sender} -- ${recipient}
#
# e edite a linha do SMTP assim:
# smtp inet n - n - - smtpd
# -o content_filter=clamav:clamav
#
#
export PATH=/usr/local/sbin:/usr/sbin:/sbin:/usr/local/bin:/usr/bin:/bin:/usr/X11R6/bin:/usr/games
#
# Config
#
INSPECT_DIR=/var/spool/filter
#SENDMAIL="/usr/sbin/sendmail -i "
SENDMAIL="/usr/bin/spamc -f -e /usr/sbin/sendmail -i "
MYHOSTNAME=`postconf -h myhostname`
REPORTHOST=`postconf -h myhostname`
#
# Exit codes <sysexits.h>
#
EX_TEMPFAIL=75
EX_UNAVAILABLE=69
EX_DENIED=77
#
# Definicoes dos nomes temporarios
#
nome_arquivo=`date +%Y%m%d%H%M%S`
nome_arquivo=in.$$.$nome_arquivo
AVCMD="/usr/bin/clamdscan --disable-summary --stdout "
NOTIFY_VIRUS=yes
#NOTIFY_PORTMASTER=yes, no, resumo
NOTIFY_POSTMASTER=resumo
viruscan() {
VIRUS=`$AVCMD $nome_arquivo`
SAIDA=$?
VIRUS=`echo $VIRUS | cut -d" " -f2-`
if [ $SAIDA -eq 1 ]; then
postlog -t postfix/virus-filter message-id=$msgid reject: VIRUS from=\<$from\> to=\<$rcpts\> 2>/dev/null
if [ "$NOTIFY_VIRUS" = "yes" ]; then
echo "From: Virus Scanner <mailer-daemon@$MYHOSTNAME>
Subject: AVISO: Email rejeitado: VIRUS Detectado
To: $from
Seu email para ($rcpts) com assunto ($subj) foi rejeitado por conter virus.
--- AVISO: Seu IP serah bloqueado em 24horas!!! ---
Virus encontrados: $VIRUS
IP: $ip $ip2
Atualize seu Anti-virus e entre em contato com o administrador,
pelo endereco postmaster@rjo.ccom.eb.mil.br.
Caso vc tenha Excedido o tamanho do arquivo anexo, seu IP nao sera bloqueado.
Procure nao enviar msgs com anexo criptografado, para que o Anti-virus consiga trabalhar.
Equipe de Suporte - 2CTA
" | $SENDMAIL -f MAILER-DAEMON -- $from
fi
if [ "$NOTIFY_POSTMASTER" = "yes" ]; then
echo "From: Virus Scanner <mailer-daemon@$MYHOSTNAME>
Subject: Postmaster Copy: VIRUS Detectado
To: postmaster@$MYHOSTNAME
Um email de $from para ($rcpts) com assunto ($subj) foi rejeitado por conter virus.
Virus encontrados: $VIRUS
" | $SENDMAIL -f MAILER-DAEMON -- postmaster@$MYHOSTNAME
else
if [ "$NOTIFY_POSTMASTER" = "resumo" ]; then
DATA=`date +%d/%m/%Y-%H:%M:%S`
echo -e "- Data/Hora - $DATA - email id: $msgid\n De: $from Para: $rcpts\n Asunto:$subj\n Virus: $VIRUS\n Origem: $ip $ip2" \
>> /root/bin/Relatorios/RESUMO
fi
fi
##################### alterado por Cap Dias #######################
if [ "$VIRUS" != "Zip.ExceededFileSize FOUND" -a "$VIRUS" != "RAR.ExceededFileSize FOUND" -a "$VIRUS" != "Encrypted.Zip FOUND" ]; then
if [ "$ip" != "127.0.0.1" ]; then
EXISTE=`grep "$ip" /root/bin/ips_bloqueados`
if [ "$EXISTE" = "" -o "$EXISTE" = " " ]; then
#echo "$ip REJECT IP Bloqueado pelo Administrador!!!" >> /etc/postfix/ip-access
#postalias hash:/etc/postfix/ip-access
#---------------- IDENTIFICANDO MÁQUINAS CONHECIDAS -----------------#
case $MES in
10.67.4.30) echo -e "$ip - Utilizando Outlook - Bloqueado em $DATA - MX(EB.MIL.BR)" >> /root/bin/ips_bloqueados ;;
10.1.8.94) echo -e "$ip - Utilizando Outlook - Bloqueado em $DATA - MX(1RM.EB.MIL.BR)" >> /root/bin/ips_bloqueados ;;
10.133.3.4) echo -e "$ip - Utilizando Outlook - Bloqueado em $DATA - MX(7CTA.EB.MIL.BR)" >> /root/bin/ips_bloqueados ;;
10.56.84.58) echo -e "$ip - Utilizando Outlook - Bloqueado em $DATA - MX(6CTA.EB.MIL.BR)" >> /root/bin/ips_bloqueados ;;
10.45.1.80) echo -e "$ip - Utilizando Outlook - Bloqueado em $DATA - MX(5CTA.EB.MIL.BR)" >> /root/bin/ips_bloqueados ;;
10.78.4.99) echo -e "$ip - Utilizando Outlook - Bloqueado em $DATA - MX(4CTA.EB.MIL.BR)" >> /root/bin/ips_bloqueados ;;
10.25.108.50) echo -e "$ip - Utilizando Outlook - Bloqueado em $DATA - MX(1CTA.EB.MIL.BR)" >> /root/bin/ips_bloqueados ;;
10.67.14.1) echo -e "$ip - Utilizando Outlook - Bloqueado em $DATA - MX(CITEX.EB.MIL.BR)" >> /root/bin/ips_bloqueados ;;
10.67.104.29) echo -e "$ip - Utilizando Outlook - Bloqueado em $DATA - MX(SEF.EB.MIL.BR)" >> /root/bin/ips_bloqueados ;;
10.67.4.99) echo -e "$ip - Utilizando Outlook - Bloqueado em $DATA - MX(CCOM.EB.MIL.BR)" >> /root/bin/ips_bloqueados ;;
*) echo -e "$ip - Utilizando Outlook - Bloqueado em $DATA" >> /root/bin/ips_bloqueados ;;
esac
#--------------------------------------------------------------------#
cat /root/bin/ips_bloqueados | sort > /tmp/ips_bloqueados.tmp
cp -f /tmp/ips_bloqueados.tmp /root/bin/ips_bloqueados
rm -f /tmp/ips_bloqueados.tmp
sed -e "/#IPS_REJEITADOS/a\ \$IPTABLES -A INPUT -j REJECT -s $ip -p tcp --dport 25\\" /etc/rc.d/init.d/iptables > /tmp/iptables.tmp
cp -f /tmp/iptables.tmp /etc/rc.d/init.d/iptables
rm -f /tmp/iptables.tmp
# Restarta o IPTABLES
/etc/rc.d/init.d/iptables start
fi
else
EXISTE=`grep "$ip2" /root/bin/ips_bloqueados`
if [ "$EXISTE" = "" -o "$EXISTE" = " " ]; then
echo -e "$ip2 - Utilizando Webmail - Bloqueado em $DATA" >> /root/bin/ips_bloqueados
cat /root/bin/ips_bloqueados | sort > /tmp/ips_bloqueados.tmp
cp -f /tmp/ips_bloqueados.tmp /root/bin/ips_bloqueados
rm -f /tmp/ips_bloqueados.tmp
sed -e "/#IPS_REJ_WEBMAIL/a\ \$IPTABLES -A INPUT -j REJECT -s $ip2 -p tcp -m multiport --dport 25,134 \# webmail\\" /etc/rc.d/init.d/iptables > /tmp/iptables.tmp
cp -f /tmp/iptables.tmp /etc/rc.d/init.d/iptables
rm -f /tmp/iptables.tmp
sed -e "/#IPS_BLOQUEADOS/a\ deny from $ip2\\" /etc/apache/conf/httpd.conf > /tmp/httpd.conf.tmp
cp -f /tmp/httpd.conf.tmp /etc/apache/conf/httpd.conf
rm -f /tmp/httpd.conf.tmp
fi
fi
fi
###################################################################
exit 0
fi
############# Modificado pelo Cap Dias #########################
echo "
-------------------------------------------
Mensagem escaneada, nenhum vírus encontrado.
Anti-vírus ClamAV - 2CTA - Div Op - SGRT" >> $nome_arquivo
################################################################
}
#
# Clean up when done or when aborting.
#
trap "rm -rf $nome_arquivo*" 0 1 2 3 15
#
# Start processing.
#
cd $INSPECT_DIR || { echo $INSPECT_DIR does not exist; exit $EX_TEMPFAIL; }
cat >$nome_arquivo || { echo Cannot save mail to file; exit $EX_TEMPFAIL; }
#head -n 100 $nome_arquivo >> /tmp/teste
#echo "---------------------------" >> /tmp/teste
from=$2
if [ "$from" != "--" ]; then
shift
else
$from=""
fi
shift ; shift
dominio=`echo $from | cut -d"@" -f2`
email=`echo $from | cut -d"@" -f1`
subj=`head -n 200 $nome_arquivo | grep -i "^Subject:" | cut -d":" -f2- | head -n 1`
msgid=`head -n 200 $nome_arquivo | grep -i "^message-id" | cut -d: -f 2- | sed 's/^ *//' | head -n 1`
##################### alterado por Cap Dias #######################
host=`head -n 10 $nome_arquivo | grep -i "Received: from" | cut -d "[" -f 2 | cut -d "]" -f 1`
ip=`echo $host | cut -d " " -f 1` # pega apenas um IP
ip2=`echo $host | grep "Received" | cut -d " " -f 3`
if [ "$ip2" = "from" ]; then
ip2=`echo $host | grep "Received" | cut -d " " -f 4`
fi
###################################################################
saida="-f $from -- $@"
rcpts=$@
viruscan
$SENDMAIL $saida <$nome_arquivo
exit 0
Criando arquivos de in e out no CBQ
Cura VMWare Player e Workstation
Manutenção básica em partições Windows
Analisador de rede com aviso em net send
Trabalhando Nativamente com Logs no Linux
Jogando Daikatana (Steam) com Patch 1.3 via Luxtorpeda no Linux
LazyDocker – Interface de Usuário em Tempo Real para o Docker
Linux Mint: Zram + Swapfile em Btrfs
O widget do Plasma 6 Área de Notificação
Após todos esses anos... youtube! (4)
[Resolvido] Conselho distribuiçao brasileira (14)









