[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: PHP header() CRLF Injection

A similar but far less dangerous vulnerability exists with the file() (and
most file read related functions) function when passing a URL as the file to
open (given that you have compiled PHP with appropriate options to allow
this).  You have the capacity to add header information to the GET request,
if you are clever about it, including keepalive, and additional requests
that the original author hadn't counted on.  Such cleverness is left as an
exercise to the reader (if you use HTTP/1.1 instead of 1.0, you may receive
unparsed chunking, severely limiting what little damage could normally be

At this point, I would like to re-voice my general objection to passing
unparsed data entered by one untrusted user directly to anyone's browser.
In general you should always know what sort of regexp any valid user input
matches, and clean it up with preg_replace() or similar function before
passing it out to the browser.  In my mind, this is a task for each
developer, although it sure would be nice if it was redundant security.


-----Original Message-----
From: Matthew Murphy [mailto:mattmurphy@xxxxxxxxx]
Sent: Saturday, September 07, 2002 6:37 PM
To: VulnDiscuss; VulnWatch; Vuln-Dev; SecurITeam News; BugTraq
Subject: PHP header() CRLF Injection

PHP's header() function is used to modify HTTP header information by
specifying a header line, such as this:

<?php header("Location: http://www.yahoo.com/";); ?>

It is commonplace to see things such as this:

--- REDIR.PHP ---
<?php header("Location: $_GET['$url']"); ?>
--- REDIR.PHP ---


Will cause a series of lines to be produced:

HTTP/1.1 302 Found
Server: Xitami
Date: Sat, 07 Sep 2002 21:50:17 GMT
Content-length: 96
Content-type: text/html
X-powered-by: PHP/4.2.3
{Location: http://www.yahoo.com/

<SCRIPT>alert(document.cookie)</SCRIPT><!--}        <-- See our code in
between the brackets
Content-type: text/html

The HTML produced is "broken" -- that is, it doesn't comply to RFC
because it doesn't have a "-->" tag.  I did this to supress the stupid
header that PHP was dumping in the response.

By using this, attackers can perform cross-site scripting attacks or
initiate downloads, in rare cases (via HTTP headers, such as
content-dispostion, etc.)

"The reason the mainstream is thought
of as a stream is because it is
so shallow."
                     - Author Unknown