예제 #1
0
def download_stix_id(command_stix_id):
    wc = StipSnsBoot.get_slack_web_client()
    # cache の STIX を返却
    stix_file_path = Feed.get_cached_file_path(
        command_stix_id.replace(':', '--'))
    file_name = '%s.xml' % (command_stix_id)
    post_slack_channel = SNSConfig.get_slack_bot_chnnel()
    wc.files_upload(initial_comment='',
                    channels=post_slack_channel,
                    file=open(stix_file_path, 'rb'),
                    filename=file_name)
    return
예제 #2
0
def download_stix(request):
    feed_file_name_id = request.GET['feed_id']
    # cache の STIX を返却
    stix_file_path = Feed.get_cached_file_path(feed_file_name_id)
    # response作成
    file_name = '%s.xml' % (feed_file_name_id)
    with open(stix_file_path, 'r', encoding='utf-8') as fp:
        output = io.StringIO()
        output.write(fp.read())
        response = HttpResponse(output.getvalue(),
                                content_type='application/xml')
        response['Content-Disposition'] = 'attachment; filename=%s' % (
            file_name)
    return response
예제 #3
0
def create_sighting_object(request):
    try:
        package_id = request.GET['package_id']
        feed_id = request.GET['feed_id']
        value_ = request.GET['value']
        type_ = request.GET['type']
        count = int(request.GET['count'])
        first_seen = request.GET['first_seen']
        last_seen = request.GET['last_seen']
        observable_id = request.GET['observable_id']

        stip_user = request.user
        feed = Feed.get_feeds_from_package_id(stip_user, package_id)
        stix_file_path = Feed.get_cached_file_path(feed_id)
        stix2 = stip_sighting.convert_to_stix2_from_stix_file_path(
            stix_file_path)

        stix2 = stip_sighting.insert_sighting_object(stix2, type_, value_,
                                                     observable_id, count,
                                                     first_seen, last_seen,
                                                     stip_user)

        stix2_str = stix2.serialize(True, ensure_ascii=False)

        _, stix2_file_path = tempfile.mkstemp()
        with open(stix2_file_path, 'w', encoding='utf-8') as fp:
            fp.write(stix2_str)
        # RS に登録する
        rs.regist_ctim_rs(feed.user, stix2.id, stix2_file_path)
        os.remove(stix2_file_path)

        file_name = '%s.json' % (stix2.id)
        output = io.StringIO()
        output.write(str(stix2_str))
        response = HttpResponse(output.getvalue(),
                                content_type='application/json')
        response['Content-Disposition'] = 'attachment; filename=%s' % (
            file_name)
        return response
    except Exception as e:
        traceback.print_exc()
        return HttpResponseServerError(str(e))
예제 #4
0
def get_feed_stix(feed_file_name_id):
    stix_file_path = Feed.get_cached_file_path(feed_file_name_id)
    return FeedStix(stix_file_path=stix_file_path)