Fun with getallheaders() and var_dump() - another excerpt from Chapter 8
In PHP, the Apache-specific functions give an extremely easy way of checking referers via the getallheaders() library function. Calling it, with PHP installed as an Apache module, returns an associative array containing all of the header names as the array keys, with their corresponding header values as the array values. Calling var_dump(getallheaders()) would display something like the following, with "Referer" as the last entry in the array:
array(9) {
["Host"]=>
string(13) "192.168.2.106"
["User-Agent"]=>
string(92) "Mozilla/5.0 (Macintosh; U; Intel Mac OS X; en-US; rv:1.8.1.3) Gecko/20070309 Firefox/2.0.0.3"
["Accept"]=>
string(99) "text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5"
["Accept-Language"]=>
string(23) "en-us,en;q=0.7,fr;q=0.3"
["Accept-Encoding"]=>
string(12) "gzip,deflate"
["Accept-Charset"]=>
string(7) "UTF-8,*"
["Keep-Alive"]=>
string(3) "300"
["Connection"]=>
string(10) "keep-alive"
["Referer"]=>
string(31) "http://192.168.2.106/utilities/"
}
However, the following shows that a simple telnet connection can set the header to anything and the server will simply believe it, since it lacks any way of verifying it.
$ telnet 192.168.2.106 80
Trying 192.168.2.106...
Connected to 192.168.2.106.
Escape character is '^]'.
GET /utilities/getallheaders.php HTTP/1.1
Host: 192.168.2.106
Referer: The Forbidden Zone
HTTP/1.1 200 OK
Date: Thu, 22 Mar 2007 02:08:01 GMT
Server: Apache/2.2.3 (Unix) PHP/5.2.1
X-Powered-By: PHP/5.2.1
Content-Length: 117
Content-Type: text/html
array(2) {
["Host"]=>
string(13) "192.168.2.106"
["Referer"]=>
string(18) "The Forbidden Zone"
}Labels: advanced ajax, excerpts

0 Comments:
Post a Comment
Links to this post:
Create a Link
<< Home