-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmitm.py
More file actions
33 lines (27 loc) · 824 Bytes
/
mitm.py
File metadata and controls
33 lines (27 loc) · 824 Bytes
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
import json
import mitmproxy.http
import socketio
# initialising socket io client
sio = socketio.Client()
# Debug output for connection to server
@sio.event
def connect():
print('SocketIO connected')
# Debug output for disconnection from server
@sio.event
def disconnect():
print('SocketIO disconnected')
# connecting to IDS server
sio.connect('http://localhost:5000/hi')
# handling proxied request
def request(flow: mitmproxy.http.HTTPFlow):
data = {
'method': flow.request.method,
'url': flow.request.pretty_url,
'headers': dict(flow.request.headers),
'content': flow.request.content.decode(),
}
sio.emit('request', data, namespace="/") # sending request to IDS
# Telling MITMProxy API to disconnect from socketio server upon exit
def done():
sio.disconnect()