2014-03-10 21:36:47 +00:00
|
|
|
from __future__ import absolute_import
|
2014-11-15 04:25:05 +00:00
|
|
|
import os
|
2014-03-10 21:36:47 +00:00
|
|
|
import re
|
2015-09-10 22:00:00 +00:00
|
|
|
|
2014-11-15 03:29:38 +00:00
|
|
|
import configargparse
|
2015-08-01 08:40:19 +00:00
|
|
|
|
2015-09-10 22:00:00 +00:00
|
|
|
from netlib.tcp import Address, sslversion_choices
|
2015-08-01 08:40:19 +00:00
|
|
|
import netlib.utils
|
2014-11-15 03:29:38 +00:00
|
|
|
from . import filt, utils, version
|
2014-04-12 05:57:19 +00:00
|
|
|
from .proxy import config
|
2012-03-17 04:20:34 +00:00
|
|
|
|
2014-01-27 01:37:29 +00:00
|
|
|
APP_HOST = "mitm.it"
|
2013-08-18 18:03:53 +00:00
|
|
|
APP_PORT = 80
|
2013-07-23 22:32:56 +00:00
|
|
|
|
2014-03-10 04:11:51 +00:00
|
|
|
|
|
|
|
class ParseException(Exception):
|
|
|
|
pass
|
|
|
|
|
2012-03-17 04:20:34 +00:00
|
|
|
|
2012-08-18 12:14:16 +00:00
|
|
|
def _parse_hook(s):
|
|
|
|
sep, rem = s[0], s[1:]
|
|
|
|
parts = rem.split(sep, 2)
|
|
|
|
if len(parts) == 2:
|
|
|
|
patt = ".*"
|
|
|
|
a, b = parts
|
|
|
|
elif len(parts) == 3:
|
|
|
|
patt, a, b = parts
|
|
|
|
else:
|
2014-11-15 03:14:08 +00:00
|
|
|
raise ParseException(
|
|
|
|
"Malformed hook specifier - too few clauses: %s" % s
|
|
|
|
)
|
2012-08-18 12:14:16 +00:00
|
|
|
|
|
|
|
if not a:
|
2014-07-21 19:06:55 +00:00
|
|
|
raise ParseException("Empty clause: %s" % str(patt))
|
2012-08-18 12:14:16 +00:00
|
|
|
|
|
|
|
if not filt.parse(patt):
|
2014-07-21 19:06:55 +00:00
|
|
|
raise ParseException("Malformed filter pattern: %s" % patt)
|
2012-08-18 12:14:16 +00:00
|
|
|
|
|
|
|
return patt, a, b
|
|
|
|
|
2012-03-17 04:20:34 +00:00
|
|
|
|
|
|
|
def parse_replace_hook(s):
|
|
|
|
"""
|
|
|
|
Returns a (pattern, regex, replacement) tuple.
|
|
|
|
|
|
|
|
The general form for a replacement hook is as follows:
|
|
|
|
|
|
|
|
/patt/regex/replacement
|
|
|
|
|
|
|
|
The first character specifies the separator. Example:
|
|
|
|
|
|
|
|
:~q:foo:bar
|
|
|
|
|
|
|
|
If only two clauses are specified, the pattern is set to match
|
|
|
|
universally (i.e. ".*"). Example:
|
|
|
|
|
|
|
|
/foo/bar/
|
|
|
|
|
|
|
|
Clauses are parsed from left to right. Extra separators are taken to be
|
|
|
|
part of the final clause. For instance, the replacement clause below is
|
|
|
|
"foo/bar/":
|
|
|
|
|
|
|
|
/one/two/foo/bar/
|
|
|
|
|
|
|
|
Checks that pattern and regex are both well-formed. Raises
|
2012-08-18 12:14:16 +00:00
|
|
|
ParseException on error.
|
2012-03-17 04:20:34 +00:00
|
|
|
"""
|
2012-08-18 12:14:16 +00:00
|
|
|
patt, regex, replacement = _parse_hook(s)
|
2012-03-17 04:20:34 +00:00
|
|
|
try:
|
|
|
|
re.compile(regex)
|
2015-05-30 00:03:28 +00:00
|
|
|
except re.error as e:
|
2014-07-21 19:06:55 +00:00
|
|
|
raise ParseException("Malformed replacement regex: %s" % str(e.message))
|
2012-08-18 12:14:16 +00:00
|
|
|
return patt, regex, replacement
|
2012-03-17 04:20:34 +00:00
|
|
|
|
|
|
|
|
2012-08-18 12:14:16 +00:00
|
|
|
def parse_setheader(s):
|
|
|
|
"""
|
|
|
|
Returns a (pattern, header, value) tuple.
|
|
|
|
|
|
|
|
The general form for a replacement hook is as follows:
|
|
|
|
|
|
|
|
/patt/header/value
|
|
|
|
|
|
|
|
The first character specifies the separator. Example:
|
|
|
|
|
|
|
|
:~q:foo:bar
|
|
|
|
|
|
|
|
If only two clauses are specified, the pattern is set to match
|
|
|
|
universally (i.e. ".*"). Example:
|
|
|
|
|
|
|
|
/foo/bar/
|
|
|
|
|
|
|
|
Clauses are parsed from left to right. Extra separators are taken to be
|
|
|
|
part of the final clause. For instance, the value clause below is
|
|
|
|
"foo/bar/":
|
|
|
|
|
|
|
|
/one/two/foo/bar/
|
|
|
|
|
|
|
|
Checks that pattern and regex are both well-formed. Raises
|
|
|
|
ParseException on error.
|
|
|
|
"""
|
|
|
|
return _parse_hook(s)
|
2011-03-12 01:30:12 +00:00
|
|
|
|
|
|
|
|
2015-08-30 00:27:38 +00:00
|
|
|
def parse_server_spec(url):
|
2015-09-16 16:45:22 +00:00
|
|
|
try:
|
|
|
|
p = netlib.utils.parse_url(url)
|
|
|
|
if p[0] not in ("http", "https"):
|
|
|
|
raise ValueError()
|
|
|
|
except ValueError:
|
2014-11-15 04:51:21 +00:00
|
|
|
raise configargparse.ArgumentTypeError(
|
2014-11-15 03:29:38 +00:00
|
|
|
"Invalid server specification: %s" % url
|
|
|
|
)
|
2015-09-16 16:45:22 +00:00
|
|
|
|
2015-08-27 23:51:13 +00:00
|
|
|
address = Address(p[1:3])
|
|
|
|
scheme = p[0].lower()
|
|
|
|
return config.ServerSpec(scheme, address)
|
2014-03-10 04:11:51 +00:00
|
|
|
|
|
|
|
|
2011-03-12 01:30:12 +00:00
|
|
|
def get_common_options(options):
|
2011-03-20 04:31:54 +00:00
|
|
|
stickycookie, stickyauth = None, None
|
2012-06-26 07:56:47 +00:00
|
|
|
if options.stickycookie_filt:
|
2011-03-12 02:14:25 +00:00
|
|
|
stickycookie = options.stickycookie_filt
|
2011-03-20 04:31:54 +00:00
|
|
|
|
2012-06-26 07:56:47 +00:00
|
|
|
if options.stickyauth_filt:
|
2011-03-20 04:31:54 +00:00
|
|
|
stickyauth = options.stickyauth_filt
|
|
|
|
|
2014-07-21 19:06:55 +00:00
|
|
|
stream_large_bodies = utils.parse_size(options.stream_large_bodies)
|
|
|
|
|
2012-03-17 04:20:34 +00:00
|
|
|
reps = []
|
|
|
|
for i in options.replace:
|
|
|
|
try:
|
|
|
|
p = parse_replace_hook(i)
|
2015-05-30 00:03:28 +00:00
|
|
|
except ParseException as e:
|
2014-11-15 04:51:21 +00:00
|
|
|
raise configargparse.ArgumentTypeError(e.message)
|
2012-03-17 04:20:34 +00:00
|
|
|
reps.append(p)
|
|
|
|
for i in options.replace_file:
|
|
|
|
try:
|
|
|
|
patt, rex, path = parse_replace_hook(i)
|
2015-05-30 00:03:28 +00:00
|
|
|
except ParseException as e:
|
2014-11-15 04:51:21 +00:00
|
|
|
raise configargparse.ArgumentTypeError(e.message)
|
2012-03-17 04:20:34 +00:00
|
|
|
try:
|
2013-06-15 22:23:44 +00:00
|
|
|
v = open(path, "rb").read()
|
2015-05-30 00:03:28 +00:00
|
|
|
except IOError as e:
|
2014-11-15 04:51:21 +00:00
|
|
|
raise configargparse.ArgumentTypeError(
|
2014-11-15 03:29:38 +00:00
|
|
|
"Could not read replace file: %s" % path
|
|
|
|
)
|
2012-03-17 04:20:34 +00:00
|
|
|
reps.append((patt, rex, v))
|
|
|
|
|
2012-08-18 12:14:16 +00:00
|
|
|
setheaders = []
|
|
|
|
for i in options.setheader:
|
|
|
|
try:
|
|
|
|
p = parse_setheader(i)
|
2015-05-30 00:03:28 +00:00
|
|
|
except ParseException as e:
|
2014-11-15 04:51:21 +00:00
|
|
|
raise configargparse.ArgumentTypeError(e.message)
|
2012-08-18 12:14:16 +00:00
|
|
|
setheaders.append(p)
|
|
|
|
|
2011-03-12 01:30:12 +00:00
|
|
|
return dict(
|
2014-07-21 19:06:55 +00:00
|
|
|
app=options.app,
|
|
|
|
app_host=options.app_host,
|
|
|
|
app_port=options.app_port,
|
|
|
|
|
|
|
|
anticache=options.anticache,
|
|
|
|
anticomp=options.anticomp,
|
|
|
|
client_replay=options.client_replay,
|
|
|
|
kill=options.kill,
|
|
|
|
no_server=options.no_server,
|
|
|
|
refresh_server_playback=not options.norefresh,
|
|
|
|
rheaders=options.rheaders,
|
|
|
|
rfile=options.rfile,
|
|
|
|
replacements=reps,
|
|
|
|
setheaders=setheaders,
|
|
|
|
server_replay=options.server_replay,
|
|
|
|
scripts=options.scripts,
|
|
|
|
stickycookie=stickycookie,
|
|
|
|
stickyauth=stickyauth,
|
|
|
|
stream_large_bodies=stream_large_bodies,
|
|
|
|
showhost=options.showhost,
|
2014-12-11 18:21:33 +00:00
|
|
|
outfile=options.outfile,
|
2014-07-21 19:06:55 +00:00
|
|
|
verbosity=options.verbose,
|
|
|
|
nopop=options.nopop,
|
2015-08-27 23:51:13 +00:00
|
|
|
replay_ignore_content=options.replay_ignore_content,
|
|
|
|
replay_ignore_params=options.replay_ignore_params,
|
|
|
|
replay_ignore_payload_params=options.replay_ignore_payload_params,
|
|
|
|
replay_ignore_host=options.replay_ignore_host
|
2011-03-12 01:30:12 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
|
2015-08-27 23:51:13 +00:00
|
|
|
def basic_options(parser):
|
2014-11-15 04:58:38 +00:00
|
|
|
parser.add_argument(
|
|
|
|
'--version',
|
2015-08-27 23:51:13 +00:00
|
|
|
action='version',
|
|
|
|
version="%(prog)s" + " " + version.VERSION
|
2014-11-15 04:58:38 +00:00
|
|
|
)
|
2014-12-28 02:07:44 +00:00
|
|
|
parser.add_argument(
|
|
|
|
'--shortversion',
|
2015-08-27 23:51:13 +00:00
|
|
|
action='version',
|
|
|
|
help="show program's short version number and exit",
|
|
|
|
version=version.VERSION
|
2014-12-28 02:07:44 +00:00
|
|
|
)
|
2012-08-17 17:04:39 +00:00
|
|
|
parser.add_argument(
|
2011-08-03 01:20:36 +00:00
|
|
|
"--anticache",
|
|
|
|
action="store_true", dest="anticache", default=False,
|
2014-11-15 03:14:08 +00:00
|
|
|
|
|
|
|
help="""
|
|
|
|
Strip out request headers that might cause the server to return
|
|
|
|
304-not-modified.
|
|
|
|
"""
|
2011-08-03 01:20:36 +00:00
|
|
|
)
|
2012-08-17 17:04:39 +00:00
|
|
|
parser.add_argument(
|
2014-11-15 03:14:08 +00:00
|
|
|
"--cadir",
|
|
|
|
action="store", type=str, dest="cadir", default=config.CA_DIR,
|
2015-05-30 00:03:28 +00:00
|
|
|
help="Location of the default mitmproxy CA files. (%s)" % config.CA_DIR
|
2011-08-03 01:20:36 +00:00
|
|
|
)
|
2012-08-17 17:04:39 +00:00
|
|
|
parser.add_argument(
|
2014-03-13 22:43:26 +00:00
|
|
|
"--host",
|
|
|
|
action="store_true", dest="showhost", default=False,
|
|
|
|
help="Use the Host header to construct URLs for display."
|
2014-03-10 04:11:51 +00:00
|
|
|
)
|
2012-08-17 17:04:39 +00:00
|
|
|
parser.add_argument(
|
2014-11-15 04:41:04 +00:00
|
|
|
"-q", "--quiet",
|
2011-03-12 01:30:12 +00:00
|
|
|
action="store_true", dest="quiet",
|
|
|
|
help="Quiet."
|
|
|
|
)
|
2012-08-17 17:04:39 +00:00
|
|
|
parser.add_argument(
|
2014-11-15 04:41:04 +00:00
|
|
|
"-r", "--read-flows",
|
2011-05-14 23:54:12 +00:00
|
|
|
action="store", dest="rfile", default=None,
|
|
|
|
help="Read flows from file."
|
|
|
|
)
|
2012-08-17 17:04:39 +00:00
|
|
|
parser.add_argument(
|
2014-11-15 04:41:04 +00:00
|
|
|
"-s", "--script",
|
2014-01-12 10:01:59 +00:00
|
|
|
action="append", type=str, dest="scripts", default=[],
|
2013-06-13 14:04:04 +00:00
|
|
|
metavar='"script.py --bar"',
|
2014-11-15 03:14:08 +00:00
|
|
|
help="""
|
|
|
|
Run a script. Surround with quotes to pass script arguments. Can be
|
|
|
|
passed multiple times.
|
|
|
|
"""
|
2011-03-12 01:30:12 +00:00
|
|
|
)
|
2012-08-17 17:04:39 +00:00
|
|
|
parser.add_argument(
|
2014-11-15 04:41:04 +00:00
|
|
|
"-t", "--stickycookie",
|
2014-11-15 03:14:08 +00:00
|
|
|
action="store",
|
|
|
|
dest="stickycookie_filt",
|
|
|
|
default=None,
|
|
|
|
metavar="FILTER",
|
2011-03-12 01:30:12 +00:00
|
|
|
help="Set sticky cookie filter. Matched against requests."
|
|
|
|
)
|
2012-08-17 17:04:39 +00:00
|
|
|
parser.add_argument(
|
2014-11-15 04:41:04 +00:00
|
|
|
"-u", "--stickyauth",
|
2011-03-20 04:31:54 +00:00
|
|
|
action="store", dest="stickyauth_filt", default=None, metavar="FILTER",
|
|
|
|
help="Set sticky auth filter. Matched against requests."
|
|
|
|
)
|
2012-08-17 17:04:39 +00:00
|
|
|
parser.add_argument(
|
2014-11-15 04:41:04 +00:00
|
|
|
"-v", "--verbose",
|
2014-03-13 22:25:13 +00:00
|
|
|
action="store_const", dest="verbose", default=1, const=2,
|
|
|
|
help="Increase event log verbosity."
|
2011-03-12 01:30:12 +00:00
|
|
|
)
|
2014-12-11 18:21:33 +00:00
|
|
|
outfile = parser.add_mutually_exclusive_group()
|
|
|
|
outfile.add_argument(
|
2014-11-15 04:41:04 +00:00
|
|
|
"-w", "--wfile",
|
2014-12-11 18:21:33 +00:00
|
|
|
action="store", dest="outfile", type=lambda f: (f, "wb"),
|
2011-03-12 01:30:12 +00:00
|
|
|
help="Write flows to file."
|
|
|
|
)
|
2014-12-11 18:21:33 +00:00
|
|
|
outfile.add_argument(
|
|
|
|
"-a", "--afile",
|
|
|
|
action="store", dest="outfile", type=lambda f: (f, "ab"),
|
|
|
|
help="Append flows to file."
|
|
|
|
)
|
2012-08-17 17:04:39 +00:00
|
|
|
parser.add_argument(
|
2014-11-15 04:41:04 +00:00
|
|
|
"-z", "--anticomp",
|
2011-07-17 02:36:38 +00:00
|
|
|
action="store_true", dest="anticomp", default=False,
|
2011-07-15 03:21:04 +00:00
|
|
|
help="Try to convince servers to send us un-compressed data."
|
|
|
|
)
|
2012-08-17 17:04:39 +00:00
|
|
|
parser.add_argument(
|
2014-11-15 04:41:04 +00:00
|
|
|
"-Z", "--body-size-limit",
|
2011-09-09 05:31:36 +00:00
|
|
|
action="store", dest="body_size_limit", default=None,
|
|
|
|
metavar="SIZE",
|
2014-11-15 03:14:08 +00:00
|
|
|
help="Byte size limit of HTTP request and response bodies."
|
2011-09-09 05:31:36 +00:00
|
|
|
" Understands k/m/g suffixes, i.e. 3m for 3 megabytes."
|
|
|
|
)
|
2014-07-21 19:06:55 +00:00
|
|
|
parser.add_argument(
|
|
|
|
"--stream",
|
|
|
|
action="store", dest="stream_large_bodies", default=None,
|
|
|
|
metavar="SIZE",
|
Fix crash while streaming
Found using fuzzing. Reproduction with pathoc, given "mitmproxy -s" and
pathod running on 9999:
get:'http://localhost:9999/p/':s'200:b\'foo\':h\'Content-Length\'=\'3\'':i58,'\x1a':r
return flow.FlowMaster.run(self)
File "/Users/aldo/mitmproxy/mitmproxy/libmproxy/controller.py", line 111, in run
self.tick(self.masterq, 0.01)
File "/Users/aldo/mitmproxy/mitmproxy/libmproxy/flow.py", line 613, in tick
return controller.Master.tick(self, q, timeout)
File "/Users/aldo/mitmproxy/mitmproxy/libmproxy/controller.py", line 101, in tick
self.handle(*msg)
File "/Users/aldo/mitmproxy/mitmproxy/libmproxy/controller.py", line 118, in handle
m(obj)
File "/Users/aldo/mitmproxy/mitmproxy/libmproxy/flow.py", line 738, in handle_responseheaders
self.stream_large_bodies.run(f, False)
File "/Users/aldo/mitmproxy/mitmproxy/libmproxy/flow.py", line 155, in run
r.headers, is_request, flow.request.method, code
File "/Users/aldo/mitmproxy/mitmproxy/netlib/http.py", line 401, in expected_http_body_size
raise HttpError(400 if is_request else 502, "Invalid content-length header: %s" % headers["content-length"])
netlib.http.HttpError: Invalid content-length header: ['\x1a3']
2014-10-26 04:58:36 +00:00
|
|
|
help="""
|
2014-11-15 03:14:08 +00:00
|
|
|
Stream data to the client if response body exceeds the given
|
|
|
|
threshold. If streamed, the body will not be stored in any way.
|
|
|
|
Understands k/m/g suffixes, i.e. 3m for 3 megabytes.
|
Fix crash while streaming
Found using fuzzing. Reproduction with pathoc, given "mitmproxy -s" and
pathod running on 9999:
get:'http://localhost:9999/p/':s'200:b\'foo\':h\'Content-Length\'=\'3\'':i58,'\x1a':r
return flow.FlowMaster.run(self)
File "/Users/aldo/mitmproxy/mitmproxy/libmproxy/controller.py", line 111, in run
self.tick(self.masterq, 0.01)
File "/Users/aldo/mitmproxy/mitmproxy/libmproxy/flow.py", line 613, in tick
return controller.Master.tick(self, q, timeout)
File "/Users/aldo/mitmproxy/mitmproxy/libmproxy/controller.py", line 101, in tick
self.handle(*msg)
File "/Users/aldo/mitmproxy/mitmproxy/libmproxy/controller.py", line 118, in handle
m(obj)
File "/Users/aldo/mitmproxy/mitmproxy/libmproxy/flow.py", line 738, in handle_responseheaders
self.stream_large_bodies.run(f, False)
File "/Users/aldo/mitmproxy/mitmproxy/libmproxy/flow.py", line 155, in run
r.headers, is_request, flow.request.method, code
File "/Users/aldo/mitmproxy/mitmproxy/netlib/http.py", line 401, in expected_http_body_size
raise HttpError(400 if is_request else 502, "Invalid content-length header: %s" % headers["content-length"])
netlib.http.HttpError: Invalid content-length header: ['\x1a3']
2014-10-26 04:58:36 +00:00
|
|
|
"""
|
2014-07-21 19:06:55 +00:00
|
|
|
)
|
2014-03-13 22:43:26 +00:00
|
|
|
|
2015-08-27 23:51:13 +00:00
|
|
|
|
|
|
|
def proxy_modes(parser):
|
|
|
|
group = parser.add_argument_group("Proxy Modes").add_mutually_exclusive_group()
|
|
|
|
group.add_argument(
|
|
|
|
"-R", "--reverse",
|
|
|
|
action="store",
|
2015-08-30 00:27:38 +00:00
|
|
|
type=parse_server_spec,
|
2015-08-27 23:51:13 +00:00
|
|
|
dest="reverse_proxy",
|
|
|
|
default=None,
|
|
|
|
help="""
|
|
|
|
Forward all requests to upstream HTTP server:
|
|
|
|
http[s][2http[s]]://host[:port]
|
|
|
|
"""
|
|
|
|
)
|
|
|
|
group.add_argument(
|
|
|
|
"--socks",
|
|
|
|
action="store_true", dest="socks_proxy", default=False,
|
|
|
|
help="Set SOCKS5 proxy mode."
|
|
|
|
)
|
|
|
|
group.add_argument(
|
|
|
|
"-T", "--transparent",
|
|
|
|
action="store_true", dest="transparent_proxy", default=False,
|
|
|
|
help="Set transparent proxy mode."
|
|
|
|
)
|
|
|
|
group.add_argument(
|
|
|
|
"-U", "--upstream",
|
|
|
|
action="store",
|
|
|
|
type=parse_server_spec,
|
|
|
|
dest="upstream_proxy",
|
|
|
|
default=None,
|
|
|
|
help="Forward all requests to upstream proxy server: http://host[:port]"
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
def proxy_options(parser):
|
2014-03-13 22:43:26 +00:00
|
|
|
group = parser.add_argument_group("Proxy Options")
|
|
|
|
group.add_argument(
|
2014-11-15 04:41:04 +00:00
|
|
|
"-b", "--bind-address",
|
2014-07-21 19:06:55 +00:00
|
|
|
action="store", type=str, dest="addr", default='',
|
|
|
|
help="Address to bind proxy to (defaults to all interfaces)"
|
2014-03-13 22:43:26 +00:00
|
|
|
)
|
|
|
|
group.add_argument(
|
2014-08-09 01:03:21 +00:00
|
|
|
"-I", "--ignore",
|
2014-10-18 16:29:35 +00:00
|
|
|
action="append", type=str, dest="ignore_hosts", default=[],
|
2014-08-09 01:03:21 +00:00
|
|
|
metavar="HOST",
|
Fix crash while streaming
Found using fuzzing. Reproduction with pathoc, given "mitmproxy -s" and
pathod running on 9999:
get:'http://localhost:9999/p/':s'200:b\'foo\':h\'Content-Length\'=\'3\'':i58,'\x1a':r
return flow.FlowMaster.run(self)
File "/Users/aldo/mitmproxy/mitmproxy/libmproxy/controller.py", line 111, in run
self.tick(self.masterq, 0.01)
File "/Users/aldo/mitmproxy/mitmproxy/libmproxy/flow.py", line 613, in tick
return controller.Master.tick(self, q, timeout)
File "/Users/aldo/mitmproxy/mitmproxy/libmproxy/controller.py", line 101, in tick
self.handle(*msg)
File "/Users/aldo/mitmproxy/mitmproxy/libmproxy/controller.py", line 118, in handle
m(obj)
File "/Users/aldo/mitmproxy/mitmproxy/libmproxy/flow.py", line 738, in handle_responseheaders
self.stream_large_bodies.run(f, False)
File "/Users/aldo/mitmproxy/mitmproxy/libmproxy/flow.py", line 155, in run
r.headers, is_request, flow.request.method, code
File "/Users/aldo/mitmproxy/mitmproxy/netlib/http.py", line 401, in expected_http_body_size
raise HttpError(400 if is_request else 502, "Invalid content-length header: %s" % headers["content-length"])
netlib.http.HttpError: Invalid content-length header: ['\x1a3']
2014-10-26 04:58:36 +00:00
|
|
|
help="""
|
|
|
|
Ignore host and forward all traffic without processing it. In
|
|
|
|
transparent mode, it is recommended to use an IP address (range),
|
|
|
|
not the hostname. In regular mode, only SSL traffic is ignored and
|
|
|
|
the hostname should be used. The supplied value is interpreted as a
|
|
|
|
regular expression and matched on the ip or the hostname. Can be
|
|
|
|
passed multiple times.
|
|
|
|
"""
|
2014-03-13 22:43:26 +00:00
|
|
|
)
|
2014-10-18 16:29:35 +00:00
|
|
|
group.add_argument(
|
|
|
|
"--tcp",
|
|
|
|
action="append", type=str, dest="tcp_hosts", default=[],
|
|
|
|
metavar="HOST",
|
2014-11-15 03:14:08 +00:00
|
|
|
help="""
|
|
|
|
Generic TCP SSL proxy mode for all hosts that match the pattern.
|
|
|
|
Similar to --ignore, but SSL connections are intercepted. The
|
|
|
|
communication contents are printed to the event log in verbose mode.
|
|
|
|
"""
|
2014-10-18 16:29:35 +00:00
|
|
|
)
|
2014-03-13 22:43:26 +00:00
|
|
|
group.add_argument(
|
2014-11-15 04:41:04 +00:00
|
|
|
"-n", "--no-server",
|
2014-03-13 22:43:26 +00:00
|
|
|
action="store_true", dest="no_server",
|
|
|
|
help="Don't start a proxy server."
|
|
|
|
)
|
|
|
|
group.add_argument(
|
2014-11-15 04:25:05 +00:00
|
|
|
"-p", "--port",
|
2014-07-21 19:06:55 +00:00
|
|
|
action="store", type=int, dest="port", default=8080,
|
|
|
|
help="Proxy service port."
|
2014-03-13 22:43:26 +00:00
|
|
|
)
|
2015-09-10 22:00:00 +00:00
|
|
|
http2 = group.add_mutually_exclusive_group()
|
|
|
|
http2.add_argument("--http2", action="store_true", dest="http2")
|
|
|
|
http2.add_argument("--no-http2", action="store_false", dest="http2",
|
|
|
|
help="Explicitly enable/disable experimental HTTP2 support. "
|
|
|
|
"Disabled by default. "
|
|
|
|
"Default value will change in a future version."
|
|
|
|
)
|
|
|
|
rawtcp = group.add_mutually_exclusive_group()
|
|
|
|
rawtcp.add_argument("--raw-tcp", action="store_true", dest="rawtcp")
|
|
|
|
rawtcp.add_argument("--no-raw-tcp", action="store_false", dest="rawtcp",
|
|
|
|
help="Explicitly enable/disable experimental raw tcp support. "
|
|
|
|
"Disabled by default. "
|
|
|
|
"Default value will change in a future version."
|
|
|
|
)
|
2015-08-27 23:51:13 +00:00
|
|
|
|
|
|
|
|
|
|
|
def proxy_ssl_options(parser):
|
|
|
|
# TODO: Agree to consistently either use "upstream" or "server".
|
|
|
|
group = parser.add_argument_group("SSL")
|
2014-03-13 22:43:26 +00:00
|
|
|
group.add_argument(
|
2015-08-27 23:51:13 +00:00
|
|
|
"--cert",
|
|
|
|
dest='certs',
|
|
|
|
default=[],
|
|
|
|
type=str,
|
|
|
|
metavar="SPEC",
|
|
|
|
action="append",
|
|
|
|
help='Add an SSL certificate. SPEC is of the form "[domain=]path". '
|
|
|
|
'The domain may include a wildcard, and is equal to "*" if not specified. '
|
|
|
|
'The file at path is a certificate in PEM format. If a private key is included '
|
|
|
|
'in the PEM, it is used, else the default key in the conf dir is used. '
|
|
|
|
'The PEM file should contain the full certificate chain, with the leaf certificate '
|
|
|
|
'as the first entry. Can be passed multiple times.')
|
2014-10-08 23:58:54 +00:00
|
|
|
group.add_argument(
|
2015-08-27 23:51:13 +00:00
|
|
|
"--ciphers-client", action="store",
|
|
|
|
type=str, dest="ciphers_client", default=config.DEFAULT_CLIENT_CIPHERS,
|
|
|
|
help="Set supported ciphers for client connections. (OpenSSL Syntax)"
|
2014-10-08 23:58:54 +00:00
|
|
|
)
|
2014-03-13 22:43:26 +00:00
|
|
|
group.add_argument(
|
2015-08-27 23:51:13 +00:00
|
|
|
"--ciphers-server", action="store",
|
|
|
|
type=str, dest="ciphers_server", default=None,
|
|
|
|
help="Set supported ciphers for server connections. (OpenSSL Syntax)"
|
2013-03-17 04:31:35 +00:00
|
|
|
)
|
2014-08-09 01:03:21 +00:00
|
|
|
group.add_argument(
|
2015-08-27 23:51:13 +00:00
|
|
|
"--client-certs", action="store",
|
|
|
|
type=str, dest="clientcerts", default=None,
|
2015-12-28 20:20:45 +00:00
|
|
|
help="Client certificate file or directory."
|
2014-08-09 01:03:21 +00:00
|
|
|
)
|
2015-06-20 12:43:50 +00:00
|
|
|
group.add_argument(
|
2015-08-27 23:51:13 +00:00
|
|
|
"--no-upstream-cert", default=False,
|
|
|
|
action="store_true", dest="no_upstream_cert",
|
|
|
|
help="Don't connect to upstream server to look up certificate details."
|
2015-06-20 15:51:56 +00:00
|
|
|
)
|
|
|
|
group.add_argument(
|
2015-08-27 23:51:13 +00:00
|
|
|
"--verify-upstream-cert", default=False,
|
|
|
|
action="store_true", dest="ssl_verify_upstream_cert",
|
|
|
|
help="Verify upstream server SSL/TLS certificates and fail if invalid "
|
|
|
|
"or not present."
|
2015-06-20 15:51:56 +00:00
|
|
|
)
|
|
|
|
group.add_argument(
|
2015-08-27 23:51:13 +00:00
|
|
|
"--upstream-trusted-cadir", default=None, action="store",
|
|
|
|
dest="ssl_verify_upstream_trusted_cadir",
|
|
|
|
help="Path to a directory of trusted CA certificates for upstream "
|
|
|
|
"server verification prepared using the c_rehash tool."
|
2015-06-20 12:43:50 +00:00
|
|
|
)
|
2015-08-27 23:51:13 +00:00
|
|
|
group.add_argument(
|
|
|
|
"--upstream-trusted-ca", default=None, action="store",
|
|
|
|
dest="ssl_verify_upstream_trusted_ca",
|
|
|
|
help="Path to a PEM formatted trusted CA certificate."
|
2014-03-13 22:43:26 +00:00
|
|
|
)
|
|
|
|
group.add_argument(
|
2015-08-27 23:51:13 +00:00
|
|
|
"--ssl-version-client", dest="ssl_version_client",
|
|
|
|
default="secure", action="store",
|
2015-08-29 10:34:01 +00:00
|
|
|
choices=sslversion_choices.keys(),
|
|
|
|
help="Set supported SSL/TLS versions for client connections. "
|
2015-08-27 23:51:13 +00:00
|
|
|
"SSLv2, SSLv3 and 'all' are INSECURE. Defaults to secure, which is TLS1.0+."
|
2014-03-13 22:43:26 +00:00
|
|
|
)
|
|
|
|
group.add_argument(
|
2015-08-27 23:51:13 +00:00
|
|
|
"--ssl-version-server", dest="ssl_version_server",
|
|
|
|
default="secure", action="store",
|
2015-08-29 10:34:01 +00:00
|
|
|
choices=sslversion_choices.keys(),
|
|
|
|
help="Set supported SSL/TLS versions for server connections. "
|
2015-08-27 23:51:13 +00:00
|
|
|
"SSLv2, SSLv3 and 'all' are INSECURE. Defaults to secure, which is TLS1.0+."
|
2012-02-27 02:05:45 +00:00
|
|
|
)
|
2014-03-13 22:43:26 +00:00
|
|
|
|
2015-08-27 23:51:13 +00:00
|
|
|
|
|
|
|
def onboarding_app(parser):
|
2014-09-14 00:22:28 +00:00
|
|
|
group = parser.add_argument_group("Onboarding App")
|
2013-03-24 20:20:26 +00:00
|
|
|
group.add_argument(
|
2014-12-11 18:21:33 +00:00
|
|
|
"--noapp",
|
2014-01-27 01:37:29 +00:00
|
|
|
action="store_false", dest="app", default=True,
|
2014-09-14 00:22:28 +00:00
|
|
|
help="Disable the mitmproxy onboarding app."
|
2013-03-24 20:20:26 +00:00
|
|
|
)
|
2013-07-23 22:32:56 +00:00
|
|
|
group.add_argument(
|
2013-08-18 18:03:53 +00:00
|
|
|
"--app-host",
|
|
|
|
action="store", dest="app_host", default=APP_HOST, metavar="host",
|
2014-11-15 03:14:08 +00:00
|
|
|
help="""
|
|
|
|
Domain to serve the onboarding app from. For transparent mode, use
|
|
|
|
an IP when a DNS entry for the app domain is not present. Default:
|
|
|
|
%s
|
|
|
|
""" % APP_HOST
|
2013-07-23 22:32:56 +00:00
|
|
|
)
|
|
|
|
group.add_argument(
|
2013-08-18 18:03:53 +00:00
|
|
|
"--app-port",
|
2014-11-15 03:14:08 +00:00
|
|
|
action="store",
|
|
|
|
dest="app_port",
|
|
|
|
default=APP_PORT,
|
|
|
|
type=int,
|
|
|
|
metavar="80",
|
2014-09-14 00:22:28 +00:00
|
|
|
help="Port to serve the onboarding app from."
|
2013-08-18 18:03:53 +00:00
|
|
|
)
|
2013-03-24 20:20:26 +00:00
|
|
|
|
2015-08-27 23:51:13 +00:00
|
|
|
|
|
|
|
def client_replay(parser):
|
2012-08-17 17:04:39 +00:00
|
|
|
group = parser.add_argument_group("Client Replay")
|
|
|
|
group.add_argument(
|
2014-11-15 04:41:04 +00:00
|
|
|
"-c", "--client-replay",
|
2015-01-05 21:12:38 +00:00
|
|
|
action="append", dest="client_replay", default=None, metavar="PATH",
|
2011-03-12 01:30:12 +00:00
|
|
|
help="Replay client requests from a saved file."
|
|
|
|
)
|
|
|
|
|
2015-08-27 23:51:13 +00:00
|
|
|
|
|
|
|
def server_replay(parser):
|
2012-08-17 17:04:39 +00:00
|
|
|
group = parser.add_argument_group("Server Replay")
|
|
|
|
group.add_argument(
|
2014-11-15 04:41:04 +00:00
|
|
|
"-S", "--server-replay",
|
2015-01-05 21:12:38 +00:00
|
|
|
action="append", dest="server_replay", default=None, metavar="PATH",
|
2011-03-12 01:30:12 +00:00
|
|
|
help="Replay server responses from a saved file."
|
|
|
|
)
|
2012-08-17 17:04:39 +00:00
|
|
|
group.add_argument(
|
2014-11-15 04:41:04 +00:00
|
|
|
"-k", "--kill",
|
2011-03-12 01:30:12 +00:00
|
|
|
action="store_true", dest="kill", default=False,
|
|
|
|
help="Kill extra requests during replay."
|
|
|
|
)
|
2012-08-17 17:04:39 +00:00
|
|
|
group.add_argument(
|
2011-03-12 01:30:12 +00:00
|
|
|
"--rheader",
|
2012-08-17 17:04:39 +00:00
|
|
|
action="append", dest="rheaders", type=str,
|
2011-03-12 01:30:12 +00:00
|
|
|
help="Request headers to be considered during replay. "
|
2014-07-21 19:06:55 +00:00
|
|
|
"Can be passed multiple times."
|
2011-03-12 01:30:12 +00:00
|
|
|
)
|
2012-08-17 17:04:39 +00:00
|
|
|
group.add_argument(
|
2011-03-12 01:30:12 +00:00
|
|
|
"--norefresh",
|
|
|
|
action="store_true", dest="norefresh", default=False,
|
2014-11-15 03:14:08 +00:00
|
|
|
help="""
|
|
|
|
Disable response refresh, which updates times in cookies and headers
|
|
|
|
for replayed responses.
|
|
|
|
"""
|
2011-03-12 01:30:12 +00:00
|
|
|
)
|
2012-08-17 17:04:39 +00:00
|
|
|
group.add_argument(
|
2012-03-05 09:05:11 +00:00
|
|
|
"--no-pop",
|
|
|
|
action="store_true", dest="nopop", default=False,
|
2012-03-05 09:56:03 +00:00
|
|
|
help="Disable response pop from response flow. "
|
2014-07-21 19:06:55 +00:00
|
|
|
"This makes it possible to replay same response multiple times."
|
2012-03-05 09:05:11 +00:00
|
|
|
)
|
2014-12-18 20:56:27 +00:00
|
|
|
payload = group.add_mutually_exclusive_group()
|
|
|
|
payload.add_argument(
|
2014-10-03 10:29:44 +00:00
|
|
|
"--replay-ignore-content",
|
|
|
|
action="store_true", dest="replay_ignore_content", default=False,
|
2014-11-15 03:14:08 +00:00
|
|
|
help="""
|
|
|
|
Ignore request's content while searching for a saved flow to replay
|
|
|
|
"""
|
2014-10-03 10:29:44 +00:00
|
|
|
)
|
2014-12-18 20:56:27 +00:00
|
|
|
payload.add_argument(
|
|
|
|
"--replay-ignore-payload-param",
|
|
|
|
action="append", dest="replay_ignore_payload_params", type=str,
|
|
|
|
help="""
|
2015-03-27 14:30:19 +00:00
|
|
|
Request's payload parameters (application/x-www-form-urlencoded or multipart/form-data) to
|
2014-12-28 02:07:44 +00:00
|
|
|
be ignored while searching for a saved flow to replay.
|
|
|
|
Can be passed multiple times.
|
2014-12-18 20:56:27 +00:00
|
|
|
"""
|
|
|
|
)
|
|
|
|
|
2014-10-03 10:29:44 +00:00
|
|
|
group.add_argument(
|
|
|
|
"--replay-ignore-param",
|
|
|
|
action="append", dest="replay_ignore_params", type=str,
|
2014-11-15 03:14:08 +00:00
|
|
|
help="""
|
|
|
|
Request's parameters to be ignored while searching for a saved flow
|
|
|
|
to replay. Can be passed multiple times.
|
|
|
|
"""
|
2014-10-08 23:58:54 +00:00
|
|
|
)
|
2015-03-07 16:38:18 +00:00
|
|
|
group.add_argument(
|
|
|
|
"--replay-ignore-host",
|
2015-05-30 00:03:28 +00:00
|
|
|
action="store_true",
|
|
|
|
dest="replay_ignore_host",
|
|
|
|
default=False,
|
|
|
|
help="Ignore request's destination host while searching for a saved flow to replay")
|
2012-03-17 04:20:34 +00:00
|
|
|
|
2015-08-27 23:51:13 +00:00
|
|
|
|
|
|
|
def replacements(parser):
|
2012-08-17 17:04:39 +00:00
|
|
|
group = parser.add_argument_group(
|
2012-03-17 04:20:34 +00:00
|
|
|
"Replacements",
|
|
|
|
"""
|
|
|
|
Replacements are of the form "/pattern/regex/replacement", where
|
|
|
|
the separator can be any character. Please see the documentation
|
|
|
|
for more information.
|
|
|
|
""".strip()
|
|
|
|
)
|
2012-08-17 17:04:39 +00:00
|
|
|
group.add_argument(
|
2012-03-17 04:20:34 +00:00
|
|
|
"--replace",
|
2012-08-17 17:04:39 +00:00
|
|
|
action="append", type=str, dest="replace", default=[],
|
2012-03-17 04:20:34 +00:00
|
|
|
metavar="PATTERN",
|
|
|
|
help="Replacement pattern."
|
|
|
|
)
|
2012-08-17 17:04:39 +00:00
|
|
|
group.add_argument(
|
2012-03-17 04:20:34 +00:00
|
|
|
"--replace-from-file",
|
2015-08-27 23:51:13 +00:00
|
|
|
action="append", type=str, dest="replace_file", default=[],
|
|
|
|
metavar="PATH",
|
|
|
|
help="""
|
2014-11-15 03:14:08 +00:00
|
|
|
Replacement pattern, where the replacement clause is a path to a
|
|
|
|
file.
|
|
|
|
"""
|
2012-03-17 04:20:34 +00:00
|
|
|
)
|
2011-03-12 01:30:12 +00:00
|
|
|
|
2015-08-27 23:51:13 +00:00
|
|
|
|
|
|
|
def set_headers(parser):
|
2012-08-18 12:14:16 +00:00
|
|
|
group = parser.add_argument_group(
|
|
|
|
"Set Headers",
|
|
|
|
"""
|
|
|
|
Header specifications are of the form "/pattern/header/value",
|
|
|
|
where the separator can be any character. Please see the
|
|
|
|
documentation for more information.
|
|
|
|
""".strip()
|
|
|
|
)
|
2012-08-17 17:13:56 +00:00
|
|
|
group.add_argument(
|
2012-08-18 12:14:16 +00:00
|
|
|
"--setheader",
|
|
|
|
action="append", type=str, dest="setheader", default=[],
|
|
|
|
metavar="PATTERN",
|
|
|
|
help="Header set pattern."
|
2012-08-06 21:09:35 +00:00
|
|
|
)
|
|
|
|
|
2015-08-27 23:51:13 +00:00
|
|
|
|
|
|
|
def proxy_authentication(parser):
|
2012-12-30 09:41:58 +00:00
|
|
|
group = parser.add_argument_group(
|
|
|
|
"Proxy Authentication",
|
|
|
|
"""
|
2013-01-02 04:35:44 +00:00
|
|
|
Specify which users are allowed to access the proxy and the method
|
2014-09-06 10:23:05 +00:00
|
|
|
used for authenticating them.
|
2013-01-02 04:35:44 +00:00
|
|
|
"""
|
2015-08-27 23:51:13 +00:00
|
|
|
).add_mutually_exclusive_group()
|
|
|
|
group.add_argument(
|
2012-12-30 09:41:58 +00:00
|
|
|
"--nonanonymous",
|
|
|
|
action="store_true", dest="auth_nonanonymous",
|
2013-01-02 04:35:44 +00:00
|
|
|
help="Allow access to any user long as a credentials are specified."
|
2012-12-30 09:41:58 +00:00
|
|
|
)
|
|
|
|
|
2015-08-27 23:51:13 +00:00
|
|
|
group.add_argument(
|
2012-12-30 09:41:58 +00:00
|
|
|
"--singleuser",
|
|
|
|
action="store", dest="auth_singleuser", type=str,
|
2013-01-02 04:35:44 +00:00
|
|
|
metavar="USER",
|
2014-11-15 03:14:08 +00:00
|
|
|
help="""
|
|
|
|
Allows access to a a single user, specified in the form
|
|
|
|
username:password.
|
|
|
|
"""
|
2012-12-30 09:41:58 +00:00
|
|
|
)
|
2015-08-27 23:51:13 +00:00
|
|
|
group.add_argument(
|
2012-12-30 09:41:58 +00:00
|
|
|
"--htpasswd",
|
2014-08-17 21:06:25 +00:00
|
|
|
action="store", dest="auth_htpasswd", type=str,
|
2013-01-02 04:35:44 +00:00
|
|
|
metavar="PATH",
|
2012-12-30 09:41:58 +00:00
|
|
|
help="Allow access to users specified in an Apache htpasswd file."
|
|
|
|
)
|
|
|
|
|
2015-08-27 23:51:13 +00:00
|
|
|
|
|
|
|
def common_options(parser):
|
|
|
|
basic_options(parser)
|
|
|
|
proxy_modes(parser)
|
|
|
|
proxy_options(parser)
|
|
|
|
proxy_ssl_options(parser)
|
|
|
|
onboarding_app(parser)
|
|
|
|
client_replay(parser)
|
|
|
|
server_replay(parser)
|
|
|
|
replacements(parser)
|
|
|
|
set_headers(parser)
|
|
|
|
proxy_authentication(parser)
|
2014-11-15 03:29:38 +00:00
|
|
|
|
|
|
|
|
|
|
|
def mitmproxy():
|
|
|
|
# Don't import libmproxy.console for mitmdump, urwid is not available on all
|
|
|
|
# platforms.
|
|
|
|
from .console import palettes
|
|
|
|
|
2014-11-15 04:25:05 +00:00
|
|
|
parser = configargparse.ArgumentParser(
|
|
|
|
usage="%(prog)s [options]",
|
2015-08-27 23:51:13 +00:00
|
|
|
args_for_setting_config_path=["--conf"],
|
|
|
|
default_config_files=[
|
2014-11-15 04:25:05 +00:00
|
|
|
os.path.join(config.CA_DIR, "common.conf"),
|
|
|
|
os.path.join(config.CA_DIR, "mitmproxy.conf")
|
|
|
|
],
|
2015-08-27 23:51:13 +00:00
|
|
|
add_config_file_help=True,
|
|
|
|
add_env_var_help=True
|
2014-11-15 04:25:05 +00:00
|
|
|
)
|
2014-11-15 03:29:38 +00:00
|
|
|
common_options(parser)
|
|
|
|
parser.add_argument(
|
2015-04-06 20:42:40 +00:00
|
|
|
"--palette", type=str, default=palettes.DEFAULT,
|
2014-11-15 03:29:38 +00:00
|
|
|
action="store", dest="palette",
|
2015-03-12 11:56:47 +00:00
|
|
|
choices=sorted(palettes.palettes.keys()),
|
2014-11-15 03:29:38 +00:00
|
|
|
help="Select color palette: " + ", ".join(palettes.palettes.keys())
|
|
|
|
)
|
2015-04-06 22:01:18 +00:00
|
|
|
parser.add_argument(
|
|
|
|
"--palette-transparent",
|
|
|
|
action="store_true", dest="palette_transparent", default=False,
|
|
|
|
help="Set transparent background for palette."
|
|
|
|
)
|
2014-11-15 03:29:38 +00:00
|
|
|
parser.add_argument(
|
2014-11-15 04:41:04 +00:00
|
|
|
"-e", "--eventlog",
|
2014-11-15 03:29:38 +00:00
|
|
|
action="store_true", dest="eventlog",
|
|
|
|
help="Show event log."
|
|
|
|
)
|
2015-08-19 20:07:39 +00:00
|
|
|
parser.add_argument(
|
|
|
|
"--no-mouse",
|
|
|
|
action="store_true", dest="no_mouse",
|
|
|
|
help="Disable mouse interaction."
|
|
|
|
)
|
2014-11-15 03:29:38 +00:00
|
|
|
group = parser.add_argument_group(
|
|
|
|
"Filters",
|
|
|
|
"See help in mitmproxy for filter expression syntax."
|
|
|
|
)
|
|
|
|
group.add_argument(
|
|
|
|
"-i", "--intercept", action="store",
|
|
|
|
type=str, dest="intercept", default=None,
|
|
|
|
help="Intercept filter expression."
|
|
|
|
)
|
2015-04-15 00:56:43 +00:00
|
|
|
group.add_argument(
|
|
|
|
"-l", "--limit", action="store",
|
|
|
|
type=str, dest="limit", default=None,
|
|
|
|
help="Limit filter expression."
|
|
|
|
)
|
2014-11-15 03:29:38 +00:00
|
|
|
return parser
|
|
|
|
|
|
|
|
|
|
|
|
def mitmdump():
|
2014-11-15 04:25:05 +00:00
|
|
|
parser = configargparse.ArgumentParser(
|
|
|
|
usage="%(prog)s [options] [filter]",
|
2015-08-27 23:51:13 +00:00
|
|
|
args_for_setting_config_path=["--conf"],
|
|
|
|
default_config_files=[
|
2014-11-15 04:25:05 +00:00
|
|
|
os.path.join(config.CA_DIR, "common.conf"),
|
|
|
|
os.path.join(config.CA_DIR, "mitmdump.conf")
|
|
|
|
],
|
2015-08-27 23:51:13 +00:00
|
|
|
add_config_file_help=True,
|
|
|
|
add_env_var_help=True
|
2014-11-15 04:25:05 +00:00
|
|
|
)
|
2014-11-15 03:29:38 +00:00
|
|
|
|
|
|
|
common_options(parser)
|
|
|
|
parser.add_argument(
|
|
|
|
"--keepserving",
|
2015-08-27 23:51:13 +00:00
|
|
|
action="store_true", dest="keepserving", default=False,
|
|
|
|
help="""
|
2014-11-15 03:29:38 +00:00
|
|
|
Continue serving after client playback or file read. We exit by
|
|
|
|
default.
|
|
|
|
"""
|
|
|
|
)
|
|
|
|
parser.add_argument(
|
2014-11-15 04:41:04 +00:00
|
|
|
"-d", "--detail",
|
2014-11-15 03:29:38 +00:00
|
|
|
action="count", dest="flow_detail", default=1,
|
|
|
|
help="Increase flow detail display level. Can be passed multiple times."
|
|
|
|
)
|
2014-11-15 04:51:21 +00:00
|
|
|
parser.add_argument('args', nargs="...")
|
2014-11-15 03:29:38 +00:00
|
|
|
return parser
|
|
|
|
|
|
|
|
|
|
|
|
def mitmweb():
|
2014-11-15 04:25:05 +00:00
|
|
|
parser = configargparse.ArgumentParser(
|
|
|
|
usage="%(prog)s [options]",
|
2015-08-27 23:51:13 +00:00
|
|
|
args_for_setting_config_path=["--conf"],
|
|
|
|
default_config_files=[
|
2014-11-15 04:25:05 +00:00
|
|
|
os.path.join(config.CA_DIR, "common.conf"),
|
|
|
|
os.path.join(config.CA_DIR, "mitmweb.conf")
|
|
|
|
],
|
2015-08-27 23:51:13 +00:00
|
|
|
add_config_file_help=True,
|
|
|
|
add_env_var_help=True
|
2014-11-15 04:25:05 +00:00
|
|
|
)
|
2014-11-15 03:29:38 +00:00
|
|
|
|
|
|
|
group = parser.add_argument_group("Mitmweb")
|
|
|
|
group.add_argument(
|
|
|
|
"--wport",
|
|
|
|
action="store", type=int, dest="wport", default=8081,
|
|
|
|
metavar="PORT",
|
|
|
|
help="Mitmweb port."
|
|
|
|
)
|
|
|
|
group.add_argument(
|
|
|
|
"--wiface",
|
|
|
|
action="store", dest="wiface", default="127.0.0.1",
|
|
|
|
metavar="IFACE",
|
|
|
|
help="Mitmweb interface."
|
|
|
|
)
|
|
|
|
group.add_argument(
|
|
|
|
"--wdebug",
|
|
|
|
action="store_true", dest="wdebug",
|
|
|
|
help="Turn on mitmweb debugging"
|
|
|
|
)
|
|
|
|
|
|
|
|
common_options(parser)
|
|
|
|
group = parser.add_argument_group(
|
|
|
|
"Filters",
|
|
|
|
"See help in mitmproxy for filter expression syntax."
|
|
|
|
)
|
|
|
|
group.add_argument(
|
|
|
|
"-i", "--intercept", action="store",
|
|
|
|
type=str, dest="intercept", default=None,
|
|
|
|
help="Intercept filter expression."
|
|
|
|
)
|
|
|
|
return parser
|