← Back to ZeroTrace Research / 2ubZ3r0

WP2Shell

Overview

WP2Shell is a critical Remote Code Execution (RCE) vulnerability affecting WordPress versions 6.9.0 through 7.0.1. This exploit chain leverages an authentication bypass, SQL injection, and privilege escalation to achieve pre-authentication RCE. The vulnerability allows an unauthenticated attacker to create an administrator account and execute arbitrary commands on the target WordPress instance.

Affected Versions

Version RangeStatus
<= 6.8.5Not affected
6.9.0 – 6.9.4Affected
7.0.0 – 7.0.1Affected

Technical Analysis

Root Cause: Route Confusion in Batch API

The vulnerability stems from a desynchronization issue in the WordPress REST API batch endpoint /batch/v1. This endpoint is unauthenticated and processes multiple sub-requests in a single call. The flaw occurs in serve_batch_request_v1() function:

  1. The function builds two parallel arrays:
    • $matches: Stores matched handlers for each sub-request
    • $validation: Stores validation results for each sub-request
  1. When a sub-request path fails wp_parse_url(), it's appended to $validation but not to $matches, causing the arrays to become misaligned.
  1. This misalignment leads to a sub-request being dispatched under a different sub-request's handler, creating a route confusion vulnerability.

Exploitation Chain

The exploit chain consists of six distinct phases:

Phase 1: Route Confusion & SQL Injection

Phase 2: UNION-Based SQL Injection

Phase 3: oEmbed Cache Creation

Phase 4: Customizer Bridge

Phase 5: Administrator Creation

Phase 6: Command Execution

Proof of Concept Exploitation

Scan with wpscan to get WordPress Version

wpscan --url http://10.0.0.5/wordpress
WPScan output identifying the WordPress version

Clone the repo

git clone https://github.com/Icex0/wp2shell-poc

Command Execution

python3 wp2shell.py shell http://10.0.0.5/wordpress -i --timeout 60

Impact Assessment

Severity: Critical

What's at Risk

  1. Complete System Compromise: Attackers gain full control of the WordPress instance
  1. Data Theft: Database contents can be extracted
  1. Server Pivot: WordPress server can be used as entry point to internal networks
  1. Defacement: Website content can be modified
  1. Malware Distribution: Site can be used to distribute malware

Mitigation Strategies

Immediate Actions

  1. Update WordPress to the latest patched version (7.0.2+)
  1. Disable REST API if not required:
    add_filter('rest_authentication_errors', function($result) {
        if (!is_user_logged_in()) {
            return new WP_Error('rest_forbidden', 'REST API restricted', array('status' => 401));
        }
        return $result;
    });

Long-term Recommendations

  1. Implement Web Application Firewall (WAF) to detect and block exploitation attempts
  1. Regular Security Audits: Conduct periodic vulnerability assessments
  1. Least Privilege Principle: Ensure WordPress filesystem permissions are properly restricted
  1. Monitoring: Implement logging and monitoring for suspicious REST API activity
  1. Backup Strategy: Maintain regular backups for quick recovery

Detection Indicators

Monitor for:

Conclusion

WP2Shell represents a critical vulnerability in WordPress that enables complete system compromise without authentication. The exploit chain demonstrates sophisticated exploitation techniques, including route confusion, SQL injection, and privilege escalation. Organizations running affected versions should prioritize patching and implement the recommended security measures immediately.