Comments (7)
Hi there. All of these features would be most welcome (and, in fact, are on my long todo list). Lets take these point by point.
- The fundamental mechanics of adding multiple scripts is pretty simple. Look at the "script" attribute of flow.FlowMaster. This should be a list. Wherever the attribute is used, extend in the obvious way to iterate through the list, and act on the scripts one by one.
- Support this by making it possible to pass the -s argument multiple times.
- Now for a difficult one - the user interface in mitmproxy itself. We will have to show the user a list of scripts that they can toggle/remove one by one. I have a nice, generalised control that can do this - the GridEditor that we use in a bunch of places. If you do the previous two items, I'll take care of this aspect of things (unless you want to have a crack).
- Arguments to scripts. This is actually a tricky design problem. There's no really nice way to pass "sub-arguments" on the command-line, especially when you can have multiple scripts each with its own arguments. There are some obvious (but inelegant) ways to do this. Any suggestions would be welcome.
from mitmproxy.
I'd like to tackle the sub-arguments thing. IMO the best way is to submit them within the -script argument in double quotes:
python mitmproxy -T -s "a.py -sub-arg 1 -sub-argx 2" -s "b.py -sub-arg "space string""
The syntax is pretty clean and you don't get any scope problems. Every script just needs to expose an argparse.ArgumentParser if it takes arguments.
This small snippet should illustrate it:
https://gist.github.com/4273413
from mitmproxy.
I as thinking something in the line of:
mitmproxy -s scriptname.py param1,param2,param3 -s scriptname2.py param1,param2,param3 -s scriptname3.py
And then using the callback function of optparse to consume arguments if present, making something like this:
userscripts = [["scriptname,py", "param1,param2,param3"], ["scriptname2.py", "param1,param2,param3"], ["scriptname3.py", ""]]
Haven't given much thought to how this would avoid screwing with the [filters] of mitmdump, had a quick look at the code and these seem to be uncollected arguments?
from mitmproxy.
Thanks for your input on this.
Using "," for splitting parameters on the command line seems to be an uncommon solution for me though. You can certainly use -script a.py param1 param2 -script b.py param1
but you limitation with this approach is that your parameters must not start with a -
. (Assuming that you don't want to hack in the argparse (not optparse!) core). Another thing is that this screws the filters of mitmdump: -script a.py i-am-a-filter-or-an-argument
. You could fix this by making the filter a regular argument. However, changing the existing syntax should be planned carefully.
If you put the whole script parameter with arguments into quotes, the handling gets easier I think.
.add_argument('-script', type=shlex.split, action='append')
results with a call of mitmdump -script "a.py -foo -bar" -script b.py
in
userscripts = [["a.py","-foo","-bar"],["b.py"]]
While I am not a big fan of the surrounding quotes myself, the syntax gets non-ambiguous and not too verbose. What do you think?
from mitmproxy.
Think you're right, breaking with the old syntax is bound to break something somewhere and doing it your way allows using value names already in use by mitmproxy, -s for example. Good spot.
from mitmproxy.
Max, I think your solution is probably the way to go. I like using argparse for this, and that would also mean that we could extract argument and type specifications programmatically if we ever do want to build a GUI for this (for now, we can just parse the arguments as on the command-line). So, we need to define a standard way for scripts to expose a parser, expand mitmproxy to take multiple -s arguments, and then tackle the GUI issues one by one (and there are quite a few).
from mitmproxy.
Any thoughts on how the scripts should expose a parser?
I'd propose adding script_argv (=["a.py","--foo","42"]
) as a second parameter to the start function (breaks compatibility though). If we do this, we could consider moving the .start() logic into the Script class as well. Is there a special reason for the current separation?
On a side note, nosetests crashes for me (SSLCert.from_der(...) => asn1 encoding routines - ASN1_get_object - too long)...
Cheers,
Max
from mitmproxy.
Related Issues (20)
- Local mode: Capture redirector process output if it crashes
- CONTENT MISSING and PROTOCOL_ERROR HOT 7
- HTTP/2 protocol error: Header block missing mandatory :path header HOT 3
- Support gRPC Insecure (http2 over tcp)
- Render HTTP/2 pseudo headers
- Some APKs get stuck while using android-unpinner HOT 1
- Unable to verify response if event-stream HOT 8
- Unable to download mitmproxy CA certificate from http://mitm.it HOT 1
- Transparent proxy mode not working. HOT 1
- CONNECT request does not include Host header HOT 6
- The windows network share cannot be accessed in local mode HOT 3
- QUIC / HTTP/3 support status HOT 3
- AssertionError in _http1 after multiple calls HOT 14
- Cannot modify headers on requests with bodies (POST etc) when stream_large_bodies is enabled HOT 1
- `mitmproxy` handles UDP connections on both `IPv4/v6` if client tries to connect through both interfaces HOT 11
- Is support x86 systems? HOT 2
- Crash for Non-HTTP/3 QUIC Protocols HOT 1
- unknown or unsupported macOS version: :dunno HOT 1
- Runtime panic when using local mode on macos HOT 5
- Concurrent decorator not supported for 'request' method. HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mitmproxy.