An interesting local file inclusion vulnerability has been recently published. An XXE (XML eXternal Entity) injection attack, which affects phpMyAdminÂ 3.4.x previous to 188.8.131.52 and 3.3.x previous to 184.108.40.206. – CVE-2011-4107
The issue is located in the libraries\import\xml.php file, where the simplexml_load_string() function is called without validating the existence of a reference to an external entity on the file:
$xml = simplexml_load_string($buffer, “SimpleXMLElement”, LIBXML_COMPACT);
Patched versions make use of theÂ libxml_disable_entity_loader() PHP function before loading the XML document, in order to prevent the injection.Â libxml_disable_entity_loader() function disables the ability to load external entities.
phpMyAdmin offers the functionality of importing a database from a user-specified XML file.Â In vulnerable versions importing a specially-crafted XML file which contains an external XML entity permits an authenticated attacker to retrieve a local fileÂ from the server or networkÂ (limited by the privileges of the user running the web server).
It is well understood that the LOAD_FILE MySQL function could be used to gain read access to files in the database file system, however there are configurations where phpMyAdmin is installed on a different host than the database and therefore exploitation of this issue could become handy in penetration testing engagements.
SECFORCE has developed a metasploit module to assist the exploitation of this vulnerability. It is available for download from ourÂ security tools section on our website.
This module automates the process of local file inclusion in the following way:
- Logging in into phpMyAdmin using provided credentials.
- Crafting an XML using XXE with the given file to read.
- Uploading the XML
- Retrieving the file from the server or network (restricted by theÂ privileges ofÂ the user running the web serverÂ ).
The module has the options shown in the following screenshot:
An example of a successful run of the module is presented in the screenshot below:
Defining XML external entity (XXE) injection attack as part of XML injection vulnerability:
XML Injection is when is is possible to change the values of an XML document and the XML parser fails to make an appropriate data validation this way making the injection possible.
XML external entity injection attack (XXE)
“External Entity: The set of valid entities can be extended by defining new entities. If the definition of an entity is a URI, the entity is called an external entity. Unless configured to do otherwise, external entities force the XML parser to access the resource specified by the URI, e.g., a file on the local machine or on a remote systems. This behavior exposes the application to XML eXternal Entity (XXE) attacks, which can be used to perform denial of service of the local system, gain unauthorized access to files on the local machine, scan remote machines, and perform denial of service of remote systems.” – (OWASP-DV-008)
<?xml version="1.0" encoding="ISO-8859-1"?> <!DOCTYPE foo [ <!ELEMENT foo ANY > <!ENTITY xxe SYSTEM "file:///c:/boot.ini" >]><foo>&xxe;</foo>
phpMyAdmin has released patched versions available for download from here.