
CVE-2026-48710漏洞验证代码
#सिद्धांत:
Starlette एक ओपन-सोर्स, हल्का Python ASGI फ्रेमवर्क है
यह समस्या Starlette फ्रेमवर्क के url डेटा संरचना प्रोसेसिंग में क्लाइंट द्वारा भेजे गए host पर भरोसा करने के कारण उत्पन्न होती है, जहाँ host को सीधे url वेरिएबल में जोड़कर आगे की प्रमाणीकरण प्रक्रिया की जाती है
मूल url uvicorn\protocols\http\httptools_impl.py में प्रोसेस होता है
def on_message_begin(self) -> None:
self.url = b""
self.expect_100_continue = False
self.headers = []
self.scope = {
"type": "http",
"asgi": {"version": self.asgi_version, "spec_version": "2.3"},
"http_version": "1.1",
"server": self.server,
"client": self.client,
"scheme": self.scheme,
"root_path": self.root_path,
"headers": self.headers,
"state": self.app_state.copy(),
}
# Parser callbacks
def on_url(self, url: bytes) -> None:
self.url += url #self.url设置为原始url
def on_header(self, name: bytes, value: bytes) -> None:
name = name.lower()
if name == b"expect" and value.lower() == b"100-continue":
self.expect_100_continue = True
self.headers.append((name, value))
def on_headers_complete(self) -> None:
http_version = self.parser.get_http_version()
method = self.parser.get_method()
self.scope["method"] = method.decode("ascii")
if http_version != "1.1":
self.scope["http_version"] = http_version
if self.parser.should_upgrade() and self._should_upgrade():
return
parsed_url = httptools.parse_url(self.url)#使用httptools拆分原始url
raw_path = parsed_url.path #raw_path设置为原始url拆分出的path(访问的path)
path = raw_path.decode("ascii") #path设置为使用ascii解码以后的原始path值
if "%" in path: #处理url解码以后的中文从重编码
path = urllib.parse.unquote(path)
full_path = self.root_path + path
full_raw_path = self.root_path.encode("ascii") + raw_path
self.scope["path"] = full_path
self.scope["raw_path"] = full_raw_path
self.scope["query_string"] = parsed_url.query or b""
(मेरे द्वारा मैन्युअल रूप से टाइप किए गए कमेंट)
यह कोड class URL: मेथड के अंदर है
कोड:\starlette\datastructures.py
host_header = None for key, value in scope["headers"]: if key == b"host": host_header = value.decode("latin-1") break if host_header is not None: url = f"{scheme}://{host_header}{path}" #基于用户传入的请求头二次定义url
starlette\routing.py में:
route_path = get_route_path(scope)
if scope["type"] == "http" and self.redirect_slashes and route_path != "/":
redirect_scope = dict(scope)
if route_path.endswith("/"):
redirect_scope["path"] = redirect_scope["path"].rstrip("/")
else:
redirect_scope["path"] = redirect_scope["path"] + "/"
for route in self.routes:
match, child_scope = route.matches(redirect_scope)
if match != Match.NONE:
redirect_url = URL(scope=redirect_scope) #调用URL方法
response = RedirectResponse(url=str(redirect_url))
await response(scope, receive, send)
return
इसका परिणाम यह होता है कि उपयोगकर्ता द्वारा host हेडर के साथ भेजा गया विकृत अनुरोध प्रमाणीकरण की आवश्यकता वाले एंडपॉइंट पर पहुँच जाता है, और रूटिंग परत में url को पुनः एक ऐसे एंडपॉइंट के रूप में परिभाषित किया जाता है जिसे प्रमाणीकरण की आवश्यकता नहीं होती
उदाहरण के लिए, http://127.0.0.1:9999/admin पर
इस url में admin एक प्रमाणीकरण-आवश्यक एंडपॉइंट है
डेटा पैकेट भेजें
url = http://127.0.0.1:9999/admin
header{
host = 123?
}
पुनः परिभाषित url बदलकर http://123?/admin हो जाता है
इस समय url को पार्स करने के लिए urlsplit फ़ंक्शन का उपयोग किया जाता है
परिणाम SplitResult(scheme='http', netloc='123', path='', query='/admin', fragment='')
चूँकि path='' है, बाद की प्रमाणीकरण प्रक्रिया यह मान लेती है कि उपयोगकर्ता वेबसाइट की रूट डायरेक्टरी तक पहुँच रहा है, इसलिए अनुरोध सीधे पास हो जाता है, और वास्तव में admin डायरेक्टरी की सामग्री लौटा दी जाती है