mitmproxy/mitmproxy/cmdline.py

862 lines
27 KiB
Python
Raw Normal View History

2016-06-01 02:06:57 +00:00
from __future__ import absolute_import, print_function, division
import base64
import os
import re
import configargparse
2015-08-01 08:40:19 +00:00
from mitmproxy import exceptions
2016-06-01 02:06:57 +00:00
from mitmproxy import filt
from mitmproxy.proxy import config
from netlib import human
2016-06-20 19:38:14 +00:00
from netlib import strutils
2016-06-01 02:06:57 +00:00
from netlib import tcp
from netlib import version
2016-06-01 02:06:57 +00:00
from netlib.http import url
APP_HOST = "mitm.it"
APP_PORT = 80
2016-07-18 02:50:10 +00:00
CA_DIR = "~/.mitmproxy"
class ParseException(Exception):
pass
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:
raise ParseException(
"Malformed hook specifier - too few clauses: %s" % s
)
if not a:
2014-07-21 19:06:55 +00:00
raise ParseException("Empty clause: %s" % str(patt))
if not filt.parse(patt):
2014-07-21 19:06:55 +00:00
raise ParseException("Malformed filter pattern: %s" % patt)
return patt, a, b
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
ParseException on error.
"""
patt, regex, replacement = _parse_hook(s)
try:
re.compile(regex)
2015-05-30 00:03:28 +00:00
except re.error as e:
2016-06-20 19:38:14 +00:00
raise ParseException("Malformed replacement regex: %s" % str(e))
return patt, regex, replacement
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)
2016-06-01 02:06:57 +00:00
def parse_server_spec(spec):
2015-09-16 16:45:22 +00:00
try:
2016-06-01 02:06:57 +00:00
p = url.parse(spec)
2016-06-20 19:38:14 +00:00
if p[0] not in (b"http", b"https"):
2015-09-16 16:45:22 +00:00
raise ValueError()
except ValueError:
2014-11-15 04:51:21 +00:00
raise configargparse.ArgumentTypeError(
2016-06-01 02:06:57 +00:00
"Invalid server specification: %s" % spec
)
2015-09-16 16:45:22 +00:00
2016-06-01 02:06:57 +00:00
address = tcp.Address(p[1:3])
scheme = p[0].lower()
return config.ServerSpec(scheme, address)
2016-03-02 17:19:33 +00:00
def parse_upstream_auth(auth):
2016-03-04 16:12:03 +00:00
pattern = re.compile(".+:")
2016-03-02 17:19:33 +00:00
if pattern.search(auth) is None:
raise configargparse.ArgumentTypeError(
"Invalid upstream auth specification: %s" % auth
)
2016-06-20 19:38:14 +00:00
return b"Basic" + b" " + base64.b64encode(strutils.always_bytes(auth))
2016-03-02 17:19:33 +00:00
def get_common_options(args):
stickycookie, stickyauth = None, None
if args.stickycookie_filt:
stickycookie = args.stickycookie_filt
if args.stickyauth_filt:
stickyauth = args.stickyauth_filt
stream_large_bodies = args.stream_large_bodies
if stream_large_bodies:
stream_large_bodies = human.parse_size(stream_large_bodies)
2014-07-21 19:06:55 +00:00
reps = []
for i in args.replace:
try:
p = parse_replace_hook(i)
2015-05-30 00:03:28 +00:00
except ParseException as e:
raise exceptions.OptionsError(e)
reps.append(p)
for i in args.replace_file:
try:
patt, rex, path = parse_replace_hook(i)
2015-05-30 00:03:28 +00:00
except ParseException as e:
raise exceptions.OptionsError(e)
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:
raise exceptions.OptionsError(
"Could not read replace file: %s" % path
)
reps.append((patt, rex, v))
setheaders = []
for i in args.setheader:
try:
p = parse_setheader(i)
2015-05-30 00:03:28 +00:00
except ParseException as e:
raise exceptions.OptionsError(e)
setheaders.append(p)
if args.outfile and args.outfile[0] == args.rfile:
if args.outfile[1] == "wb":
raise exceptions.OptionsError(
"Cannot use '{}' for both reading and writing flows. "
"Are you looking for --afile?".format(args.rfile)
)
else:
raise exceptions.OptionsError(
"Cannot use '{}' for both reading and appending flows. "
"That would trigger an infinite loop."
)
# Proxy config
certs = []
for i in args.certs:
parts = i.split("=", 1)
if len(parts) == 1:
parts = ["*", parts[0]]
certs.append(parts)
body_size_limit = args.body_size_limit
if body_size_limit:
try:
body_size_limit = human.parse_size(body_size_limit)
except ValueError, e:
raise exceptions.OptionsError(
"Invalid body size limit specification: %s" % body_size_limit
)
return dict(
app=args.app,
app_host=args.app_host,
app_port=args.app_port,
anticache=args.anticache,
anticomp=args.anticomp,
client_replay=args.client_replay,
kill=args.kill,
no_server=args.no_server,
refresh_server_playback=not args.norefresh,
rheaders=args.rheaders,
rfile=args.rfile,
2014-07-21 19:06:55 +00:00
replacements=reps,
setheaders=setheaders,
server_replay=args.server_replay,
scripts=args.scripts,
2014-07-21 19:06:55 +00:00
stickycookie=stickycookie,
stickyauth=stickyauth,
stream_large_bodies=stream_large_bodies,
showhost=args.showhost,
outfile=args.outfile,
verbosity=args.verbose,
nopop=args.nopop,
replay_ignore_content=args.replay_ignore_content,
replay_ignore_params=args.replay_ignore_params,
replay_ignore_payload_params=args.replay_ignore_payload_params,
replay_ignore_host=args.replay_ignore_host,
body_size_limit = body_size_limit,
cadir = args.cadir,
certs = certs,
clientcerts = args.clientcerts,
listen_host = args.addr,
listen_port = args.port,
)
def basic_options(parser):
2014-11-15 04:58:38 +00:00
parser.add_argument(
'--version',
action='version',
version="%(prog)s" + " " + version.VERSION
2014-11-15 04:58:38 +00:00
)
parser.add_argument(
'--sysinfo',
action='store_true',
dest='sysinfo',
)
parser.add_argument(
'--shortversion',
action='version',
help="show program's short version number and exit",
version=version.VERSION
)
2012-08-17 17:04:39 +00:00
parser.add_argument(
"--anticache",
action="store_true", dest="anticache", default=False,
help="""
Strip out request headers that might cause the server to return
304-not-modified.
"""
)
2012-08-17 17:04:39 +00:00
parser.add_argument(
"--cadir",
2016-07-18 02:50:10 +00:00
action="store", type=str, dest="cadir", default=CA_DIR,
help="Location of the default mitmproxy CA files. (%s)" % CA_DIR
)
2012-08-17 17:04:39 +00:00
parser.add_argument(
"--host",
action="store_true", dest="showhost", default=False,
help="Use the Host header to construct URLs for display."
)
2012-08-17 17:04:39 +00:00
parser.add_argument(
"-q", "--quiet",
action="store_true", dest="quiet",
help="Quiet."
)
2012-08-17 17:04:39 +00:00
parser.add_argument(
"-r", "--read-flows",
action="store", dest="rfile", default=None,
help="Read flows from file."
)
2012-08-17 17:04:39 +00:00
parser.add_argument(
"-s", "--script",
action="append", type=str, dest="scripts", default=[],
metavar='"script.py --bar"',
help="""
Run a script. Surround with quotes to pass script arguments. Can be
passed multiple times.
"""
)
2012-08-17 17:04:39 +00:00
parser.add_argument(
"-t", "--stickycookie",
action="store",
dest="stickycookie_filt",
default=None,
metavar="FILTER",
help="Set sticky cookie filter. Matched against requests."
)
2012-08-17 17:04:39 +00:00
parser.add_argument(
"-u", "--stickyauth",
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(
"-v", "--verbose",
action="store_const", dest="verbose", default=2, const=3,
help="Increase log verbosity."
)
outfile = parser.add_mutually_exclusive_group()
outfile.add_argument(
"-w", "--wfile",
action="store", dest="outfile", type=lambda f: (f, "wb"),
help="Write flows to file."
)
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(
"-z", "--anticomp",
action="store_true", dest="anticomp", default=False,
help="Try to convince servers to send us un-compressed data."
)
2012-08-17 17:04:39 +00:00
parser.add_argument(
"-Z", "--body-size-limit",
action="store", dest="body_size_limit", default=None,
metavar="SIZE",
help="Byte size limit of HTTP request and response bodies."
" 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",
help="""
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.
"""
2014-07-21 19:06:55 +00:00
)
def proxy_modes(parser):
2016-06-29 02:26:08 +00:00
group = parser.add_argument_group("Proxy Modes")
group.add_argument(
"-R", "--reverse",
action="store",
type=parse_server_spec,
dest="reverse_proxy",
default=None,
help="""
Forward all requests to upstream HTTP server:
http[s]://host[:port]. Clients can always connect both
via HTTPS and HTTP, the connection to the server is
determined by the specified scheme.
"""
)
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):
group = parser.add_argument_group("Proxy Options")
group.add_argument(
"-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)"
)
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",
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-10-18 16:29:35 +00:00
group.add_argument(
"--tcp",
action="append", type=str, dest="tcp_hosts", default=[],
metavar="HOST",
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 log in verbose mode.
"""
2014-10-18 16:29:35 +00:00
)
group.add_argument(
"-n", "--no-server",
action="store_true", dest="no_server",
help="Don't start a proxy server."
)
group.add_argument(
"-p", "--port",
2014-07-21 19:06:55 +00:00
action="store", type=int, dest="port", default=8080,
help="Proxy service port."
)
2016-02-17 22:46:44 +00:00
group.add_argument(
"--no-http2",
action="store_false", dest="http2",
help="""
Explicitly disable HTTP/2 support.
If your OpenSSL version supports ALPN, HTTP/2 is enabled by default.
"""
)
2016-03-01 09:40:32 +00:00
parser.add_argument(
"--upstream-auth",
action="store", dest="upstream_auth", default=None,
2016-03-02 17:19:33 +00:00
type=parse_upstream_auth,
2016-03-01 09:40:32 +00:00
help="""
Proxy Authentication:
username:password
"""
)
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",
2016-01-27 09:12:18 +00:00
help="Explicitly enable/disable experimental raw tcp support. "
"Disabled by default. "
"Default value will change in a future version."
)
def proxy_ssl_options(parser):
# TODO: Agree to consistently either use "upstream" or "server".
group = parser.add_argument_group("SSL")
group.add_argument(
"--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(
"--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
)
group.add_argument(
"--ciphers-server", action="store",
type=str, dest="ciphers_server", default=None,
help="Set supported ciphers for server connections. (OpenSSL Syntax)"
)
2014-08-09 01:03:21 +00:00
group.add_argument(
"--client-certs", action="store",
type=str, dest="clientcerts", default=None,
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(
"--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(
"--add-upstream-certs-to-client-chain", default=False,
action="store_true", dest="add_upstream_certs_to_client_chain",
help="Add all certificates of the upstream server to the certificate chain "
"that will be served to the proxy client, as extras."
)
group.add_argument(
"--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(
"--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
)
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."
)
group.add_argument(
"--ssl-version-client", dest="ssl_version_client",
default="secure", action="store",
2016-06-01 02:06:57 +00:00
choices=tcp.sslversion_choices.keys(),
2015-08-29 10:34:01 +00:00
help="Set supported SSL/TLS versions for client connections. "
"SSLv2, SSLv3 and 'all' are INSECURE. Defaults to secure, which is TLS1.0+."
)
group.add_argument(
"--ssl-version-server", dest="ssl_version_server",
default="secure", action="store",
2016-06-01 02:06:57 +00:00
choices=tcp.sslversion_choices.keys(),
2015-08-29 10:34:01 +00:00
help="Set supported SSL/TLS versions for server connections. "
"SSLv2, SSLv3 and 'all' are INSECURE. Defaults to secure, which is TLS1.0+."
)
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(
"--noapp",
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
)
group.add_argument(
"--app-host",
action="store", dest="app_host", default=APP_HOST, metavar="host",
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
)
group.add_argument(
"--app-port",
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-03-24 20:20:26 +00:00
def client_replay(parser):
2012-08-17 17:04:39 +00:00
group = parser.add_argument_group("Client Replay")
group.add_argument(
"-c", "--client-replay",
2015-01-05 21:12:38 +00:00
action="append", dest="client_replay", default=None, metavar="PATH",
help="Replay client requests from a saved file."
)
def server_replay(parser):
2012-08-17 17:04:39 +00:00
group = parser.add_argument_group("Server Replay")
group.add_argument(
"-S", "--server-replay",
2015-01-05 21:12:38 +00:00
action="append", dest="server_replay", default=None, metavar="PATH",
help="Replay server responses from a saved file."
)
2012-08-17 17:04:39 +00:00
group.add_argument(
"-k", "--kill",
action="store_true", dest="kill", default=False,
help="Kill extra requests during replay."
)
2012-08-17 17:04:39 +00:00
group.add_argument(
"--rheader",
2012-08-17 17:04:39 +00:00
action="append", dest="rheaders", type=str,
help="Request headers to be considered during replay. "
2014-07-21 19:06:55 +00:00
"Can be passed multiple times."
)
2012-08-17 17:04:39 +00:00
group.add_argument(
"--norefresh",
action="store_true", dest="norefresh", default=False,
help="""
Disable response refresh, which updates times in cookies and headers
for replayed responses.
"""
)
2012-08-17 17:04:39 +00:00
group.add_argument(
"--no-pop",
action="store_true", dest="nopop", default=False,
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."
)
payload = group.add_mutually_exclusive_group()
payload.add_argument(
"--replay-ignore-content",
action="store_true", dest="replay_ignore_content", default=False,
help="""
Ignore request's content while searching for a saved flow to replay
"""
)
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
be ignored while searching for a saved flow to replay.
Can be passed multiple times.
"""
)
group.add_argument(
"--replay-ignore-param",
action="append", dest="replay_ignore_params", type=str,
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
)
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")
def replacements(parser):
2012-08-17 17:04:39 +00:00
group = parser.add_argument_group(
"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(
"--replace",
2012-08-17 17:04:39 +00:00
action="append", type=str, dest="replace", default=[],
metavar="PATTERN",
help="Replacement pattern."
)
2012-08-17 17:04:39 +00:00
group.add_argument(
"--replace-from-file",
action="append", type=str, dest="replace_file", default=[],
metavar="PATH",
help="""
Replacement pattern, where the replacement clause is a path to a
file.
"""
)
def set_headers(parser):
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(
"--setheader",
action="append", type=str, dest="setheader", default=[],
metavar="PATTERN",
help="Header set pattern."
)
def proxy_authentication(parser):
group = parser.add_argument_group(
"Proxy Authentication",
"""
Specify which users are allowed to access the proxy and the method
2014-09-06 10:23:05 +00:00
used for authenticating them.
"""
).add_mutually_exclusive_group()
group.add_argument(
"--nonanonymous",
action="store_true", dest="auth_nonanonymous",
help="Allow access to any user long as a credentials are specified."
)
group.add_argument(
"--singleuser",
action="store", dest="auth_singleuser", type=str,
metavar="USER",
help="""
Allows access to a a single user, specified in the form
username:password.
"""
)
group.add_argument(
"--htpasswd",
2014-08-17 21:06:25 +00:00
action="store", dest="auth_htpasswd", type=str,
metavar="PATH",
help="Allow access to users specified in an Apache htpasswd file."
)
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)
def mitmproxy():
# Don't import mitmproxy.console for mitmdump, urwid is not available on all
# platforms.
from .console import palettes
parser = configargparse.ArgumentParser(
usage="%(prog)s [options]",
args_for_setting_config_path=["--conf"],
default_config_files=[
2016-07-18 02:50:10 +00:00
os.path.join(CA_DIR, "common.conf"),
os.path.join(CA_DIR, "mitmproxy.conf")
],
add_config_file_help=True,
add_env_var_help=True
)
common_options(parser)
parser.add_argument(
"--palette", type=str, default=palettes.DEFAULT,
action="store", dest="palette",
choices=sorted(palettes.palettes.keys()),
help="Select color palette: " + ", ".join(palettes.palettes.keys())
)
parser.add_argument(
"--palette-transparent",
action="store_true", dest="palette_transparent", default=False,
help="Set transparent background for palette."
)
parser.add_argument(
"-e", "--eventlog",
action="store_true", dest="eventlog",
help="Show event log."
)
parser.add_argument(
"-f", "--follow",
action="store_true", dest="follow",
help="Follow flow list."
)
parser.add_argument(
"--no-mouse",
action="store_true", dest="no_mouse",
help="Disable mouse interaction."
)
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."
)
group.add_argument(
"-l", "--limit", action="store",
type=str, dest="limit", default=None,
help="Limit filter expression."
)
return parser
def mitmdump():
parser = configargparse.ArgumentParser(
usage="%(prog)s [options] [filter]",
args_for_setting_config_path=["--conf"],
default_config_files=[
2016-07-18 02:50:10 +00:00
os.path.join(CA_DIR, "common.conf"),
os.path.join(CA_DIR, "mitmdump.conf")
],
add_config_file_help=True,
add_env_var_help=True
)
common_options(parser)
parser.add_argument(
"--keepserving",
action="store_true", dest="keepserving", default=False,
help="""
Continue serving after client playback or file read. We exit by
default.
"""
)
parser.add_argument(
"-d", "--detail",
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="...")
return parser
def mitmweb():
parser = configargparse.ArgumentParser(
usage="%(prog)s [options]",
args_for_setting_config_path=["--conf"],
default_config_files=[
2016-07-18 02:50:10 +00:00
os.path.join(CA_DIR, "common.conf"),
os.path.join(CA_DIR, "mitmweb.conf")
],
add_config_file_help=True,
add_env_var_help=True
)
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"
)
group.add_argument(
"--wsingleuser",
action="store", dest="wsingleuser", type=str,
metavar="USER",
help="""
Allows access to a a single user, specified in the form
username:password.
"""
)
group.add_argument(
"--whtpasswd",
action="store", dest="whtpasswd", type=str,
metavar="PATH",
help="Allow access to users specified in an Apache htpasswd file."
)
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