phpMyAdmin setup.php save Action Arbitrary PHP Code Injection (PMASA-2009-3) - Nessus

High   Plugin ID: 36170

This page contains detailed information about the phpMyAdmin setup.php save Action Arbitrary PHP Code Injection (PMASA-2009-3) Nessus plugin including available exploits and PoCs found on GitHub, in Metasploit or Exploit-DB for verifying of this vulnerability.

Plugin Overview


ID: 36170
Name: phpMyAdmin setup.php save Action Arbitrary PHP Code Injection (PMASA-2009-3)
Filename: phpmyadmin_pmasa_2009_3.nasl
Vulnerability Published: N/A
This Plugin Published: 2009-04-16
Last Modification Time: 2022-04-11
Plugin Version: 1.25
Plugin Type: remote
Plugin Family: CGI abuses
Dependencies: phpMyAdmin_detect.nasl
Required KB Items [?]: www/PHP, www/phpMyAdmin
Excluded KB Items: Settings/disable_cgi_scanning

Vulnerability Information


Severity: High
Vulnerability Published: N/A
Patch Published: N/A
CVE [?]: CVE-2009-1151
CPE [?]: cpe:/a:phpmyadmin:phpmyadmin
Exploited by Malware: True

Synopsis

The remote web server contains a PHP application that may allow execution of arbitrary code.

Description

The setup script included with the version of phpMyAdmin installed on the remote host does not properly sanitize user-supplied input to several variables before using them to generate a config file for the application. Using specially crafted POST requests, an unauthenticated, remote attacker may be able to leverage this issue to execute arbitrary PHP code.

Note that the application is also reportedly affected by several other issues, although Nessus has not actually checked for them.

Solution

Upgrade to phpMyAdmin 2.11.9.5 / 3.1.3.1 or apply the patch referenced in the project's advisory.

Public Exploits


Target Network Port(s): 80
Target Asset(s): Services/www
Exploit Available: True (Metasploit Framework, Exploit-DB, GitHub, Immunity Canvas, Core Impact, D2 Elliot)
Exploit Ease: No exploit is required

Here's the list of publicly known exploits and PoCs for verifying the phpMyAdmin setup.php save Action Arbitrary PHP Code Injection (PMASA-2009-3) vulnerability:

  1. Metasploit: exploit/unix/webapp/phpmyadmin_config
    [PhpMyAdmin Config File Code Injection]
  2. Exploit-DB: exploits/php/webapps/8921.sh
    [EDB-8921: phpMyAdmin - '/scripts/setup.php' PHP Code Injection]
  3. Exploit-DB: exploits/php/webapps/16913.rb
    [EDB-16913: phpMyAdmin - Config File Code Injection (Metasploit)]
  4. GitHub: https://github.com/duckstroms/Web-CTF-Cheatsheet
    [CVE-2009-1151]
  5. GitHub: https://github.com/minervais/pocs
    [CVE-2009-1151: phpMyAdmin '/scripts/setup.php' PHP Code Injection RCE PoC (CVE-2009-1151)]
  6. GitHub: https://github.com/w181496/Web-CTF-Cheatsheet
    [CVE-2009-1151]
  7. GitHub: https://github.com/pagvac/pocs
    [CVE-2009-1151: PhpMyAdmin '/scripts/setup.php' PHP Code Injection RCE PoC (CVE-2009-1151)]
  8. D2 Elliot: phpmyadmin_file_upload.html
    [Phpmyadmin File Upload]
  9. Immunity Canvas: CANVAS

Before running any exploit against any system, make sure you are authorized by the owner of the target system(s) to perform such activity. In any other case, this would be considered as an illegal activity.

WARNING: Beware of using unverified exploits from sources such as GitHub or Exploit-DB. These exploits and PoCs could contain malware. For more information, see how to use exploits safely.

Risk Information


CVSS Score Source [?]: CVE-2009-1151
CVSS V2 Vector: AV:N/AC:L/Au:N/C:P/I:P/A:P/E:H/RL:OF/RC:C
CVSS Base Score:7.5 (High)
Impact Subscore:6.4
Exploitability Subscore:10.0
CVSS Temporal Score:6.5 (Medium)
CVSS Environmental Score:NA (None)
Modified Impact Subscore:NA
Overall CVSS Score:6.5 (Medium)

Go back to menu.

Plugin Source


This is the phpmyadmin_pmasa_2009_3.nasl nessus plugin source code. This script is Copyright (C) 2009-2022 Tenable Network Security, Inc.

#%NASL_MIN_LEVEL 70300
#
# (C) Tenable Network Security, Inc.
#

include('deprecated_nasl_level.inc');
include('compat.inc');

if (description)
{
  script_id(36170);
  script_version("1.25");
  script_set_attribute(attribute:"plugin_modification_date", value:"2022/04/11");

  script_cve_id("CVE-2009-1151");
  script_bugtraq_id(34236);
  script_xref(name:"CISA-KNOWN-EXPLOITED", value:"2022/04/15");
  script_xref(name:"SECUNIA", value:"34430");

  script_name(english:"phpMyAdmin setup.php save Action Arbitrary PHP Code Injection (PMASA-2009-3)");

  script_set_attribute(attribute:"synopsis", value:
"The remote web server contains a PHP application that may allow
execution of arbitrary code.");
  script_set_attribute(attribute:"description", value:
"The setup script included with the version of phpMyAdmin installed on
the remote host does not properly sanitize user-supplied input to
several variables before using them to generate a config file for the
application.  Using specially crafted POST requests, an
unauthenticated, remote attacker may be able to leverage this issue to
execute arbitrary PHP code.

Note that the application is also reportedly affected by several other
issues, although Nessus has not actually checked for them.");
  script_set_attribute(attribute:"see_also", value:"http://www.phpmyadmin.net/home_page/security/PMASA-2009-3.php");
  script_set_attribute(attribute:"solution", value:
"Upgrade to phpMyAdmin 2.11.9.5 / 3.1.3.1 or apply the patch referenced
in the project's advisory.");
  script_set_cvss_base_vector("CVSS2#AV:N/AC:L/Au:N/C:P/I:P/A:P");
  script_set_cvss_temporal_vector("CVSS2#E:H/RL:OF/RC:C");
  script_set_attribute(attribute:"cvss_score_source", value:"CVE-2009-1151");

  script_set_attribute(attribute:"exploitability_ease", value:"No exploit is required");
  script_set_attribute(attribute:"exploit_available", value:"true");
  script_set_attribute(attribute:"exploit_framework_core", value:"true");
  script_set_attribute(attribute:"d2_elliot_name", value:"Phpmyadmin File Upload");
  script_set_attribute(attribute:"exploit_framework_d2_elliot", value:"true");
  script_set_attribute(attribute:"exploited_by_malware", value:"true");
  script_set_attribute(attribute:"metasploit_name", value:'PhpMyAdmin Config File Code Injection');
  script_set_attribute(attribute:"exploit_framework_metasploit", value:"true");
  script_set_attribute(attribute:"exploit_framework_canvas", value:"true");
  script_set_attribute(attribute:"canvas_package", value:"CANVAS");
  script_cwe_id(94);

  script_set_attribute(attribute:"plugin_publication_date", value:"2009/04/16");

  script_set_attribute(attribute:"plugin_type", value:"remote");
  script_set_attribute(attribute:"cpe", value:"cpe:/a:phpmyadmin:phpmyadmin");
  script_set_attribute(attribute:"thorough_tests", value:"true");
  script_end_attributes();

  script_category(ACT_ATTACK);
  script_family(english:"CGI abuses");

  script_copyright(english:"This script is Copyright (C) 2009-2022 Tenable Network Security, Inc.");

  script_dependencies("phpMyAdmin_detect.nasl");
  script_require_keys("www/phpMyAdmin", "www/PHP");
  script_exclude_keys("Settings/disable_cgi_scanning");
  script_require_ports("Services/www", 80);

  exit(0);
}


include("global_settings.inc");
include("misc_func.inc");
include("http.inc");
include("url_func.inc");


port = get_http_port(default:80, embedded:FALSE, php:TRUE);


# Define some variables.
key = string(SCRIPT_NAME, "']; system(id); #");
val = 'NESSUS';
eoltype = "unix";


# Test an install.
install = get_kb_item(string("www/", port, "/phpMyAdmin"));
if (isnull(install)) exit(0);
matches = eregmatch(string:install, pattern:"^(.+) under (/.*)$");
if (!isnull(matches))
{
  dir = matches[2];

  # nb: phpMyAdmin 3.x has its setup script in a different location. We're not
  #     testing it because we don't believe the vulnerability is exploitable in
  #     that version.
  foreach script (make_list("/scripts/setup.php"))
  {
    url = string(dir, script);

    clear_cookiejar();
    res = http_send_recv3(method:"GET", item:url, port:port, exit_on_fail:TRUE);

    # If the config can't be written to disk, this cannot be exploited - even
    # if the software is unpatched.  In which case, only continue if paranoid.
    if ('Can not load or save configuration' >< res[2])
    {
      if (report_paranoia < 2)
        exit(1, "The system might be unpatched, but cannot be exploited.");
      else
        config_writeable = FALSE;
    }
    else config_writeable = TRUE;

    # Extract the token.
    token = NULL;

    pat = 'input type="hidden" name="token" value="([^"]+)"';
    matches = egrep(string:res[2], pattern:pat);
    if (matches)
    {
      foreach match (split(matches, keep:FALSE))
      {
        item = eregmatch(pattern:pat, string:match);
        if (!isnull(item))
        {
          token = item[1];
          break;
        }
      }
    }
    if (isnull(token)) continue;

    # Try to exploit the issue.
    #
    # nb: we verify the vulnerability only by displaying the config file;
    #     if the config file is not writable, this will produce a result 
    #     even though the vulnerability is not really exploitable. 
    configuration = string(
      'a:1:{',
        's:7:"Servers";a:1:{',
          'i:0;a:1:{',
            's:', strlen(key), ':"', key, '";',
            's:', strlen(val), ':"', val, '";',
          '}',
        '}',
      '}'
    );
    postdata = string(
      "token=", token, "&",
      "action=display&",
      "configuration=", urlencode(str:configuration), "&",
      "eoltype=", eoltype
    );

    req = http_mk_post_req(
      port        : port,
      item        : url, 
      data        : postdata,
      add_headers : make_array(
        "Content-Type", "application/x-www-form-urlencoded"
      )
    );
    res = http_send_recv_req(port:port, req:req, exit_on_fail:TRUE);

    # There's a problem if our key was accepted.
    if (string("$cfg['Servers'][$i]['", key, "'] = '", val, "';") >< res[2])
    {
      if (!config_writeable)
      {
        report = string(
          "\n",
          "Even though the software is unpatched, the web server does not\n",
          "have permission to write the configuration file to disk, which\n",
          "means the vulnerability cannot be exploited at this time.\n"
        );
        security_hole(port:port, extra:report);
      }
      else security_hole(port);
    }
  }
}

The latest version of this script can be found in these locations depending on your platform:

  • Linux / Unix:
    /opt/nessus/lib/nessus/plugins/phpmyadmin_pmasa_2009_3.nasl
  • Windows:
    C:\ProgramData\Tenable\Nessus\nessus\plugins\phpmyadmin_pmasa_2009_3.nasl
  • Mac OS X:
    /Library/Nessus/run/lib/nessus/plugins/phpmyadmin_pmasa_2009_3.nasl

Go back to menu.

How to Run


Here is how to run the phpMyAdmin setup.php save Action Arbitrary PHP Code Injection (PMASA-2009-3) as a standalone plugin via the Nessus web user interface (https://localhost:8834/):

  1. Click to start a New Scan.
  2. Select Advanced Scan.
  3. Navigate to the Plugins tab.
  4. On the top right corner click to Disable All plugins.
  5. On the left side table select CGI abuses plugin family.
  6. On the right side table select phpMyAdmin setup.php save Action Arbitrary PHP Code Injection (PMASA-2009-3) plugin ID 36170.
  7. Specify the target on the Settings tab and click to Save the scan.
  8. Run the scan.

Here are a few examples of how to run the plugin in the command line. Note that the examples below demonstrate the usage on the Linux / Unix platform.

Basic usage:

/opt/nessus/bin/nasl phpmyadmin_pmasa_2009_3.nasl -t <IP/HOST>

Run the plugin with audit trail message on the console:

/opt/nessus/bin/nasl -a phpmyadmin_pmasa_2009_3.nasl -t <IP/HOST>

Run the plugin with trace script execution written to the console (useful for debugging):

/opt/nessus/bin/nasl -T - phpmyadmin_pmasa_2009_3.nasl -t <IP/HOST>

Run the plugin with using a state file for the target and updating it (useful for running multiple plugins on the target):

/opt/nessus/bin/nasl -K /tmp/state phpmyadmin_pmasa_2009_3.nasl -t <IP/HOST>

Go back to menu.

References


BID | SecurityFocus Bugtraq ID: Secunia Advisory: CWE | Common Weakness Enumeration:
  • CWE-94 (Weakness) Improper Control of Generation of Code ('Code Injection')
See also: Similar and related Nessus plugins:
  • 39569 - Debian DSA-1824-1 : phpmyadmin - several vulnerabilities
  • 36012 - FreeBSD : phpmyadmin -- insufficient output sanitizing when generating configuration file (06f9174f-190f-11de-b2f0-001c2514716c)
  • 39570 - GLSA-200906-03 : phpMyAdmin: Multiple vulnerabilities
  • 40108 - openSUSE Security Update : phpMyAdmin (phpMyAdmin-711)
  • 36081 - openSUSE 10 Security Update : phpMyAdmin (phpMyAdmin-6133)
  • 99661 - phpMyAdmin 4.0.x < 4.0.10.16 Multiple Vulnerabilities (PMASA-2016-17, PMASA-2016-22 - PMASA-2016-24, PMASA-2016-26 - PMASA-2016-28)
  • 99662 - phpMyAdmin 4.4.x < 4.4.15.7 Multiple Vulnerabilities (PMASA-2016-17, PMASA-2016-19, PMASA-2016-21 - PMASA-2016-24, PMASA-2016-26 - PMASA-2016-28)
  • 99663 - phpMyAdmin 4.6.x < 4.6.3 Multiple Vulnerabilities (PMASA-2016-17 - PMASA-2016-28)
  • 59211 - phpMyAdmin simplexml_load_string() Function Information Disclosure (PMASA-2011-17)
  • 57346 - phpMyAdmin 3.3.x / 3.4.x < 3.3.10.2 / 3.4.3.1 Multiple Vulnerabilities (PMASA-2011-5 - PMASA-2011-8)
  • 62312 - phpMyAdmin server_sync.php Backdoor (PMASA-2012-5)
  • 66295 - phpMyAdmin 3.5.x < 3.5.8.1 / 4.x < 4.0.0-rc3 Multiple Vulnerabilities (PMASA-2013-2 - PMASA-2013-5
  • 79599 - phpMyAdmin 4.0.x < 4.0.10.6 / 4.1.x < 4.1.14.7 / 4.2.x < 4.2.12 Multiple Vulnerabilities (PMASA-2014-13 - PMASA-2014-16)
  • 79797 - phpMyAdmin 4.0.x < 4.0.10.7 / 4.1.x < 4.1.14.8 / 4.2.x < 4.2.13.1 Multiple Vulnerabilities (PMASA-2014-17 - PMASA-2014-18)
  • 143253 - phpMyAdmin 4.7.x < 4.7.7 XSRF (PMASA-2017-9)
  • 143262 - phpMyAdmin 4.3.x < 4.7.8 XSS (PMASA-2018-1)
  • 110722 - phpMyAdmin 4.8.x < 4.8.2 Vulnerability (PMASA-2018-4)
  • 119601 - phpMyAdmin 4.x < 4.8.4 Multiple Vulnerabilities (PMASA-2018-6) (PMASA-2018-8)
  • 123416 - phpMyAdmin 4.x < 4.8.5 Multiple Vulnerabilities (PMASA-2019-1) (PMASA-2019-2)
  • 125856 - phpMyAdmin 4.x < 4.9.0 CSRF vulnerablity (PMASA-2019-4)
  • 131319 - phpMyAdmin 4.7.7 < 4.9.2 SQLi (PMASA-2019-5)
  • 138595 - phpMyAdmin 4.x < 4.9.4 / 5.x < 5.0.1 SQLi (PMASA-2020-1)
  • 126705 - phpMyAdmin 4.0 < 4.8.5 Multiple Vulnerabilities (PMASA-2019-1), (PMASA-2019-2)
  • 129696 - phpMyAdmin <= 4.9.1 Cross-Site Request Forgery Vulnerability
  • 144649 - phpMyAdmin 4.9.0 < 4.9.6 / 5.0.0 < 5.0.3 Multiple Vulnerabilities (PMASA-2020-5, PMASA-2020-6)
  • 51425 - phpMyAdmin error.php BBcode Tag XSS (PMASA-2010-9)
  • 19950 - phpMyAdmin grab_globals.lib.php subform Parameter Traversal Local File Inclusion

Version


This page has been produced using Nessus Professional 10.1.2 (#68) LINUX, Plugin set 202205072148.
Plugin file phpmyadmin_pmasa_2009_3.nasl version 1.25. For more plugins, visit the Nessus Plugin Library.

Go back to menu.