• http://www.vgroupnetwork.com.ar/foro/39761-manuales-comandos-de-frecuentes-gnu-linux.html

Abriendose a la Internet.

caudio

*nix powered Mod
Empecemos con los hechos.

Al tener una Pentium III de gateway, decidi tomarme el tiempo de compilar todo desde 0 e instalar un Gentoo con Kernel construido por mi y que estuviera optimizado al maximo para el poco hardware que tenia.

Junto con mi nueva configuracion, decidi hacer un pequeño cambio en mi firewall.. uno chiquito para facilitarme la vida a mi.. Abrir el puerto 22....

Antes de hacerlo me dije a mi mismo que iba a sufrir un peligro.. que seguramente alguien iba a escanear mi IP.. que lo iba a encontrar abierto y le iba a meter un ataque..
Pero no pense que TAAAAN RAPIDO!!

Mi servidorcito solo lleva 4 dias arriba!

fakeuser@baikonur ~ $ uptime
19:51:25 up 4 days, 8:19, 3 users, load average: 1.23, 1.09, 1.02


Y esto es solo un extracto de los logs!!

Código:
Oct  1 17:25:02 baikonur sshd[13577]: Invalid user cuarentena from *********
Oct  1 17:25:03 baikonur sshd[13579]: reverse mapping checking getaddrinfo for *********.static.tie.cl [*********] failed - POSSIBLE BREAK-IN ATTEMPT!
Oct  1 17:25:03 baikonur sshd[13579]: Invalid user cuenta1 from *********
Oct  1 17:25:04 baikonur sshd[13581]: reverse mapping checking getaddrinfo for *********.static.tie.cl [*********] failed - POSSIBLE BREAK-IN ATTEMPT!
Oct  1 17:25:04 baikonur sshd[13581]: Invalid user cuenta10 from *********
Oct  1 17:25:05 baikonur sshd[13583]: reverse mapping checking getaddrinfo for *********.static.tie.cl [*********] failed - POSSIBLE BREAK-IN ATTEMPT!
Oct  1 17:25:05 baikonur sshd[13583]: Invalid user cuenta11 from *********
Oct  1 17:25:06 baikonur sshd[13585]: reverse mapping checking getaddrinfo for *********.static.tie.cl [*********] failed - POSSIBLE BREAK-IN ATTEMPT!
Oct  1 17:25:06 baikonur sshd[13585]: Invalid user cuenta12 from *********
Oct  1 17:25:06 baikonur sshd[13587]: reverse mapping checking getaddrinfo for *********.static.tie.cl [*********] failed - POSSIBLE BREAK-IN ATTEMPT!
Oct  1 17:25:06 baikonur sshd[13587]: Invalid user cuenta13 from *********
Oct  1 17:25:07 baikonur sshd[13589]: reverse mapping checking getaddrinfo for *********.static.tie.cl [*********] failed - POSSIBLE BREAK-IN ATTEMPT!
Oct  1 17:25:07 baikonur sshd[13589]: Invalid user cuenta14 from *********
Oct  1 17:25:08 baikonur sshd[13591]: reverse mapping checking getaddrinfo for *********.static.tie.cl [*********] failed - POSSIBLE BREAK-IN ATTEMPT!
Oct  1 17:25:08 baikonur sshd[13591]: Invalid user cuenta15 from *********
Oct  1 17:25:13 baikonur sshd[13593]: reverse mapping checking getaddrinfo for *********.static.tie.cl [*********] failed - POSSIBLE BREAK-IN ATTEMPT!
Oct  1 17:25:13 baikonur sshd[13593]: Invalid user cuenta16 from *********
Oct  1 17:25:14 baikonur sshd[13595]: reverse mapping checking getaddrinfo for *********.static.tie.cl [*********] failed - POSSIBLE BREAK-IN ATTEMPT!
Oct  1 17:25:14 baikonur sshd[13595]: Invalid user cuenta17 from *********
Oct  1 17:25:15 baikonur sshd[13597]: reverse mapping checking getaddrinfo for *********.static.tie.cl [*********] failed - POSSIBLE BREAK-IN ATTEMPT!
Hay un chileno que me esta agarrando de boludo!!!

por supuesto que banee la IP inmediatamente y ahora le meti un fail2ban al server, pero esto me demuestra que hacia mucho que no salia a la "calle".. tanto tiempo detras de mis hermosos muros parece que me hicieron blandito...
 

caudio

*nix powered Mod
Update.

Ahora tengo otro muchacho..

Código:
Oct  2 20:10:36 baikonur sshd[8500]: Invalid user oracle from ********
Oct  2 20:10:39 baikonur sshd[8502]: Invalid user test from ********
 

caudio

*nix powered Mod
Bueno.. desde ayer tengo a fail2ban funcionando en mi servidor casero, esperando por el chileno para que siga con su ataque de diccionario..
Asi que aca les paso una mini guia para instalarlo. es en Gentoo pero en ubuntu por ejemplo solo cambia la instalacion por un hermoso "apt-get install fail2ban"


En Gentoo:

Código:
emerge fail2ban
Luego de que se termine de compilar:

Vamos al archivo de configuracion :

/etc/fail2ban/jail.conf

y configuramos los parametros por defecto, y las jaulas que querramos activar, o sea los servicios que queremos monitorear con fail2ban

en mi caso es:

Código:
[DEFAULT]
# ignorar los intentos desde el servidor

ignoreip = 127.0.0.1

#Tiempo por defecto del ban

bantime  = 600

#Maximos intentos fallidos de logueo

maxretry = 3

# Esto describe el metodo que usa fail2ban para leer los logs y modificaciones en los mismos. esta en auto por defecto

backend = auto

#Aca empiezo con la configuracion especifica de la jaula para el servidor ssh.  en mi caso solo tengo ese servicio escuchando asi que solo #uso esa jaula

[ssh-iptables]

#Lo habilito
enabled  = true
#Elijo el filtro a usar
filter   = sshd
#La accion a tomar
action   = iptables[name=SSH, port=ssh, protocol=tcp]
           sendmail-whois[name=SSH, dest=mimail@midominio.com.ar, sender=fail2ban@baikonur.midominio.com.ar]
# El archivo donde revisar por failed logins. Cabe destacar que este archivo puede variar de acuerdo a la configuracion del demonio sshd

logpath  = /var/log/messages
#Maximos intentos fallidos.
maxretry = 5
Para Iniciarlo ejecutamos:

Código:
fail2ban-client start
Para cargar nuevas configuraciones:

Código:
fail2ban-client reload
Y para que inicie en nuestro gentoo al inicio del sistema:

Código:
rc-update add fail2ban default
la anterior es una configuracion muy sencilla pero que funciona para evitar el tipo de ataques descriptos anteriormente. sin ir mas lejos. intentando yo mismo desde otro server entrar con login incorrecto veo al 5 intento una hermosa regla de iptables generada en rojo:


Código:
baikonur fail2ban # iptables -L | grep DROP
Chain INPUT (policy DROP)
Chain FORWARD (policy DROP)
Chain OUTPUT (policy DROP)
DROP       udp  --  anywhere             anywhere            udp dpt:epmap
DROP       udp  --  anywhere             anywhere            udp dpt:microsoft-ds
DROP       udp  --  anywhere             anywhere            udp dpts:netbios-ns:netbios-ssn
DROP       udp  --  anywhere             anywhere            udp spt:netbios-ns dpts:1024:65535
DROP       tcp  --  anywhere             anywhere            tcp dpt:epmap
DROP       tcp  --  anywhere             anywhere            tcp dpt:netbios-ssn
DROP       tcp  --  anywhere             anywhere            tcp dpt:microsoft-ds
DROP       udp  --  anywhere             anywhere            udp dpt:1900
DROP       udp  --  anywhere             anywhere            udp spt:domain
DROP       udp  --  anywhere             anywhere            udp dpt:1900
DROP       udp  --  anywhere             anywhere            udp spt:domain
DROP       all  --  anywhere             255.255.255.255
DROP       all  --  anywhere             192.168.2.255
DROP       all  --  anywhere             255.255.255.255
DROP       all  --  anywhere             BASE-ADDRESS.MCAST.NET/4
DROP       all  --  anywhere             anywhere            state INVALID
DROP       tcp  --  anywhere             anywhere            tcp flags:!FIN,SYN,RST,ACK/SYN
[COLOR=red]DROP       all  --  ******.static.slicehost.net  anywhere[/COLOR]
LOG        all  --  anywhere             anywhere            LOG level info prefix `Shorewall:logdrop:DROP:'
DROP       all  --  anywhere             anywhere
LOG        all  --  anywhere             anywhere            LOG level info prefix `Shorewall:net2all:DROP:'
DROP       all  --  anywhere             anywhere
DROP       all  --  anywhere             255.255.255.255
DROP       all  --  anywhere             192.168.2.255
DROP       all  --  anywhere             255.255.255.255
DROP       all  --  anywhere             BASE-ADDRESS.MCAST.NET/4
DROP       all  --  255.255.255.255      anywhere
DROP       all  --  BASE-ADDRESS.MCAST.NET/4  anywhere
LOG        all  --  255.255.255.255      anywhere            LOG level info prefix `Shorewall:smurfs:DROP:'
DROP       all  --  255.255.255.255      anywhere
LOG        all  --  192.168.2.255        anywhere            LOG level info prefix `Shorewall:smurfs:DROP:'
DROP       all  --  192.168.2.255        anywhere
LOG        all  --  255.255.255.255      anywhere            LOG level info prefix `Shorewall:smurfs:DROP:'
DROP       all  --  255.255.255.255      anywhere
LOG        all  --  BASE-ADDRESS.MCAST.NET/4  anywhere            LOG level info prefix `Shorewall:smurfs:DROP:'
DROP       all  --  BASE-ADDRESS.MCAST.NET/4  anywhere
En resumen. Cada 5 intento fallido, la IP que lo genero recibe un ban temporal de 10 minutos. si bien no es un castigo demasiado extricto, logra dificultar el ataque, ya que te toma muchisimo tiempo el lograr pasar el diccionario completo. Si a esto le sumas un buen uso de claves, con una complejidad aceptable de ellas y el cambio de las mismas tras un tiempo determinado, seria raro que alguien pueda entrar de esta manera. Pero bueno, como siempre hay que recordar: "Security, is a state of mind"
 
Última edición:
Arriba