mirror of
https://github.com/MISP/misp-galaxy.git
synced 2024-11-22 23:07:19 +00:00
Add [agencies] refs
This commit is contained in:
parent
0d26334448
commit
bb28408b14
5 changed files with 4751 additions and 33 deletions
4689
clusters/intelligence-agencies.json
Normal file
4689
clusters/intelligence-agencies.json
Normal file
File diff suppressed because it is too large
Load diff
9
galaxies/intelligence-agencies.json
Normal file
9
galaxies/intelligence-agencies.json
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
{
|
||||||
|
"description": "List of intelligence agencies",
|
||||||
|
"icon": "ninja",
|
||||||
|
"name": "intelligence-agencies",
|
||||||
|
"namespace": "intelligence-agency",
|
||||||
|
"type": "intelligence-agency",
|
||||||
|
"uuid": "3ef969e7-96cd-4048-aa83-191ac457d0db",
|
||||||
|
"version": 1
|
||||||
|
}
|
0
tools/WikipediaAPI/lol.html
Normal file
0
tools/WikipediaAPI/lol.html
Normal file
|
@ -3,19 +3,19 @@ from modules.intel import IntelAgency, Meta, Galaxy, Cluster
|
||||||
import os
|
import os
|
||||||
import uuid
|
import uuid
|
||||||
import json
|
import json
|
||||||
import re
|
|
||||||
|
|
||||||
from bs4 import BeautifulSoup
|
from bs4 import BeautifulSoup
|
||||||
|
|
||||||
CLUSTER_PATH = '../../clusters'
|
CLUSTER_PATH = '../../clusters'
|
||||||
GALAXY_PATH = '../../galaxies'
|
GALAXY_PATH = '../../galaxies'
|
||||||
GALAXY_NAME = 'intelligence-agencies'
|
GALAXY_NAME = 'intelligence-agencies'
|
||||||
UUID = str(uuid.uuid4())
|
UUID = "3ef969e7-96cd-4048-aa83-191ac457d0db"
|
||||||
|
WIKIPEDIA_URL = "https://en.wikipedia.org"
|
||||||
|
|
||||||
def get_UUIDs():
|
def get_UUIDs():
|
||||||
if GALAXY_NAME in os.listdir(CLUSTER_PATH):
|
if f"{GALAXY_NAME}.json" in os.listdir(CLUSTER_PATH):
|
||||||
uuids = {}
|
uuids = {}
|
||||||
with open(os.path.join(CLUSTER_PATH, GALAXY_NAME)) as fr:
|
with open(os.path.join(CLUSTER_PATH, f"{GALAXY_NAME}.json")) as fr:
|
||||||
galaxy_json = json.load(fr)
|
galaxy_json = json.load(fr)
|
||||||
for cluster in galaxy_json["values"]:
|
for cluster in galaxy_json["values"]:
|
||||||
uuids[cluster["value"]] = cluster["uuid"]
|
uuids[cluster["value"]] = cluster["uuid"]
|
||||||
|
@ -28,18 +28,29 @@ def get_notes_on_lower_level(content):
|
||||||
if li.find('ul'):
|
if li.find('ul'):
|
||||||
notes.extend(get_notes_on_lower_level(li.find('ul')))
|
notes.extend(get_notes_on_lower_level(li.find('ul')))
|
||||||
else:
|
else:
|
||||||
notes.append(li.text)
|
a_tag = li.find('a')
|
||||||
|
|
||||||
|
title = li.text
|
||||||
|
link_href = None
|
||||||
|
description = li.text
|
||||||
|
|
||||||
|
if a_tag:
|
||||||
|
title = a_tag.get('title', description)
|
||||||
|
if a_tag.has_attr('href'):
|
||||||
|
link_href = f'{WIKIPEDIA_URL}{a_tag["href"]}'
|
||||||
|
|
||||||
|
notes.append((title, link_href, description, None))
|
||||||
return notes
|
return notes
|
||||||
|
|
||||||
def get_agencies_from_country(heading, current_country, uuids):
|
def get_agencies_from_country(heading, current_country, uuids):
|
||||||
agencies = []
|
agencies = []
|
||||||
content = heading.find_next('ul')
|
content = heading.find_next('ul')
|
||||||
agency_names = get_notes_on_lower_level(content)
|
agency_names = get_notes_on_lower_level(content)
|
||||||
for name in agency_names:
|
for name, links, description, synonyms in agency_names:
|
||||||
if uuids and name in uuids:
|
if uuids and name in uuids:
|
||||||
agencies.append(IntelAgency(value=name, uuid=uuids[name], meta=Meta(country=current_country)))
|
agencies.append(IntelAgency(value=name, uuid=uuids[name], meta=Meta(country=current_country, refs=[links]), description=description))
|
||||||
else:
|
else:
|
||||||
agencies.append(IntelAgency(value=name, meta=Meta(country=current_country), uuid=str(uuid.uuid4())))
|
agencies.append(IntelAgency(value=name, meta=Meta(country=current_country, refs=[links]), uuid=str(uuid.uuid4()), description=description))
|
||||||
return agencies
|
return agencies
|
||||||
|
|
||||||
def extract_info(content, uuids):
|
def extract_info(content, uuids):
|
||||||
|
@ -93,6 +104,5 @@ if __name__ == '__main__':
|
||||||
)
|
)
|
||||||
for agency in agencies:
|
for agency in agencies:
|
||||||
cluster.add_value(agency)
|
cluster.add_value(agency)
|
||||||
print(cluster.values)
|
|
||||||
print(cluster.uuid)
|
|
||||||
cluster.save_to_file(os.path.join(CLUSTER_PATH, f'{GALAXY_NAME}.json'))
|
cluster.save_to_file(os.path.join(CLUSTER_PATH, f'{GALAXY_NAME}.json'))
|
||||||
|
|
|
@ -1,9 +1,30 @@
|
||||||
from dataclasses import dataclass, field, asdict
|
from dataclasses import dataclass, field, asdict, is_dataclass
|
||||||
import json
|
import json
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class Meta:
|
class Meta:
|
||||||
country: str = ""
|
country: str = ""
|
||||||
|
refs: list = field(default_factory=list)
|
||||||
|
synonyms: list = field(default_factory=list)
|
||||||
|
|
||||||
|
def custom_asdict(obj):
|
||||||
|
if is_dataclass(obj):
|
||||||
|
result = {}
|
||||||
|
for field_name, field_def in obj.__dataclass_fields__.items():
|
||||||
|
value = getattr(obj, field_name)
|
||||||
|
if field_name == 'meta':
|
||||||
|
meta_value = custom_asdict(value)
|
||||||
|
meta_value = {k: v for k, v in meta_value.items() if not (k in ['refs', 'synonyms'] and (not v or all(e is None for e in v)))}
|
||||||
|
value = meta_value
|
||||||
|
elif isinstance(value, (list, tuple)) and all(is_dataclass(i) for i in value):
|
||||||
|
value = [custom_asdict(i) for i in value]
|
||||||
|
elif isinstance(value, list) and all(e is None for e in value):
|
||||||
|
continue
|
||||||
|
result[field_name] = value
|
||||||
|
return result
|
||||||
|
else:
|
||||||
|
return obj
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class IntelAgency:
|
class IntelAgency:
|
||||||
|
@ -34,31 +55,20 @@ class Galaxy:
|
||||||
file.write(json.dumps(asdict(self), indent=4))
|
file.write(json.dumps(asdict(self), indent=4))
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class Cluster():
|
class Cluster:
|
||||||
def __init__(
|
authors: str
|
||||||
self,
|
category: str
|
||||||
authors: str,
|
description: str
|
||||||
category: str,
|
name: str
|
||||||
description: str,
|
source: str
|
||||||
name: str,
|
type: str
|
||||||
source: str,
|
uuid: str
|
||||||
type: str,
|
version: int
|
||||||
uuid: str,
|
values: list = field(default_factory=list)
|
||||||
version: int,
|
|
||||||
):
|
|
||||||
self.authors = authors
|
|
||||||
self.category = category
|
|
||||||
self.description = description
|
|
||||||
self.name = name
|
|
||||||
self.source = source
|
|
||||||
self.type = type
|
|
||||||
self.uuid = uuid
|
|
||||||
self.version = version
|
|
||||||
self.values = []
|
|
||||||
|
|
||||||
def add_value(self, value: IntelAgency):
|
def add_value(self, value: IntelAgency):
|
||||||
self.values.append(value)
|
self.values.append(value)
|
||||||
|
|
||||||
def save_to_file(self, path: str):
|
def save_to_file(self, path: str):
|
||||||
with open(path, "w") as file:
|
with open(path, "w") as file:
|
||||||
file.write(json.dumps(asdict(self), indent=4))
|
file.write(json.dumps(custom_asdict(self), indent=4, ensure_ascii=False))
|
Loading…
Reference in a new issue