通常情况下curl被用来访问远程链接,并取回数据。但是curl支持很多协议。下面是一段php手册中关于curl的描述:

PHP supports libcurl, a library created by Daniel Stenberg, that allows you to connect and communicate to many different types of servers with many different types of protocols. libcurl currently supports the http, https, ftp, gopher, telnet, dict, file, and ldap protocols. libcurl also supports HTTPS certificates, HTTP POST, HTTP PUT, FTP uploading (this can also be done with PHP’s ftp extension), HTTP form based upload, proxies, cookies, and user+password authentication.

从上面这段描述中可以看出,curl支持file协议。使用file协议用户可以使用file:///etc/passwd这样的url来访问本地文件。所以如果用户可以控制curl_exec()函数的参数,那么用户就可以读取服务器上的任意文件。 在Zen Cart中就存在这样的漏洞。 下面是一段Zen Cart的描述:

Zen Cart is an open source online store management system. It is PHP-based, using a MySQL database and HTML components. Support is provided for several languages and currencies, and it is freely available under the GNU General Public License.

Zen Cart有一个extras的目录,里面有一些测试脚本,其中一个就叫做curltest.php这个脚本用来测试PHP的curl库是否正确运行。 其中传给curl_exec()的url参数没有合理的过滤,就会导致读取服务器文件的漏洞。 下面是关于这个漏洞的详细描述:

如果用户可以控制curl_exec()中的url,那么就可能导致一系列的漏洞。 例如:攻击者可能使用file:///协议来读取服务器上的敏感文件例如:file:///etc/passwd文件。也可能通过它来访问防火墙后面的服务器。例如:使用http://192.168.0.1或ftp://192.168.0.1 老版本的libcurl是支持SCP的,这会导致执行任意命令的漏洞例如: “scp://name:passwd@host/a’;date > /tmp/test;'”