-
Notifications
You must be signed in to change notification settings - Fork 0
/
mitmfox_main.py
66 lines (49 loc) · 2.36 KB
/
mitmfox_main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
"""
Copyright (c) 2023 Gregor Gottschewski
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
documentation files (the “Software”), to deal in the Software without restriction, including without limitation the
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit
persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
"""
import requests
import json
import argparse
from mitmproxy import http
from mitmproxy.tools.main import mitmdump
parser = argparse.ArgumentParser(
prog="MitmFox Client",
description="Runs mitmproxy and sends responses and requests to a MitmFox Server",
epilog="PLEASE READ THE LICENSE BEFORE USING",
)
parser.add_argument("server_address", type=str, help="address of MitmFox server")
args = parser.parse_args()
server_address = args.server_address
def get_body_decoded(b: bytes):
try:
return b.decode("utf-8")
except UnicodeDecodeError:
return ""
def send_to_server(server: str, json_data: dict):
requests.post(server, json=json_data)
def response(flow: http.HTTPFlow) -> None:
response_body = get_body_decoded(flow.response.content)
request_body = get_body_decoded(flow.request.content)
body = {
"url": flow.request.url,
"method": flow.request.method,
"response_body": response_body,
"request_body": request_body,
"status_code": flow.response.status_code,
"response_headers": json.dumps(dict(flow.response.headers)),
"request_headers": json.dumps(dict(flow.request.headers))
}
send_to_server(server_address, body)
if __name__ == '__main__':
server_address = server_address
mitmdump(['-s', __file__])