コード例 #1
0
 def response(self, flow):
     try:
         data = flow.response.content
         data = json.loads(data)
         if flowfilter.match(
                 flowfilter.parse(
                     '~u https://qf.56.com/wxexam/v2/singleMode/getQuestion.do'
                 ), flow):
             global Question, Option
             Question = question = data['data']['title']
             answer = self.m.db.col.find_one({"question": question})
             Option = option = [
                 data['data']['answera'], data['data']['answerb'],
                 data['data']['answerc']
             ]
             if answer is None:
                 print(question)
             else:
                 trueAnsewer = ''
                 strindex = ''
                 print('have answer')
                 c = flow.response.content
                 for index in range(len(Option)):
                     if (Option[index] == answer['answer']):
                         if index == 1:
                             strindex = 'answera'
                         elif index == 2:
                             strindex = 'answerb'
                         else:
                             strindex = 'answerc'
                         trueAnsewer = data['data'][strindex] + '[标准答案]'
                         flow.response.content = flow.response.content.replace(
                             bytes(data['data'][strindex], encoding='utf8'),
                             bytes(trueAnsewer, encoding='utf8'))
                 # print(flow.response.content)
                 return
         if flowfilter.match(
                 flowfilter.parse(
                     '~u https://qf.56.com/wxexam/v2/singleMode/answer.do'),
                 flow):
             answer = data['data']['rightAnswer']
             _answer = self.m.db.col.find_one({"question": Question})
             if _answer is None:
                 print('插入' + {
                     "question": Question,
                     "answer": Option[answer - 1]
                 })
                 self.m.db.col.insert({
                     "question": Question,
                     "answer": Option[answer - 1]
                 })
             else:
                 print('更新')
                 self.m.db.col.update({"question": Question},
                                      {"answer": Option[answer - 1]})
             return
     except Exception:
         pass
コード例 #2
0
ファイル: test_flow.py プロジェクト: CottageLabs/mitmproxy
    def test_match(self):
        f = tflow.ttcpflow()
        assert not flowfilter.match("~b nonexistent", f)
        assert flowfilter.match(None, f)
        assert not flowfilter.match("~b nonexistent", f)

        f = tflow.ttcpflow(err=True)
        assert flowfilter.match("~e", f)

        tutils.raises(ValueError, flowfilter.match, "~", f)
コード例 #3
0
ファイル: test_flow.py プロジェクト: MatthewShao/mitmproxy
    def test_match(self):
        f = tflow.ttcpflow()
        assert not flowfilter.match("~b nonexistent", f)
        assert flowfilter.match(None, f)
        assert not flowfilter.match("~b nonexistent", f)

        f = tflow.ttcpflow(err=True)
        assert flowfilter.match("~e", f)

        tutils.raises(ValueError, flowfilter.match, "~", f)
コード例 #4
0
ファイル: test_flow.py プロジェクト: MatthewShao/mitmproxy
    def test_match(self):
        f = tflow.tflow(resp=True)
        assert not flowfilter.match("~b test", f)
        assert flowfilter.match(None, f)
        assert not flowfilter.match("~b test", f)

        f = tflow.tflow(err=True)
        assert flowfilter.match("~e", f)

        tutils.raises(ValueError, flowfilter.match, "~", f)
コード例 #5
0
ファイル: test_flow.py プロジェクト: CottageLabs/mitmproxy
    def test_match(self):
        f = tflow.tflow(resp=True)
        assert not flowfilter.match("~b test", f)
        assert flowfilter.match(None, f)
        assert not flowfilter.match("~b test", f)

        f = tflow.tflow(err=True)
        assert flowfilter.match("~e", f)

        tutils.raises(ValueError, flowfilter.match, "~", f)
コード例 #6
0
ファイル: mitmdump.py プロジェクト: bolearnpython/js-spider
def request(flow: http.HTTPFlow) -> None:
    '''
    演示request事件效果, 请求的时候输出提示
    :param flow:
    :return:
    '''
    if flowfilter.match(filter_url, flow):
        print(flow.request.headers)
        print(u'ip')
    if flowfilter.match(filter_url1, flow):
        print(u'baidu')
コード例 #7
0
 def response(self, flow):
     """
     篡改 response返回数据
     :param flow:
     :return:
     """
     if flowfilter.match(self.globle_filter,
                         flow) or self.globle_filter is None:
         for rule in self.rules:
             if rule.get("filter"):
                 if flowfilter.match(rule.get("filter"), flow):
                     redirect_http(flow, rule, self.filepath)
             else:
                 redirect_http(flow, rule, self.filepath)
コード例 #8
0
    def response(self, flow):
        if flowfilter.match(self.new_fliter, flow):
            flow.response.replace(r'"gold":0', '"gold":999')

            text = flow.response.text
            data = json.loads(text)
            self.remain = data.get('data').get('cur_num')
            print_color('remain count:{}'.format(self.remain))

        if flowfilter.match(self.get_fliter, flow):
            if self.remain > 0 and len(self.urls) >= 2:
                flows = [f.copy() for f in self.flows]
                ctx.master.commands.call("replay.client", flows)
                time.sleep(0.2)
コード例 #9
0
ファイル: mitmdump.py プロジェクト: bolearnpython/js-spider
def response(flow: http.HTTPFlow) -> None:
    if flowfilter.match(filter_url, flow):
        flow.response.headers["server"] = "ip_nginx"
        flow.response.headers["newheader"] = "88888"
        reflector = b""
        flow.response.content = flow.response.content.replace(
            b"debugger", reflector)
        print(flow.response.content)
    if flowfilter.match(filter_url1, flow):
        flow.response.headers["server"] = "nginx"
        flow.response.headers["newheader"] = "99999"
        reflector = b""
        flow.response.content = flow.response.content.replace(
            b"debugger", reflector)
コード例 #10
0
    def request(self, flow):

        ip_filter = "~u %s" % self.host

        if flowfilter.match(ip_filter, flow):

            for req_head in flow.request.headers:
                self.request_header = f"{self.request_header}{req_head} : {flow.request.headers[req_head]}\n"
                # self.req_headers.append(req_head + ":" + flow.request.headers[req_head])

            self.req_data = [
                flow.id,
                str(datetime.datetime.now()),
                str(flow.request.host),
                str(f"{flow.request.url}||{flow.request.http_version}"),
                str(flow.request.method),
                # str(self.req_headers),
                str(self.request_header),  # new header logic
                str(flow.request.text),
            ]

            self.database.conn.execute(
                'INSERT INTO request VALUES (?,?,?,?,?,?,?)', self.req_data)

            del self.req_data[:]
            self.request_header = ''
コード例 #11
0
 def request(self, flow):
     host = flow.request.host
     if "authorization" in flow.request.headers:
         self.hosts[host] = flow.request.headers["authorization"]
     elif flowfilter.match(self.flt, flow):
         if host in self.hosts:
             flow.request.headers["authorization"] = self.hosts[host]
コード例 #12
0
 def request(self, flow):
     if flowfilter.match(self.filter, flow):
         url = flow.request.url
         if not url in self.urls:
             print_color(url)
             self.flows.append(flow)
             self.urls.add(url)
コード例 #13
0
    def response(self, flow):
        '''
        HTTPEvent 下面所有事件参数都是 flow 类型 HTTPFlow
        可以在API下面查到 HTTPFlow, 下面有一个属性response 类型 TTPResponse
        HTTPResponse 有个属性为 content 就是response内容,更多属性可以查看 文档
        :param flow: 
        :return: 
        '''

        if flowfilter.match(self.filter, flow):
            #匹配上后证明抓到的是问题了, 查答案
            data = flow.response.content
            quiz = json.loads(data)
            #获取问题,当前数据是模拟的,有可能和实际处理不一致
            question = quiz['quiz']
            print(question)

            #获取答案
            answer = self.answer_set.find_one({"quiz":question})
            if answer is None:
                print('no answer')
            else:
                answerIndex = int(answer['answer'])-1
                options = answer['options']
                print(options[answerIndex])
コード例 #14
0
 def request(self, flow):
     '''
     演示request事件效果, 请求的时候输出提示
     :param flow: 
     :return: 
     '''
     if flowfilter.match(self.filter,flow):
         print(u'准备请求答案')
コード例 #15
0
 def response(self, flow):
     if flowfilter.match(self.filter, flow):
         print("Flow matches filter:")
         print(flow)
     if (flow.server_conn.sni != None) & (str(flow.server_conn.sni).find(
             self.raw_filter) != -1):
         print("Flow matches SNI hostname:")
         print(flow)
コード例 #16
0
 def response(self, flow: http.HTTPFlow):
     if flowfilter.match(self.http_code_ok, flow):
         """只有 200 状态进入"""
         ctx.log('code %s' % flow.response.status_code)
         """匹配目标网址"""
         if flowfilter.match(self.MOVIE_path, flow):
             if flow.response.content:
                 pretty_path = str(flow.request.path.rstrip())
                 pretty_path = pretty_path.replace('/', '_') \
                     .replace(':', '_') \
                     .replace('&', '_')
                 pretty_path = pretty_path[:250] + '.json'
                 res_content = flow.response.content.decode('utf-8')
                 path = os.path.join(self.folder_path, pretty_path)
                 with open(path, 'w+', encoding='utf-8') as f:
                     f.write(str(res_content) + '\n')
                     print("保存成功")
コード例 #17
0
ファイル: baidu_mitm.py プロジェクト: zhoujie903/LearnPython
 def request(self, flow):
     if flowfilter.match(self.filter, flow):
         url = flow.request.url
         ctx.log.info(click.style(url, fg="red"))
         for pid in ['1', '4', '2', '6']:
             u = re.sub(r'productid=\d', 'productid={}'.format(pid), url)
             ctx.log.info(click.style(u, fg="red"))
             requests.get(u)
コード例 #18
0
    def get_nearest_matching_flow(self, flow, flt):
        fidx = self.view.index(flow)
        dist = 1

        fprev = fnext = True
        while fprev or fnext:
            fprev, _ = self.get_from_pos(fidx - dist)
            fnext, _ = self.get_from_pos(fidx + dist)

            if fprev and flowfilter.match(flt, fprev):
                return fprev
            elif fnext and flowfilter.match(flt, fnext):
                return fnext

            dist += 1

        return None
コード例 #19
0
ファイル: dumper.py プロジェクト: Yoginski/mitmproxy
 def match(self, f):
     if self.flow_detail == 0:
         return False
     if not self.filter:
         return True
     elif flowfilter.match(self.filter, f):
         return True
     return False
コード例 #20
0
ファイル: dumper.py プロジェクト: teneen/mitmproxy
 def match(self, f):
     if self.flow_detail == 0:
         return False
     if not self.filter:
         return True
     elif flowfilter.match(self.filter, f):
         return True
     return False
コード例 #21
0
ファイル: master.py プロジェクト: mkagenius/mitmproxy
    def get_nearest_matching_flow(self, flow, flt):
        fidx = self.view.index(flow)
        dist = 1

        fprev = fnext = True
        while fprev or fnext:
            fprev, _ = self.get_from_pos(fidx - dist)
            fnext, _ = self.get_from_pos(fidx + dist)

            if fprev and flowfilter.match(flt, fprev):
                return fprev
            elif fnext and flowfilter.match(flt, fnext):
                return fnext

            dist += 1

        return None
コード例 #22
0
ファイル: master.py プロジェクト: teneen/mitmproxy
 def _process_flow(self, f):
     should_intercept = (self.state.intercept
                         and flowfilter.match(self.state.intercept, f)
                         and not f.request.is_replay
                         and f.reply.state == "handled")
     if should_intercept:
         f.intercept(self)
     return f
コード例 #23
0
ファイル: master.py プロジェクト: teneen/mitmproxy
 def process_flow(self, f):
     should_intercept = (self.state.intercept
                         and flowfilter.match(self.state.intercept, f)
                         and not f.request.is_replay
                         and f.reply.state == "handled")
     if should_intercept:
         f.intercept(self)
     signals.flowlist_change.send(self)
     signals.flow_change.send(self, flow=f)
コード例 #24
0
class TNWZ:
    '''
    从抓包可以看到 问题包的链接最后是 findQuiz
    '''
    def __init__(self):
        #添加一个过滤器,只处理问题包
        self.filter = flowfilter.parse('~u findQuiz')
       #连接答案数据库
        self.conn = MongoClient('localhost', 27017)
        self.db = self.conn.tnwz
        self.answer_set = self.db.quizzes

    def request(self, flow):
        '''
        演示request事件效果, 请求的时候输出提示
        :param flow: 
        :return: 
        '''
        if flowfilter.match(self.filter,flow):
            print(u'准备请求答案')

    def responseheaders(self, flow):
         '''
        演示responseheaders事件效果, 添加头信息
        :param flow: 
        :return: 
        '''
        if flowfilter.match(self.filter, flow):
            flow.response.headers['Cache-Control'] = 'no-cache'
            flow.response.headers['Pragma'] = 'no-cache'

    def response(self, flow):
        '''
        HTTPEvent 下面所有事件参数都是 flow 类型 HTTPFlow
        可以在API下面查到 HTTPFlow, 下面有一个属性response 类型 TTPResponse
        HTTPResponse 有个属性为 content 就是response内容,更多属性可以查看 文档
        :param flow: 
        :return: 
        '''

        if flowfilter.match(self.filter, flow):
            #匹配上后证明抓到的是问题了, 查答案
            data = flow.response.content
            quiz = json.loads(data)
            #获取问题,当前数据是模拟的,有可能和实际处理不一致
            question = quiz['quiz']
            print(question)

            #获取答案
            answer = self.answer_set.find_one({"quiz":question})
            if answer is None:
                print('no answer')
            else:
                answerIndex = int(answer['answer'])-1
                options = answer['options']
                print(options[answerIndex])
コード例 #25
0
 def process_flow(self, f):
     should_intercept = any([
         self.state.intercept and flowfilter.match(self.state.intercept, f)
         and not f.request.is_replay,
         f.intercepted,
     ])
     if should_intercept:
         f.intercept(self)
     signals.flowlist_change.send(self)
     signals.flow_change.send(self, flow=f)
コード例 #26
0
ファイル: master.py プロジェクト: mkagenius/mitmproxy
 def process_flow(self, f):
     should_intercept = any(
         [
             self.state.intercept and flowfilter.match(self.state.intercept, f) and not f.request.is_replay,
             f.intercepted,
         ]
     )
     if should_intercept:
         f.intercept(self)
     signals.flowlist_change.send(self)
     signals.flow_change.send(self, flow=f)
コード例 #27
0
ファイル: Real_Time.py プロジェクト: ZhaoGuan/GZ_proxy
 def response(self, flow):
     match_result = flowfilter.match(self.filter_match, flow)
     # print(self.filter_match)
     print(match_result)
     if match_result:
         insert_realtime_data(flow.request.url, flow.request.method, flow.request.scheme, flow.request.host,
                              flow.request.port,
                              flow.request.path, flow.request.http_version, json.dumps(dict(flow.request.headers)),
                              flow.request.content,
                              flow.response.http_version, flow.response.status_code, flow.response.reason,
                              json.dumps(dict(flow.response.headers)),
                              flow.response.content, flow.response.text)
コード例 #28
0
ファイル: filter_flows.py プロジェクト: ZhaoGuan/GZ_proxy
 def response(self, flow: http.HTTPFlow) -> None:
     print(flow.request.url)
     # match = flowfilter.match('!(~u kika)', flow)
     match = flowfilter.match(None, flow)
     print(match)
     if match:
         print('!!!!!!!!!!!!!!!!!')
         # ctx.log.info("Flow matches filter:")
         # ctx.log.info(flow)
         print(flow.request.url)
         print('!!!!!!!!!!!!!!!!!')
     elif match == None:
         pass
コード例 #29
0
 def response(self, flow):
     content_new = ''
     #sys.stdout.write("Hello")
     f = open('sadu123.txt', 'a')
     if flowfilter.match(self.filter, flow):
         flow.intercept()
         content_old = (flow.response.content).decode()
         content_new = content_old + (2000 - len(content_old)) * ' '
         flow.response.content = flow.response.content.replace(
             content_old.encode(), content_new.encode())
         flow.resume()
         f.write(str(flow))  #print("Flow matches filter:")
     f.close()
コード例 #30
0
ファイル: recorder.py プロジェクト: five3/rapapi
    def response(self, flow):
        self.response_no += 1
        ctx.log.info(f"Response had received: {self.response_no}")
        ctx.log.info(f"capture url: {flow.request.url}")

        if flowfilter.match(self.filter,
                            flow) and flow.record_status == RecordStatus.START:
            for exclude in self.exclude_url_prefix:
                if exclude and exclude in flow.request.url:
                    ctx.log.info(f"skip for exclude: {exclude}")
                    return

            ctx.log.info(f"recording: {flow.request.url}")
            """
            Content Need Save as below:
                method, url, header, content 
            """
            request = flow.request
            headers = dict(request.headers)
            request_no = int(headers.pop('request_no'))
            request_data = {
                'method': request.method,
                'url': request.url,
                'headers': headers,
                'content': request.content,
                'text': request.text
            }
            """
            Content Need Save as below:
                status_code, reason, headers, content
            """
            response = flow.response
            response_no = self.response_no
            response_data = {
                'status_code': response.status_code,
                'reason': response.reason,
                'headers': dict(response.headers),
                'content': response.content,
                'text': response.text
            }

            mongo_util.save_record({
                'request_no': request_no,
                'request_data': request_data,
                'response_no': response_no,
                'response_data': response_data
            })
            self.index += 1
        elif flow.record_status == RecordStatus.STOP and self.index > 0:
            self.index = 0
コード例 #31
0
 def request(self, flow):
     
     ## Filter requests targeting the '/fhir' endpoint
     if flowfilter.match(self.filter, flow):
         method   = flow.request.method
         resource = flow.request.path.replace("/fhir", "")
         
         print(method, resource)
                     
         # if not self.redis.exists('methods'):
         #     print('No methods')
             
         
         self.redis.hincrby('resource:get:count', resource, 1)
コード例 #32
0
 def request(self, flow: http.HTTPFlow):
     if self.flt:
         cookie_list: List[Tuple[str, str]] = []
         if flowfilter.match(self.flt, flow):
             for (domain, port, path), c in self.jar.items():
                 match = [
                     domain_match(flow.request.host, domain),
                     flow.request.port == port,
                     flow.request.path.startswith(path)
                 ]
                 if all(match):
                     cookie_list.extend(c.items())
         if cookie_list:
             # FIXME: we need to formalise this...
             flow.metadata["stickycookie"] = True
             flow.request.headers["cookie"] = cookies.format_cookie_header(cookie_list)
コード例 #33
0
 def request(self, flow: http.HTTPFlow):
     if self.flt:
         cookie_list = []  # type: List[Tuple[str,str]]
         if flowfilter.match(self.flt, flow):
             for (domain, port, path), c in self.jar.items():
                 match = [
                     domain_match(flow.request.host, domain),
                     flow.request.port == port,
                     flow.request.path.startswith(path)
                 ]
                 if all(match):
                     cookie_list.extend(c.items())
         if cookie_list:
             # FIXME: we need to formalise this...
             flow.metadata["stickycookie"] = True
             flow.request.headers["cookie"] = cookies.format_cookie_header(cookie_list)
コード例 #34
0
    def test_match(self):
        f = tflow.twebsocketflow()
        assert not flowfilter.match("~b nonexistent", f)
        assert flowfilter.match(None, f)
        assert not flowfilter.match("~b nonexistent", f)

        f = tflow.twebsocketflow(err=True)
        assert flowfilter.match("~e", f)

        with pytest.raises(ValueError):
            flowfilter.match("~", f)
コード例 #35
0
    def test_match(self):
        f = tflow.twebsocketflow()
        assert not flowfilter.match("~b nonexistent", f)
        assert flowfilter.match(None, f)
        assert not flowfilter.match("~b nonexistent", f)

        f = tflow.twebsocketflow(err=True)
        assert flowfilter.match("~e", f)

        with pytest.raises(ValueError):
            flowfilter.match("~", f)
コード例 #36
0
ファイル: test_http.py プロジェクト: sjhgithub/mitmproxy-1
    def test_match(self):
        f = tflow.tflow(resp=True)
        assert not flowfilter.match("~b test", f)
        assert flowfilter.match(None, f)
        assert not flowfilter.match("~b test", f)

        f = tflow.tflow(err=True)
        assert flowfilter.match("~e", f)

        with pytest.raises(ValueError):
            flowfilter.match("~", f)
コード例 #37
0
 def request(self, flow):
     if self.flt:
         l = []
         if flowfilter.match(self.flt, flow):
             for domain, port, path in self.jar.keys():
                 match = [
                     domain_match(flow.request.host, domain),
                     flow.request.port == port,
                     flow.request.path.startswith(path)
                 ]
                 if all(match):
                     c = self.jar[(domain, port, path)]
                     l.extend([cookies.format_cookie_header(c[name].items(multi=True)) for name in c.keys()])
         if l:
             # FIXME: we need to formalise this...
             flow.request.stickycookie = True
             flow.request.headers["cookie"] = "; ".join(l)
コード例 #38
0
ファイル: test_flowfilter.py プロジェクト: s4chin/mitmproxy
def test_match():
    with pytest.raises(ValueError):
        flowfilter.match('[foobar', None)

    assert flowfilter.match(None, None)
    assert not flowfilter.match('foobar', None)
コード例 #39
0
ファイル: filter_flows.py プロジェクト: cortesi/mitmproxy
 def response(self, flow: http.HTTPFlow) -> None:
     if flowfilter.match(self.filter, flow):
         ctx.log.info("Flow matches filter:")
         ctx.log.info(flow)
コード例 #40
0
ファイル: filter_flows.py プロジェクト: MSwit/Spiele
 def response(self, flow):
     if flowfilter.match(self.filter, flow):
         print("Flow matches filter:")
         print(flow)
コード例 #41
0
ファイル: io.py プロジェクト: StevenVanAcker/mitmproxy
 def add(self, f: flow.Flow):
     if self.flt and not flowfilter.match(self.flt, f):
         return
     d = f.get_state()
     tnetstring.dump(d, self.fo)
コード例 #42
0
 def response(self, flow: http.HTTPFlow) -> None:
     if flowfilter.match(self.filter, flow):
         print("Flow matches filter:")
         print(flow)
コード例 #43
0
def request(flow) -> None:
    filter_ = flowfilter.parse(FLOW_FILTER)
    if flowfilter.match(filter_, flow):
        _logger.info("handle request: %s%s", flow.request.host, flow.request.path)
        request_handler = RequestHandler()
        request_handler(flow.request.path, flow)