linux correo

Post on 02-Dec-2014

191 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

Portantier Information Security – Servicios de Correo con GNU/Linux

Servicios de correo con GNU/Linux

2011-07-12 (v1.0)

Portantier Information Security – Servicios de Correo con GNU/Linux

Fabian Portantier

● Consultor en Seguridad Informática

● Fanático de GNU/Linux (Debian)

● Mail: fabian@portantier.com

● Web: www.portantier.com

Portantier Information Security – Servicios de Correo con GNU/Linux

¿Qué es el correo electrónico?

Portantier Information Security – Servicios de Correo con GNU/Linux

MDA MTAsi.com

MTAno.com

MDA

MUApepe@no.com

MUAjose@si.com

INTERNET

Mailbox

Mailbox

Componentes

Portantier Information Security – Servicios de Correo con GNU/Linux

Protocolos Involucrados

Portantier Information Security – Servicios de Correo con GNU/Linux

DNS – Jerarquía de nombres

Portantier Information Security – Servicios de Correo con GNU/Linux

DNS registros involucrados

● MX: Mail Exchange

● PTR: Pointer

Portantier Information Security – Servicios de Correo con GNU/Linux

DNS en el correo electrónico

● Consulta a registros MX

● Verificación de registros PTR

Portantier Information Security – Servicios de Correo con GNU/Linux

DNSfabian@debian:~$ dig gmail.com MX

; <<>> DiG 9.7.3 <<>> gmail.com MX;; global options: +cmd;; Got answer:;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 56005;; flags: qr rd ra; QUERY: 1, ANSWER: 5, AUTHORITY: 0, ADDITIONAL: 0

;; QUESTION SECTION:;gmail.com. IN MX

;; ANSWER SECTION:gmail.com. 3567 IN MX 20 alt2.gmail-smtp-in.l.google.com.gmail.com. 3567 IN MX 30 alt3.gmail-smtp-in.l.google.com.

;; Query time: 14 msec;; SERVER: 192.168.0.1#53(192.168.0.1);; WHEN: Mon May 30 00:23:17 2011;; MSG SIZE rcvd: 150

Portantier Information Security – Servicios de Correo con GNU/Linux

SMTP

● Simple Mail Transfer Protocol

● RFC 821(Original)

● RFC 1123 (Correcciones)

● RFC 2821 (ESMTP)

Portantier Information Security – Servicios de Correo con GNU/Linux

SMTP

● Basado en intercambio de textos

● Preguntas y Respuestas

● Puerto TCP 25

● Sin autenticación

Portantier Information Security – Servicios de Correo con GNU/Linux

SMTP-AUTH

● Extensión de SMTP

● Verificación de clientes

● Control de Accesos

Portantier Information Security – Servicios de Correo con GNU/Linux

Telnet a un servidor SMTPfabian@debian:~$ telnet alt2.gmail-smtp-in.l.google.com 25Trying 74.125.77.27...Connected to alt2.gmail-smtp-in.l.google.com.Escape character is '^]'.220 mx.google.com ESMTP s7si8758240eeb.92HELO fabian.debian.org250 mx.google.com at your serviceMAIL FROM: <fabian@portantier.com>250 2.1.0 OK s7si8758240eeb.92RCPT TO: <fabianmp@gmail.com>250 2.1.5 OK s7si8758240eeb.92DATA354 Go ahead s7si8758240eeb.92TEXTO QUE QUIEROENVIAR POR CORREO..550-5.7.1 [186.58.27.102] The IP you're using to send mail is not authorized to550-5.7.1 send email directly to our servers. Please use the SMTP relay at your550-5.7.1 service provider instead.

Portantier Information Security – Servicios de Correo con GNU/Linux

Open Source SMTP Servers

● Postfix

● Sendmail

● Exim

● Varios más...

Portantier Information Security – Servicios de Correo con GNU/Linux

¿Cual elegir?

de tin, marín dedo pingüé...cucara macara piquere...

Portantier Information Security – Servicios de Correo con GNU/Linux

Postfix !

(www.postfix.org)

Portantier Information Security – Servicios de Correo con GNU/Linux

Ventajas de Postfix

● Estable

● Seguro

● Rápido

● Flexible

● Fácil

Portantier Information Security – Servicios de Correo con GNU/Linux

Instalación en Debian GNU/Linux

apt-get install postfix

;)

Portantier Information Security – Servicios de Correo con GNU/Linux

/etc/postfix/main.cf

/etc/postfix/master.cf

Archivos de Configuración

Portantier Information Security – Servicios de Correo con GNU/Linux

main.cf

myorigin = $myhostname

mydestination = $myhostname localhost.$mydomain localhost $mydomain

smtpd_banner = $myhostname ESMTP $mail_name (Debian/GNU)

biff = no

append_dot_mydomain = no

#delay_warning_time = 4h

readme_directory = no

Portantier Information Security – Servicios de Correo con GNU/Linux

Enviando mails localmente

echo "CONTENIDO DEL CORREO" | mail -s "mail de prueba" fabian

Portantier Information Security – Servicios de Correo con GNU/Linux

Leyendo mails (I)

fabian@debian:~$ cat /var/mail/fabian From root@debian.localdomain Tue May 31 16:36:53 2011Return-Path: <root@debian.localdomain>X-Original-To: fabianDelivered-To: fabian@debian.localdomainReceived: by debian.localdomain (Postfix, from userid 0)

id 15EB982E35; Tue, 31 May 2011 16:36:53 -0300 (ART)To: fabian@debian.localdomainSubject: mail de pruebaMessage-Id: <20110531193653.15EB982E35@debian.localdomain>Date: Tue, 31 May 2011 16:36:53 -0300 (ART)From: root@debian.localdomain (root)Status: ROContent-Length: 21Lines: 1

CONTENIDO DEL CORREO

Portantier Information Security – Servicios de Correo con GNU/Linux

Leyendo mails (II)

mutt

Portantier Information Security – Servicios de Correo con GNU/Linux

Herramientas

● postconf: Consultar / modificar configuración

● postsuper: Gestión de colas y correos

● qshape: Reporta el estado de las colas

● sendmail: Envía correos

● Algunas otras...

Portantier Information Security – Servicios de Correo con GNU/Linux

Tipos de Direcciones

● Correo local: cuentas de shell del propio sistema

● Casillas virtuales: no tienen cuenta de shell, pero somos el destino final de las mismas

● Alias virtuales: Siempre se redirigen, aunque puede que vuelvan al mismo servidor

● Relay: Sólo si actuamos como nodo de reenvío de correo.

Portantier Information Security – Servicios de Correo con GNU/Linux

Bind (I)

/etc/bind/named.conf.local

zone "example.com" { type master; file "/etc/bind/zones/example.com.db"; };

Portantier Information Security – Servicios de Correo con GNU/Linux

Bind (II)

/etc/bind/zones/example.com.db

example.com. IN SOA ns1.example.com. admin.example.com. ( 2006081401 28800 3600 604800 38400 )

example.com. IN NS ns1.example.com.example.com. IN MX 10 mta.example.com.

www IN A 192.168.0.2mta IN A 127.0.0.1ns1 IN A 192.168.0.1

Portantier Information Security – Servicios de Correo con GNU/Linux

Nuestra infraestructura de correo

● Configuración del servidor DNS

● Configuración de dominios en Postfix

● Enviar correos entre servidores

Portantier Information Security – Servicios de Correo con GNU/Linux

Servidor DNS

/etc/bind/named.conf.local

zone "hosted.com" { type master; file "/etc/bind/zones/hosted.com.db"; };

Portantier Information Security – Servicios de Correo con GNU/Linux

Servidor DNS

/etc/bind/named/zones/hosted.com.db

hosted.com. IN SOA ns1.hosted.com. admin.hosted.com. ( 201006071 ; serial 8H ; refresh 2H ; retry 4W ; expire 1D ; minimum TTL )

hosted.com. IN NS ns1.hosted.com.hosted.com. IN MX 10 mta.hosted.com.

www IN A 172.16.66.1mta IN A 172.16.66.1ns1 IN A 172.16.66.1

Portantier Information Security – Servicios de Correo con GNU/Linux

Dominios en Postfix

/etc/postfix/main.cf

mydomain = hosted.commyorigin = $mydomainmydestination = $myhostname localhost localhost.$mydomain $mydomain

smtpd_banner = $myhostname ESMTP $mail_name (Debian/GNU)

biff = noappend_dot_mydomain = noreadme_directory = no

Portantier Information Security – Servicios de Correo con GNU/Linux

Enviando correos con telnet

telnet mailserver.com 25MAIL FROM: yo@yo.comRCPT: TO: tu@tu.comDATA

Subject: holaFrom: q@q.com To: m@m.comcuerpo del mensaje.

Portantier Information Security – Servicios de Correo con GNU/Linux

Encabezados

Date Fecha (requerido)From Emisor (requerido)Message-Id Identificador únicoTo ReceptorSubject AsuntoCc Otros recipientesReply-To A quién responder el mensajeContent-type Estructura del mensajeMIME-Version Cumplimiento RFC1521Received Camino tomadoReturn-Path Identifica el camino de vuelta

Portantier Information Security – Servicios de Correo con GNU/Linux

Encabezados Extendidos

No son estándar, y se utilizan para propósitos informativos. La cantidad total no está documentada.

Ejemplos:

X-Mailer: Ximian Evolution 1.4.3X-Priority: 3X-Spam-Checker-Version: dspam-1.0.3

Portantier Information Security – Servicios de Correo con GNU/Linux

Cuerpo del mensaje (body)

Debe ser sólo texto plano y seguirle inmediamente a los encabezados.

Puede contener archivos adjuntos, preferentemente codificados en 7-bits (para que el MTA no los rompa).

Portantier Information Security – Servicios de Correo con GNU/Linux

Archivos adjuntos

Deben ser convertidos a texto plano(sólo caracteres imprimibles)

Portantier Information Security – Servicios de Correo con GNU/Linux

Codificación MIME Base 64

Multipurpose Internet Mail Extensions

Definida en RFC 1421 y RFC 2045

Permiten convertir archivos binarios a ASCII

Caracteres A-Z, a-z, 0-9, '+' y '/'. ('=' para sufijos.)

Herramientas: mpack, munpack, uudeview.

Usado en casi todos los clientes modernos (v 1.0)

Portantier Information Security – Servicios de Correo con GNU/Linux

Tipos de contenido

El tipo de contenido codificado en MIME, definido por el IANA. (No sólo aplican al email)

Referencias:http://en.wikipedia.org/wiki/Internet_media_typewww.iana.org/assignments/media-types

Ejemplo:Content-type: text/plain

Portantier Information Security – Servicios de Correo con GNU/Linux

Content-type (valores comunes)

text/plainTexto simple. El valor por defecto.

multipart/mixedIndica que hay texto y archivos adjuntos.

message/rfc822Adjunta otro correo electrónico

multipart/alternativeAdjunta una versión alternativa (ejemplo: texto y html)

Portantier Information Security – Servicios de Correo con GNU/Linux

Límite MIME (boundary)

Separa las distintas partes del mensaje

Ejemplo:Content-Type: multipart/mixed; boundary='/9DWx/yDrb'

--/9DWx/yDrbContent-Type: text/plain; charset=us-ascii

--/9DWx/yDrbContent-Type: application/x-zip-compressedContent-Disposition: attachment; filename=”file.zip”Content-Transfer-Encoding: base64

Portantier Information Security – Servicios de Correo con GNU/Linux

Control de contenidos

smtpd_*_restrictionsFiltros para origen y destino

*_checksFiltros para body, headers, attachments

FiltrosMecanismos de filtrado externos

Portantier Information Security – Servicios de Correo con GNU/Linux

Restricciones por origen / destino

● ¿De dónde viene el cliente?

● ¿Quién pretende ser el cliente?

● ¿El cliente tiene privilegios especiales?

● ¿Quién es el remitente?

● ¿Quién es el destinatario?

Portantier Information Security – Servicios de Correo con GNU/Linux

Restricciones por origen / destino

● ¿Se brindó la información de forma adecuada?

● ¿Se brindó en el orden apropiado?

● ¿Se brindó toda la información?

● ¿Es posible corroborar esa información?

Portantier Information Security – Servicios de Correo con GNU/Linux

Restricciones por origen / destino

● El mensaje no es recibido por el servidor

● No se envían notificaciones de rechazo

● La responsabilidad queda en el cliente

Portantier Information Security – Servicios de Correo con GNU/Linux

Restricciones por origen / destino

smtpd_client_restrictionsIP y/o el Hostname del cliente

smtpd_helo_restrictionsEl anterior, más argumento de HELO/EHLO

smtpd_sender_restrictionsEl anterior, más el argumento de 'MAIL FROM'

smtpd_recipient_restrictionsEl anterior, más el argumento de 'RCPT TO'

Portantier Information Security – Servicios de Correo con GNU/Linux

Restricciones por origen / destino

smtpd_data_restrictionsDetecta envío de contenido antes de 'DATA'

smtpd_etrn_restrictionsDefine qué clientes pueden utilizar el comando 'ETRN'

ETRN: Pide al servidor limpiar la cola de mails

Portantier Information Security – Servicios de Correo con GNU/Linux

Tipos de restricción

Genéricas

permitdeferrejectwarn_if_rejectreject_unauth_pipelining

Portantier Information Security – Servicios de Correo con GNU/Linux

Tipos de restricción

Intercambiables

smtpd_helo_required (requiere helo/ehlo)strict_rfc821_envelopes (no recomendado)disable_vrfy_command (deshabilita VRFY)allow_percent_hack (% → @)swap_bangpath (! → @, redes UUCP)

Portantier Information Security – Servicios de Correo con GNU/Linux

Cumplimiento de estándares

smtpd_helo_required = yes

Portantier Information Security – Servicios de Correo con GNU/Linux

Aplicando restricciones

Bloquea las direcciones IP listadas

smtpd_client_restrictions =check_client_access hash:/etc/postfix/clients

Portantier Information Security – Servicios de Correo con GNU/Linux

Aplicando restricciones

Filtra el HELO/EHLO

smtpd_helo_restrictions = check_helo_access pcre:/etc/postfix/helo_checks

Portantier Information Security – Servicios de Correo con GNU/Linux

Aplicando restricciones

Filtra las direcciones del archivo 'senders'Filtra los remitentes de dominios que no existen

smtpd_sender_restrictions =check_sender_access hash:/etc/postfix/sendersreject_unknown_sender_domain

Portantier Information Security – Servicios de Correo con GNU/Linux

Aplicando restricciones

Bloquea si no somos 'forwarders' o 'destinatarios'

smtpd_recipient_restrictions =reject_unauth_destination

Portantier Information Security – Servicios de Correo con GNU/Linux

Aplicando restricciones

Bloquea a los clientes que hacen 'pipelining' sin que el servidor se los haya permitido

smtpd_data_restrictions =reject_unauth_pipelining

Portantier Information Security – Servicios de Correo con GNU/Linux

Peleando contra los virus

Portantier Information Security – Servicios de Correo con GNU/Linux

Clamsmtp

● Utiliza ClamAV para la detección de virus

● Escucha en un puerto TCP

● Recibe los correos, los analiza y los devuelve

● Postfix los toma de nuevo y los procesa

● Permite correr scripts al detectar virus

Portantier Information Security – Servicios de Correo con GNU/Linux

Clamsmtp

apt-get install clamsmtpd

Portantier Information Security – Servicios de Correo con GNU/Linux

/etc/clamsmtpd.conf

OutAddress: 10025

Listen: 127.0.0.1:10026

Header: X-AV-Checked: ClamAV using ClamSMTP

Bounce: off

Quarantine: off

Portantier Information Security – Servicios de Correo con GNU/Linux

/etc/postfix/main.cf

#Define el filtro a utilizarcontent_filter = scan:127.0.0.1:10026

#Procesa el correo sin modificarreceive_override_options = no_address_mappings

Portantier Information Security – Servicios de Correo con GNU/Linux

/etc/postfix/master.cf

# AV scan filter (used by content_filter)scan unix - - n - 16 smtp -o smtp_send_xforward_command=yes

Portantier Information Security – Servicios de Correo con GNU/Linux

/etc/postfix/master.cf

# For injecting mail back into postfix from the filter127.0.0.1:10025 inet n - n - 16 smtpd -o content_filter= -o receive_override_options=

no_unknown_recipient_checks,no_header_body_checks

-o smtpd_helo_restrictions= -o smtpd_client_restrictions= -o smtpd_sender_restrictions= -o smtpd_recipient_restrictions=

permit_mynetworks, reject -o mynetworks_style=host -o smtpd_authorized_xforward_hosts=127.0.0.0/8

Portantier Information Security – Servicios de Correo con GNU/Linux

La prueba EICAR

ftp://download.trendmicro.com/products/eicar-file/eicar.com

Portantier Information Security – Servicios de Correo con GNU/Linux

Logs

postfix/smtp[5450]: 67DC183233: to=<fabian@example.com>, relay=127.0.0.1[127.0.0.1]:10026, delay=0.36, delays=0.17/0.08/0.11/0, dsn=2.0.0, status=sent (250 Virus Detected; Discarded Email)

clamsmtpd: 100005: from=root@tumail.com, to=fabian@example.com, status=VIRUS:Eicar-Test-Signature

Portantier Information Security – Servicios de Correo con GNU/Linux

Peleando contra el spam

Portantier Information Security – Servicios de Correo con GNU/Linux

Tipos de filtrado

● Sesión SMTP● Origen / Destino● Encabezados / Archivos adjuntos● Búsqueda de patrones● Análisis Bayesiano● DNSBL o RBL

Portantier Information Security – Servicios de Correo con GNU/Linux

disable_vrfy_command = yessmtpd_helo_required = yessmtpd_recipient_restrictions = reject_unknown_sender_domain reject_unknown_recipient_domain reject_rbl_client list.dsbl.org reject_rbl_client sbl.spamhaus.org reject_rbl_client cbl.abuseat.org reject_rbl_client dul.dnsbl.sorbs.net

/etc/postfix/main.cf

Portantier Information Security – Servicios de Correo con GNU/Linux

/etc/postfix/main.cf

smtpd_helo_restrictions =permit_mynetworksreject_invalid_hostname *reject_unknown_helo_hostname *reject_non_fqdn_hostname *

* Dependiendo del caso, puede no ser recomendable.

Portantier Information Security – Servicios de Correo con GNU/Linux

/etc/postfix/main.cf

smtpd_client_restrictions = permit_mynetworks, check_client_access hash:/etc/postfix/client_restrictions reject_rbl_client sbl-xbl.spamhaus.org reject_rbl_client cn.countries.nerd.dk reject_rbl_client kr.countries.nerd.dk reject_rbl_client pl.countries.nerd.dk reject_rbl_client sa.countries.nerd.dk reject_rbl_client zen.spamhaus.org

Portantier Information Security – Servicios de Correo con GNU/Linux

Recomendado

default_rbl_reply = $rbl_code Service unavailable; $rbl_class [$rbl_what] blocked using $rbl_domain${rbl_reason?; $rbl_reason}. For whitelisting, contact via http://mydomain.dom/blocked.php

Portantier Information Security – Servicios de Correo con GNU/Linux

Almacenamiento de correos

Portantier Information Security – Servicios de Correo con GNU/Linux

mbox

● Todos los correos en un sólo archivo● Cada correo empieza con “From ”● El final lo marca una línea en blanco● Antiguamente popular● No está definido en ninguna RFC● Presenta problemas de bloqueo

Portantier Information Security – Servicios de Correo con GNU/Linux

mbox

From hansolo@ixazon.dynip.com Sat Aug 03 2002Received: from ... by ... with ESMTP;Subject: PruebaFrom: <build.9.0.2416@ixazon.dynip.com>To: <junkdtectr@carolina.rr.com>

>Desde el principio de los tiempos, la gente ha escrito cartas.

From someoneelse@loa.invalid Sun Aug 04 2002Received: from ... by ... with SMTPSubject: IggeretTo: <you@aoeu.snth>

Ha iggeret hazot niktava blashon ivrit.

Portantier Information Security – Servicios de Correo con GNU/Linux

Maildir

● Cada correo en un archivo único

● Subdirectorios 'tmp', 'new' y 'cur'

● De 'tmp' los mensajes pasan a 'new'

● Los clientes de correo mueven de 'new' a 'cur'

● Maildir++

Portantier Information Security – Servicios de Correo con GNU/Linux

Protocolo IMAP

Portantier Information Security – Servicios de Correo con GNU/Linux

IMAP

● Internet Message Access Protocol

● Versión actual: IMAP 4 Revisión 1 (IMAP4rev1)

● RFC 3501 (http://tools.ietf.org/html/rfc3501)

Portantier Information Security – Servicios de Correo con GNU/Linux

Ventajas IMAP vs POP3

● Modos de operación online / offline● Soporte para múltiples clientes simultáneos● Acceso a partes MIME● Estado de los mensajes del lado del servidor● Búsquedas del lado del servidor● Preparado para ser extensible

Portantier Information Security – Servicios de Correo con GNU/Linux

El Proyecto Dovecot

Portantier Information Security – Servicios de Correo con GNU/Linux

Dovecot

● Open Source (www.dovecot.org)

● Primera versión: Junio 2002

● Pensado para ser rápido, seguro y fácil

● Soporta mbox y Maildir

Portantier Information Security – Servicios de Correo con GNU/Linux

Dovecot

apt-get install dovecot-imapd

Portantier Information Security – Servicios de Correo con GNU/Linux

Dovecot

/etc/dovecot/dovecot.conf

mail_location: mbox:~/mail:INBOX=/var/mail/%u

Portantier Information Security – Servicios de Correo con GNU/Linux

Dovecot

dovecot -n

Portantier Information Security – Servicios de Correo con GNU/Linux

Dovecot

# telnet 127.0.0.1 143Trying 127.0.0.1...Connected to 127.0.0.1.Escape character is '^]'.* OK [CAPABILITY IMAP4rev1] Dovecot Ready.. login fabian password. OK [CAPABILITY IMAP4rev1] Logged in

Portantier Information Security – Servicios de Correo con GNU/Linux

Dovecot

. list "" "*"* LIST (\NoInferiors \Marked) "/" "INBOX". OK List completed.

. status INBOX (messages)* STATUS "INBOX" (MESSAGES 29). OK Status completed.

. select INBOX

Portantier Information Security – Servicios de Correo con GNU/Linux

Dovecot

. fetch 29 rfc822.header* 29 FETCH (RFC822.HEADER {618}Delivered-To: fabian@example.comReceived: from debian.example.com (localhost [127.0.0.1])To: fabian@example.comSubject: mememeDate: Tue, 21 Jun 2011 23:47:53 -0300 (ART)From: root@example.com (root)). OK Fetch completed.

Portantier Information Security – Servicios de Correo con GNU/Linux

Dovecot

. fetch 29 rfc822.text* 29 FETCH (RFC822.TEXT {7}Este es el cuerpo del mensaje). OK Fetch completed.

. logout* BYE LOGOUT received. OK CompletedConnection closed by foreign host.

Portantier Information Security – Servicios de Correo con GNU/Linux

Servicios de Webmail

Portantier Information Security – Servicios de Correo con GNU/Linux

Webmail

● Facilitan el trabajo remoto

● Reemplazan al cliente de correo

● Varios proyectos disponibles

Portantier Information Security – Servicios de Correo con GNU/Linux

Webmail

● Squirrelmail (http://squirrelmail.org)

● Roundcube (http://roundcube.net)

● Horde3 (www.horde.org)

● Muchos más!

Portantier Information Security – Servicios de Correo con GNU/Linux

Squirrelmail

● Open Source

● Desarrollado en PHP

● Primera versión en 1999

● Muy estable y utilizado

Portantier Information Security – Servicios de Correo con GNU/Linux

Squirrelmail

apt-get install squirrelmail

Portantier Information Security – Servicios de Correo con GNU/Linux

Squirrelmail

/etc/squirrelmail/config.php

/etc/squirrelmail/config_local.php

/etc/squirrelmail/conf.pl

Portantier Information Security – Servicios de Correo con GNU/Linux

Squirrelmail

copiar:/etc/squirrelmail/apache.conf

a:/etc/apache2/sites-enabled/squirrelmail

Portantier Information Security – Servicios de Correo con GNU/Linux

Squirrelmail

/etc/init.d/apache restart

Portantier Information Security – Servicios de Correo con GNU/Linux

Squirrelmail

# firefox http://127.0.0.1/squirrelmail

Portantier Information Security – Servicios de Correo con GNU/Linux

Squirrelmail

Webmail :)

top related