
تحليل ثابت للكود لـ WordPress (و PHP)

تحليل ثابت للكود البرمجي للإضافات/القوالب في ووردبريس (ولغة PHP)
كل ما عليك هو استنساخ المستودع، تثبيت المتطلبات وتشغيل السكريبت
$ git clone https://github.com/webarx-security/wpbullet wpbullet$ cd wpbullet$ pip install -r requirements.txt$ python wpbullet.pyالخيارات المتاحة:
--path (required) System path or download URL
Examples:
--path="/path/to/plugin"
--path="https://wordpress.org/plugins/example-plugin"
--path="https://downloads.wordpress.org/plugin/example-plugin.1.5.zip"
--enabled (optional) Check only for given modules, ex. --enabled="SQLInjection,CrossSiteScripting"
--disabled (optional) Don't check for given modules, ex. --disabled="SQLInjection,CrossSiteScripting"
--cleanup (optional) Automatically remove content of .temp folder after scanning remotely downloaded plugin (boolean)
--report (optional) Saves result inside reports/ directory in JSON format (boolean)
$ 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