[zz]Exploiting PHP SELF
Eric Butera emailed me with a very interesting topic about protecting against PHP_SELF exploits. I thought it might be a good idea to gather a few test cases demonstrating the problem. Why PHP allows these URL’s is beyond me and it wouldn’t take much work to filter out these malicious URL’s in the PHP code.
For any of you that don’t know, it’s possible to inject code into PHP_SELF. It works by supplying a “/” after the actual PHP file then entering your desired code. I’ve done 4 test cases which show how it’s possible to inject javascript and perform a redirect on code which doesn’t filter PHP_SELF correctly.
Test case 1Injects data into a HTTP header, although this scenario is not very likely I thought I would include it to show that even running htmlentities or htmlspecialchars won’t save you from attack completely.
Test case 2Shows how easy it is to inject XSS into links, this is very likely as many PHP applications ofter refer to the same page to change the current action/display.
Test case 3A search page often includes references to PHP_SELF and can be exploited as easily as links.
Test case 4Finally I show how code can be injected directly on the page without the need to break out of anything.
The test cases can be downloaded here:-
Test cases
推荐阅读
-
php中$_SERVER[PHP_SELF] 和 $_SERVER[SCRIPT_NAME]之间的区别
-
不要轻信 PHP_SELF的安全问题
-
PHP中new static()与new self()的区别异同分析
-
php面向对象程序设计中self与static的区别分析
-
php 中self,this的区别和操作方法实例分析
-
php self,$this,const,static,->的使用
-
PHP编程过程中需要了解的this,self,parent的区别
-
PHP_SELF,SCRIPT_NAME,REQUEST_URI区别
-
PHP的new static和new self的区别与使用
-
php类中的$this,static,final,const,self这几个关键字使用方法