Archive for July, 2007

Network Monitor

July 8, 2007

 tcpdump

Creación de un LiveCD con OpenBSD 4.0

July 7, 2007

Para este proceso nosotros realizaremos lo siguiente para evitar que nuestro sistema tenga información redundante o se haga un ciclo al momento de copiar todo el sistema trabajaremos sobre 2 máquinas, una que será llamada firewall y otra que será backup para ello llevaremos la siguiente secuencia de pasos.
Nota: Podrás ocupar VMware o algún otro programa de emulación como QEMU

1. Instalar el sistema base en los 2 equipos
2. Configurar el firewall tal y como deseamos que quede en el livecd con las aplicaciones y reglas predefinidas.
3. Copiar todo el sistema a la máquina backup
4. Personalizar y compilar el kernel del livecd

Una vez configurado el sistema en el firewall procederemos a enviar todo el sistema por medio de una tubería a la máquina backup de la siguiente forma.

# tar -pzcf – / | ssh root@backup dd of=/tmp/firewall.tgz
tar: Removing leading / from absolute path names in the archive

Si es la primera vez que nos conectamos a esta máquina se importará su clave del host a lo que responderemos Yes

The authenticity of host ‘backup (192.168.100.4)’ can’t be established.
RSA key fingerprint is xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx.
Are you sure you want to continue connecting (yes/no)? yes

En su defecto simplemente escribiremos el password del usuario con el que deseamos conectarnos.

root@backup’s password:

Tecleamos el password de root o del usuario que hayamos elegido.

Con esto estamos empaquetando todo el sistema y esta siendo enviado via ssh a la máquina backup y será almacenado en el directorio /tmp con el nombre de firewall.tgz

Una vez terminado tendremos algunos errores pero no se preocupen nada grave simplemente son archivos que se encuentran trabajando y por lo tanto no se puede hacer una copia exacta de ellos.

tar: Ustar cannot archive a socket /var/cron/tabs/.sock
tar: Ustar cannot archive a socket /var/empty/dev/log
tar: Ustar cannot archive a socket /dev/log
280052+5 records in
280053+1 records out
143387179 bytes transferred in 141.512 secs (1013248 bytes/sec)

Ahora estando en la máquina backup teclearemos lo siguiente uno para crear la carpeta y para desempaquetar todo el sistema anterior.

Nota: Es importante saber que ahí hay suficiente espacio o en su defecto poner otro directorio con mayor capacidad, para ver que particiones tienen suficiente espacio podriamos teclear df –h:

# df -h
Filesystem Size Used Avail Capacity Mounted on
/dev/wd0a 503M 38.1M 440M 8% /
/dev/wd0g 3.0G 2.0K 2.8G 0% /home
/dev/wd0f 3.0G 137M 2.7G 5% /tmp
/dev/wd0d 3.0G 504M 2.3G 18% /usr
/dev/wd0e 3.0G 4.4M 2.8G 0% /var
Aquí podremos observar que en /usr tenemos 2.3 gb libres suficientes para nuestra tarea.
Aunque podría ser cualquier otro directorio

# mkdir /usr/livecd
# tar -pzxf /tmp/firewall.tgz -C /usr/livecd/
# mkdir -p /usr/livecd/backups/dev; chmod 755 /usr/livecd/backups/dev

Borraremos información que podría ser sensitiva como el historial del shell o algun otro documento importante, así como también serán borradas claves de ssh, para que al iniciar el sistema cree una nueva de acuerdo al nuevo equipo en que se esta iniciando el livecd.

# rm -i /usr/livecd/root/{.history,.viminfo}
# rm -i /usr/livecd/home/*/{.history,.viminfo}
# rm -rf /usr/livecd/{src,ports}/*
# rm /usr/livecd/etc/ssh/*key*
# rm -rf /usr/livecd/var/tmp/*
# rm -rf /usr/livecd/tmp/*

También los logs serán eliminados

for log_file in `find /usr/livecd/var/log -type f`
do
echo “” > $log_file
done

Necesitamos respaldar algunos directorios que serán utilizados después

cp -pR /usr/livecd/{var,etc,root,home} /usr/livecd/backups/
cp -pR /usr/livecd/dev/MAKEDEV /usr/livecd/backups/dev/

Instalación de cruchgen , crunchide y libstubs

En la máquina de backup procederemos a instalar algunos programas que serán necesarios para la construcción y compilación del nuevo sistema como son crunchgen y crunchide, así como la librería libstubs.

Primero que nada debemos desempaquetar estos archivos ya que no se encuentran de manera preinstalada dentro de OpenBSD he aquí la secuencia de pasos:

Extracción de las fuentes de OpenBSD que en nuestro caso se encuentran en el CDROM, en caso de no tener el CDROM pueden bajarlo del sitio.
ftp://ftp.openbsd.org/pub/OpenBSD/4.0

Teniendo listo nuestro cdrom de OpenBSD procederemos a montar la unidad y desempaquetar el archivo src.tar.gz y sys.tar.gz:

Procederemos con lo siguiente:

Para montar la unidad de cdrom

# mount /dev/cd0a /mnt/
# cd /usr/src; tar xzf /mnt/4.0/i386/src.tar.gz
# tar zxf /mnt/4.0/i386/sys.tar.gz

Importante: Desmontar la unidad ya que si no posteriormente muestra un error en algun momento de la compilación.

# umount /mnt/

Una vez hecho esto podremos proceder a la compilación de los paquetes anteriores.

Instalación de crunchgen

# cd /usr/src/distrib/crunch/crunchgen/
# make; make install
cc -O2 -pipe -g -Wall -DMF_NAMES=’”Makefile.bsd-wrapper”,”Makefile”‘ -nostdinc -idirafter /usr/include -c crunchgen.c
sh /usr/src/distrib/crunch/crunchgen/mkskel.sh /usr/src/distrib/crunch/crunchgen/crunched_main.c > crunched_skel.c
cc -O2 -pipe -g -Wall -DMF_NAMES=’”Makefile.bsd-wrapper”,”Makefile”‘ -nostdinc -idirafter /usr/include -c crunched_skel.c
cc -o crunchgen crunchgen.o crunched_skel.o
nroff -Tascii -mandoc crunchgen.1 > crunchgen.cat1
install -c -s -o root -g bin -m 555 crunchgen /usr/bin/crunchgen
install -c -o root -g bin -m 444 crunchgen.cat1 /usr/share/man/cat1/crunchgen.0

Instalación de crunchide

# cd /usr/src/distrib/crunch/crunchide/
# make; make install
cc -O2 -pipe -nostdinc -idirafter /usr/include -c crunchide.c
cc -O2 -pipe -nostdinc -idirafter /usr/include -c elf_hide.c
cc -O2 -pipe -nostdinc -idirafter /usr/include -c ecoff_hide.c
cc -o crunchide crunchide.o elf_hide.o ecoff_hide.o
nroff -Tascii -mandoc crunchide.1 > crunchide.cat1
install -c -s -o root -g bin -m 555 crunchide /usr/bin/crunchide
install -c -o root -g bin -m 444 crunchide.cat1 /usr/share/man/cat1/crunchide.0

Instalación de la libreria libstubs

# cd /usr/src/distrib/special/libstubs/
# make; make install
cc -O2 -pipe -g -Os -D__DBINTERFACE_PRIVATE -c setlocale.c -o setlocale.o
cc -O2 -pipe -g -Os -D__DBINTERFACE_PRIVATE -c db.c -o db.o
building standard stubs library
ranlib libstubs.a
install -c -o root -g bin -m 600 libstubs.a /usr/lib/libstubs.a
ranlib -t /usr/lib/libstubs.a
chmod 444 /usr/lib/libstubs.a

Personalización del kernel

Ahora editaremos el siguiente archivo /usr/src/sys/arch/i386/conf/RAMDISK_CD

# cd /usr/src/sys/arch/i386/conf/

Por cualquier error que se puede cometer crearemos un archivo de respaldo de RAMDISK_CD de la siguiente forma

# cp RAMDISK_CD RAMDISK_CD.anterior
# vi RAMDISK_CD

Buscamos, agregamos y comentamos las siguientes líneas

option RAMDISK_HOOKS
option MINIROOTSIZE=3800
option MFS
option UNION
config bsd root on cd0a
#config bsd root on rd0a swap on rd0b and wd0b and sd0b

Podemos iniciar nuestro CD con algunas reglas de firewall

pseudo-device bpfilter 8
pseudo-device pf 1
pseudo-device pflog 1

A continuación modificaremos el siguiente archivo, al igual que el anterior haremos un respaldo de este archivo por algun cambio que pudiera ocurrir
/usr/src/distrib/i386/common/Makefile.inc

#cd /usr/src/distrib/i386/common/
#cp Makefile.inc Makefile.inc.anterior
#vi Makefile.inc

Ahora localizamos las siguientes líneas

#strip ${.OBJDIR}/boot
#strip -R .comment ${.OBJDIR}/boot

Reemplazamos las anteriores por la siguiente línea
strip -s -R .comment -K cngetc ${.OBJDIR}/boot

Ahora las siguientes

#strip bsd.strip
#strip -R .comment bsd.strip

Quitamos o comentamos las anteriores y se reemplazaran por esta.
strip -s -R .comment -K cngetc bsd.strip

Una vez hecho esto guardamos los cambios hechos y salimos.

Compilación del KERNEL RAMDISK

Este proceso puede tomar tiempo dependiendo de la velocidad del sistema además de que realizaremos unas tareas adicionales para verificar que todo este bien

Nota: Si diéramos un ls sobre este directorio veríamos que solo hay algunos paquetes, posteriormente se generan varios de los cuales nosotros solo necesitaremos el kernel generado bsd y el archivo cdrom40.fs

# cd /usr/src/sys/arch/i386/conf
# config RAMDISK_CD
# cd ../compile/RAMDISK_CD/
# make clean; make depend; make

Ahora la imagen de arranque será creada cuando es la primera vez que se hace esto el fólder obj se encuentra vació pero para evitar problemas simplemente borramos su contenido en caso que exista.

Una vez compilado el kernel tendrá que ser copiado a la nueva carpeta de livecd

# cd /usr/src/distrib/i386/ramdisk_cd/
# rm -rf obj/*
# make
# cp bsd /usr/livecd ; chown root:wheel /usr/livecd/bsd ; chmod 644 /usr/livecd/bsd
# cp cdrom40.fs /usr/livecd/

Ahora en el archivo /usr/livecd/etc/rc
# cd /usr/livecd/etc/
# vi rc
# Despues de : rm -f /fastboot # XXX (root now writeable)
echo ‘Montando unidades mfs’
mount_mfs -s 51200 -o async,nosuid,nodev,noatime swap /var
mount_mfs -i 4096 -s 6144 -o async,nosuid,nodev,noatime swap /etc
mount_mfs -i 128 -s 2048 -o async,noatime swap /dev
mount_mfs -s 6144 -o async,nosuid,nodev,noatime swap /tmp
mount_mfs -s 8192 -o async,nosuid,nodev,noatime swap /home
mount_mfs -s 8192 -o async,nosuid,nodev,noatime swap /root
sleep 2
echo -n ‘Copiando archivos: var ‘
cp -pR /backups/var/* /var
echo -n ‘etc ‘
cp -pR /backups/etc/* /etc
echo -n ‘dev ‘
cp -pR /backups/dev/* /dev
echo ‘root’
cp -pR /backups/root/.[a-z]* /root
echo ‘Creando nodos del dipositivo’
cd /dev && sh MAKEDEV all

Una vez finalizado esto eliminaremos las siguientes lineas en el archivo
/usr/livecd/backups/etc/rc

umount -a >/dev/null 2>&1
mount -uw / # root on nfs requires this, others aren’t hurt
rm -f /fastboot # XXX (root now writeable)

mount -s /usr >/dev/null 2>&1
mount -s /var >/dev/null 2>&1

echo clearing /tmp
# prune quickly with one rm, then use find to clean up /tmp/[lq]*
# (not needed with mfs /tmp, but doesn’t hurt there…)
(cd /tmp && rm -rf [a-km-pr-zA-Z]* &&
find . ! -name . ! -name lost+found ! -name quota.user
! -name quota.group -execdir rm -rf — {} ; -type d -prune)

Ahora si deseamos escribir un nuevo password para root al momento de iniciar el equipo en /usr/livecd/backups/etc/rc.local
# Add your local startup actions here.
# We need a root Password
echo ‘Escribe en nuevo password para root’
passwd

Actualizar el /usr/livecd/etc/fstab

# cd /usr/livecd/etc/
# vi fstab

Como nuestro sistema se estará ejecutando desde nuestro cdrom no se necesitan todas esas líneas así que pueden borrarse y reemplazar por solo estas

/dev/cd0a / cd9660 ro,noatime 0 0
/dev/fd0a /mnt/floppy msdos rw,noauto 0 0

También el floppy es marcado por que desde ahí serán leídas las configuraciones que permitirán iniciar las reglas del firewall.

Creamos el archivo boot.conf

# vi boot.conf
Y agregamos las siguientes lineas

set image /bsd
set timeout 5

Creación de la imagen
# cd /usr/livecd/
# mkhybrid -b cdrom40.fs -c boot.catalog -R -v -o /var/tmp/kauil.iso /usr/livecd/

Dudas y comentarios y cualquier otra aportación a peques@openbsd.com.mx

Bibliografía

http://www.openbsd-wiki.org/index.php?title=LiveCD
http://archives.neohapsis.com/archives/openbsd/2005-09/1348.html
http://www.blackant.net/other/docs/howto-bootable-cdrom-openbsd.php
http://www.threatmind.net/secwiki/OpenBSDLiveCD#head-d3925af4dcd407645974d11f07a30b088fc52e15

hide version xchat :P

July 7, 2007

 /set irc_hide_version on

Block ssh bruteforce attempts

July 5, 2007

Most people with a box on public IP, and with a sshd listening on port 22, notices a lot of bruteforce attempts. These attempts are filling up logs, and are a pure annoyance. Here’s how I “solved” it..

In OpenBSD 3.7, pf got a really nice feature called max-src-conn-rate, which specifies how quickly new connections can be made. Connecting hosts exceeding this limit can be put into a table, and all states including that hosts IP address, can also be flushed.

When I have the offending IPs in a table, it can easily be blocked early on in our ruleset. But since I don’t want to block a host forever, or even until the next reboot, I’m gonna use a small utility to clean out this table once in a while.

Let’s start with the magic pf rule:

# special rule for ssh
pass in on $ext_if proto tcp from any to ($ext_if) port ssh \
flags S/SA keep state \
(max-src-conn-rate 3/30, overload flush global)

The keyword here is ofcourse “max-src-conn-rate”. The arguments tell pf to put every IP exceeding a connection rate of more than 3 connections in every 30 seconds, in a table called “ssh-bruteforce”. How often do valid users connect to ssh that often? Ofcourse you can set this to 6/60 or something more apropriate for your environment. Last but not least pf kills all states originating from the bad host.

To keep the bad boys out, I add a block rule early on in my ruleset:

# block the ssh bruteforce bastards
block drop in quick on $ext_if from

Great, now the table are getting populated with bad hosts, and they’re getting blocked. But as I said earlier, I don’t want to block them forever. This is were expiretable comes in handy. This utility, written by Henrik Gustafsson, takes a look at a table, and removes (”expires”) entires older then the specified amount of time.

It’s in ports (sysutils/expiretable), but was commited after 3.8 was tagged, so you’ll have to go -current, or compile/install it by hand. Then add this to roots crontab:

*/5 * * * * /usr/local/sbin/expiretable -t 3600 ssh-bruteforce

Every five minutes, I expire entries older than one hour.

This is how I get rid of thousands of login attempts filling my logs.

Comment posted by
at 7/6/2007 3:00:01 PM

Está muy bien, lo implementaré para Mexinética porque sí, tenemos una cantidad obscena de gente llenando los logs a lo estúpido..

Comment posted by
at 7/6/2007 2:59:00 PM

Está muy bien, lo implementaré para Mexinética porque sí, tenemos una cantidad obscena de gente llenando los logs a lo estúpido..

Create a NetBSD LiveCD

July 5, 2007

Introduction
You may have various reasons to create a LiveCD.
Create a custom installer for your application and distribute it to the customers, create a desktop enviroment and boot it off your CD whenever you cannot access your own computer or maybe you have a diskless router and you want to run your O.S off the CD.
Implementation
There are two ways to create a LiveCD running NetBSD.
The “old” way is to create a boot floppy sized image.
The boot image must be exactly the size of either a 1200, 1440, or a 2880 kB floppy, and mkisofs will use this size when creating the output iso9660 filesystem.
The image will have a kernel with root file system inserted into it.
For i386, compile your custom kernel or you can use kernel config from /usr/src/sys/arch/i386/conf/INSTALL.
Then do following:

Create a directory where you will build your image and cd to it.
# cd /my_build/dir
Copy your custom kernel to this directory.
# cp /usr/src/sys/arch/i386/compile/obj/${MYKERNEL}/netbsd .
Create file system of the directory with files for your LiveCD.
# makefs -s ${FS_SIZE} -t ffs md.img ${IMG_DIR}
where ${FS_SIZE} is the size of your md.img and IMG_DIR is where you have your file system.

Now you need to insert the image into your kernel, wich then will get extracted of the kernel and mounted as memory file system:
# mdsetimage -v -s netbsd md.img
Compress your kernel to save space and rename it (optional step):
# gzip -f -9 netbsd ; mv netbsd.gz netbsd
For vnconfig, newfs and disklabel to “understand” the notion of floppy288 you need to edit your /etc/disktab and add there:

floppy288|2.88MB 3.5in Extra High Density Floppy:\
:ty=floppy:se#512:nt#2:rm#300:ns#36:nc#80:\
:pa#5760:oa#0:ba#4096:fa#512:ta=4.2BSD:\
:pb#5760:ob#0:\
:pc#5760:oc#0:

Create virtual disk and file system on it.
# dd if=/dev/zero of=image.fs count=5760
# vnconfig -t floppy288 -v -c /dev/vnd0d image.fs
# disklabel -rw /dev/vnd0d floppy288
# newfs -m 0 -o space -i 204800 /dev/rvnd0a

Bootstrap your virtual disk:
# /usr/sbin/installboot -v -m i386 -o timeout=3,console=pc -t ffs /dev/rvnd0a /usr/mdec/bootxx_ffsv1
Mount the virtual disk you just created and copy over your kernel and second stage boot loader.
# mount /dev/vnd0a /mnt
# cp /boot /mnt/
# cp netbsd /mnt/
# umount /mnt
# vnconfig -u vnd0d

Create a directory for your ISO image and copy your image there.
# cp image.fs cdisodir/
You can put some additional files to the cdisodir, they will be avaliable when you mounted your CD.

Create ISO image.
# mkisofs -l -J -R -o livecd.iso -c boot.catalog -b image.fs cdisodir

The new way is to use cdboot file instead of boot floppy.
This will allow you to use kernel beyond 2880 kB.
To compile cdboot, run:
# cd /usr/src/sys/arch/i386/stand/cdboot ; make
This time we will not create a floppy image. We dont need it since we can use cdboot instead.
Put cdboot to your cdisodir.
# cp /usr/src/sys/arch/i386/stand/cdboot/cdboot cdisodir/
Copy over your kernel with rootfs inserted into it and second stage boot loader to your ISO directory.
# cp netbsd cdisodir/
# cp /boot cdisodir/

Create ISO image
# mkisofs -l -J -R -o livecd.iso -c boot.catalog -b cdboot -no-emul-boot cdisodir
Notice the -no-emul-boot option. It’s becouse the boot image is not an image of a floppy.

To check your ISO image, you can mount it as virtual device:
# vnconfig -v -c /dev/vnd0d livecd.iso
# mount -t cd9660 /dev/vnd0a /mnt

When you’re done:
# umount /mnt
# vnconfig -u vnd0d

Thats all, its done. )

Special thanks to Yazzy )

Nessus Ubuntu

July 2, 2007

Lets install Nessus in Ubuntu in a few steps )

Open a terminal window and type in:

sudo apt-get install nessus

sudo apt-get install nessusd

sudo nessus-adduser

then add a user to nessus, set user and passwd, to login when ready.

sudo ln -fs /etc/init.d/nessusd /etc/rc2.d/S20nessusd

sudo /etc/init.d/nessusd start

sudo gedit /usr/share/applications/Nessus.desktop

Insert the following lines into the new file

[Desktop Entry]
Name=Nessus
Comment=Nessus
Exec=nessus
Icon=/usr/share/pixmaps/nessus.xpm
Terminal=false
Type=Application
Categories=Application;System;

After that you can find Nessus in the Gnome menu under Applications -> System Tools.

Y tu que hardware eres? :P

July 1, 2007

jejeje, me salio que soy el disipador de calor xD, aver chequen que harware son ustedes P

para checar que hardware son den click aqui )

Suse webmail server, postfix + cyrus + squirrelmail

July 1, 2007

we gonna install a Suse webmail server in a just few steaps, firts of all we install:

-Apache2 by yast

-Cyrus imap pop3

-imap server

-Ldap by yast too

-then we go to network services in yast, and we install mail server, that is the tool who is goin to config the webmail server with postfix cyrus and ldap.

-we can allways install openmailadmin and mysql to administrated cyrus

-then to have a webmail client we can use squirrelmail and install it into the web directory.

to config squirrelmail, we go to the squirrelmail config folder and we do ./config then the config window will show, after that, we choice option D then cyrus for autoconfig.

at this point we allready have a webmail server up and runing )

and thats all, i hope this can help to set up a fast webmail server.

any question

dmesg@mail.ru