예제 #1
0
파일: dump.py 프로젝트: xuzhe/mitmproxy
    def __init__(self, server, options, filtstr, outfile=sys.stdout):
        flow.FlowMaster.__init__(self, server, flow.State())
        self.outfile = outfile
        self.o = options

        if filtstr:
            self.filt = filt.parse(filtstr)
        else:
            self.filt = None

        if self.o.response_script:
            self.set_response_script(self.o.response_script)  
        if self.o.request_script:
            self.set_request_script(self.o.request_script)  

        if options.stickycookie:
            self.set_stickycookie(options.stickycookie)

        if options.stickyauth:
            self.set_stickyauth(options.stickyauth)

        if options.wfile:
            path = os.path.expanduser(options.wfile)
            try:
                f = file(path, "wb")
                self.fwriter = flow.FlowWriter(f)
            except IOError, v:
                raise DumpError(v.strerror)
예제 #2
0
    def __init__(self, server, options, filtstr, outfile=sys.stdout):
        flow.FlowMaster.__init__(self, server, flow.State())
        self.outfile = outfile
        self.o = options
        self.anticache = options.anticache
        self.anticomp = options.anticomp
        self.eventlog = options.eventlog
        self.showhost = options.showhost
        self.refresh_server_playback = options.refresh_server_playback

        if filtstr:
            self.filt = filt.parse(filtstr)
        else:
            self.filt = None

        if options.stickycookie:
            self.set_stickycookie(options.stickycookie)

        if options.stickyauth:
            self.set_stickyauth(options.stickyauth)

        if options.wfile:
            path = os.path.expanduser(options.wfile)
            try:
                f = file(path, "wb")
                self.start_stream(f, self.filt)
            except IOError, v:
                raise DumpError(v.strerror)
예제 #3
0
    def __init__(self, server, options, filtstr, outfile=sys.stdout):
        flow.FlowMaster.__init__(self, server, flow.State())
        self.outfile = outfile
        self.o = options
        self.anticache = options.anticache
        self.anticomp = options.anticomp
        self.eventlog = options.eventlog
        self.refresh_server_playback = options.refresh_server_playback

        if filtstr:
            self.filt = filt.parse(filtstr)
        else:
            self.filt = None

        if options.stickycookie:
            self.set_stickycookie(options.stickycookie)

        if options.stickyauth:
            self.set_stickyauth(options.stickyauth)

        if options.wfile:
            path = os.path.expanduser(options.wfile)
            try:
                f = file(path, "wb")
                self.start_stream(f)
            except IOError, v:
                raise DumpError(v.strerror)
예제 #4
0
파일: console.py 프로젝트: nezza/mitmproxy
 def set_beep(self, txt):
     if txt:
         self.state.beep = filt.parse(txt)
         if not self.state.beep:
             return "Invalid filter expression."
     else:
         self.state.beep = None
예제 #5
0
파일: console.py 프로젝트: nezza/mitmproxy
 def set_intercept(self, txt):
     if txt:
         self.state.intercept = filt.parse(txt)
         if not self.state.intercept:
             return "Invalid filter expression."
     else:
         self.state.intercept = None
예제 #6
0
파일: dump.py 프로젝트: xuzhe/mitmproxy
    def __init__(self, server, options, filtstr, outfile=sys.stdout):
        flow.FlowMaster.__init__(self, server, flow.State())
        self.outfile = outfile
        self.o = options

        if filtstr:
            self.filt = filt.parse(filtstr)
        else:
            self.filt = None

        if self.o.response_script:
            self.set_response_script(self.o.response_script)
        if self.o.request_script:
            self.set_request_script(self.o.request_script)

        if options.stickycookie:
            self.set_stickycookie(options.stickycookie)

        if options.stickyauth:
            self.set_stickyauth(options.stickyauth)

        if options.wfile:
            path = os.path.expanduser(options.wfile)
            try:
                f = file(path, "wb")
                self.fwriter = flow.FlowWriter(f)
            except IOError, v:
                raise DumpError(v.strerror)
예제 #7
0
파일: console.py 프로젝트: nezza/mitmproxy
 def set_limit(self, txt):
     if txt:
         f = filt.parse(txt)
         if not f:
             return "Invalid filter expression."
         self.state.set_limit(f)
     else:
         self.state.set_limit(None)
예제 #8
0
파일: console.py 프로젝트: nezza/mitmproxy
 def set_stickycookie(self, txt):
     if txt:
         self.stickycookie = filt.parse(txt)
         if not self.stickycookie:
             return "Invalid filter expression."
     else:
         self.stickyhosts = {}
         self.stickycookie = None
예제 #9
0
 def set_stickyauth(self, txt):
     if txt:
         flt = filt.parse(txt)
         if not flt:
             return "Invalid filter expression."
         self.stickyauth_state = StickyAuthState(flt)
         self.stickyauth_txt = txt
     else:
         self.stickyauth_state = None
         self.stickyauth_txt = None
예제 #10
0
 def set_stickycookie(self, txt):
     if txt:
         flt = filt.parse(txt)
         if not flt:
             return "Invalid filter expression."
         self.stickycookie_state = StickyCookieState(flt)
         self.stickycookie_txt = txt
     else:
         self.stickycookie_state = None
         self.stickycookie_txt = None
예제 #11
0
 def set_intercept(self, txt):
     if txt:
         f = filt.parse(txt)
         if not f:
             return "Invalid filter expression."
         self.intercept = f
         self.intercept_txt = txt
     else:
         self.intercept = None
         self.intercept_txt = None
예제 #12
0
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:
        raise ParseException("Empty clause: %s"%str(patt))

    if not filt.parse(patt):
        raise ParseException("Malformed filter pattern: %s"%patt)

    return patt, a, b
예제 #13
0
        patt = ".*"
        regex, replacement = parts
    elif len(parts) == 3:
        patt, regex, replacement = parts
    else:
        raise ParseReplaceException("Malformed replacement specifier - too few clauses: %s" % s)

    if not regex:
        raise ParseReplaceException("Empty replacement regex: %s" % str(patt))

    try:
        re.compile(regex)
    except re.error, e:
        raise ParseReplaceException("Malformed replacement regex: %s" % str(e.message))

    if not filt.parse(patt):
        raise ParseReplaceException("Malformed replacement filter pattern: %s" % patt)

    return patt, regex, replacement


def get_common_options(options):
    stickycookie, stickyauth = None, None
    if options.stickycookie_all:
        stickycookie = ".*"
    elif options.stickycookie_filt:
        stickycookie = options.stickycookie_filt

    if options.stickyauth_all:
        stickyauth = ".*"
    elif options.stickyauth_filt: