def list(hid=None):
     data = Vulnerability.list_vulnerability(hid=hid)
     try:
         format_data = Vulnerability.format_source_module(data)
     except Exception as E:
         format_data = data
         logger.error(E)
     context = list_data_return(200, CODE_MSG.get(200), format_data)
     return context
    def list_by_hid(hid=None):
        orm_models = PortServiceModel.objects.filter(hid=hid).order_by('port')
        data = PortServiceSerializer(orm_models, many=True).data

        try:
            format_data = PortService.format_banner(data)
        except Exception as E:
            format_data = data
            logger.error(E)
        return format_data
 def list():
     orm_models = CredentialModel.objects.all().order_by('username')
     data = CredentialSerializer(orm_models, many=True).data
     try:
         format_data = Credential.format_tag(data)
     except Exception as E:
         format_data = data
         logger.error(E)
     context = list_data_return(200, CODE_MSG.get(200), format_data)
     return context
Esempio n. 4
0
 def get_ipaddress(hid):
     """查找一个ipaddress的hid"""
     result = CoreHost.get_by_hid(hid)
     if result is not None:
         try:
             return result.get('ipaddress')
         except Exception as E:
             logger.error(E)
             return None
     else:
         return None
def register_options(options_list=None):
    """注册参数"""
    if options_list is None:
        options_list = []
    options = []
    try:
        for option in options_list:
            options.append(option.to_dict())
        return options
    except Exception as E:
        logger.error(E)
        return []
 def add_or_update(hid=None,
                   source_module_loadpath=None,
                   extra_data=None,
                   desc=None):
     default_dict = {
         'hid': hid,
         'source_module_loadpath': source_module_loadpath,
         'extra_data': extra_data,
         'desc': desc,
         'update_time': int(time.time())
     }  # 没有此主机数据时新建
     model, created = VulnerabilityModel.objects.get_or_create(
         hid=hid,
         source_module_loadpath=source_module_loadpath,
         extra_data=extra_data,
         defaults=default_dict)
     if created is True:
         return True  # 新建后直接返回
     # 有历史数据
     with transaction.atomic():
         try:
             model = VulnerabilityModel.objects.select_for_update().get(
                 hid=hid,
                 source_module_loadpath=source_module_loadpath,
                 extra_data=extra_data,
             )
             model.hid = hid
             model.source_module_loadpath = source_module_loadpath
             model.update_time = int(time.time())
             model.extra_data = extra_data
             model.desc = desc
             model.save()
             return True
         except Exception as E:
             logger.error(E)
             return False