Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:47870 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 20920 invoked from network); 11 Apr 2010 16:23:13 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 11 Apr 2010 16:23:13 -0000 Authentication-Results: pb1.pair.com header.from=keith@karsites.net; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=keith@karsites.net; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain karsites.net from 81.168.74.150 cause and error) X-PHP-List-Original-Sender: keith@karsites.net X-Host-Fingerprint: 81.168.74.150 unknown Received: from [81.168.74.150] ([81.168.74.150:10896] helo=karsites.localdomain) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 7A/91-11452-E67F1CB4 for ; Sun, 11 Apr 2010 12:23:10 -0400 Received: from www.karsites.net (localhost [127.0.0.1]) by karsites.localdomain (Postfix) with ESMTP id 51C923BFD4 for ; Sun, 11 Apr 2010 17:23:07 +0100 (BST) Received: (from keith@localhost) by www.karsites.net (8.14.3/8.14.3/Submit) id o3BGN6Bp006070 for internals@lists.php.net; Sun, 11 Apr 2010 17:23:06 +0100 Received: by www.karsites.net (tmda-sendmail, from uid 501); Sun, 11 Apr 2010 17:23:06 +0100 (BST) Date: Sun, 11 Apr 2010 17:23:04 +0100 (BST) To: internals@lists.php.net Message-ID: User-Agent: Alpine 2.00 (LFD 1167 2008-08-23) MIME-Version: 1.0 Content-Type: MULTIPART/MIXED; BOUNDARY="655616-157359358-1271002984=:5158" X-Delivery-Agent: TMDA/1.0.3 (Seattle Slew) Reply-To: Keith Roberts Subject: Making reading files from remote URL's more secure From: keith@karsites.net (Keith Roberts) --655616-157359358-1271002984=:5158 Content-Type: TEXT/PLAIN; format=flowed; charset=UTF-8 Content-Transfer-Encoding: QUOTED-PRINTABLE Hi all. I've been reading about the security implications of turning=20 allow_url_fopen 'on' for certain PHP applications that need=20 to read files from a remote URL. To recap, please read this old article about Remote=20 file inclusion vulnerabilities: http://lwn.net/Articles/203904/ I'm just wondering if the ability to read files from a=20 remote URL could be moved into a set of functions dedicated=20 to that purpose alone? Then remove the URL reading ability=20 from the standard file reading functions, to make those more=20 secure? The new set of remote file reading functions could be=20 prefixed with 'url_'. This would make it easier to distinguish between the local=20 file reading functions, and those that read from remote=20 URL's. So the normal fopen() function would only work on files=20 locally, regardless of whether allow_url_open was turned on. allow_url_open would only enable the file functions=20 with the 'url_' prefix. setting allow_url_open to 'OFF' would disable those remote=20 file reading functions, prefixed with 'url_'. To read a file from localhost just use the normal syntax: To read a file from a remote URL use: To write a file to a remote URL use: To make sure that an attacker cannot use url_fopen() in an=20 attack script, these url_ prefixed remote file read/write=20 functions could also take another required parameter, $md5hash. fopen (PHP 4, PHP 5) fopen =E2=80=94 Opens file or URL Description fopen ( string $filename, string $mode, $md5hash [, bool $use_include_path =3D false [, resource $context ]] ) As in: $md5hash is a value that the 'url_' prefixed remote file=20 reading/writing functions checks before opening the remote=20 URL. If the $md5hash parmeter does not match what the function=20 expects, then the function fails with an error message, and=20 refuses to open the remote file. If the $md5hash was stored on the localhost, then the=20 attacker would not have access to it, and the url_ prefixed=20 remote file functions would fail with the error message,=20 "Cannot open remote URL - invalid hash key". These remote file opening attempts would also appear in the=20 PHP error log, making it easier to spot such security=20 attacks. Any ideas how the $md5hash KEY could be stored on localhost,=20 so PHP can read it, and then compare that KEY with the value=20 the programmer passes into the url_fopen($file, $mode, $md5hash)=20 function? Kind Regards, Keith Roberts ----------------------------------------------------------------- Websites: http://www.karsites.net http://www.php-debuggers.net All email addresses are challenge-response protected with TMDA [http://tmda.net] ----------------------------------------------------------------- --655616-157359358-1271002984=:5158--