编写静态代码分析工具
我想编写一个静态代码分析工具来查找 PHP 代码中的 SQLi 漏洞。通常,我只是使用脚本来分离函数,并 grep 它们以进行不充分的清理。显然这种方法是有局限性的。
我要编写的程序的概要是:
- 查找对 mysql_query 的所有调用
- 查找对调用 mysql_query 的函数的所有引用
- 跟踪进入每个查询调用的所有变量,并查明是否对它们运行 mysql_real_escape_string。
我在写这篇文章时陷入了两种方法之间。我要么选择 PHP 扩展,要么从头开始将其独立编写。
使用 PHP 扩展的优点是我不必制作自己的标记器、解析器等(我想,这是基于 XDebug 扩展的功能)。
有编写 PHP 扩展经验的人对如何解决这个问题有什么建议吗?
I'd like to write a static code analysis tool for finding SQLi vulnerabilities in PHP code. Usually, I just use a script to separate functions, and grep them for inadequate sanitisation. Obviously this approach is limited.
The outline of the program I want to write is:
- Find all calls to mysql_query
- Find all references to the functions that call mysql_query
- Track all variables that go into each query call, and find out if mysql_real_escape_string is run on them.
I'm caught between two approaches to writing this. Either I go for a PHP extension, or write it as a standalone from scratch.
The advantages of using a PHP extension is that I wouldn't have to make my own tokenizer, parser etc (I presume, basing this on the capabilities of the XDebug extension).
Does anyone with experience in writing PHP extensions have any advice on how to approach the problem?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我建议查看 RIPS Scanner 项目并查看其源代码以获取想法。它完全执行您想要执行的功能。
I suggest looking at the RIPS Scanner project and review its source code for ideas. It performs exactly the functions you wish to do.