Ejemplo n.º 1
0
def create_the_hive_alert(source, item_id, tag):
    # # TODO: check items status (processed by all modules)
    # # TODO: add item metadata: decoded content, link to auto crawled content, pgp correlation, cryptocurrency correlation...
    # # # TODO: description, add AIL link:show items ?
    tags = list(r_serv_metadata.smembers('tag:{}'.format(item_id)))

    artifacts = [
        AlertArtifact(dataType='uuid-ail', data=r_serv_db.get('ail:uuid')),
        AlertArtifact(dataType='file',
                      data=item_basic.get_item_filepath(item_id),
                      tags=tags)
    ]

    # Prepare the sample Alert
    sourceRef = str(uuid.uuid4())[0:6]
    alert = Alert(title='AIL Leak',
                  tlp=3,
                  tags=tags,
                  description='AIL Leak, triggered by {}'.format(tag),
                  type='ail',
                  source=source,
                  sourceRef=sourceRef,
                  artifacts=artifacts)

    # Create the Alert
    id = None
    try:
        response = HiveApi.create_alert(alert)
        if response.status_code == 201:
            #print(json.dumps(response.json(), indent=4, sort_keys=True))
            print('Alert Created')
            print('')
            id = response.json()['id']
        else:
            print('ko: {}/{}'.format(response.status_code, response.text))
            return 0
    except:
        print('hive connection error')
Ejemplo n.º 2
0
def get_item_filepath(item_id):
    return item_basic.get_item_filepath(item_id)
Ejemplo n.º 3
0
def create_the_hive_alert(source, item_id, tag):
    # # TODO: check items status (processed by all modules)
    # # TODO: add item metadata: decoded content, link to auto crawled content, pgp correlation, cryptocurrency correlation...
    # # # TODO: description, add AIL link:show items ?
    tags = list(r_serv_metadata.smembers('tag:{}'.format(item_id)))

    path = item_basic.get_item_filepath(item_id)
    paste_handle = open(path, 'rb')
    paste_data = paste_handle.read()
    tmp_path = None

    if is_gzip_file(paste_data[0:2]
                    ):  # if gzip, create a new file to supply to TheHive
        paste_handle.close(
        )  # TheHive expects a file handle, that's why we create a new file
        tmp_data = gzip.decompress(paste_data)
        tmp_path = path + '.unzip'
        with open(tmp_path, 'wb+') as f:
            f.write(tmp_data)
        paste_handle = open(tmp_path, 'rb')
        if path.endswith(
                ".gz"
        ):  # remove .gz from submitted path to TheHive beause we've decompressed it
            path = path[:-3]

    path = os.path.basename(
        os.path.normpath(path)
    ) + ".txt"  # get last part of path, add .txt so it's easier to open when downloaded from TheHive

    artifacts = [
        AlertArtifact(dataType='uuid-ail', data=r_serv_db.get('ail:uuid')),
        AlertArtifact(dataType='file', data=(paste_handle, path), tags=tags)
    ]

    # Prepare the sample Alert
    sourceRef = str(uuid.uuid4())[0:6]
    alert = Alert(title='AIL Leak',
                  tlp=3,
                  tags=tags,
                  description='AIL Leak, triggered by {}'.format(tag),
                  type='ail',
                  source=source,
                  sourceRef=sourceRef,
                  artifacts=artifacts)

    # Create the Alert
    id = None
    try:
        response = HiveApi.create_alert(alert)
        if response.status_code == 201:
            #print(json.dumps(response.json(), indent=4, sort_keys=True))
            print('Alert Created')
            print('')
            id = response.json()['id']
        else:
            print('ko: {}/{}'.format(response.status_code, response.text))
            return 0
    except:
        print('hive connection error')

    paste_handle.close()
    if tmp_path is not None:  # this file has been send to TheHive, we won't ever need it again
        os.remove(tmp_path)