-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhttpmim.py
41 lines (40 loc) · 895 Bytes
/
httpmim.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
'''
HTTP man in middle. Prints all traffic. Useful for investigating how http works. Although Chrome Dev Tools prolly have something like this already.
'''
target="www.banana.com"
import socket
S = socket.socket()
S.bind(("127.0.0.1", 80))
S.listen(1)
(c, address) = S.accept()
c.settimeout(.5)
s = socket.socket()
s.settimeout(5)
s.connect((target, 80))
print("Both parties ready. ")
print("It's started. ")
fake = 'GET / HTTP/1.1\r\nHost: ' + target + '\r\n'
print(fake)
fake=fake.encode()
chunk = b''
try:
while not (len(chunk)>=5 and chunk[-1]=='\n' and chunk[-3]=='\n'):
chunk+=c.recv(4096)
except:
print(chunk)
chunk = chunk[chunk.index(b'\n'):]
chunk = chunk[chunk.index(b'\n'):]
print(chunk.decode())
s.send(fake)
s.send(chunk)
r=b' '
chunk=b''
while r!=b'':
r=s.recv(4096)
chunk+=r
print()
print(chunk.decode())
c.send(chunk)
s.close()
c.close()
input('end')