如果系统没有采用上述根目录分离的目录结构,我们还有一种解决问题的办法,即在页面文档根目录下创建专用的私有数据存储目录,如“/shop”,然后在这个目录中创建.htaccess文件,通过.htaccess文件拒绝所有HTTP访问(适用于Apache服务器): $ cat /shop/.htaccess order deny, allow deny from all
下面这个简单的PHP程序将输出CGI参数b的值以及HTTP_REFERER的值: kris@valiant:~/www < cat test.php < ?php print "The value of b is $bn"; print "The value of HTTP_REFERER is $HTTP_REFERERn"; ? > 用telnet连接到80端口,我们能够向上述脚本提供任意的参数值b,同时还可以任意提供HTTP_REFERER值。我们把下面的几行发送到服务器: GET /~kris/test.php?b=this+is+a+test HTTP/1.0 Host: valiant.koehntopp.de Referer: http://www.attacker.com/die_sucker_die.html 下面是完整的会话过程: kris@valiant:~/www < telnet valiant 80 Trying 193.102.57.3... Connected to valiant.koehntopp.de. Escape character is '^]'. GET /~kris/test.php?b=this+is+a+test HTTP/1.0 Host: valiant.koehntopp.de Referer: http://www.attacker.com/die_sucker_die.html HTTP/1.1 200 OK Date: Sat, 08 Apr 2000 06:44:02 GMT Server: Apache/1.3.9 (Unix) (SuSE/Linux) PHP/4.0RC2-dev mod_ssl/2.4.7 OpenSSL/0.9.4 X-Powered-By: PHP/4.0RC2-dev Connection: close Content-Type: text/html The value of b is this is a test The value of HTTP_REFERER is http://www.attacker.com/die_sucker_die.html Connection closed by foreign host. 注意b的值必须以URL编码格式输入。要将字符串进行URL编码,可使用一个简单的PHP程序,例如: kris@valiant:~/www < cat urlencode.php #! /home/kris/bin/php -q < ?php print urlencode($argv[1])."n"; ? > kris@valiant:~/www < ./urlencode.php "this is a test" this+is+a+test 发送HTTP POST请求只是稍微复杂一点:现在应该在这个请求中包含一个合法的Content-Type头以及正确的内容长度字节数。下面是具体过程: kris@valiant:~/www < telnet valiant 80 Trying 193.102.57.3... Connected to valiant.koehntopp.de. Escape character is '^]'. POST /~kris/test.php HTTP/1.0 Host: valiant.koehntopp.de Referer: http://www.attacker.com/die_sucker_die.html Content-Type: application/x-www-form-urlencoded Content-Length: 16 b=this+is+a+test HTTP/1.1 200 OK Date: Sat, 08 Apr 2000 06:55:11 GMT Server: Apache/1.3.9 (Unix) (SuSE/Linux) PHP/4.0RC2-dev mod_ssl/2.4.7 OpenSSL/0.9.4 X-Powered-By: PHP/4.0RC2-dev Connection: close Content-Type: text/html The value of b is this is a test The value of HTTP_REFERER is http://www.attacker.com/die_sucker_die.html Connection closed by foreign host. 另外一种常见的错误是把内部应用的状态数据通过< INPUT TYPE="HIDDEN" >标记从一个页面传递到另一个页面。把内部应用的状态放到信任界限之外就如把应用的心脏挖出来放到了攻击者的面前。对于如此缺乏安全保障的应用,任何想要摧毁它的攻击者都可以轻易地引导该应用并得到任何想要的效果。应用的状态应该通过会话变量保存在服务器上,永远不应该跨越信任界限。所有的We