2019-11-22 17:36:24 +01:00
|
|
|
#!/usr/bin/env python3
|
2024-01-17 13:13:14 +01:00
|
|
|
|
|
|
|
from __future__ import annotations
|
2019-11-22 17:36:24 +01:00
|
|
|
|
|
|
|
from pathlib import Path
|
|
|
|
from pymisp import MISPEvent
|
|
|
|
import json
|
2020-01-23 10:27:40 +01:00
|
|
|
from typing import List
|
2019-11-22 17:36:24 +01:00
|
|
|
|
|
|
|
|
|
|
|
def feed_meta_generator(path: Path):
|
|
|
|
manifests = {}
|
2024-01-17 13:13:14 +01:00
|
|
|
hashes: list[str] = []
|
2019-11-22 17:36:24 +01:00
|
|
|
|
|
|
|
for f_name in path.glob('*.json'):
|
|
|
|
if str(f_name.name) == 'manifest.json':
|
|
|
|
continue
|
|
|
|
event = MISPEvent()
|
|
|
|
event.load_file(str(f_name))
|
|
|
|
manifests.update(event.manifest)
|
|
|
|
hashes += [f'{h},{event.uuid}' for h in event.attributes_hashes('md5')]
|
|
|
|
|
|
|
|
with (path / 'manifest.json').open('w') as f:
|
|
|
|
json.dump(manifests, f)
|
|
|
|
|
|
|
|
with (path / 'hashes.csv').open('w') as f:
|
|
|
|
for h in hashes:
|
|
|
|
f.write(f'{h}\n')
|