-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
executable file
·86 lines (63 loc) · 1.97 KB
/
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
from mitmproxy.options import Options
from mitmproxy.proxy.config import ProxyConfig
from mitmproxy.proxy.server import ProxyServer
from mitmproxy.tools.dump import DumpMaster
import threading
import asyncio
import time
import re
class InstagramDM(object):
"""
Leaves message as unseen by blocking the seen request.
Leaves story as unseen by blocking the seen request.
"""
_targets = [
r"https://i.instagram.com/api/v1/direct_v2/threads/.*/items/.*/seen/",
r"https://www.instagram.com/stories/reel/seen"
]
def match_url(self, url):
"""
Match url against target url
"""
coms = [
re.compile(url) for url in self._targets
]
return any([True if re.search(c_url, url) else False for c_url in coms])
def request(self, flow):
"""Kill spesific request.
"""
if self.match_url(flow.request.pretty_url) and flow.request.method == "POST":
print("Marked as unseen :)")
flow.kill()
class MitmClass:
"""Lunch mitmproxy within python.
"""
def __init__(self, host, port, addons):
self.options = Options(
listen_host=str(host),
listen_port=int(port),
http2=True)
self.mitm = DumpMaster(
self.options,
with_termlog=False,
with_dumper=False)
self.addons = addons
self.config_server()
def config_server(self):
config = ProxyConfig(self.options)
self.mitm.server = ProxyServer(config)
self.mitm.addons.add(self.addons)
def loop_in_thread(loop, m):
asyncio.set_event_loop(loop)
m.mitm.run_loop(loop.run_forever)
if __name__ == "__main__":
# setup
mitm = MitmClass(
host="127.0.0.1",
port="8080",
addons=InstagramDM()
)
# run mitm mproxy in backgroud
loop = asyncio.get_event_loop()
t = threading.Thread(target=loop_in_thread, args=(loop, mitm))
t.start()