Seguridad en Aplicaciones Web
         Siempre hay nuevos tricks
    “Un ejemplo con Apache Web Server”


Chema Alonso
chema@informatica64.com
@chemaalonso
http://www.elladodelmal.com
http://www.informatica64.com
Web Penetration Testing
Apache Web Server
Vulnerabilidades

  Tecnología                               Personas




                                           - Administrador
- ApacheWeb Server                         - Desarrollador
- Aplicaciones (módulos, CMS, framewoks)   - Usuario
- Protocolos (HTTP, HTTP-s, WebDAV)
Vulnerabilidades Software
Evaluación
Fase 1: Reconocimiento del Software
El mensaje de Error
Mensajes de Apache
200 OK
301 Redirect
400 Bad Request
403 Forbidden
405 Not Allowed
404 Not Found
411 Length Required
500 Internal Server Error
501 Method Not Implement
Banner
HTTP/1.1 200 OK
Date: Thu, 27 Oct 2011 09:54:01 GMT
Server: Apache/2.3.15-dev (Unix)
               mod_ssl/2.3.15-dev OpenSSL/1.0.0c
Last-Modified: Thu, 27 Oct 2011 09:10:27 GMT
ETag: "102b9a6-8c14-4b04424b5c6c0"
Accept-Ranges: bytes
Content-Length: 35860
Vary: Accept-Encoding
Cache-Control: max-age=3600
Expires: Thu, 27 Oct 2011 10:54:01 GMT
Connection: close
Content-Type: text/html; charset=utf-8
Banner

http://www.fundaciondedalo.org




     http://httpd.apache.org/security/vulnerabilities_22.html
Banner

http://www.marca.com




                 ¿Versión?
Ocultado el Banner
VARIABLES DE OCULTACIÓN DE BANNER
Fingerprinting
FINGERPRINTING


HTTPRINT

(MD5)FAVICON

BUSCAR MANUAL DE APACHE
Framework Error Messages
 Frameworks JSP
Framework Error Messages
Framework WebDNA
Framework Error Messages
Framework Coldfusion
HPC: HTTP Parameter Contamination
HPP
Fase 2: Fallos en la configuración
LDAP Policía
LDAP Policía
HTTP Methods
GET → Dame una página
POST → Te envío datos
PUT → Te envío un fichero
DELETE → Borra este fichero
TRACE → Devuélveme esto
HEAD -> Dame el tamaño del archivo
CONNECT → Hazme de Proxy
….
Métodos Permitidos
OPTIONS /folder HTTP/1.0
Subir una shell
PUT /shell.php HTTP/1.1
Host: Server.com
Content-Type: text/plain
Content-Length:XXX

<?PHP ...
Robar Cookies HTTP-Only
-   Cookies mantienen la sesión
-   Si un usuario la roba → Hijacking
-   Por seguridad cookies no son accesibles por Javascript
    para evitar robos XSS → HTTPOnly
Ataque Trace (Jeremiah Grossman)
1) Un ataque XSS → fuerza un Trace contra el servidor
víctima
2) En la petición Trace se añade la cookie
3) Una vez en la conexión HTTP se roba con Javascript
Servicio Proxy

- Permite a un cliente navegar a través de un servidor Web:

      1) Ataques remotos con la dirección IP del servidor

      2) Conectarse a servidores internos no publicados

- Formas de detección

1)    Método Connect
2)    Proxy transparente
3)    Reverse Proxy
Connect Method
Transparent Proxy
Mod_Proxy D.O.S.
Mod_Proxy: Reverse Proxy Bug
Mod_Proxy: Reverse Proxy Bug
Bug: RewriteRule ^(.*) http://internalserver:80$




GET @InternalNotAccessibleServer/console HTTP/1.0
Host: www.publicserver.com
VERB Tampering: SQL Injection
1) En auditorias de seguridad se descubren vulnerabilidades SQL injection

2) Se reportan al cliente

3) Parchea el bug

4) Comprobamos el bug




HEAD /admin/login.asp?user=‘;shutdown;
Host: victim
Fase 3: Human Fails
Robots.txt
Directory Listing
.listing
.DS_Store Files
Mod_Negotiation
Mod_user_dir
.SVN/Entries
RANGE Bytes + Gzip D.O.S.
-   Permite solicitar partes de archivos
-   Pensado para descargas grandes
-   El atacante solicita muchos pequeños pedazos
-   El servidor tiene que comprimirlos con gzip
-   Al final se satura la CPU del sistema y cae


HEAD / HTTP/1.1
Host: www.fundaciondedalo.org
Range:bytes=0-10
Accept-Encoding: gzip
Connection: close
SLOWRIS GET/POST
{Almost} All implemented in FOCA PRO 3
Seguridad en Apache Web Server

Seguridad en Apache Web Server