Skip to content

Commit 039a726

Browse files
committed
feat:refactor mitm proxy be dynamic with the domain and token
1 parent 9c26d9d commit 039a726

File tree

1 file changed

+22
-3
lines changed

1 file changed

+22
-3
lines changed

examples/hybrid/utils/proxy-server.py renamed to examples/utils/proxy-server.py

+22-3
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@
66
# Configuration
77
TARGET_HOST = "instabug.com"
88
ORIGINAL_DOMAIN = "api.instabug.com"
9-
NEW_DOMAIN = "st001012dream11.instabug.com"
10-
TARGET_TOKEN = "dfed1c768730afbd56efafd571b4cbaa"
9+
NEW_DOMAIN = os.getenv('Domain')
10+
TARGET_TOKEN = os.getenv('Key')
1111
ALL_REQUESTS_FILE = "InterceptedRequests.json"
12+
CAPTURED_RESPONSE_FILE = "captured_response.json"
13+
1214
def save_to_json(data, filename):
1315
try:
1416
if os.path.exists(filename):
@@ -24,6 +26,19 @@ def save_to_json(data, filename):
2426
except Exception as e:
2527
ctx.log.error(f"Error saving to {filename}: {str(e)}")
2628

29+
def save_captured_response(response_body):
30+
try:
31+
if isinstance(response_body, str):
32+
response_json = json.loads(response_body)
33+
else:
34+
response_json = json.loads(response_body.decode('utf-8'))
35+
36+
with open(CAPTURED_RESPONSE_FILE, 'w') as f:
37+
json.dump(response_json, f, indent=2)
38+
39+
except Exception as e:
40+
ctx.log.error(f"Error saving captured response: {str(e)}")
41+
2742
def should_intercept(url: str) -> bool:
2843
return TARGET_HOST in url
2944

@@ -69,6 +84,10 @@ def response(flow: http.HTTPFlow) -> None:
6984
'headers': dict(flow.response.headers),
7085
'content': flow.response.get_text()
7186
}
87+
88+
response_body = flow.response.get_text()
89+
save_captured_response(response_body)
90+
7291
flow.metadata['captured_response'] = captured_response
7392

7493
ctx.log.info("Restoring original request details")
@@ -95,4 +114,4 @@ def response(flow: http.HTTPFlow) -> None:
95114
"body": flow.response.get_text() if flow.response.get_text() else None
96115
}
97116
}
98-
save_to_json(request_response_data, ALL_REQUESTS_FILE)
117+
save_to_json(flow.response, ALL_REQUESTS_FILE)

0 commit comments

Comments
 (0)