Exemplo n.º 1
0
 def _regist_20(self, stix_package, community, via):
     try:
         StixFiles.objects.get(package_id=stix_package['id'])
         return False
     except DoesNotExist:
         _regist_stix(json.dumps(stix_package, indent=4), community, via)
         return True
Exemplo n.º 2
0
    def get_isight_stix(self, start_time=None, end_time=None):
        #登録情報を取得
        isight_adapter = isightAdapter.get()
        community = isight_adapter.community
        uploader = isight_adapter.uploader
        via = Vias.get_via_adapter_isight(uploader)
        try:
            #範囲内のリストを取得する
            l = self._get_isight_stix_report_list(start_time, end_time)
        except Exception as e:
            traceback.print_exc()
            raise e

        #last_requested更新
        isight_adapter.modify_last_requested()

        #リストの各要素をSTIXで取得してregistする
        count = 0
        for report_id in l:
            try:
                content = self._get_isight_stix_report(report_id)
                #ファイル登録
                #self._regist_isight_stix(content,community,via)
                _regist_stix(content, community, via)
                count += 1
            except Exception as e:
                #エラーが発生した場合はログを表示して処理は実行する
                traceback.print_exc()
        return count
Exemplo n.º 3
0
 def _regist_12(self, stix_package, community, via):
     try:
         StixFiles.objects.get(package_id=stix_package.id_)
         return False
     except DoesNotExist:
         _regist_stix(stix_package.to_xml(), community, via)
         return True
Exemplo n.º 4
0
    def get_misp_stix(self,
                      from_dt=None,
                      to_dt=None,
                      identity=default_identity_name):
        # identity を更新
        self.mc.identity_name = identity
        # misp アダプタの設定を取得
        misp_conf = MispAdapter.get()
        url = misp_conf.url
        stix_id_prefix = misp_conf.stix_id_prefix
        apikey = misp_conf.apikey
        published_only = misp_conf.published_only
        # 登録情報を取得
        community = misp_conf.community
        uploader = misp_conf.uploader
        via = Vias.get_via_adapter_misp(uploader)

        # mispから取得
        try:
            if url[-1] != '/':
                url += '/'
            url = url + 'events/xml/download.json'
            md = MISPDownloader(url, apikey)
            text = md.get(from_dt=from_dt, to_dt=to_dt)
            if text is None:
                return 0
            stix_packages = self.mc.convert(text=text.encode(),
                                            published_only=published_only,
                                            stix_id_prefix=stix_id_prefix)
        except Exception as e:
            traceback.print_exc()
            raise e

        # last_requested更新
        misp_conf.modify_last_requested()

        count = 0
        # ひとつずつ取得する
        for stix_package in stix_packages:
            try:
                # stix一つごとに登録処理
                # 取得したSTIXを登録
                try:
                    StixFiles.objects.get(package_id=stix_package.id_)
                except DoesNotExist:
                    # 存在しない場合は登録する
                    _regist_stix(stix_package.to_xml(), community, via)
                    count += 1
            except Exception as e:
                # エラーが発生した場合はログを表示して処理は実行する
                traceback.print_exc()

        # 件数を返却
        return count
Exemplo n.º 5
0
    def get_otx_stix(self, mtimestamp=None):
        # OTXアダプタの設定を取得
        otx_conf = OtxAdapter.get()
        key = otx_conf.apikey
        # 登録情報を取得
        community = otx_conf.community
        uploader = otx_conf.uploader
        via = Vias.get_via_adapter_otx(uploader)

        # otxから取得
        try:
            proxies = System.get_request_proxies()
            otx = OTXv2(key, proxies)
            slices = otx.getsince(mtimestamp)
        except Exception as e:
            traceback.print_exc()
            raise e

        # last_requested更新
        otx_conf.modify_last_requested()

        count = 0
        # ひとつずつ取得する
        for slice_ in slices:
            try:
                # stix一つごとに登録処理
                stix = StixExport(slice_)
                stix.build()
                content = stix.to_xml()
                # 取得したSTIXを登録
                _regist_stix(content, community, via)
                count += 1
            except Exception as e:
                # エラーが発生した場合はログを表示して処理は実行する
                traceback.print_exc()
        # 件数を返却
        return count