format examples

This commit is contained in:
Maximilian Hils 2016-05-29 01:23:39 -07:00
parent 8638000cfa
commit 17382b963e
11 changed files with 28 additions and 23 deletions

View File

@ -21,4 +21,4 @@ def request(context, flow):
return
address = proxy_address(flow)
if flow.live:
flow.live.change_upstream_proxy_server(address)
flow.live.change_upstream_proxy_server(address)

View File

@ -23,7 +23,8 @@ class ViewPigLatin(contentviews.View):
ret = ''
for word in words:
idx = -1
while word[idx] in string.punctuation and (idx * -1) != len(word): idx -= 1
while word[idx] in string.punctuation and (idx * -1) != len(word):
idx -= 1
if word[0].lower() in 'aeiou':
if idx == -1:
ret += word[0:] + "hay"

View File

@ -22,7 +22,6 @@ Usage:
"""
import re
# This regex extracts splits the host header into host and port.
# Handles the edge case of IPv6 addresses containing colons.
# https://bugzilla.mozilla.org/show_bug.cgi?id=45891
@ -47,4 +46,4 @@ def request(context, flow):
port = int(m.group("port"))
flow.request.host = sni or host_header
flow.request.port = port
flow.request.port = port

View File

@ -162,8 +162,11 @@ def response(context, flow):
# If the current url is in the page list of context.HARLog or
# does not have a referrer, we add it as a new pages object.
if (flow.request.url in context.HARLog.get_page_list() or
flow.request.headers.get('Referer') is None):
is_new_page = (
flow.request.url in context.HARLog.get_page_list() or
flow.request.headers.get('Referer') is None
)
if is_new_page:
page_id = context.HARLog.create_page_id()
context.HARLog.add(
HAR.pages({

View File

@ -16,7 +16,6 @@ import sys
class Wrapper(object):
def __init__(self, port, extra_arguments=None):
self.port = port
self.extra_arguments = extra_arguments
@ -142,7 +141,7 @@ class Wrapper(object):
'--toggle',
action='store_true',
help='just toggle the proxy configuration')
# parser.add_argument('--honeyproxy', action='store_true', help='run honeyproxy instead of mitmproxy')
# parser.add_argument('--honeyproxy', action='store_true', help='run honeyproxy instead of mitmproxy')
parser.add_argument(
'-p',
'--port',
@ -155,8 +154,8 @@ class Wrapper(object):
if args.toggle:
wrapper.toggle_proxy()
# elif args.honeyproxy:
# wrapper.wrap_honeyproxy()
# elif args.honeyproxy:
# wrapper.wrap_honeyproxy()
else:
wrapper.wrap_mitmproxy()

View File

@ -3,7 +3,6 @@ from pathod import test
class Test:
"""
Testing the requests module with
a pathod instance started for

View File

@ -3,12 +3,12 @@ from pathod import test
class Test:
"""
Testing the requests module with
a single pathod instance started
for the test suite.
"""
@classmethod
def setup_class(cls):
cls.d = test.Daemon()

View File

@ -4,6 +4,7 @@ This example shows two ways to redirect flows to other destinations.
from mitmproxy.models import HTTPResponse
from netlib.http import Headers
def request(context, flow):
# pretty_host takes the "Host" header of the request into account,
# which is useful in transparent mode where we usually only have the IP

View File

@ -2,39 +2,39 @@ from netlib.http import decoded
import re
from six.moves import urllib
def start(context, argv) :
#set of SSL/TLS capable hosts
def start(context, argv):
# set of SSL/TLS capable hosts
context.secure_hosts = set()
def request(context, flow) :
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 :
# 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) :
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
# 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://'):
# 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
# 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)

View File

@ -10,6 +10,7 @@ mitmdump -T --host --tcp ".*" -q -s examples/tcp_message.py
'''
from netlib.utils import clean_bin
def tcp_message(ctx, tcp_msg):
modified_msg = tcp_msg.message.replace("foo", "bar")

View File

@ -40,6 +40,7 @@ class _TlsStrategy(object):
"""
Abstract base class for interception strategies.
"""
def __init__(self):
# A server_address -> interception results mapping
self.history = collections.defaultdict(lambda: collections.deque(maxlen=200))
@ -78,6 +79,7 @@ class ProbabilisticStrategy(_TlsStrategy):
"""
Fixed probability that we intercept a given connection.
"""
def __init__(self, p):
self.p = p
super(ProbabilisticStrategy, self).__init__()