Bastion (HTB)
Bastion is a relatively straightforward box with one strange quirk: to enumerate appropriately, you have to mount a VHD within an SMB share (that you also have to mount…). It isn’t difficult to do these things, but it does take some creative thinking to consider. Privilege escalation leverages the insecure manner in which mRemoteNG stores credentials. You can exploit this in a couple of cool ways through the mRemoteNG GUI itself—or, you can opt for the quick (but forgettable) Python script that wasn’t available until after the box was released.
Initial Scan
Not much to look into aside from SMB.
Enumerating SMB
It’s always worth testing to see if SMB permits null (aka anonymous) sessions. We need a share to try authenticating to first. So I list out the shares.
ADMIN$
, C$
, and IPC$
are all default shares. Backups
is the only one that stands out. I attempt to authenticate to it with no credentials.
My null session worked. I have read access to the Backups
share.
Although there aren’t that many files in the share, some are massive. Here’s a quick look of the interesting directory WindowsImageBackup
.
Virtual hard disks? Definitely something to look at. But 5418299392
blocks? That’s over two terabytes. We need a way to enumerate the VHDs without downloading them entirely.
Mounting shares and VHD files
If I mount the share, I can view it as if it were part of my own file system.
The VHDs, though, aren’t readable this way. To browse through them, I have to mount those as well. For VHD files, I have to first install guestmount
.
Then I create a new directory as the mountpoint.
And I mount the VHD file.
Now I can browse through the file system as if it were part of my own.
Note: One of the VHDs wouldn’t mount properly. Turns out it isn’t necessary to mount anyway.
Now with read access to the VHD, my first instinct is to go for the flags, but there’s nothing at C:\Users\L4mpje\Desktop
or C:\Users\Administrator\Desktop
. So I clearly don’t have the right access just yet.
Next thing to do would be to search for user credentials. After checking for credentials lying around in obvious places, I go for the SAM and SECURITY files.
SAM and SECURITY
Depending on your version of Windows, these can be in a few different locations. Here, they’re in C:\Windows\System32\config
.
I copy them from the mounted drive to my Kali box.
To get the hashes, I use samdump2
and pass the SYSTEM
and SAM
files as arguments.
The L4mpje hash takes seconds to crack with hashcat
.
The password for use L4mpje is bureaulampje. The Administrator and Guest account hashes are marked as *disabled*
, so this is the best we’ll get.
To get in, I ssh
as L4mpje@10.10.10.134 with the recovered password.
The user flag is on L4mpje’s Desktop.
Privilege Escalation: mRemoteNG Credentials
With Windows privilege escalation, if nothing stands out in the Users folder, I move on to checking what software is installed. Here, mRemoteNG
stands out.
I can find the version number in the changelog file and search for a known exploit, but this doesn’t get us very far.
A search for “mRemoteNG stored credentials”, however, results in exactly what we’re looking for:
mRemoteNG uses insecure methods for password storage and can provide droves of valid credentials during an assessment or competition.
As the post explains, mRemoteNG is used to help manage remote connections (e.g., SSH, RDP). Credentials for these sessions may be stored insecurely in a file called confCons.xml
. Lo and behold, I can find an encrypted password (right beside Username=”Administrator”) in C:\Users\L4mpje\AppData\Roaming\mRemoteNG\confCons.xml.
This specifies that the protocol is RDP. We can assume that this credential would be reused for SSH as well. We can abuse these stored credentials in a few different ways.
Method 1: Extended Tools password lookup
The previously linked-to blog post describes a method via the GUI, which seems to be the intended way in this box. I switch over to a Windows VM, download mRemoteNG, and start it up.
I import the confCons.xml file by going to File > Open Connection File… I see two saved connections.
“DC” is the one we’re after. This is the stored Administrator RDP connection.
The blog post explains that I need to create a new Extended Tool that acts as a password decrypter. I go to Tools > External Tools and click New.
- Display Name can be anything really. (I put
Password Lookup
per the blog.) - Filename should be
CMD
. - Arguments should be
/k echo %password%
.
Once the tool is created, I right-click the connection (DC) and select External Tools > Password Lookup. A command prompt appears with the password in cleartext.
With these credentials, I can SSH in as Administrator . . .
. . . and grab the flag.
Method 2: Connecting directly from mRemoteNG
We actually don’t have to uncover the password at all to get Administrator access. If you’ve started up mRemoteNG and imported confCons.xml, just:
- Change the IP address from 127.0.0.1 to 10.10.10.134.
- Change the connection method from RDP to SSH version 2. (Our nmap scan showed SSH but not RDP.)
Right-click the connection (DC) from the connections list, click Connect, and you’ll have an interactive SSH session as Administrator.
Method 3: Decrypting with mremoteng_decrypt.py
Sometime after the box was released, a neat script called mRemoteNG_Decrypt.py popped up. All you have to do is copy the encrypted password from confCons.xml and pass it as a string to get the plaintext credential.
Not as satisfying as the other methods, but it’s always good to have a quick-and-dirty way that doesn’t involve spinning up a separate Windows environment and installing software.