mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2024-11-23 00:01:36 +00:00
Craft anchor is now specified as a regex
Unifies this with anchor points.
This commit is contained in:
parent
c5992b8d23
commit
ae9f470d2b
@ -8,6 +8,7 @@ from netlib import http_uastrings
|
||||
from . import pathoc, pathod, version, utils, language
|
||||
|
||||
|
||||
|
||||
def args_pathoc(argv, stdout=sys.stdout, stderr=sys.stderr):
|
||||
preparser = argparse.ArgumentParser(add_help=False)
|
||||
preparser.add_argument(
|
||||
@ -234,13 +235,17 @@ def args_pathod(argv, stdout=sys.stdout, stderr=sys.stderr):
|
||||
action="append",
|
||||
metavar="ANCHOR",
|
||||
help="""
|
||||
Add an anchor. Specified as a string with the form pattern=pagespec, or
|
||||
pattern=filepath
|
||||
Add an anchor. Specified as a string with the form
|
||||
pattern=spec or pattern=filepath, where pattern is a regular
|
||||
expression.
|
||||
"""
|
||||
)
|
||||
parser.add_argument(
|
||||
"-c", dest='craftanchor', default="/p", type=str,
|
||||
help='Anchorpoint for URL crafting commands. (/p)'
|
||||
"-c", dest='craftanchor', default=pathod.DEFAULT_ANCHOR, type=str,
|
||||
help="""
|
||||
Regular expression specifying anchor point for URL crafting
|
||||
commands. (%s)
|
||||
"""%pathod.DEFAULT_ANCHOR
|
||||
)
|
||||
parser.add_argument(
|
||||
"--confdir",
|
||||
@ -394,6 +399,13 @@ def args_pathod(argv, stdout=sys.stdout, stderr=sys.stderr):
|
||||
return parser.error(v)
|
||||
args.sizelimit = sizelimit
|
||||
|
||||
try:
|
||||
args.craftanchor = re.compile(args.craftanchor)
|
||||
except re.error:
|
||||
return parser.error(
|
||||
"Invalid regex in craft anchor: %s" % args.craftanchor
|
||||
)
|
||||
|
||||
anchors = []
|
||||
for patt, spec in args.anchors:
|
||||
if os.path.isfile(spec):
|
||||
|
@ -4,6 +4,8 @@ import os
|
||||
import sys
|
||||
import threading
|
||||
import urllib
|
||||
import re
|
||||
|
||||
from netlib import tcp, http, wsgi, certutils, websockets
|
||||
|
||||
from . import version, app, language, utils, log
|
||||
@ -15,6 +17,7 @@ DEFAULT_CERT_DOMAIN = "pathod.net"
|
||||
CONFDIR = "~/.mitmproxy"
|
||||
CERTSTORE_BASENAME = "mitmproxy"
|
||||
CA_CERT_NAME = "mitmproxy-ca.pem"
|
||||
DEFAULT_ANCHOR = r"/p/?"
|
||||
|
||||
logger = logging.getLogger('pathod')
|
||||
|
||||
@ -246,10 +249,9 @@ class PathodHandler(tcp.BaseHandler):
|
||||
nexthandler, retlog["response"] = self.serve_crafted(i[1])
|
||||
return nexthandler, retlog
|
||||
|
||||
if not self.server.nocraft and utils.matchpath(
|
||||
path,
|
||||
self.server.craftanchor):
|
||||
spec = urllib.unquote(path)[len(self.server.craftanchor) + 1:]
|
||||
m = utils.MemBool()
|
||||
if m(self.server.craftanchor.match(path)):
|
||||
spec = urllib.unquote(path)[len(m.v.group()):]
|
||||
websocket_key = websockets.check_client_handshake(headers)
|
||||
self.settings.websocket_key = websocket_key
|
||||
if websocket_key and not spec:
|
||||
@ -323,7 +325,7 @@ class Pathod(tcp.TCPServer):
|
||||
addr,
|
||||
ssl=False,
|
||||
ssloptions=None,
|
||||
craftanchor="/p",
|
||||
craftanchor=re.compile(DEFAULT_ANCHOR),
|
||||
staticdir=None,
|
||||
anchors=(),
|
||||
sizelimit=None,
|
||||
@ -380,6 +382,8 @@ class Pathod(tcp.TCPServer):
|
||||
"""
|
||||
A policy check that verifies the request size is withing limits.
|
||||
"""
|
||||
if self.nocraft:
|
||||
return "Crafting disabled.", None
|
||||
try:
|
||||
req = req.resolve(settings)
|
||||
l = req.maximum_length(settings)
|
||||
|
@ -1,8 +1,9 @@
|
||||
import threading
|
||||
import Queue
|
||||
|
||||
import requests
|
||||
import requests.packages.urllib3
|
||||
import pathod
|
||||
from . import pathod
|
||||
|
||||
requests.packages.urllib3.disable_warnings()
|
||||
|
||||
|
@ -127,8 +127,3 @@ def daemonize(stdin='/dev/null', stdout='/dev/null', stderr='/dev/null'): # pra
|
||||
os.dup2(si.fileno(), sys.stdin.fileno())
|
||||
os.dup2(so.fileno(), sys.stdout.fileno())
|
||||
os.dup2(se.fileno(), sys.stderr.fileno())
|
||||
|
||||
|
||||
def matchpath(path, spec):
|
||||
if path == spec or path.startswith(spec + "/"):
|
||||
return True
|
||||
|
Loading…
Reference in New Issue
Block a user