Pentesting gRPC-Web
Reading time: 7 minutes
tip
Aprenda e pratique Hacking AWS:
HackTricks Training AWS Red Team Expert (ARTE)
Aprenda e pratique Hacking GCP:
HackTricks Training GCP Red Team Expert (GRTE)
Aprenda e pratique Hacking Azure:
HackTricks Training Azure Red Team Expert (AzRTE)
Supporte o HackTricks
- Confira os planos de assinatura!
- Junte-se ao đŹ grupo do Discord ou ao grupo do telegram ou siga-nos no Twitter đŠ @hacktricks_live.
- Compartilhe truques de hacking enviando PRs para o HackTricks e HackTricks Cloud repositĂłrios do github.
Resumo rĂĄpido do protocolo e superfĂcie de ataque
- Transport: gRPCâWeb speaks a browserâcompatible variant of gRPC over HTTP/1.1 or HTTP/2 via a proxy (Envoy/APISIX/grpcwebproxy/etc.). Only unary and serverâstreaming calls are supported.
- Content-Types you will see:
- application/grpc-web (binary framing)
- application/grpc-web-text (base64-encoded framing for HTTP/1.1 streaming)
- Framing: every message is prefixed with a 5âbyte gRPC header (1âbyte flags + 4âbyte length). In gRPCâWeb, trailers (grpc-status, grpc-message, âŠ) are sent inside the body as a special frame: first byte with MSB set (0x80) followed by a length and a HTTP/1.1âstyle header block.
- Common request headers: x-grpc-web: 1, x-user-agent: grpc-web-javascript/âŠ, grpc-timeout, grpc-encoding. Responses expose grpc-status/grpc-message via trailers/body frames and often via Access-Control-Expose-Headers for browsers.
- Securityârelevant middleware often present:
- Envoy grpc_web filter and gRPCâJSON transcoder (HTTP<->gRPC bridge)
- Nginx/APISIX gRPCâWeb plugins
- CORS policies on the proxy
O que isso significa para atacantes:
- VocĂȘ pode criar requests manualmente (binĂĄrio ou base64 text), ou deixar ferramentas gerarem/codificarem eles.
- Erros de CORS no proxy podem permitir chamadas gRPCâWeb crossâsite autenticadas (semelhante a problemas clĂĄssicos de CORS).
- Pontes de JSON transcoding podem expor métodos gRPC inadvertidamente como endpoints HTTP não autenticados se rotas/autenticação estiverem mal configuradas.
Testando gRPCâWeb a partir do CLI
Mais fĂĄcil: buf curl (speaks gRPCâWeb natively)
- List methods via reflection (if enabled):
# list methods (uses reflection)
buf curl --protocol grpcweb https://host.tld --list-methods
- Chamar um mĂ©todo com input JSON, lidando automaticamente com o gRPCâWeb framing e headers:
buf curl --protocol grpcweb \
-H 'Origin: https://example.com' \
-d '{"field":"value"}' \
https://host.tld/pkg.svc.v1.Service/Method
- Se reflection estiver desabilitado, forneça um schema/descriptor set com --schema ou aponte para arquivos .proto locais. Veja buf help curl.
Raw com curl (headers manuais + framed body)
Para o modo binĂĄrio (application/grpc-web), envie um framed payload (5âbyte prefix + protobuf message). Para o modo texto, codifique em base64 o framed payload.
# 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
Dica: Forçar modo base64/text com application/grpc-web-text quando intermediårios HTTP/1.1 interrompem o streaming binårio.
Verificar comportamento de 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'
- Uma configuração vulnerĂĄvel frequentemente reflete um Origin arbitrĂĄrio e envia Access-Control-Allow-Credentials: true, permitindo chamadas autenticadas crossâsite. TambĂ©m verifique se Access-Control-Expose-Headers inclui grpc-status, grpc-message (muitas implantaçÔes expĂ”em estes para client libs).
For generic techniques to abuse CORS, check CORS - Misconfigurations & Bypass.
Manipulando payloads gRPCâWeb
gRPCâWeb usa Content-Type: application/grpc-web-text como um stream de frames gRPC encapsulado em base64 para compatibilidade com navegadores. VocĂȘ pode decode/modify/encode frames para adulterar campos, inverter flags, ou injetar payloads.
Use a ferramenta gprc-coder (e sua extensĂŁo para Burp) para acelerar roundâtrips.
Manual com gGRPC Coder Tool
- Decodifique o payload:
echo "AAAAABYSC0FtaW4gTmFzaXJpGDY6BVhlbm9u" | python3 grpc-coder.py --decode --type grpc-web-text | protoscope > out.txt
- Editar o conteĂșdo do payload decodificado
nano out.txt
2: {"Amin Nasiri Xenon GRPC"}
3: 54
7: {"<script>alert(origin)</script>"}
- Encode o novo payload
protoscope -s out.txt | python3 grpc-coder.py --encode --type grpc-web-text
- Usar a saĂda no Burp interceptor:
AAAAADoSFkFtaW4gTmFzaXJpIFhlbm9uIEdSUEMYNjoePHNjcmlwdD5hbGVydChvcmlnaW4pPC9zY3JpcHQ+
Manual with gRPCâWeb Coder Burp Suite Extension
VocĂȘ pode usar gRPCâWeb Coder Burp Suite Extension dentro do gRPCâWeb Pentest Suite, o que Ă© mais fĂĄcil. Leia as instruçÔes de instalação e uso no repositĂłrio.
Analysing gRPCâWeb JavaScript files
AplicaçÔes web que usam gRPCâWeb entregam pelo menos um bundle JS/TS gerado. Reverse them para extrair services, methods e message shapes.
- Tente usar gRPC-Scan para parsear bundles.
- Procure por paths de método como /
. / , nĂșmeros/tipos de campos de mensagem, e interceptadores customizados que adicionam auth headers.
- Download the JavaScript gRPCâWeb file
- Scan it with grpc-scan.py:
python3 grpc-scan.py --file main.js
- Analise a saĂda e teste os novos endpoints e novos serviços:
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 |
+--------------+----------------+--------------+
Armadilhas de bridging e transcodificação JSON
Muitas implantaçÔes colocam um proxy Envoy (ou similar) na frente do servidor gRPC:
- O filtro grpc_web traduz POSTs HTTP/1.1 em HTTP/2 gRPC.
- O gRPCâJSON Transcoder expĂ”e mĂ©todos gRPC como endpoints HTTP JSON quando opçÔes .proto (google.api.http) estĂŁo presentes.
Do ponto de vista de pentesting:
- Tente chamadas HTTP JSON diretas para /
. / com application/json quando um transcoder estiver habilitado (incompatibilidades de auth/route sĂŁo comuns):
curl -i https://host.tld/pkg.svc.v1.Service/Method \
-H 'Content-Type: application/json' \
-d '{"field":"value"}'
- Revise se métodos/parùmetros desconhecidos são rejeitados ou repassados. Algumas configs encaminham paths não correspondentes para o upstream, ocasionalmente contornando auth ou validação de requests.
- Observe x-envoy-original-path e headers relacionados adicionados por proxies. Upstreams que confiam neles podem ser abusados se o proxy falhar em sanitizĂĄ-los.
ReferĂȘncias
- Hacking into gRPCâWeb Article by Amin Nasiri
- gRPCâWeb Pentest Suite
- gRPCâWeb protocol notes (PROTOCOLâWEB.md)
tip
Aprenda e pratique Hacking AWS:
HackTricks Training AWS Red Team Expert (ARTE)
Aprenda e pratique Hacking GCP:
HackTricks Training GCP Red Team Expert (GRTE)
Aprenda e pratique Hacking Azure:
HackTricks Training Azure Red Team Expert (AzRTE)
Supporte o HackTricks
- Confira os planos de assinatura!
- Junte-se ao đŹ grupo do Discord ou ao grupo do telegram ou siga-nos no Twitter đŠ @hacktricks_live.
- Compartilhe truques de hacking enviando PRs para o HackTricks e HackTricks Cloud repositĂłrios do github.
HackTricks