lunes, 15 de marzo de 2010

FreeBSD 8: dovecot postfix spamassassin

Error a el momento de instalar maia:

===> Compressing manual pages for p5-Mail-DomainKeys-1.0
===> Registering installation for p5-Mail-DomainKeys-1.0
===> Returning to build of maia-1.0.2a_3
===> maia-1.0.2a_3 depends on file: /usr/local/lib/perl5/site_perl/5.10.1/Mail /SPF/Query.pm - not found
===> Verifying install for /usr/local/lib/perl5/site_perl/5.10.1/Mail/SPF/Que ry.pm in /usr/ports/mail/p5-Mail-SPF-Query

===> p5-Mail-SPF-Query-1.999.1 conflicts with installed package(s):
p5-Mail-SPF-2.007

They install files into the same place.
Please remove them first with pkg_delete(1).
*** Error code 1

Stop in /usr/ports/mail/p5-Mail-SPF-Query.
*** Error code 1

Stop in /usr/ports/security/maia.
*** Error code 1

Stop in /usr/ports/security/maia.

sábado, 6 de marzo de 2010

FreeBSD 7/8: Firewall con pf

Hola, vamos aqui poniendo lo relacionado a pf, para iniciar como puedo ver los numeros de mis reglas, por que cuando me bloquean me dice que regla fue pero no se cual es:

pfctl -vvs rules | grep @

Gracias a: https://calomel.org/pf_config.html

FreeBSD 8: Configurando ssh con llaves publicas

ssh tiene muchas opciones para hacerlo aun mas seguro, cuando tienes abierto el puerto atraves de tu firewall y lo tienes configurado por default, esta abierta la opcion: usuario+passwd.

Esto hace que en los logs de tu firewall aparezcan varios intentos de acceso tratando con diccionarios y esto le quita CPU a tu firewall como servidor.

Por ello es mas conveniente crear tu llaves y autentificarse con ellas, asi ya puedes deshabilitar el usuario+password.

Para ello tienes que tener configurado el sshd_config asi:

# $OpenBSD: sshd_config,v 1.80 2008/07/02 02:24:18 djm Exp $
# $FreeBSD: src/crypto/openssh/sshd_config,v 1.49.2.1.2.1 2009/10/25 01:1

# This is the sshd server system-wide configuration file. See
# sshd_config(5) for more information.

# This sshd was compiled with PATH=/usr/bin:/bin:/usr/sbin:/sbin

# The strategy used for options in the default sshd_config shipped with
# OpenSSH is to specify options with their default value where
# possible, but leave them commented. Uncommented options change a
# default value.

# Note that some of FreeBSD's defaults differ from OpenBSD's, and
# FreeBSD has a few additional options.

#VersionAddendum FreeBSD-20090522

#Port 22
#Protocol 2
#AddressFamily any
#ListenAddress 0.0.0.0
#ListenAddress ::

# Disable legacy (protocol version 1) support in the server for new
# installations. In future the default will change to require explicit
# activation of protocol 1
Protocol 2

# HostKey for protocol version 1
#HostKey /etc/ssh/ssh_host_key
# HostKeys for protocol version 2
#HostKey /etc/ssh/ssh_host_rsa_key
#HostKey /etc/ssh/ssh_host_dsa_key

# Lifetime and size of ephemeral version 1 server key
#KeyRegenerationInterval 1h
#ServerKeyBits 1024

# Logging
# obsoletes QuietMode and FascistLogging
#SyslogFacility AUTH
#LogLevel INFO

# Authentication:

#LoginGraceTime 2m
PermitRootLogin yes
#StrictModes yes
#MaxAuthTries 6
#MaxSessions 10

#RSAAuthentication yes
#PubkeyAuthentication yes
#AuthorizedKeysFile .ssh/authorized_keys

# For this to work you will also need host keys in /etc/ssh/ssh_known_hosts
#RhostsRSAAuthentication no
# similar for protocol version 2
#HostbasedAuthentication no
# Change to yes if you don't trust ~/.ssh/known_hosts for
# RhostsRSAAuthentication and HostbasedAuthentication
#IgnoreUserKnownHosts no
# Don't read the user's ~/.rhosts and ~/.shosts files
#IgnoreRhosts yes

# Change to yes to enable built-in password authentication.
PasswordAuthentication no
PermitEmptyPasswords no

# Change to no to disable PAM authentication
ChallengeResponseAuthentication no

# Kerberos options
#KerberosAuthentication no
#KerberosOrLocalPasswd yes
#KerberosTicketCleanup yes
#KerberosGetAFSToken no

# GSSAPI options
#GSSAPIAuthentication no
#GSSAPICleanupCredentials yes

# Set this to 'no' to disable PAM authentication, account processing,
# and session processing. If this is enabled, PAM authentication will
# be allowed through the ChallengeResponseAuthentication and
# PasswordAuthentication. Depending on your PAM configuration,
# PAM authentication via ChallengeResponseAuthentication may bypass
# the setting of "PermitRootLogin without-password".
# If you just want the PAM account and session checks to run without
# PAM authentication, then enable this but set PasswordAuthentication
# and ChallengeResponseAuthentication to 'no'.
UsePAM no

#AllowAgentForwarding yes
#AllowTcpForwarding yes
#GatewayPorts no
#X11Forwarding yes
#X11DisplayOffset 10
#X11UseLocalhost yes
#PrintMotd yes
#PrintLastLog yes
#TCPKeepAlive yes
#UseLogin no
#UsePrivilegeSeparation yes
#PermitUserEnvironment no
#Compression delayed
#ClientAliveInterval 0
#ClientAliveCountMax 3
#UseDNS yes
#PidFile /var/run/sshd.pid
#MaxStartups 10
#PermitTunnel no
#ChrootDirectory none

# no default banner path
#Banner none

# override default of no subsystems
Subsystem sftp /usr/libexec/sftp-server

# Example of overriding settings on a per-user basis
#Match User anoncvs
# X11Forwarding no
# AllowTcpForwarding no
# ForceCommand cvs server

#2010-03-04
AllowUsers root@192.168.50.120 root@192.168.50.100 root@192.168.50.3

La ultima linea marcado en bold, no viene en la configuracion original, con esto aun puedes darle mas seguridad a tu ssh, por que aqui solo le estas permitiendo a el usuario root poder accesar pero solo de las ip's ahi indicadas y puedes tambien hacerlo de la forma:

root@example.com

Si tienes un dns funcional.

Todo lo marcado en bold es lo que hago para tener un ssh mas seguro. Linux por default tiene habilitado el usuario root pero en FreeBSD no, es a veces un poco incomodo tener que estar haciendo el su o usar el sudo por ello yo prefiero tener el root abierto.

En el sistema donde estoy haciendo esto, necesito darle las llaves de los clientes que tienen permitido accesar.

Esos clientes tienen que tener ya listas sus llaves publicas, si no las tienen solo ejecutan este comando en cada uno de ellos(hablando de Linux/Unix):

ssh-keygen

Si gustan le dan una frase, pero luego se las va a estar solicitando, aqui solo denle enter hasta que termine la operacion, luego ya vamos a tener tiempo para investigar mas este parte.

Su sistema les va a poner las llevas en el home del usuario con el que las generaron, si fue root en /root/.ssh/

1; id_rsa
2; id_rsa.pub

2) es la llave publica la otra es la llave privada, esa se queda en su cliente a nadie se la tienen que dar, es su seguro.

En windows pueden hacer todo bajando el paquete completo de putty, ahi viene un modulo que se llama: PuTTYgen con el hacen todo graficamente.

Bien de lado del equipo que deseamos accesar debemos darle las llaves, estas se guardan en la misma ruta donde se guardan las llaves de cada usuario, en el archivo de nombre:

authorized_keys

es un archivo de texto, aqui vas las llaves asi:

ssh-rsa
7asdf87sdaf978dsa90f7s9da0f790ds7fdsaf980dsfn9sd87f09sd809sad8a78d709s7f9asd7f09sad7f9IUU=(=)(=)(JMN=(=)(=)MN==?=
%%$·"%khbyiubyUYBIUYyiy&786IUbuiinOYT0= pepito@example.com

es mi llave publica, es un listado grande que debe de ir en una sola linea de este archivo, aqui podemos poner cuantas llaves quieran, cada una es para cada usuario.

Y con esto listo, solo arrancamos el servicio y prueban.

/etc/rc.d/ssh start

Abren su cliente ssh y adentro, saludos!!!

miércoles, 3 de marzo de 2010

FreeBSD 8: Crear Jails.

Bien he estado viendo esto de las jails, que bonitas son, es una forma de virtualizar nativa. El handbook esta muy claro, nomas deseo aqui plasmar ciertas cosas que me ha sucedido.

Si por alguna razon ya que tenemos nuestro buildworld listo, y deseamos llevar a cabo el paso donde lo mandamos a el directorio de nuestro jail por ejemplo:

make installworld DESTDIR=$D

Pero si nuestro /tmp lo tenemos montado por seguridad con el parametro noexec, el comando anterior no funcionara y saldra con error.

Este es mi src.conf, quiero optmizarlo a el maximo para mis jails:

WITHOUT_APM="yes"
WITHOUT_ATM="yes"
WITHOUT_ASSERT_DEBUG="yes"
WITHOUT_AT="yes"
WITHOUT_AUTHPF="yes"
WITHOUT_BIND="yes"
WITHOUT_BLUETOOTH="yes"
WITHOUT_BOOT="yes"
WITHOUT_CALENDAR="yes"
WITHOUT_CDDL="yes"
WITHOUT_CVS="yes"
WITHOUT_DICT="yes"
WITHOUT_EXAMPLES="yes"
WITHOUT_FLOPPY="yes"
WITHOUT_FREEBSD_UPDATE="yes"
WITHOUT_GAMES="yes"
WITHOUT_GPIB="yes"
WITHOUT_GSSAPI="yes"
WITHOUT_INET6="yes"
WITHOUT_HTML="yes"
WITHOUT_IPFILTER="yes"
WITHOUT_IPFW="yes"
WITHOUT_IPX="yes"
WITHOUT_JAIL="yes"
WITHOUT_KERBEROS="yes"
WITHOUT_KVM="yes"
WITHOUT_LPR="yes"
WITHOUT_MAILWRAPPER="yes"
WITHOUT_MAN="yes"
WITHOUT_NDIS="yes"
WITHOUT_NIS="yes"
WITHOUT_PF="yes"
WITHOUT_PPP="yes"
WITHOUT_PMC="yes"
WITHOUT_PROFILE="yes"
WITHOUT_QUOTAS="yes"
WITHOUT_RCMDS="yes"
WITHOUT_RCS="yes"
WITHOUT_SENDMAIL="yes"
WITHOUT_SHAREDOCS="yes"
WITHOUT_SYSCONS="yes"
WITHOUT_SYSINSTALL="yes"
WITHOUT_TELNET="yes"
WITHOUT_USB="yes"
WITHOUT_WIRELESS="yes"
WITHOUT_WPA_SUPPLICANT_EAPOL="yes"

Hay muchas cosas aqui que se que no me sirven e investigando al respecto(googleando) de las que desconozco he llegado a este archivo, varios buildworld tronados, pero al fin tengo mi arhivo final.

Cuando estaba haciendo el buildworld, salio un error, desgraciadamente no alcance a plasmarlo aqui, pero este linea del src.conf me estaba causando el problema:

WITHOUT_INSTALLLIB="yes"

Enseguida me salio este otro error:

Error 2:===> usr.sbin/ifmcstat (all)

cc -O2 -pipe -DINET6 -DNDEBUG -std=gnu99 -fstack-protector -Wsystem-headers -Wall -Wno-format-y2k -Wno-uninitialized -Wno-pointer-sign -c /usr/src/usr.sbin/ifmcstat/ifmcstat.c
/usr/src/usr.sbin/ifmcstat/ifmcstat.c:170: warning: 'in6_ifinfo' used but never defined
cc -O2 -pipe -DINET6 -DNDEBUG -std=gnu99 -fstack-protector -Wsystem-headers -Wall -Wno-format-y2k -Wno-uninitialized -Wno-pointer-sign -c /usr/src/usr.sbin/ifmcstat/printb.c
cc -O2 -pipe -DINET6 -DNDEBUG -std=gnu99 -fstack-protector -Wsystem-headers -Wall -Wno-format-y2k -Wno-uninitialized -Wno-pointer-sign -o ifmcstat ifmcstat.o printb.o
ifmcstat.o(.text+0xb96): In function `main':
: undefined reference to `in6_ifinfo'
*** Error code 1

Stop in /usr/src/usr.sbin/ifmcstat.
*** Error code 1

Mismo error, aqui solo quitamos el WITHOUT_NCP=yes, vamos a regresarlo, necesitamos saber cual esta causando esto...

Stop in /usr/src/usr.sbin.
*** Error code 1

Stop in /usr/src.
*** Error code 1

Stop in /usr/src.
*** Error code 1

Stop in /usr/src.

Ya habia tenido este error antes, y no supe quien lo causo, pero ya por fin mi buildworld funciono y tengo mis jails listas.

Aun estoy esperando que alguien del foro de freebsd, vean my src.conf y comenten al respecto para ver si esta correcto, si puedo aun eliminar mas cosas y agregar algunas, si estoy siendo muy estricto con el, etc. En fin lo que necesito es el src.conf para todas mis jails.

Archivos en comun

Ahora vamos a ver tenemos un host y sus jails, las jails tiene la siguiente funcion:

jail1 --> apache+mysql
jail2 --> bind
jail3 -->spam
jail4 -->mail

El hosts tiene su archivo rc.conf para cada jail asi:

##############################################################
### Jail Configuration #######################################
##############################################################
jail_enable="YES" # Set to NO to disable starting of any jails
jail_list="jail1 jail2 jail3" # Space separated list of names of jails
jail1_set_hostname_allow="NO" # Allow root user in a jail to change its hostname
jail2_set_hostname_allow="NO"
jail3_set_hostname_allow="NO"
##############################################################
############### JAIL1 ######################
##############################################################
jail_jail1_rootdir="/jails/jail1" # Jail's root directory
jail_jail1_hostname="apache.example.com" # Jail's hostname
jail_jail1_interface="fxp0" # Jail's interface variable to c
jail_jail1_ip="192.168.50.2" # Jail's primary IPv4 and IPv6 a
jail_jail1_devfs_enable="YES" # mount devfs in the jail
jail1_sysvipc_allow="NO"
##############################################################
############### JAIL2 ######################
##############################################################
jail_jail2_rootdir="/jails/jail2" # Jail's root directory
jail_jail2_hostname="dns.example.com" # Jail's hostname
jail_jail2_interface="fxp0" # Jail's interface variable to c
jail_jail2_ip="192.168.50.3" # Jail's primary IPv4 and IPv6 a
jail_jail2_devfs_enable="YES" # mount devfs in the jail
jail2_sysvipc_allow="NO"
##############################################################
############### JAIL3 ######################
##############################################################
jail_jail3_rootdir="/jails/jails3" # Jail's root directory
jail_jail3_hostname="spam.example.com" # Jail's hostname
jail_jail3_interface="fxp0" # Jail's interface variable to c
jail_jail3_ip="192.168.50.4" # Jail's primary IPv4 and IPv6 a
jail_jail3_devfs_enable="YES" # mount devfs in the jail
jail3_sysvipc_allow="NO"

Con esto arrancan mis jails al reiniciar el equipo.

Bien ahora que archivos tienen en comun los jails:
rc.conf
hosts
resolv.conf
ports-supfile

rc.conf:

##############################################################
### Important initial Boot-time options ####################
##############################################################

cleanvar_enable="YES" # Clean the /var directory
root_rw_mount="YES" # Set to NO to inhibit remounting root read-write.
fsck_y_enable="YES" # Set to YES to do fsck -y if the initial preen fails.
fsck_y_flags="" # Additional flags for fsck -y
background_fsck="NO" # Attempt to run fsck in the background where possible
##############################################################
### Network configuration sub-section ######################
##############################################################
### Basic network and firewall/security options: ###
hostname="spam.example.com"
hostid_enable="YES" # Set host UUID.
hostid_file="/etc/hostid" # File with hostuuid.
icmp_log_redirect="NO" # Set to YES to log ICMP REDIRECT packets
network_interfaces="lo fxp0" # List of network interfaces (or "auto").
ifconfig_lo0="inet 127.0.0.1" # default loopback device configuration.
ifconfig_fxp0="inet 192.168.50.4 netmask 255.255.255.0"
inetd_enable="NO"

### Network daemon (miscellaneous) ###
syslogd_enable="YES" # Run syslog daemon (or NO).
syslogd_program="/usr/sbin/syslogd" # path to syslogd, if you want a different
syslogd_flags="-ss" # Flags to syslogd (if enabled).
# kerberos. Do not run the admin daemons on slave servers
#
kerberos5_server_enable="NO" # Run a kerberos 5 master server (or NO).

### Network daemon (NFS): All need rpcbind_enable="YES" ###
amd_enable="NO" # Run amd service with $amd_flags (or NO).

### SNMP daemon ###
# Be sure to understand the security implications of running SNMP v1/v2
# in your network.
bsnmpd_enable="NO" # Run the SNMP daemon (or NO).
bsnmpd_flags="" # Flags for bsnmpd.

### Network routing options: ###
defaultrouter="192.168.50.1" # Set to default gateway (or NO).

### Miscellaneous network options: ###
icmp_bmcastecho="NO" # respond to broadcast ping packets

### IPv6 options: ###
ipv6_enable="NO" # Set to YES to set up for IPv6.

##############################################################
### System console options #################################
##############################################################

keyboard="" # keyboard device to use (default /dev/kbd0).
keymap="NO" # keymap in /usr/share/syscons/keymaps/* (or NO).
keyrate="fast" # keyboard rate to: slow, normal, fast (or NO).
keybell="NO" # See kbdcontrol(1) for options. Use "off" to disable.
keychange="NO" # function keys default values (or NO).
cursor="destructive" # cursor type {normal|blink|destructive} (or NO
scrnmap="NO" # screen map in /usr/share/syscons/scrnmaps/* (or NO).
blanktime="NO" # blank time (in seconds) or "NO" to turn it off.
saver="NO" # screen saver: Uses /boot/kernel/${saver}_saver.ko
moused_enable="NO" # Run the mouse daemon.

##############################################################
### Mail Transfer Agent (MTA) options ######################
##############################################################

mta_start_script="/etc/rc.sendmail"
# Script to start your chosen MTA, called by /etc/rc.
# Settings for /etc/rc.sendmail and /etc/rc.d/sendmail:
sendmail_enable="NONE" # Run the sendmail inbound daemon (YES/NO).

##############################################################
### Miscellaneous administrative options ###################
##############################################################

auditd_enable="NO" # Run the audit daemon.
auditd_program="/usr/sbin/auditd" # Path to the audit daemon.
auditd_flags="" # Which options to pass to the audit daemon.
cron_enable="YES" # Run the periodic job daemon.
cron_program="/usr/sbin/cron" # Which cron executable to run (if enabled).
cron_dst="YES" # Handle DST transitions intelligently (YES/NO)
cron_flags="" # Which options to pass to the cron daemon.
quota_enable="NO" # turn on quotas on startup (or NO).
check_quotas="NO" # Check quotas on startup (or NO).
quotaon_flags="-a" # Turn quotas on for all file systems (if enabled)
quotaoff_flags="-a" # Turn quotas off for all file systems at shutdown
quotacheck_flags="-a" # Check all file system quotas (if enabled)

# Emulation/compatibility services provided by /etc/rc.d/abi
kern_securelevel_enable="NO" # kernel security level (see security(7))
kern_securelevel="-1" # range: -1..3 ; `-1' is the most insecure
update_motd="NO" # update version info in /etc/motd (or NO)
dmesg_enable="NO" # Save dmesg(8) to /var/run/dmesg.boot
newsyslog_enable="YES" # Run newsyslog at startup.
newsyslog_flags="-CN" # Newsyslog flags to create marked files
mixer_enable="NO" # Run the sound mixer.
sshd_enable="YES" # Enable sshd
sshd_program="/usr/sbin/sshd" # path to sshd, if you want a different one.
sshd_flags="-4" # Additional flags for sshd.
rcpbind_enable="NO"
clear_tmp_enable="YES"

Marque en negritas las partes que cambian de jail a jail lo demas todo por default, la unica manera de accesar a las jails es por el mismo host o via ssh.

hosts:
aqui ya saben que tiene que llevar correcto?
resolv.conf:
nuestro dns
ports-supfile:
datos para actualizar los ports.

Paquetes Necesarios

Que paquetes necesito yo en mis jails:

screeen
cvsup-without-gui
portupgrade

Son los necesito como minimo para cada jail.

Archivo de Host

Aqui tengo el archivo que uso para el hosts, si lo observan ahi opciones que se deseo tenga el hosts, como PF, ZFS, entre ellas.

Este es:

WITHOUT_APM="yes"
WITHOUT_ATM="yes"
WITHOUT_ASSERT_DEBUG="yes"
WITHOUT_AT="yes"
WITHOUT_BIND="yes"
WITHOUT_BLUETOOTH="yes"
WITHOUT_BOOT="yes"
WITHOUT_CALENDAR="yes"
WITHOUT_CVS="yes"
WITHOUT_DICT="yes"
WITHOUT_EXAMPLES="yes"
WITHOUT_FLOPPY="yes"
WITHOUT_FREEBSD_UPDATE="yes"
WITHOUT_GAMES="yes"
WITHOUT_GPIB="yes"
WITHOUT_GSSAPI="yes"
WITHOUT_INET6="yes"
WITHOUT_HTML="yes"
WITHOUT_IPFILTER="yes"
WITHOUT_IPFW="yes"
WITHOUT_IPX="yes"
WITHOUT_KERBEROS="yes"
WITHOUT_KVM="yes"
WITHOUT_LPR="yes"
WITHOUT_MAILWRAPPER="yes"
WITHOUT_MAN="yes"
WITHOUT_NDIS="yes"
WITHOUT_NIS="yes"
WITHOUT_PPP="yes"
WITHOUT_PMC="yes"
WITHOUT_PROFILE="yes"
WITHOUT_QUOTAS="yes"
WITHOUT_RCMDS="yes"
WITHOUT_RCS="yes"
WITHOUT_SENDMAIL="yes"
WITHOUT_SHAREDOCS="yes"
WITHOUT_SYSCONS="yes"
WITHOUT_SYSINSTALL="yes"
WITHOUT_TELNET="yes"
WITHOUT_WIRELESS="yes"
WITHOUT_WPA_SUPPLICANT_EAPOL="yes"

Con este quiero trabajar.