
一个针对 WordPress 插件/主题(和 PHP)的静态代码分析工具
只需克隆仓库,安装依赖项并运行脚本:
$ git clone https://github.com/webarx-security/wpbullet wpbullet$ cd wpbullet$ pip install -r requirements.txt$ python wpbullet.py可用选项:
--path (必需) 系统路径或下载 URL
示例:
--path="/path/to/plugin"
--path="https://wordpress.org/plugins/example-plugin"
--path="https://downloads.wordpress.org/plugin/example-plugin.1.5.zip"
--enabled (可选) 仅检查给定的模块,例如 --enabled="SQLInjection,CrossSiteScripting"
--disabled (可选) 不检查给定的模块,例如 --disabled="SQLInjection,CrossSiteScripting"
--cleanup (可选) 在远程下载插件后自动删除 .temp 文件夹内容(布尔值)
--report (可选) 将结果以 JSON 格式保存到 reports/ 目录下(布尔值)
$ python wpbullet.py --path="/var/www/wp-content/plugins/plugin-name"
创建模块非常灵活,允许重写每个模块的 BaseClass 方法,也可以创建自己的方法。
Modules 目录中的每个模块都实现了 core.modules.BaseClass 的属性和方法,因此每个模块必需的参数是 BaseClass。
创建完成后,模块需要导入到 modules/__init__.py 中。模块名和类名必须一致,以便模块能够被加载。
如果您提交拉取请求以添加新模块,请同时提供该模块的单元测试。
Modules/ExampleVulnerability.py
from core.modules import BaseClass
class ExampleVulnerability(object):
# Vulnerability name
name = "Cross-site Scripting"
# Vulnerability severity
severity = "Low-Medium"
# Functions causing vulnerability
functions = [
"print"
"echo"
]
# Functions/regex that prevent exploitation
blacklist = [
"htmlspecialchars",
"esc_attr"
]
正则模式在 core.modules.BaseClass.build_pattern 中生成,因此可以在每个模块类中重写。
Modules/ExampleVulnerability.py
import copy
...
# Build dynamic regex pattern to locate vulnerabilities in given content
def build_pattern(self, content, file):
user_input = copy.deepcopy(self.user_input)
variables = self.get_input_variables(self, content)
if variables:
user_input.extend(variables)
if self.blacklist:
blacklist_pattern = r"(?!(\s?)+(.*(" + '|'.join(self.blacklist) + ")))"
else:
blacklist_pattern = ""
self.functions = [self.functions_prefix + x for x in self.functions]
pattern = r"((" + '|'.join(self.functions) + ")\s{0,}\(?\s{0,1}" + blacklist_pattern + ".*(" + '|'.join(user_input) + ").*)"
return pattern
运行单元测试:$ python3 -m unittest