Professional Documents
Culture Documents
2011-07-12 (v1.0)
PortantierInformationSecurityServiciosdeCorreoconGNU/Linux
Fabian Portantier
Consultor en Seguridad Informtica Fantico de GNU/Linux (Debian) Mail: fabian@portantier.com Web: www.portantier.com
PortantierInformationSecurityServiciosdeCorreoconGNU/Linux
Qu es el correo electrnico?
PortantierInformationSecurityServiciosdeCorreoconGNU/Linux
Componentes
MUA jose@si.com
Mailbox
MDA
MTA si.com
INTERNET
MTA no.com
MDA
Mailbox
MUA pepe@no.com
PortantierInformationSecurityServiciosdeCorreoconGNU/Linux
Protocolos Involucrados
PortantierInformationSecurityServiciosdeCorreoconGNU/Linux
PortantierInformationSecurityServiciosdeCorreoconGNU/Linux
PTR: Pointer
PortantierInformationSecurityServiciosdeCorreoconGNU/Linux
Consulta a registros MX
PortantierInformationSecurityServiciosdeCorreoconGNU/Linux
DNS
fabian@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
PortantierInformationSecurityServiciosdeCorreoconGNU/Linux
SMTP
Simple Mail Transfer Protocol RFC 821(Original) RFC 1123 (Correcciones) RFC 2821 (ESMTP)
PortantierInformationSecurityServiciosdeCorreoconGNU/Linux
SMTP
PortantierInformationSecurityServiciosdeCorreoconGNU/Linux
SMTP-AUTH
Extensin de SMTP
Verificacin de clientes
Control de Accesos
PortantierInformationSecurityServiciosdeCorreoconGNU/Linux
PortantierInformationSecurityServiciosdeCorreoconGNU/Linux
Cual elegir?
PortantierInformationSecurityServiciosdeCorreoconGNU/Linux
Postfix ! (www.postfix.org)
PortantierInformationSecurityServiciosdeCorreoconGNU/Linux
Ventajas de Postfix
PortantierInformationSecurityServiciosdeCorreoconGNU/Linux
Archivos de Configuracin
/etc/postfix/main.cf /etc/postfix/master.cf
PortantierInformationSecurityServiciosdeCorreoconGNU/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
PortantierInformationSecurityServiciosdeCorreoconGNU/Linux
PortantierInformationSecurityServiciosdeCorreoconGNU/Linux
mutt
PortantierInformationSecurityServiciosdeCorreoconGNU/Linux
Herramientas
postconf: Consultar / modificar configuracin postsuper: Gestin de colas y correos qshape: Reporta el estado de las colas sendmail: Enva correos Algunas otras...
PortantierInformationSecurityServiciosdeCorreoconGNU/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: Slo si actuamos como nodo de reenvo de correo.
PortantierInformationSecurityServiciosdeCorreoconGNU/Linux
Bind (I)
/etc/bind/named.conf.local zone "example.com" { type master; file "/etc/bind/zones/example.com.db"; };
PortantierInformationSecurityServiciosdeCorreoconGNU/Linux
Bind (II)
/etc/bind/zones/example.com.db example.com. IN SOA ns1.example.com. admin.example.com. ( 2006081401 28800 3600 604800 38400 ns1.example.com. mta.example.com.
PortantierInformationSecurityServiciosdeCorreoconGNU/Linux
Servidor DNS
PortantierInformationSecurityServiciosdeCorreoconGNU/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 ns1.hosted.com. mta.hosted.com.
PortantierInformationSecurityServiciosdeCorreoconGNU/Linux
Dominios en Postfix
/etc/postfix/main.cf
mydomain = hosted.com myorigin = $mydomain mydestination = $myhostname localhost localhost.$mydomain $mydomain smtpd_banner = $myhostname ESMTP $mail_name (Debian/GNU) biff = no append_dot_mydomain = no readme_directory = no
PortantierInformationSecurityServiciosdeCorreoconGNU/Linux
Encabezados
Date From Message-Id To Subject Cc Reply-To Content-type MIME-Version Received Return-Path Fecha (requerido) Emisor (requerido) Identificador nico Receptor Asunto Otros recipientes A quin responder el mensaje Estructura del mensaje Cumplimiento RFC1521 Camino tomado Identifica el camino de vuelta
PortantierInformationSecurityServiciosdeCorreoconGNU/Linux
Encabezados Extendidos
No son estndar, y se utilizan para propsitos informativos. La cantidad total no est documentada. Ejemplos: X-Mailer: Ximian Evolution 1.4.3 X-Priority: 3 X-Spam-Checker-Version: dspam-1.0.3
PortantierInformationSecurityServiciosdeCorreoconGNU/Linux
Debe ser slo texto plano y seguirle inmediamente a los encabezados. Puede contener archivos adjuntos, preferentemente codificados en 7-bits (para que el MTA no los rompa).
PortantierInformationSecurityServiciosdeCorreoconGNU/Linux
Archivos adjuntos
PortantierInformationSecurityServiciosdeCorreoconGNU/Linux
Tipos de contenido
El tipo de contenido codificado en MIME, definido por el IANA. (No slo aplican al email) Referencias: http://en.wikipedia.org/wiki/Internet_media_type www.iana.org/assignments/media-types Ejemplo: Content-type: text/plain
PortantierInformationSecurityServiciosdeCorreoconGNU/Linux
Control de contenidos
smtpd_*_restrictions Filtros para origen y destino *_checks Filtros para body, headers, attachments Filtros Mecanismos de filtrado externos
PortantierInformationSecurityServiciosdeCorreoconGNU/Linux
De dnde viene el cliente? Quin pretende ser el cliente? El cliente tiene privilegios especiales? Quin es el remitente? Quin es el destinatario?
PortantierInformationSecurityServiciosdeCorreoconGNU/Linux
Se brind la informacin de forma adecuada? Se brind en el orden apropiado? Se brind toda la informacin? Es posible corroborar esa informacin?
PortantierInformationSecurityServiciosdeCorreoconGNU/Linux
smtpd_data_restrictions Detecta envo de contenido antes de 'DATA' smtpd_etrn_restrictions Define qu clientes pueden utilizar el comando 'ETRN' ETRN: Pide al servidor limpiar la cola de mails
PortantierInformationSecurityServiciosdeCorreoconGNU/Linux
Tipos de restriccin
PortantierInformationSecurityServiciosdeCorreoconGNU/Linux
Tipos de restriccin
Intercambiables smtpd_helo_required strict_rfc821_envelopes disable_vrfy_command allow_percent_hack swap_bangpath (requiere helo/ehlo) (no recomendado) (deshabilita VRFY) (% @) (! @, redes UUCP)
PortantierInformationSecurityServiciosdeCorreoconGNU/Linux
Cumplimiento de estndares
smtpd_helo_required = yes
PortantierInformationSecurityServiciosdeCorreoconGNU/Linux
Aplicando restricciones
PortantierInformationSecurityServiciosdeCorreoconGNU/Linux
Aplicando restricciones
Filtra el HELO/EHLO
smtpd_helo_restrictions = check_helo_access pcre:/etc/postfix/helo_checks
PortantierInformationSecurityServiciosdeCorreoconGNU/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/senders reject_unknown_sender_domain
PortantierInformationSecurityServiciosdeCorreoconGNU/Linux
Aplicando restricciones
PortantierInformationSecurityServiciosdeCorreoconGNU/Linux
Aplicando restricciones
Bloquea a los clientes que hacen 'pipelining' sin que el servidor se los haya permitido
smtpd_data_restrictions = reject_unauth_pipelining
PortantierInformationSecurityServiciosdeCorreoconGNU/Linux
PortantierInformationSecurityServiciosdeCorreoconGNU/Linux
Clamsmtp
Utiliza ClamAV para la deteccin 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
PortantierInformationSecurityServiciosdeCorreoconGNU/Linux
Clamsmtp
PortantierInformationSecurityServiciosdeCorreoconGNU/Linux
/etc/clamsmtpd.conf
OutAddress: 10025 Listen: 127.0.0.1:10026 Header: X-AV-Checked: ClamAV using ClamSMTP Bounce: off Quarantine: off
PortantierInformationSecurityServiciosdeCorreoconGNU/Linux
/etc/postfix/main.cf
#Define el filtro a utilizar content_filter = scan:127.0.0.1:10026 #Procesa el correo sin modificar receive_override_options = no_address_mappings
PortantierInformationSecurityServiciosdeCorreoconGNU/Linux
/etc/postfix/master.cf
PortantierInformationSecurityServiciosdeCorreoconGNU/Linux
/etc/postfix/master.cf
# For injecting mail back into postfix from the filter 127.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
PortantierInformationSecurityServiciosdeCorreoconGNU/Linux
La prueba EICAR
ftp://download.trendmicro.com/products/eicar-file/eicar.com
PortantierInformationSecurityServiciosdeCorreoconGNU/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-TestSignature
PortantierInformationSecurityServiciosdeCorreoconGNU/Linux
PortantierInformationSecurityServiciosdeCorreoconGNU/Linux
Tipos de filtrado
Sesin SMTP Origen / Destino Encabezados / Archivos adjuntos Bsqueda de patrones Anlisis Bayesiano DNSBL o RBL
PortantierInformationSecurityServiciosdeCorreoconGNU/Linux
/etc/postfix/main.cf
disable_vrfy_command = yes smtpd_helo_required = yes smtpd_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
PortantierInformationSecurityServiciosdeCorreoconGNU/Linux
/etc/postfix/main.cf
smtpd_helo_restrictions = permit_mynetworks reject_invalid_hostname * reject_unknown_helo_hostname * reject_non_fqdn_hostname * * Dependiendo del caso, puede no ser recomendable.
PortantierInformationSecurityServiciosdeCorreoconGNU/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
PortantierInformationSecurityServiciosdeCorreoconGNU/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
PortantierInformationSecurityServiciosdeCorreoconGNU/Linux
Almacenamiento de correos
PortantierInformationSecurityServiciosdeCorreoconGNU/Linux
mbox
Todos los correos en un slo archivo Cada correo empieza con From El final lo marca una lnea en blanco Antiguamente popular No est definido en ninguna RFC Presenta problemas de bloqueo
PortantierInformationSecurityServiciosdeCorreoconGNU/Linux
mbox
From hansolo@ixazon.dynip.com Sat Aug 03 2002 Received: from ... by ... with ESMTP; Subject: Prueba From: <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 2002 Received: from ... by ... with SMTP Subject: Iggeret To: <you@aoeu.snth> Ha iggeret hazot niktava blashon ivrit.
PortantierInformationSecurityServiciosdeCorreoconGNU/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++
PortantierInformationSecurityServiciosdeCorreoconGNU/Linux
Protocolo IMAP
PortantierInformationSecurityServiciosdeCorreoconGNU/Linux
IMAP
Modos de operacin online / offline Soporte para mltiples clientes simultneos Acceso a partes MIME Estado de los mensajes del lado del servidor Bsquedas del lado del servidor Preparado para ser extensible
PortantierInformationSecurityServiciosdeCorreoconGNU/Linux
El Proyecto Dovecot
PortantierInformationSecurityServiciosdeCorreoconGNU/Linux
Dovecot
Open Source (www.dovecot.org) Primera versin: Junio 2002 Pensado para ser rpido, seguro y fcil Soporta mbox y Maildir
PortantierInformationSecurityServiciosdeCorreoconGNU/Linux
Dovecot
PortantierInformationSecurityServiciosdeCorreoconGNU/Linux
Dovecot
PortantierInformationSecurityServiciosdeCorreoconGNU/Linux
Dovecot
dovecot -n
PortantierInformationSecurityServiciosdeCorreoconGNU/Linux
Dovecot
# telnet 127.0.0.1 143 Trying 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
PortantierInformationSecurityServiciosdeCorreoconGNU/Linux
Dovecot
. list "" "*" * LIST (\NoInferiors \Marked) "/" "INBOX" . OK List completed. . status INBOX (messages) * STATUS "INBOX" (MESSAGES 29) . OK Status completed. . select INBOX
PortantierInformationSecurityServiciosdeCorreoconGNU/Linux
Dovecot
. fetch 29 rfc822.header * 29 FETCH (RFC822.HEADER {618} Delivered-To: fabian@example.com Received: from debian.example.com (localhost [127.0.0.1]) To: fabian@example.com Subject: mememe Date: Tue, 21 Jun 2011 23:47:53 -0300 (ART) From: root@example.com (root) ) . OK Fetch completed.
PortantierInformationSecurityServiciosdeCorreoconGNU/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 Completed Connection closed by foreign host.
PortantierInformationSecurityServiciosdeCorreoconGNU/Linux
Servicios de Webmail
PortantierInformationSecurityServiciosdeCorreoconGNU/Linux
Webmail
Webmail
Squirrelmail
Open Source Desarrollado en PHP Primera versin en 1999 Muy estable y utilizado
PortantierInformationSecurityServiciosdeCorreoconGNU/Linux
Squirrelmail
PortantierInformationSecurityServiciosdeCorreoconGNU/Linux
Squirrelmail
PortantierInformationSecurityServiciosdeCorreoconGNU/Linux
Squirrelmail
PortantierInformationSecurityServiciosdeCorreoconGNU/Linux
Squirrelmail
/etc/init.d/apache restart
PortantierInformationSecurityServiciosdeCorreoconGNU/Linux
Squirrelmail
# firefox http://127.0.0.1/squirrelmail
PortantierInformationSecurityServiciosdeCorreoconGNU/Linux
Squirrelmail
Webmail :)
PortantierInformationSecurityServiciosdeCorreoconGNU/Linux