Example #1
0
def check_url(task_id, task_access_key):
    """
    接收来自浏览器的流量,对流量进行解析分类之后,存放到redis中,支持多个用户同时协作对一个任务进行测试
    
    :param task_id: 
    :param task_access_key: 
    :return: 
    """
    from common.config_util import get_system_config
    try:
        post_data = request.get_json(force=True)
        current_user_name = session["user_name"]

        if TaskService.count(where=(Task.id == task_id,
                                    Task.access_key == task_access_key)) == 0:
            return jsonify(status=403,
                           message="发送失败",
                           data={
                               "extra_info":
                               "taskid或者accesskey不正确,插件请同步一次最新任务",
                               "site":
                               get_system_config()['front_end']['index']
                           })
        tasks = TaskService.get_fields_by_where(
            where=(Task.id == task_id, Task.access_key == task_access_key))

        if tasks[0].task_status in [TaskStatus.DONE, TaskStatus.KILLED]:
            return jsonify(status=400,
                           message="发送失败",
                           data={
                               "extra_info": "该任务已经结束,客户端请重新同步或者创建最新任务",
                               "site":
                               get_system_config()['front_end']['index']
                           })

        if post_data is not None and "data" in post_data and RedisService.create_urlclassifications(
                task_id, post_data):
            raw_request_data = post_data.get('data', '{}')
            scan_celery.delay(raw_request_data, task_id, current_user_name,
                              TaskStatus.NONE)
            return jsonify(status=200,
                           message="发送成功",
                           data={"extra_info": "发送到后端扫描引擎成功"})

        return jsonify(status=200,
                       message="发送失败",
                       data={"extra_info": "发送到后端引擎的数据不符合格式或者已经发送过"})

    except Exception as e:
        logger.exception("check_url exception")
        return jsonify(status=500,
                       message="未知异常",
                       data={"extra_info": "创建任务时出现未知异常,请联系管理员查看异常日志"})
Example #2
0
    def request_handler(self, request, user_info):
        """
        将请求发送到MQ中
        :param request: 
        :return: 
        Simple example code:

        print(request.body_arguments)
        print(request.headers)
        print(request.body)
        print(request.cookies)
        print(request.version)
        print(request.protocol)
        print(request.host_name)
        print(request.uri)
        print(request.method)
        """
        if not user_info:
            return
        task_id = user_info.current_task_id
        current_user_name = user_info.user_name
        raw_request_data = self.wrap_request(request, user_info)

        # 是否为满足条件的请求
        current_task = RedisService.get_task(task_id)
        if current_task and "hook_rule" in current_task:
            # *.xx.com
            hook_rule = str(current_task.hook_rule).replace("*", ".*")
            if not str(raw_request_data["data"]
                       ["url"]).startswith(hook_rule) and re.match(
                           r'' + hook_rule, raw_request_data["data"]["url"],
                           re.S) is None:
                return

        if RedisService.create_urlclassifications(task_id, raw_request_data):
            logger.info("满足正则条件,发送流量到MQ中")
            scan_celery.delay(raw_request_data["data"], task_id,
                              current_user_name, TaskStatus.NONE)