如果系統沒有采用上述根目錄分離的目錄結構,我們還有一種解決問題的辦法,即在頁面文檔根目錄下創建專用的私有數據存儲目錄,如“/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