Servidores Privados Virtuales (VPS) Tutorial para el Congreso Internacional de Software Libre GULEV 2004 Derechos reservados © 2004 Sandino Araico Sánchez.

1 Servidores Privados Virtuales (VPS) Tutorial para el Co...
Author: Adán Herrero
0 downloads 2 Views

1 Servidores Privados Virtuales (VPS) Tutorial para el Congreso Internacional de Software Libre GULEV 2004 Derechos reservados © 2004 Sandino Araico Sánchez Se permite ilimitadamente el uso, copia, redistribución con o sin modificaciones siempre y cuando se mantenga el aviso de derecho de autor y se anoten al final de la presentación todas las modificaciones que se llevan a cabo conservando la historia de las modificaciones que hagan las demás personas e indicando la fecha de cada modificación y el nombre de la persona que la llevó a cabo.

2 ¿Qué es VPS? Virtual Private Server Servidor Privado Virtual

3 [root@carnitas root] ps fax PID TTY STAT TIME COMMAND 1 ? S 0:04 init [3] 2 ? SW 0:00 [keventd] 3 ? SW 0:00 [kapmd] 4 ? SWN 0:00 [ksoftirqd_CPU0] 5 ? Z 1:06 [kswapd ] 6 ? SW 0:08 [bdflush] 7 ? SW 5:57 [kupdated] 8 ? SW 6:56 [kjournald] 61 ? SW 0:00 [khubd] 109 ? SW< 0:00 [mdrecoveryd] 1186 ? SW 0:03 [kreiserfsd] 31375 ? S 4:59 syslogd -m 0 21127 ? S 5:16 klogd -x 350 ? S 0:00 /usr/sbin/apmd -p 10 -w 5 -W -P /etc/sysconfig/apm-scripts/apmscript 17503 ? S 0:00 /usr/sbin/sshd 2482 ? S 0:18 \_ /usr/sbin/sshd 26369 pts/19 S 0:00 | \_ -bash 15624 pts/19 S 0:00 | \_ screen -r 6378 ? S 0:00 \_ /usr/sbin/sshd 22919 pts/22 S 0:00 | \_ -bash 18816 pts/22 S 0:00 | \_ tail --follow=name /var/log/info 2924 ? S 0:00 \_ /usr/sbin/sshd 3507 pts/23 S 0:00 \_ -bash 5315 pts/23 R 0:00 \_ ps fax 5193 ? SL 0:00 ntpd -U ntp -g 11656 ? S 0:00 gpm -t ps/2 -m /dev/psaux 18722 ? S 0:00 crond 27300 ? S 0:00 /usr/sbin/atd 8063 ? S 0:00 /usr/local/sbin/rebootmgr --pidfile /var/run/rebootmgr.pid fedora fedora-pruebas gentoo mandrake redhat 10923 ? S 0:00 login -- ruth 16086 tty2 S 0:01 \_ -bash 14621 tty3 S 0:00 /sbin/mingetty tty3 15563 tty4 S 0:00 /sbin/mingetty tty4 21516 tty5 S 0:00 /sbin/mingetty tty5 13617 tty6 S 0:00 /sbin/mingetty tty6 2390 ? S 76:58 SCREEN 1833 pts/7 S 0:00 \_ /bin/bash 3889 pts/8 S 0:01 \_ /bin/bash 32320 pts/9 S 0:00 \_ /bin/bash 5109 pts/10 S 0:06 \_ /bin/bash 90 pts/13 S 0:00 \_ /bin/bash 6877 pts/17 S 0:00 \_ /bin/bash 24449 ? S 0:00 login -- viewlog 3085 tty1 S 0:00 \_ /bin/sh /var/log/viewlogs.sh 4594 tty1 S 0:00 \_ tail --follow=name boot.log cron dmesg ksyms.0 maillog messages mysqld.log secure apache/*log Funcionamiento Servidor madre Servidor hijo ipv4root is now 192.168.4.6 New security context is 49154 [root@carnitas /] ps fax PID TTY STAT TIME COMMAND 29351 pts/23 S 0:00 /bin/bash -login 30000 pts/23 R+ 0:00 \_ ps fax 31178 ? Ss 0:04 /usr/sbin/cron 8298 ? Ss 0:00 /usr/sbin/sshd 12965 ? Ss 0:00 /usr/sbin/syslogd -m 0 [root@carnitas /] ipv4root is now 192.168.4.9 New security context is 49153 [root@fedora-pruebas /] ps fax PID TTY STAT TIME COMMAND 11416 pts/23 S 0:00 /bin/bash -login 642 pts/23 R 0:00 \_ ps fax 27525 ? S 2:10 /usr/sbin/rcd -r 468 ? S 34:22 SCREEN 11908 pts/2 S 0:00 \_ /bin/bash 17447 pts/2 S 125:19 | \_ top 24134 pts/3 S 0:00 \_ /bin/bash 15032 pts/4 S 0:01 \_ /bin/bash 30409 pts/5 S 0:09 \_ /bin/bash 27016 pts/6 S 0:03 \_ /bin/bash 18787 pts/12 S 0:06 \_ /bin/bash 19997 ? S 0:00 crond 26925 ? S 0:04 /usr/libexec/postfix/master 15234 ? S 0:00 xinetd -stayalive -pidfile /var/run/xinetd.pid 3983 ? S 0:09 /usr/sbin/sshd 12499 ? S 0:35 \_ sshd: root@pts/0 14284 pts/0 S 0:00 \_ -bash 10672 pts/0 S 0:00 \_ screen -r 21878 ? S 3:32 syslogd -m 0 [root@fedora-pruebas /] ipv4root is now 192.168.4.10 127.0.4.10 New security context is 49163 [root@fedora-install /] ps fax PID TTY STAT TIME COMMAND 21576 pts/23 S 0:00 /bin/bash -login 1092 pts/23 R 0:00 \_ ps fax 28746 ? S 0:00 /usr/bin/freshclam -d -p /var/run/clamav/freshclam.pid 27546 ? S 0:08 /usr/sbin/clamd 8936 ? S 0:00 \_ /usr/sbin/clamd 12545 pts/18 S 0:00 su jabber -c /usr/sbin/jabberd -H /var/lib/jabber -c /var/run/jabber/jabber.xml 8519 pts/18 S 0:00 \_ /usr/sbin/jabberd -H /var/lib/jabber -c /var/run/jabber/jabber.xml 21987 pts/18 S 0:00 \_ /usr/sbin/jabberd -H /var/lib/jabber -c /var/run/jabber/jabber.xml 11587 ? S 0:00 /usr/lib/courier-imap/sbin/courierlogger pop3d-ssl 27159 ? S 0:00 /usr/lib/courier-imap/libexec/couriertcpd -address=0 -stderrlogger=/usr/lib/courier-imap/sbin/courierlogger -stderrl 27614 ? S 0:00 /usr/lib/courier-imap/sbin/courierlogger pop3d 23069 ? S 0:00 /usr/lib/courier-imap/libexec/couriertcpd -address=0 -stderrlogger=/usr/lib/courier-imap/sbin/courierlogger -stderrl 15630 ? S 0:00 /usr/lib/courier-imap/sbin/courierlogger imapd-ssl 6387 ? S 0:00 /usr/lib/courier-imap/libexec/couriertcpd -address=0 -stderrlogger=/usr/lib/courier-imap/sbin/courierlogger -stderrl 7574 ? S 0:00 /usr/lib/courier-imap/sbin/courierlogger imapd 29190 ? S 0:00 /usr/lib/courier-imap/libexec/couriertcpd -address=0 -stderrlogger=/usr/lib/courier-imap/sbin/courierlogger -stderrl 75 ? S 0:00 /usr/lib/courier-imap/sbin/courierlogger -pid=/var/run/authdaemon.courier-imap/pid -start /usr/lib/courier-imap/libe 7065 ? S 0:00 \_ /usr/lib/courier-imap/libexec/authlib/authdaemond.plain 16345 ? S 0:00 \_ /usr/lib/courier-imap/libexec/authlib/authdaemond.plain 342 ? S 0:00 \_ /usr/lib/courier-imap/libexec/authlib/authdaemond.plain 9778 ? S 0:00 \_ /usr/lib/courier-imap/libexec/authlib/authdaemond.plain 30034 ? S 0:00 \_ /usr/lib/courier-imap/libexec/authlib/authdaemond.plain 18176 ? S 0:00 \_ /usr/lib/courier-imap/libexec/authlib/authdaemond.plain 12295 ? S 0:00 /usr/libexec/postfix/master 5888 ? S 0:00 \_ qmgr -l -t fifo -u 22906 ? S 0:00 \_ pickup -l -t fifo -u 7880 ? S 0:03 /usr/bin/spamd -d -x -u spamd -m 6 -H /var/cache/spamd 13036 ? S 0:01 \_ spamd child 29368 ? S 0:01 \_ spamd child 12580 ? S 0:01 \_ spamd child 13315 ? S 0:01 \_ spamd child 23456 ? S 0:01 \_ spamd child 27050 ? S 0:00 \_ spamd child 16011 ? S 0:00 /usr/sbin/httpd 9849 ? S 0:00 \_ /usr/sbin/rotatelogs /var/log/httpd/sapodesk.access.log.%Y%B%d 604800 21818 ? S 0:00 \_ /usr/sbin/httpd 17319 ? S 0:00 \_ /usr/sbin/httpd 16118 ? S 0:00 \_ /usr/sbin/httpd 15154 ? S 0:00 \_ /usr/sbin/httpd 22121 ? S 0:00 \_ /usr/sbin/httpd 19986 ? S 0:00 \_ /usr/sbin/httpd 22846 ? S 0:00 \_ /usr/sbin/httpd 11579 ? S 0:00 \_ /usr/sbin/httpd 3342 pts/18 S 0:00 /bin/sh /usr/bin/safe_mysqld --defaults-file=/etc/my.cnf 23346 pts/18 S 0:00 \_ /usr/libexec/mysqld --defaults-file=/etc/my.cnf --basedir=/usr --datadir=/var/lib/mysql --user=mysql --pid-file= 28855 pts/18 S 0:00 \_ /usr/libexec/mysqld --defaults-file=/etc/my.cnf --basedir=/usr --datadir=/var/lib/mysql --user=mysql --pid-f 30840 pts/18 S 0:00 \_ /usr/libexec/mysqld --defaults-file=/etc/my.cnf --basedir=/usr --datadir=/var/lib/mysql --user=mysql --p 19176 pts/18 S 0:00 \_ /usr/libexec/mysqld --defaults-file=/etc/my.cnf --basedir=/usr --datadir=/var/lib/mysql --user=mysql --p 24053 ? S 15:00 /usr/sbin/rcd -r 30151 ? S 0:00 crond 26749 ? S 0:03 /usr/sbin/sshd 8813 ? S 0:11 \_ sshd: root@pts/1 29821 pts/1 S 0:00 | \_ -bash 4149 pts/1 S 0:00 | \_ screen 2753 ? S 1:02 | \_ SCREEN 8203 pts/11 S 0:00 | \_ /bin/bash 21729 pts/11 S 58:56 | | \_ top 3848 pts/14 S 0:04 | \_ /bin/bash 9026 pts/15 S 0:00 | \_ /bin/bash 17204 pts/20 S 0:00 | \_ /bin/bash 602 pts/21 S 0:00 | \_ /bin/bash 12312 pts/18 S 0:01 | \_ /bin/bash 3484 ? S 0:00 \_ sshd: root@pts/16 12719 pts/16 S 0:00 \_ -bash 24044 pts/16 S 0:00 \_ tail --follow=name /var/log/boot.log /var/log/cron /var/log/dmesg /var/log/httpd/access_log /var/log/htt 6578 pts/16 S 0:00 \_ tail --follow=name /var/log/boot.log /var/log/cron /var/log/dmesg /var/log/httpd/access_log /var/log/htt 1220 ? S 0:05 syslogd -m 0 [root@fedora-install /]

4 Herramientas VMWare UML Bochs Linux-Vserver FreeVPS Virtualizacion: Encapsulamiento:

5 Virtualización Se tiene una capa de virtualización donde se ejecuta una máquina virtual como un proceso del sistema operativo anfitrión

6 Virtualización La máquina virtual (junto con todos sus procesos) compite por tiempo de procesador como un solo proceso contra el resto de los procesos del sistema

7 Virtualización La capa de virtualización consume recursos del sistema El sistema anfitrión no puede ver los procesos ni los sistemas de archivos de los sistemas huéspedes

8 Aislamiento No se maneja el concepto de virtualización de hardware Se crean grupos de procesos que se encuentran aislados del resto del sistema Existen tres niveles de aislamiento, directorio raíz, dirección IP y contexto Se busca la mayor optimización en el uso de los recursos de la máquina.

9 Aislamiento Todos los procesos de todos los servidores virtuales compiten individualmente por recursos del sistema (procesador, memoria, acceso a los sistemas de archivos) El sistema operativo anfitrión puede ver todos sus procesos además de los procesos de los sistemas operativos huéspedes

10 Aislamiento Los directorios raíz de los sistemas operativos huéspedes son subdirectorios del directorio raíz del sistema operativo anfitrión El sistema operativo anfitrión puede auditar a los sistemas operativos huéspedes

11 Aislamiento No se pueden instalar sistemas operativos heterogéneos puesto que todos los procesos comparten el mismo kernel Un ataque exitoso al sistema operativo anfitrión proporciona acceso ilimitado a todos los sistemas operativos huéspedes

12 Aislamiento FreeVPS Parches contra kerneles de Red Hat Mayor encapsulamiento al costo de menor eficiencia Linux-Vserver parches contra kerneles de kernel.org Mayor eficiencia al costo de menor encapsulamiento

13 Linux-Vserver Parche contra kernel Linux (kernel.org) 3 llamadas de encapsulamiento: chroot chbind chcontext Resource limits POSIX Capabilities

14 Linux-Vserver [0] CAP_CHOWN change file ownership and group. [5] CAP_KILL send a signal to a process with a different real or effective user ID [6] CAP_SETGID permit setgid(2), setgroups(2), and forged gids on socket credentials passing [7] CAP_SETUID permit set*uid(2), and forged uids on socket credentials passing [8] CAP_SETPCAP transfer/remove any capability in permitted set to/from any pid [9] CAP_LINUX_IMMUTABLE allow modification of S_IMMUTABLE and S_APPEND file attributes [11] CAP_NET_BROADCAST permit broadcasting and listening to multicast [12] CAP_NET_ADMIN permit interface configuration, IP firewall, masquerading, accounting, socket debugging, routing tables, bind to any address, enter promiscuous mode, multicasting,...

15 Linux-Vserver [13] CAP_NET_RAW permit usage of RAW and PACKET sockets [16] CAP_SYS_MODULE insert and remove kernel modules [18] CAP_SYS_CHROOT permit chroot(2) [19] CAP_SYS_PTRACE permit ptrace() of any process [21] CAP_SYS_ADMIN this list would be too long, it basically allows to do everything else, not mentioned in another capability. [22] CAP_SYS_BOOT permit reboot(2) [23] CAP_SYS_NICE allow raising priority and setting priority on other processes, modify scheduling [24] CAP_SYS_RESOURCE override resource limits, quota, reserved space on fs,... [27] CAP_MKNOD permit the privileged aspects of mknod(2)\ Also see Examples [E01],[E02], and [E03].

16 Linux-Vserver [0] RLIMIT_CPU CPU time in seconds. process is sent a SIGXCPU signal after reaching the soft limit, and SIGKILL on hard limit. [4] RLIMIT_CORE maximum size of core files generated [5] RLIMIT_RSS number of pages the process's resident set can consume (the number of virtual pages resident in RAM) [6] RLIMIT_NPROC The maximum number of processes that can be created for the real user ID of the calling process. [7] RLIMIT_NOFILE Specifies a value one greater than the maximum file descriptor number that can be opened by this process. [8] RLIMIT_MEMLOCK The maximum number of virtual memory pages that may be locked into RAM using mlock() and mlockall(). [9] RLIMIT_AS The maximum number of virtual memory pages available to the process (address space limit).

17 Linux-Vserver [8] VXF_SCHED_HARD activate the Hard CPU scheduling [9] VXF_SCHED_PRIO use the context token bucket for calculating the process priorities [10] VXF_SCHED_PAUSE put all processes in this context on the hold queue, not scheduling them any longer [16] VXF_VIRT_MEM virtualize the memory information so that the VM and RSS limits are used for meminfo and friends [17] VXF_VIRT_UPTIME virtualize the uptime, beginning with the time of context creation [18] VXF_VIRT_CPU [24] VXF_HIDE_MOUNT show empty proc/{pid}/mounts [25] VXF_HIDE_NETIF hide network interfaces and addresses not permitted by the network context

18 Linux-Vserver [0] VXC_SET_UTSNAME allow the context to change the host and domain name with the appropriate kernel Syscall [1] VXC_SET_RLIMIT allow the context to modify the resource limits (within the vserver limits). [8] VXC_RAW_ICMP allow raw icmp packets in a secure way (this makes ping work from inside) [16] VXC_SECURE_MOUNT permit secure mounts, which at the moment means that the nodev mount option is added.

19 Linux-Vserver La separación de contextos permite aislar grupos de procesos dentro de un contexto para que no puedan ver procesos de otros contextos. Cualquier interacción con procesos de un contexto distinto está prohibida.

20 Linux-Vserver Se requiere un tipo distinto de separación para aislar procesos dentro de un subconjunto de las direcciones de red disponibles. Está prohibido que un proceso escuche una dirección de red distinta a las que se encuentra restringido.

21 Linux-Vserver El problema principal del sistema chroot utilizado en Linux reside en que la información es volátil, puede ser cambiada en la siguiente llamada a chroot. Esto ha permitido el desarrollo de técnicas para escapar del directorio al que se está confinado.

22 Linux-Vserver + GR Security Restricciones a procesos dentro de chroot PAX Auditoría de procesos Restricciones de acceso a /proc Restricciones de acceso a recursos de la red ACL

23 Linux-Vserver + GR Security http://sandino.net/parches/vserver/

24 Ejemplos

25 Esconder el DBMS Servidor anfitrión 200.33.123.132 127.0.123.132 MySQL puerto 3306 200.33.123.132 Apache/PHP puerto 80 clientes

26 Proceso vulnerable Servidor anfitrión 200.33.123.132 127.0.123.132 MySQL puerto 3306 200.33.123.132 Tomcat puerto 8080 clientes chpax -pEmrxs

27 Dilución de DOS Servidor anfitrión 200.33.123.132 200.33.123.133 127.0.123.130 200.33.123.132 SMTP 200.33.123.133 SMTP Servidores SMTP entregando correo Dominios con poco spam mayor prioridad dominios con mucho spam menor prioridad Mailboxes Antispam Antivirus 127.0.123.130

28 DMZ Servidor anfitrión 200.33.4.13 - 18 200.33.4.13 HTTP clientes 200.33.4.14 SMTP 200.33.4.15 POP3 200.33.4.17 IMAP 200.33.4.16 FTP 200.33.4.18 FTP /var/www/html/home

29 Otra DMZ Servidor anfitrión 200.33.4.123 172.16.4.13 HTTP clientes 172.16.4.14 SMTP 172.16.4.15 POP3 172.16.4.17 IMAP 172.16.4.16 FTP 172.16.4.18 FTP /var/www/html/home NAT

30 Exploit testing Servidor anfitrión 200.33.133.233 cliente hostil 200.33.133.233 Servicio vulnerable Auditoría Log

31 Honeypot Servidor anfitrión 200.33.133.233 200.33.133.252 clientes hostiles 200.33.133.233 Servicios vulnerables Auditoría Log Sniffer

32 Verificación de firmas Servidor anfitriónTripwire/AIDE Repositorio Servidores hijos /bin /lib /etc /usr/bin /usr/sbin /bin /lib /etc /usr/bin /usr/sbin /bin /lib /etc /usr/bin /usr/sbin /bin /lib /etc /usr/bin /usr/sbin

33 Balanceo de carga SAN /vservers/home Anfitrión AAnfitrión B /var/www VPS DirectorClientes

34 Servidores privados virtuales Servidor anfitrión 200.33.133.233 127.0.133.233 clientes 200.33.133.234 127.0.133.234 Servidores hijos 200.33.133.237 127.0.133.237 200.33.133.235 127.0.133.235 200.33.133.236 127.0.133.236

35 ¿Alguna otra idea?

36 ¿Quieren verlo en vivo?

37 ¿Preguntas? ¿Es mi VPS inmune a los virus? ¿Es mi VPS resistente a ataques de buffer overflow? ¿Es mi VPS resistente a ataques de SQL injection? Si mi kernel es vulnerable mis VPS son vulnerables? ¿Es mi VPS vulnerable a un DDOS? ¿Es mi VPS vulnerable a un 0day?

38 Referencias http://linux-vserver.org http://grsecurity.net http://sandino.net/parches/vserver http://www.freevps.com/ http://user-mode-linux.sourceforge.net/ http://linux-vserver.org/Linux-VServer-Paper http://bochs.sourceforge.net/ http://wt.xpilot.org/publications/posix.1e/ http://www.vmware.com