freeBuf
主站

分类

漏洞 工具 极客 Web安全 系统安全 网络安全 无线安全 设备/客户端安全 数据安全 安全管理 企业安全 工控安全

特色

头条 人物志 活动 视频 观点 招聘 报告 资讯 区块链安全 标准与合规 容器安全 公开课

官方公众号企业安全新浪微博

FreeBuf.COM网络安全行业门户,每日发布专业的安全资讯、技术剖析。

FreeBuf+小程序

FreeBuf+小程序

Wpbullet:一款针对WordPress(PHP)的静态代码分析工具
2019-06-28 15:00:33

今天给大家介绍的是一款名叫Wpbullet的工具,广大安全研究人员可以使用这款工具来对WordPress、插件、主题以及其他PHP项目进行静态代码分析。

bvbvbv.png

工具安装

大家可以直接从Wpbullet的GitHub代码库中将项目克隆至本地,然后安装工具的依赖组件,并运行工具脚本:

$ 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"

创建模块

Wpbullet的模块可扩展性以及灵活性都非常高,它允许我们重写每一个模块的BaseClass方法并实现我们自己的方法。

Modules目录中的每一个模块都继承了core.modules.BaseClass类的属性以及方法,因此每一个模块都需要的参数就是BaseClass了。

创建完成之后,模块需要在modules/__init__.py中导入。模块名和类名必须保持一致,否则Wpbullet将无法正常加载。

如果你想要在本项目的GitHub上pull request的话,请附带模块的单元测试数据。

模块样本

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

defbuild_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 + xfor x in self.functions]

    pattern = r"((" +'|'.join(self.functions) + ")\s{0,}\(?\s{0,1}" + blacklist_pattern +".*(" + '|'.join(user_input) + ").*)"

    return pattern

模块单元测试

$ python3 -m unittest

项目地址

Wpbullet:【GitHub传送门

 * 参考来源:webarx-security,FB小编Alpha_h4ck编译,转载请注明来自FreeBuf.COM

# WordPress # php # Wpbullet # 静态代码 # 分析工具
本文为 独立观点,未经允许不得转载,授权请联系FreeBuf客服小蜜蜂,微信:freebee2022
被以下专辑收录,发现更多精彩内容
+ 收入我的专辑
+ 加入我的收藏
相关推荐
  • 0 文章数
  • 0 关注者