Esempio n. 1
0
    def _get_ip_domain_list(self, target_lists):
        ip_list = set()
        domain_list = set()
        for item in target_lists:
            if not item:
                continue

            if utils.is_vaild_ip_target(item):
                if not utils.not_in_black_ips(item):
                    raise Exception("{} 在黑名单IP中".format(item))
                ip_list.add(item)

            elif utils.is_valid_domain(item):
                domain_list.add(item)

            else:
                raise Exception("{} 无效的目标".format(item))

        return ip_list, domain_list
Esempio n. 2
0
    def run(self):
        target_temp_list = []
        for info in self.ip_info_list:
            if isinstance(info, modules.IPInfo):
                for port_info in info.port_info_list:
                    port_id = port_info.port_id
                    if port_id == 80:
                        continue

                    target_temp1 = "{}:{}".format(info.ip, port_id)
                    target_temp_list.append(target_temp1)

            elif isinstance(info, str) and utils.is_vaild_ip_target(info):
                target_temp_list.append("{}:443".format(info))

            elif isinstance(info, str) and ":" in info:
                target_temp_list.append(info)

        cert_map = services.fetch_cert(target_temp_list)

        for target in cert_map:
            pass

        return cert_map
Esempio n. 3
0
    def post(self):
        """
        任务提交
        """
        args = self.parse_args(add_task_fields)

        name = args.pop('name')
        target = args.pop('target')
        target = target.strip().lower()

        task_data = {
            "name": name,
            "target": target,
            "start_time": "-",
            "end_time": "-",
            "task_tag": "task",  #标记为正常下发的任务
            "service": [],
            "status": "waiting",
            "options": args,
            "type": "domain"
        }

        logger.info(task_data)

        target_lists = re.split(r",|\s", target)
        # 清除空白符
        target_lists = list(filter(None, target_lists))
        ip_target_list = []
        ret_items = []

        for item in target_lists:
            if not utils.is_valid_domain(
                    item) and not utils.is_vaild_ip_target(item):
                return utils.build_ret(ErrorMsg.TargetInvalid,
                                       data={"target": item})

            if utils.is_vaild_ip_target(item):
                if not utils.not_in_black_ips(item):
                    return utils.build_ret(ErrorMsg.IPInBlackIps,
                                           data={"ip": item})

        for item in target_lists:
            if utils.is_valid_domain(item):
                ret_item = {"target": item, "type": "domain"}
                domain_task_data = task_data.copy()
                domain_task_data["target"] = item
                _task_data = submit_task(domain_task_data)
                ret_item["task_id"] = _task_data.get("task_id", "")
                ret_item["celery_id"] = _task_data.get("celery_id", "")
                ret_items.append(ret_item)

            elif utils.is_vaild_ip_target(item):
                if utils.not_in_black_ips(item):
                    ip_target_list.append(item)
                else:
                    ret_item = {
                        "target": item,
                        "type": "in black ip list",
                        "task_id": "",
                        "celery_id": ""
                    }
                    ret_items.append(ret_item)

            else:
                ret_item = {
                    "target": item,
                    "type": "unknown",
                    "task_id": "",
                    "celery_id": ""
                }
                ret_items.append(ret_item)

        if ip_target_list:
            ip_task_data = task_data.copy()
            ip_task_data["target"] = " ".join(ip_target_list)
            ip_task_data["type"] = "ip"

            ret_item = {
                "target": ip_task_data["target"],
                "type": ip_task_data["type"]
            }

            _task_data = submit_task(ip_task_data)

            ret_item["task_id"] = _task_data.get("task_id", "")
            ret_item["celery_id"] = _task_data.get("celery_id", "")
            ret_items.append(ret_item)

        ret_data = {
            "items": ret_items,
            "options": args,
            "message": "success",
            "code": 200
        }

        return ret_data