Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Save decoded GRPC/Protocol Buffer content with mitmdump #6870

FreelancerCGN opened this issue May 22, 2024 · 1 comment

Save decoded GRPC/Protocol Buffer content with mitmdump #6870

FreelancerCGN opened this issue May 22, 2024 · 1 comment
kind/triage Unclassified issues


Copy link

FreelancerCGN commented May 22, 2024

Problem Description

I would like to save the decoded GRPC/Protocol Buffer content with mitmdump.

Example output:

gRPC message 0 (compressed False)
[message]    1
[message]    1.1
[message]    1.1.1

I called mitmdump with

/usr/local/bin/mitmdump --listen-host <IP ADDRESS> --listen-port <PORT> --mode upstream:http://<IP>:<PORT> --no-rawtcp --scripts --set block_global=false --set http3=false --set flow_detail=3 --set dumper_default_contentview=hex

At the script I tried almost everything I found here and at StackOverflow etc. I managed only to save the encoded binary content, not the decoded protobuf result (similar to the dump output of mitmdump).

Examples (not working):

import mitmproxy
import time
from mitmproxy import http

# def response(flow: http.HTTPFlow) -> None:
def response(flow):

if flow.request.pretty_url.endswith("test"):

   timestr = time.strftime("%Y%m%d-%H%M%S")
   with open("log/" + timestr + "-mitm-response-test.log", "wb") as f:
      # f.write(flow.response.content) # doesn't work
      # f.write(flow.response.text) # doesn't work
      # f.write(flow.response.get_content(False)) # doesn't work
      # f.write(flow.response.get_text()) # doesn't work
      # f.write(flow.response.get_text(False).encode()) # doesn't work

It's clearly a HTTP/2.0 request and a HTTP/2.0 response, no HTTP/1.1. And it's a GRPC/Protocol Buffer request/response, no "classic" Protocol Buffer.

How to solve this problem?

Steps to reproduce the behavior:

System Information

Mitmproxy: 10.3.0
Python: 3.10.12
OpenSSL: OpenSSL 3.2.1 30 Jan 2024
Platform: Linux-5.15.0-107-generic-x86_64-with-glibc2.35

@FreelancerCGN FreelancerCGN added the kind/triage Unclassified issues label May 22, 2024
Copy link

mhils commented May 23, 2024

I don't think we have a good way to export the pretty-printed result from a contentview at the moment. But this does definitely sound useful!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
kind/triage Unclassified issues
None yet

No branches or pull requests

2 participants