Beispiel #1
0
 def call_task(kind, kwargs, expires=3600):
     """用于建立task任务"""
     logger.info("建立任务,kind: {} kwargs:{}".format(kind, kwargs))
     try:
         task_instance = CeleryTask._get_celery_task_instance(kind)
         result = task_instance.apply_async(kwargs=kwargs, expires=expires)
         return result.task_id
     except Exception as E:
         logger.error("未找到对应的任务实例,kind: {} Except:{}".format(kind, E))
         return None
Beispiel #2
0
 def _sub_domain_store(pid, retval):
     logger.info("subdomain 存储结果: {} {}".format(pid, retval))
     domain = retval.get('domain')
     subdomains = retval.get('subdomain')
     try:
         for website in subdomains:
             Website.update_website(pid=pid, domain=domain, website=website)
     except Exception as E:
         logger.error("存储结果失败,异常: {}".format(E))
         return False
     return True
Beispiel #3
0
    def _port_scan_store(pid, retval):
        logger.info("portscan 存储结果: {} {}".format(pid, retval))
        format_result = {}
        scanResult = retval.get('result')
        domain = retval.get('domain')
        try:
            for one in scanResult:
                if one.get('data').get('error') is None:
                    if one.get('data').get('versioninfo') is None:
                        info = {}
                    else:
                        info = one.get('data').get('versioninfo')
                    if format_result.get(one.get('ipaddress')) is None:

                        format_result[one.get('ipaddress')] = [{'port': one.get('port'),
                                                                'service': one.get('data').get('service'),
                                                                'info': info
                                                                }]
                    else:
                        format_result[one.get('ipaddress')].append({'port': one.get('port'),
                                                                    'service': one.get('data').get('service'),
                                                                    'info': info
                                                                    })
                else:  # 扫描中包含错误
                    pass
            for ipaddress in format_result:
                ipaddress_update_result = IPaddress.update_ipaddress(pid=pid, ipaddress=ipaddress, domain=domain)
                ipid = ipaddress_update_result.get('id')
                ports = format_result.get(ipaddress)
                for port in ports:
                    port_update_result = Port.update_port(ipid=ipid,
                                                          port=port.get('port'),
                                                          service=port.get('service'),
                                                          info=port.get('info'))
                    # 更新
                    webServiceList = ['http', 'https']
                    if port.get('service') in webServiceList:
                        # 更新web服务到website
                        websiteWithIPaddress = "{}:{}".format(ipaddress, port.get('port'))
                        Website.update_website(pid=pid, domain=domain, website=websiteWithIPaddress)



        except Exception as E:
            logger.error("存储结果失败,异常: {}".format(E))
            return False
        return True
Beispiel #4
0
 def get_celery_result_scheduler(self):
     """循环调用函数,用于处理celery结果"""
     try:
         msg = self.redis_celery_result_sub.parse_response()
     except Exception as E:
         logger.warning("redis连接错误")
         return False
     try:
         result = json.loads(msg[2])
         task_id = result.get('task_id')
         status = result.get('status')
         retval = result.get('retval')
         einfo = result.get('einfo')
         logger.info("开始存储任务结果,task_id: {}".format(task_id))
         flag = Task.update_task(task_id=task_id,
                                 status=status,
                                 retval=retval,
                                 einfo=einfo)
         logger.info("存储任务完成,task_id: {}".format(task_id))
         return True
     except Exception as E:
         logger.warning("json解析task结果失败,详细信息: {} 异常:{}".format(msg, E))
Beispiel #5
0
 def _webcheck_store(pid, retval):
     logger.info("wafw00f 存储结果: {} {}".format(pid, retval))
     for one in retval:
         website = one.get('website')
         wid = Website.get_wid_by_website(pid, website)
         if wid is None:
             logger.warning("数据库中无法找到网站:{}".format(website))
             continue
         else:
             # 更新网站存活信息
             Website.update_website_alive(wid, one.get('alive'))
             # 更新cdn信息
             WebsiteCDN.update_website_cdn(wid=wid, hascdn=one.get('hascdn'), ipaddress=one.get('ipaddress'),
                                           title=one.get('title'))
             # 更新techs信息
             techs = one.get('techs')
             for tech in techs:
                 WebsiteTech.update_website_tech(wid=wid, name=tech.get('name'), version=tech.get('version'),
                                                 icon=tech.get('icon'))
             # 更新waf信息
             waf = one.get('waf')
             WebsiteWaf.update_website_waf(wid=wid, hasWaf=waf.get('haswaf'), waf=waf.get('waf'),
                                           detect_tech=waf.get('detectTech'))
     return True