
WordPress(およびPHP)向けの静的コード分析

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 (オプション) 結果をreports/ディレクトリにJSON形式で保存します(ブール値)
$ 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