之前Fl里有Smarty模版的XSS自动修复功能,但一直没有PHP模版的支持。主要是Smarty模版识别变量输出比较简单,判断是否是$打头,并且里面没有赋值之类的操作就可以了。 但PHP模版就非常麻烦了,PHP定界符之间可以写任何的PHP代码,不知道什么时候会进行输出。
之前Fl里有Smarty模版的XSS自动修复功能,但一直没有PHP模版的支持。主要是Smarty模版识别变量输出比较简单,判断是否是$打头,并且里面没有赋值之类的操作就可以了。
但PHP模版就非常麻烦了,PHP定界符之间可以写任何的PHP代码,不知道什么时候会进行输出。即使使用echo进行输出,echo后面也可以接很多东西,字符串、变量、表达式、函数调用等等,如:
这种情况下,之前一直没有解决这个问题的思路。如果为了这个功能去实现PHP的词法分析功能,就太麻烦了。
猛然间发现了PHP里提供了词法分析是方法,token_get_all函数(这个函数很早就有了)。
将PHP文本传入该函数后,就可以得到TOKEN列表。具体可以见PHP的官方文档:http://php.net/manual/en/function.token-get-all.php
有了这个方法就好办了,拿到token列表,寻找echo的TOKEN,到;或者?>结束,判断是否已经有了对应的转义方式或者标识为不转义,如果没有则加上对应的转义方式(PHP下都是使用函数来转义的)。
代码实现不是很复杂,具体见github上的项目文件:https://github.com/welefen/Fl/blob/master/src/Util/Tpl/PHP.class.php
ps: php虽然函数名和参数设计上有很多问题,但函数真实非常多。或者功能都有对应的函数
其实浏览器也可以把类似的接口暴漏给JS,这样很多工具都不用在实现一遍词法分析了。
原文地址:Fl里新增PHP模版的XSS自动修复功能, 感谢原作者分享。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

Dreamweaver Mac version
Visual web development tools

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software