Last active
March 31, 2026 07:06
-
-
Save kjam/4959e6a52e07e20224d56bf1fe0cd92f to your computer and use it in GitHub Desktop.
mitm-claude-v-qwen
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # dump_claude_full.py | |
| # See more examples here: https://github.com/mitmproxy/mitmproxy/tree/main/examples | |
| from mitmproxy import http | |
| import json, os, time | |
| OUTPUT_DIR = "claude_captures" | |
| os.makedirs(OUTPUT_DIR, exist_ok=True) | |
| def _safe_json_parse(text: str): | |
| try: | |
| return json.loads(text) | |
| except Exception as e: | |
| print(e) | |
| print("error with response: %s" % text) | |
| return None | |
| def request(flow: http.HTTPFlow): | |
| if "anthropic.com" in flow.request.pretty_host: | |
| model_name = "claude" | |
| else: | |
| # CHANGE THIS IF USING DIFFERENT MODELS OR BUILD LOGIC FOR PARSING FROM JSON | |
| model_name = "qwen35" | |
| ts = time.strftime("%Y%m%d-%H%M%S") | |
| filename = os.path.join(OUTPUT_DIR, f"{model_name}_{ts}_{flow.id}.log") | |
| body = flow.request.get_text() | |
| data = _safe_json_parse(body) | |
| if data is None: | |
| print("error with response: %s" % body) | |
| with open(filename, "w", encoding="utf-8") as f: | |
| if data: | |
| json.dump(data, f, sort_keys=True, indent=4, ensure_ascii=False) | |
| flow.metadata["dump_file"] = filename | |
| print(f"[+] Captured request → {filename}") | |
| def response(flow: http.HTTPFlow): | |
| if "anthropic.com" in flow.request.pretty_host: | |
| model_name = "claude" | |
| else: | |
| model_name = "qwen35" | |
| filename = flow.metadata.get("dump_file") | |
| if not filename: | |
| ts = time.strftime("%Y%m%d-%H%M%S") | |
| filename = os.path.join(OUTPUT_DIR, f"{model_name}_{ts}_{flow.id}.log") | |
| text = flow.response.get_text() | |
| data = _safe_json_parse(text) | |
| with open(filename, "a", encoding="utf-8") as f: | |
| if data: | |
| json.dump(data, f, sort_keys=True, indent=4, ensure_ascii=False) | |
| print(f"[+] Appended response → {filename}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment