如何检查php文件是否被混淆?
有什么方法可以使用 php 检查 php 文件是否已被混淆?我在想可能是正则表达式(例如 ioncube 的编码文件包含一个很长的字母字符串等。
is there any way we can check if a php file has been obfuscated, using php? I was thinking regex maybe (for instance ioncube's encoded file contains a very long alphabet string, etc.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
一种想法是检查空格。混淆器要做的第一件事就是删除多余的空格。您可以查看的另一件事是每行的字符数,因为混淆器会将所有代码放入几行(一行?)中。
One idea is to check for whitespace. The first thing that an obfuscator will do is to remove extra whitespace. Another thing you can look for is the number of characters per line, as obfuscators will put all the code into few (one?) lines.
通常,混淆器会初始化非常大的数组,以将变量转换为意义不大的名称(例如,请参阅混淆器文章
技术可能是搜索这些超大型数组,靠近类/文件的顶部等。您也许可以挂接 xdebug 来检查/查找这些数组,当然整个事情取决于混淆。检查源代码,可能有他们使用过的模式,您可以搜索。
Often, obsfuscators initialize very large arrays to translate variables into less meaningful names (eg. see obsfucator article
One technique may be to search for these super-large arrays, close to the top of the class/file etc. You may be able to hook xdebug up to examine/look for these. The whole thing of course depends on the obsfuscation technique used. Check the source code, there may be patterns they've used that you can search on.
我认为您可以使用 token_get_all() 来解析文件 - 然后计算一些统计数据。例如,检查函数调用的数量(实际上混淆器使用一些 eval() 字符串,而不使用其他任何东西)并计算平均函数长度 - 对于混淆器,它通常约为 3-5 个字符,对于普通 PHP 代码,它应该更大。您还可以使用字典查找函数/变量名称、检查注释等。我认为如果您知道要检测的所有混淆器格式 - 这会很容易。
I think you can use token_get_all() to parse the file - then compute some statistics. For example check for number of function calls(in calse obfuscator uses some eval() string and nothing else) and calculate average function length - for obfuscators it will usually be about 3-5 chars, for normal PHP code it should be much bigger. You can also use dictionary lookup for function/variable names, check for comments etc. I think if you know all obfuscator formats that you want to detect - it will be easy.