diff options
Diffstat (limited to 'examples')
-rw-r--r-- | examples/change_upstream_proxy.py | 2 | ||||
-rw-r--r-- | examples/custom_contentviews.py | 8 | ||||
-rw-r--r-- | examples/dns_spoofing.py | 3 | ||||
-rwxr-xr-x[-rw-r--r--] | examples/flowbasic | 19 | ||||
-rw-r--r-- | examples/har_extractor.py | 7 | ||||
-rw-r--r-- | examples/mitmproxywrapper.py | 7 | ||||
-rw-r--r-- | examples/pathod/test_setup.py | 1 | ||||
-rw-r--r-- | examples/pathod/test_setupall.py | 2 | ||||
-rw-r--r-- | examples/redirect_requests.py | 1 | ||||
-rw-r--r-- | examples/sslstrip.py | 22 | ||||
-rwxr-xr-x[-rw-r--r--] | examples/stickycookies | 8 | ||||
-rw-r--r-- | examples/tcp_message.py | 5 | ||||
-rw-r--r-- | examples/tls_passthrough.py | 2 |
13 files changed, 45 insertions, 42 deletions
diff --git a/examples/change_upstream_proxy.py b/examples/change_upstream_proxy.py index 9c454897..34a6eece 100644 --- a/examples/change_upstream_proxy.py +++ b/examples/change_upstream_proxy.py @@ -21,4 +21,4 @@ def request(context, flow): return address = proxy_address(flow) if flow.live: - flow.live.change_upstream_proxy_server(address)
\ No newline at end of file + flow.live.change_upstream_proxy_server(address) diff --git a/examples/custom_contentviews.py b/examples/custom_contentviews.py index f3b7317f..034f356c 100644 --- a/examples/custom_contentviews.py +++ b/examples/custom_contentviews.py @@ -1,7 +1,8 @@ import string import lxml.html import lxml.etree -from mitmproxy import utils, contentviews +from mitmproxy import contentviews +from netlib import strutils class ViewPigLatin(contentviews.View): @@ -10,7 +11,7 @@ class ViewPigLatin(contentviews.View): content_types = ["text/html"] def __call__(self, data, **metadata): - if utils.isXML(data): + if strutils.isXML(data): parser = lxml.etree.HTMLParser( strip_cdata=True, remove_blank_text=True @@ -23,7 +24,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" diff --git a/examples/dns_spoofing.py b/examples/dns_spoofing.py index 7eb79695..8d715f33 100644 --- a/examples/dns_spoofing.py +++ b/examples/dns_spoofing.py @@ -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
\ No newline at end of file + flow.request.port = port diff --git a/examples/flowbasic b/examples/flowbasic index 4a87b86a..74af4e08 100644..100755 --- a/examples/flowbasic +++ b/examples/flowbasic @@ -8,7 +8,7 @@ Note that request and response messages are not automatically replied to, so we need to implement handlers to do this. """ -from mitmproxy import flow +from mitmproxy import flow, controller from mitmproxy.proxy import ProxyServer, ProxyConfig @@ -19,18 +19,15 @@ class MyMaster(flow.FlowMaster): except KeyboardInterrupt: self.shutdown() - def handle_request(self, f): - f = flow.FlowMaster.handle_request(self, f) - if f: - f.reply() - return f + @controller.handler + def request(self, f): + f = flow.FlowMaster.request(self, f) + print(f) - def handle_response(self, f): - f = flow.FlowMaster.handle_response(self, f) - if f: - f.reply() + @controller.handler + def response(self, f): + f = flow.FlowMaster.response(self, f) print(f) - return f config = ProxyConfig( diff --git a/examples/har_extractor.py b/examples/har_extractor.py index 371e2282..6806989d 100644 --- a/examples/har_extractor.py +++ b/examples/har_extractor.py @@ -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({ diff --git a/examples/mitmproxywrapper.py b/examples/mitmproxywrapper.py index 7ea10715..6841d05f 100644 --- a/examples/mitmproxywrapper.py +++ b/examples/mitmproxywrapper.py @@ -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() diff --git a/examples/pathod/test_setup.py b/examples/pathod/test_setup.py index 5dbc456d..32fcb214 100644 --- a/examples/pathod/test_setup.py +++ b/examples/pathod/test_setup.py @@ -3,7 +3,6 @@ from pathod import test class Test: - """ Testing the requests module with a pathod instance started for diff --git a/examples/pathod/test_setupall.py b/examples/pathod/test_setupall.py index cb84b7b2..cc0ec2e4 100644 --- a/examples/pathod/test_setupall.py +++ b/examples/pathod/test_setupall.py @@ -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() diff --git a/examples/redirect_requests.py b/examples/redirect_requests.py index c0a0ccba..3ff8f9e4 100644 --- a/examples/redirect_requests.py +++ b/examples/redirect_requests.py @@ -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 diff --git a/examples/sslstrip.py b/examples/sslstrip.py index 369427a2..1bc89946 100644 --- a/examples/sslstrip.py +++ b/examples/sslstrip.py @@ -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) diff --git a/examples/stickycookies b/examples/stickycookies index 8f11de8d..43e5371d 100644..100755 --- a/examples/stickycookies +++ b/examples/stickycookies @@ -21,19 +21,19 @@ class StickyMaster(controller.Master): except KeyboardInterrupt: self.shutdown() - def handle_request(self, flow): + @controller.handler + def request(self, flow): hid = (flow.request.host, flow.request.port) if "cookie" in flow.request.headers: self.stickyhosts[hid] = flow.request.headers.get_all("cookie") elif hid in self.stickyhosts: flow.request.headers.set_all("cookie", self.stickyhosts[hid]) - flow.reply() - def handle_response(self, flow): + @controller.handler + def response(self, flow): hid = (flow.request.host, flow.request.port) if "set-cookie" in flow.response.headers: self.stickyhosts[hid] = flow.response.headers.get_all("set-cookie") - flow.reply() config = proxy.ProxyConfig(port=8080) diff --git a/examples/tcp_message.py b/examples/tcp_message.py index c63368e4..2c210618 100644 --- a/examples/tcp_message.py +++ b/examples/tcp_message.py @@ -8,7 +8,8 @@ tcp_message Inline Script Hook API Demonstration example cmdline invocation: mitmdump -T --host --tcp ".*" -q -s examples/tcp_message.py ''' -from netlib.utils import clean_bin +from netlib import strutils + def tcp_message(ctx, tcp_msg): modified_msg = tcp_msg.message.replace("foo", "bar") @@ -21,4 +22,4 @@ def tcp_message(ctx, tcp_msg): "client" if tcp_msg.sender == tcp_msg.client_conn else "server", tcp_msg.sender.address, "server" if tcp_msg.receiver == tcp_msg.server_conn else "client", - tcp_msg.receiver.address, clean_bin(tcp_msg.message))) + tcp_msg.receiver.address, strutils.clean_bin(tcp_msg.message))) diff --git a/examples/tls_passthrough.py b/examples/tls_passthrough.py index 8c8fa4eb..23afe3ff 100644 --- a/examples/tls_passthrough.py +++ b/examples/tls_passthrough.py @@ -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__() |