mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2025-02-01 15:55:28 +00:00
Merge branch 'master' of ssh.github.com:mitmproxy/mitmproxy
This commit is contained in:
commit
b1d2da19f9
@ -3,6 +3,7 @@ add_header.py Simple script that just adds a header to every request
|
||||
change_upstream_proxy.py Dynamically change the upstream proxy
|
||||
dns_spoofing.py Use mitmproxy in a DNS spoofing scenario.
|
||||
dup_and_replay.py Duplicates each request, changes it, and then replays the modified request.
|
||||
filt.py Use mitmproxy's filter expressions in your script.
|
||||
iframe_injector.py Inject configurable iframe into pages.
|
||||
modify_form.py Modify all form submissions to add a parameter.
|
||||
modify_querystring.py Modify all query strings to add a parameters.
|
||||
|
15
examples/filt.py
Normal file
15
examples/filt.py
Normal file
@ -0,0 +1,15 @@
|
||||
# This scripts demonstrates how to use mitmproxy's filter pattern in inline scripts.
|
||||
# Usage: mitmdump -s "filt.py FILTER"
|
||||
|
||||
from libmproxy import filt
|
||||
|
||||
def start(context, argv):
|
||||
print argv
|
||||
if len(argv) != 2:
|
||||
raise ValueError("Usage: -s 'filt.py FILTER'")
|
||||
context.filter = filt.parse(argv[1])
|
||||
|
||||
def response(context, flow):
|
||||
if flow.match(context.filter):
|
||||
print("Flow matches filter:")
|
||||
print(flow)
|
@ -26,7 +26,8 @@ def done(context):
|
||||
|
||||
@concurrent
|
||||
def response(context, flow):
|
||||
if flow.response.headers.get_first("Connection", None) == "Upgrade":
|
||||
value = flow.response.headers.get_first("Connection", None)
|
||||
if value and value.upper() == "UPGRADE":
|
||||
# We need to send the response manually now...
|
||||
flow.client_conn.send(flow.response.assemble())
|
||||
# ...and then delegate to tcp passthrough.
|
||||
|
@ -232,7 +232,7 @@ class ServerPlaybackState:
|
||||
r = flow.request
|
||||
|
||||
_, _, path, _, query, _ = urlparse.urlparse(r.url)
|
||||
queriesArray = urlparse.parse_qsl(query)
|
||||
queriesArray = urlparse.parse_qsl(query, keep_blank_values=True)
|
||||
|
||||
key = [
|
||||
str(r.port),
|
||||
|
@ -75,14 +75,14 @@ def get_server(dummy_server, options):
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
def mitmproxy(): # pragma: nocover
|
||||
def mitmproxy(args=None): # pragma: nocover
|
||||
from . import console
|
||||
|
||||
check_versions()
|
||||
assert_utf8_env()
|
||||
|
||||
parser = cmdline.mitmproxy()
|
||||
options = parser.parse_args()
|
||||
options = parser.parse_args(args)
|
||||
if options.quiet:
|
||||
options.verbose = 0
|
||||
|
||||
@ -102,13 +102,13 @@ def mitmproxy(): # pragma: nocover
|
||||
pass
|
||||
|
||||
|
||||
def mitmdump(): # pragma: nocover
|
||||
def mitmdump(args=None): # pragma: nocover
|
||||
from . import dump
|
||||
|
||||
check_versions()
|
||||
|
||||
parser = cmdline.mitmdump()
|
||||
options = parser.parse_args()
|
||||
options = parser.parse_args(args)
|
||||
if options.quiet:
|
||||
options.verbose = 0
|
||||
options.flow_detail = 0
|
||||
@ -136,13 +136,13 @@ def mitmdump(): # pragma: nocover
|
||||
pass
|
||||
|
||||
|
||||
def mitmweb(): # pragma: nocover
|
||||
def mitmweb(args=None): # pragma: nocover
|
||||
from . import web
|
||||
|
||||
check_versions()
|
||||
parser = cmdline.mitmweb()
|
||||
|
||||
options = parser.parse_args()
|
||||
options = parser.parse_args(args)
|
||||
if options.quiet:
|
||||
options.verbose = 0
|
||||
|
||||
|
@ -420,7 +420,7 @@ var FlowActions = {
|
||||
});
|
||||
},
|
||||
clear: function(){
|
||||
$.post("/flows/" + flow.id);
|
||||
$.post("/clear");
|
||||
}
|
||||
};
|
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -15,6 +15,8 @@ def test_load_scripts():
|
||||
f += " -"
|
||||
if "iframe_injector" in f:
|
||||
f += " foo" # one argument required
|
||||
if "filt" in f:
|
||||
f += " ~a"
|
||||
if "modify_response_body" in f:
|
||||
f += " foo bar" # two arguments required
|
||||
try:
|
||||
|
@ -125,6 +125,10 @@ class TestServerPlaybackState:
|
||||
r.request.path = "voing"
|
||||
assert s._hash(r) != s._hash(r2)
|
||||
|
||||
r.request.path = "path?blank_value"
|
||||
r2.request.path = "path?"
|
||||
assert s._hash(r) != s._hash(r2)
|
||||
|
||||
def test_headers(self):
|
||||
s = flow.ServerPlaybackState(["foo"], [], False, False, None, False, None, False)
|
||||
r = tutils.tflow(resp=True)
|
||||
@ -197,12 +201,12 @@ class TestServerPlaybackState:
|
||||
r2 = tutils.tflow(resp=True)
|
||||
r2.request.headers["Content-Type"] = ["application/x-www-form-urlencoded"]
|
||||
r2.request.content = "paramx=x¶m1=1"
|
||||
# same parameters
|
||||
# same parameters
|
||||
assert s._hash(r) == s._hash(r2)
|
||||
# ignored parameters !=
|
||||
# ignored parameters !=
|
||||
r2.request.content = "paramx=x¶m1=2"
|
||||
assert s._hash(r) == s._hash(r2)
|
||||
# missing parameter
|
||||
# missing parameter
|
||||
r2.request.content="paramx=x"
|
||||
assert s._hash(r) == s._hash(r2)
|
||||
# ignorable parameter added
|
||||
@ -223,7 +227,7 @@ class TestServerPlaybackState:
|
||||
r2 = tutils.tflow(resp=True)
|
||||
r2.request.headers["Content-Type"] = ["application/json"]
|
||||
r2.request.content = '{"param1":"1"}'
|
||||
# same content
|
||||
# same content
|
||||
assert s._hash(r) == s._hash(r2)
|
||||
# distint content (note only x-www-form-urlencoded payload is analysed)
|
||||
r2.request.content = '{"param1":"2"}'
|
||||
@ -238,7 +242,7 @@ class TestServerPlaybackState:
|
||||
r2 = tutils.tflow(resp=True)
|
||||
r2.request.headers["Content-Type"] = ["application/x-www-form-urlencoded"]
|
||||
r2.request.content = "paramx=x"
|
||||
# same parameters
|
||||
# same parameters
|
||||
assert s._hash(r) == s._hash(r2)
|
||||
|
||||
def test_ignore_content(self):
|
||||
|
@ -116,7 +116,7 @@ var FlowActions = {
|
||||
});
|
||||
},
|
||||
clear: function(){
|
||||
$.post("/flows/" + flow.id);
|
||||
$.post("/clear");
|
||||
}
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user