Spaces:
Sleeping
Sleeping
Upload 8 files
Browse files- README.md +47 -14
- alerting.py +70 -0
- app.py +83 -0
- customization.py +47 -0
- input_processing.py +51 -0
- models.py +41 -0
- requirements.txt +8 -0
- threat_intelligence.py +72 -0
README.md
CHANGED
@@ -1,14 +1,47 @@
|
|
1 |
-
|
2 |
-
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Cybersecurity AI Platform
|
2 |
+
|
3 |
+
## Overview
|
4 |
+
|
5 |
+
The Cybersecurity AI Platform is a comprehensive solution designed to harness the power of advanced open-source AI models, including large language models (LLMs), small language models (SLMs), and cybersecurity-specific AI models available on the Hugging Face Hub. The platform provides robust capabilities for threat detection, anomaly detection, and vulnerability assessment, making it an essential tool for cybersecurity professionals.
|
6 |
+
|
7 |
+
## Features
|
8 |
+
|
9 |
+
- **Integration of advanced AI models**: Utilize state-of-the-art AI models such as `gpt-3`, `bert-base-uncased`, `roberta-large`, `distilbert-base-uncased`, `albert-base-v2`, `tinybert`, `cybersecurity-bert`, `malware-detection-bert`, and `phishing-detection-bert`.
|
10 |
+
- **User-friendly interface with Gradio**: Develop an intuitive and user-friendly interface using Gradio to interact with the AI models, providing various input options such as text, file uploads, and real-time data streams for analysis.
|
11 |
+
- **Real-time monitoring and alerting**: Implement real-time monitoring capabilities to continuously analyze network traffic and system logs for potential threats, with customizable alert thresholds and notification methods.
|
12 |
+
- **Modular architecture**: Implement a modular architecture to allow easy integration and updating of AI models, input processing modules, and alerting and monitoring modules.
|
13 |
+
- **Integration with external threat intelligence feeds**: Fetch real-time data on emerging threats, vulnerabilities, and attack patterns from external threat intelligence services and open-source platforms like MISP and OpenCTI.
|
14 |
+
- **User customization options**: Allow users to set specific thresholds for different types of alerts, customize notification methods, and enable or disable specific AI models based on their requirements.
|
15 |
+
|
16 |
+
## Setup and Deployment
|
17 |
+
|
18 |
+
To set up and deploy the Cybersecurity AI Platform on Hugging Face Spaces, follow these steps:
|
19 |
+
|
20 |
+
1. **Create a Hugging Face account**: Sign up for a Hugging Face account if you don't already have one.
|
21 |
+
2. **Set up a new Space**: Go to the Hugging Face Spaces page and create a new Space. Choose the appropriate template for your project (e.g., Gradio).
|
22 |
+
3. **Clone the repository**: Clone the `githubnext/workspace-blank` repository to your local machine.
|
23 |
+
4. **Install dependencies**: Ensure you have all the necessary dependencies installed, including Gradio and the required AI models from Hugging Face Hub.
|
24 |
+
5. **Develop the platform**: Implement the cybersecurity AI platform as described in the task, including integrating AI models, creating the Gradio interface, and setting up real-time monitoring and alerting.
|
25 |
+
6. **Test the platform**: Thoroughly test the platform to ensure it works as expected and meets the requirements.
|
26 |
+
7. **Push the code to Hugging Face**: Push your code to the newly created Space on Hugging Face. This will automatically deploy your platform.
|
27 |
+
8. **Monitor and maintain**: Regularly monitor the platform for any issues and update it as needed to ensure optimal performance and security.
|
28 |
+
|
29 |
+
## Usage Examples
|
30 |
+
|
31 |
+
### Interacting with the Platform using Gradio
|
32 |
+
|
33 |
+
The Gradio interface provides an intuitive and user-friendly way to interact with the Cybersecurity AI Platform. Here are some examples of how to use the platform:
|
34 |
+
|
35 |
+
1. **Text Input**: Enter text for analysis, such as threat intelligence reports, system logs, or email content. The platform will process the input and display the results, including visualizations and detailed reports.
|
36 |
+
2. **File Uploads**: Upload files for analysis, including log files, configuration files, or email attachments. The platform will analyze the files and provide insights into potential threats or vulnerabilities.
|
37 |
+
3. **Real-time Data Streams**: Input real-time data streams, such as network traffic, for continuous monitoring and analysis. The platform will provide real-time alerts and visualizations to help you stay on top of potential threats.
|
38 |
+
|
39 |
+
### Customizing the Platform
|
40 |
+
|
41 |
+
The Cybersecurity AI Platform offers various customization options to meet your specific security requirements:
|
42 |
+
|
43 |
+
- **Alert Settings**: Set specific thresholds for different types of alerts and customize notification methods such as email, SMS, and in-app notifications.
|
44 |
+
- **Input Processing**: Customize input processing settings for different input options, including text, file uploads, and real-time data streams.
|
45 |
+
- **AI Model Selection**: Enable or disable specific AI models based on your requirements and configure model-specific settings such as confidence thresholds and analysis parameters.
|
46 |
+
|
47 |
+
By leveraging the power of advanced AI models and providing a user-friendly interface, the Cybersecurity AI Platform aims to enhance your cybersecurity capabilities and help you stay ahead of emerging threats.
|
alerting.py
ADDED
@@ -0,0 +1,70 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import smtplib
|
2 |
+
from email.mime.text import MIMEText
|
3 |
+
from email.mime.multipart import MIMEMultipart
|
4 |
+
|
5 |
+
class AlertingSystem:
|
6 |
+
def __init__(self):
|
7 |
+
self.alert_thresholds = {
|
8 |
+
"phishing": 0.8,
|
9 |
+
"malware": 0.8,
|
10 |
+
"anomaly": 0.8
|
11 |
+
}
|
12 |
+
self.notification_methods = {
|
13 |
+
"email": self.send_email,
|
14 |
+
"sms": self.send_sms,
|
15 |
+
"in_app": self.send_in_app_notification
|
16 |
+
}
|
17 |
+
|
18 |
+
def set_alert_threshold(self, alert_type, threshold):
|
19 |
+
self.alert_thresholds[alert_type] = threshold
|
20 |
+
|
21 |
+
def get_alert_threshold(self, alert_type):
|
22 |
+
return self.alert_thresholds.get(alert_type, 0.8)
|
23 |
+
|
24 |
+
def send_alert(self, alert, method="email"):
|
25 |
+
notification_method = self.notification_methods.get(method)
|
26 |
+
if notification_method:
|
27 |
+
notification_method(alert)
|
28 |
+
else:
|
29 |
+
print(f"Notification method {method} not supported.")
|
30 |
+
|
31 |
+
def send_email(self, alert):
|
32 |
+
sender_email = "[email protected]"
|
33 |
+
receiver_email = "[email protected]"
|
34 |
+
subject = "Cybersecurity Alert"
|
35 |
+
body = f"Alert: {alert}"
|
36 |
+
|
37 |
+
msg = MIMEMultipart()
|
38 |
+
msg["From"] = sender_email
|
39 |
+
msg["To"] = receiver_email
|
40 |
+
msg["Subject"] = subject
|
41 |
+
msg.attach(MIMEText(body, "plain"))
|
42 |
+
|
43 |
+
try:
|
44 |
+
with smtplib.SMTP("smtp.example.com", 587) as server:
|
45 |
+
server.starttls()
|
46 |
+
server.login(sender_email, "your_password")
|
47 |
+
server.sendmail(sender_email, receiver_email, msg.as_string())
|
48 |
+
print("Email sent successfully.")
|
49 |
+
except Exception as e:
|
50 |
+
print(f"Failed to send email: {e}")
|
51 |
+
|
52 |
+
def send_sms(self, alert):
|
53 |
+
# Implement SMS sending logic here
|
54 |
+
print(f"SMS Alert: {alert}")
|
55 |
+
|
56 |
+
def send_in_app_notification(self, alert):
|
57 |
+
# Implement in-app notification logic here
|
58 |
+
print(f"In-app Notification: {alert}")
|
59 |
+
|
60 |
+
def monitor_real_time_data(self, data_stream, model_name, analyze_text):
|
61 |
+
for data in data_stream:
|
62 |
+
result = analyze_text(data, model_name)
|
63 |
+
if result["score"] >= self.get_alert_threshold(model_name):
|
64 |
+
self.send_alert(result)
|
65 |
+
|
66 |
+
def customize_notification_method(self, method, custom_function):
|
67 |
+
self.notification_methods[method] = custom_function
|
68 |
+
|
69 |
+
def get_notification_methods(self):
|
70 |
+
return list(self.notification_methods.keys())
|
app.py
ADDED
@@ -0,0 +1,83 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import pipeline
|
3 |
+
import requests
|
4 |
+
import json
|
5 |
+
import time
|
6 |
+
import threading
|
7 |
+
|
8 |
+
# Load AI models
|
9 |
+
def load_models():
|
10 |
+
models = {
|
11 |
+
"gpt-3": pipeline("text-generation", model="gpt-3"),
|
12 |
+
"bert-base-uncased": pipeline("text-classification", model="bert-base-uncased"),
|
13 |
+
"roberta-large": pipeline("text-classification", model="roberta-large"),
|
14 |
+
"distilbert-base-uncased": pipeline("text-classification", model="distilbert-base-uncased"),
|
15 |
+
"albert-base-v2": pipeline("text-classification", model="albert-base-v2"),
|
16 |
+
"tinybert": pipeline("text-classification", model="tinybert"),
|
17 |
+
"cybersecurity-bert": pipeline("text-classification", model="cybersecurity-bert"),
|
18 |
+
"malware-detection-bert": pipeline("text-classification", model="malware-detection-bert"),
|
19 |
+
"phishing-detection-bert": pipeline("text-classification", model="phishing-detection-bert")
|
20 |
+
}
|
21 |
+
return models
|
22 |
+
|
23 |
+
models = load_models()
|
24 |
+
|
25 |
+
# Define functions to interact with AI models
|
26 |
+
def analyze_text(text, model_name):
|
27 |
+
model = models.get(model_name)
|
28 |
+
if model:
|
29 |
+
return model(text)
|
30 |
+
else:
|
31 |
+
return "Model not found."
|
32 |
+
|
33 |
+
def analyze_file(file, model_name):
|
34 |
+
content = file.read().decode("utf-8")
|
35 |
+
return analyze_text(content, model_name)
|
36 |
+
|
37 |
+
# Real-time monitoring and alerting
|
38 |
+
alert_thresholds = {
|
39 |
+
"phishing": 0.8,
|
40 |
+
"malware": 0.8,
|
41 |
+
"anomaly": 0.8
|
42 |
+
}
|
43 |
+
|
44 |
+
def monitor_real_time_data(data_stream, model_name):
|
45 |
+
for data in data_stream:
|
46 |
+
result = analyze_text(data, model_name)
|
47 |
+
if result["score"] >= alert_thresholds.get(model_name, 0.8):
|
48 |
+
send_alert(result)
|
49 |
+
|
50 |
+
def send_alert(alert):
|
51 |
+
# Implement notification methods (e.g., email, SMS, in-app notifications)
|
52 |
+
print(f"Alert: {alert}")
|
53 |
+
|
54 |
+
# Gradio interface
|
55 |
+
def gradio_interface():
|
56 |
+
with gr.Blocks() as demo:
|
57 |
+
gr.Markdown("# Cybersecurity AI Platform")
|
58 |
+
|
59 |
+
with gr.Tab("Text Input"):
|
60 |
+
text_input = gr.Textbox(label="Enter text for analysis")
|
61 |
+
model_dropdown = gr.Dropdown(choices=list(models.keys()), label="Select AI Model")
|
62 |
+
text_output = gr.Textbox(label="Analysis Result")
|
63 |
+
text_button = gr.Button("Analyze Text")
|
64 |
+
text_button.click(analyze_text, inputs=[text_input, model_dropdown], outputs=text_output)
|
65 |
+
|
66 |
+
with gr.Tab("File Upload"):
|
67 |
+
file_input = gr.File(label="Upload file for analysis")
|
68 |
+
model_dropdown = gr.Dropdown(choices=list(models.keys()), label="Select AI Model")
|
69 |
+
file_output = gr.Textbox(label="Analysis Result")
|
70 |
+
file_button = gr.Button("Analyze File")
|
71 |
+
file_button.click(analyze_file, inputs=[file_input, model_dropdown], outputs=file_output)
|
72 |
+
|
73 |
+
with gr.Tab("Real-time Data Stream"):
|
74 |
+
data_stream_input = gr.Textbox(label="Enter real-time data stream URL")
|
75 |
+
model_dropdown = gr.Dropdown(choices=list(models.keys()), label="Select AI Model")
|
76 |
+
real_time_output = gr.Textbox(label="Real-time Monitoring Result")
|
77 |
+
real_time_button = gr.Button("Start Monitoring")
|
78 |
+
real_time_button.click(monitor_real_time_data, inputs=[data_stream_input, model_dropdown], outputs=real_time_output)
|
79 |
+
|
80 |
+
demo.launch()
|
81 |
+
|
82 |
+
if __name__ == "__main__":
|
83 |
+
gradio_interface()
|
customization.py
ADDED
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
class Customization:
|
2 |
+
def __init__(self):
|
3 |
+
self.alert_thresholds = {}
|
4 |
+
self.notification_methods = {}
|
5 |
+
self.custom_alert_rules = []
|
6 |
+
self.input_processing_settings = {}
|
7 |
+
self.model_settings = {}
|
8 |
+
|
9 |
+
def set_alert_threshold(self, alert_type, threshold):
|
10 |
+
self.alert_thresholds[alert_type] = threshold
|
11 |
+
|
12 |
+
def get_alert_threshold(self, alert_type):
|
13 |
+
return self.alert_thresholds.get(alert_type, 0.8)
|
14 |
+
|
15 |
+
def customize_notification_method(self, method, custom_function):
|
16 |
+
self.notification_methods[method] = custom_function
|
17 |
+
|
18 |
+
def get_notification_methods(self):
|
19 |
+
return list(self.notification_methods.keys())
|
20 |
+
|
21 |
+
def create_custom_alert_rule(self, rule):
|
22 |
+
self.custom_alert_rules.append(rule)
|
23 |
+
|
24 |
+
def get_custom_alert_rules(self):
|
25 |
+
return self.custom_alert_rules
|
26 |
+
|
27 |
+
def set_input_processing_setting(self, setting, value):
|
28 |
+
self.input_processing_settings[setting] = value
|
29 |
+
|
30 |
+
def get_input_processing_setting(self, setting):
|
31 |
+
return self.input_processing_settings.get(setting, None)
|
32 |
+
|
33 |
+
def enable_model(self, model_name):
|
34 |
+
self.model_settings[model_name] = {"enabled": True}
|
35 |
+
|
36 |
+
def disable_model(self, model_name):
|
37 |
+
self.model_settings[model_name] = {"enabled": False}
|
38 |
+
|
39 |
+
def set_model_setting(self, model_name, setting, value):
|
40 |
+
if model_name not in self.model_settings:
|
41 |
+
self.model_settings[model_name] = {}
|
42 |
+
self.model_settings[model_name][setting] = value
|
43 |
+
|
44 |
+
def get_model_setting(self, model_name, setting):
|
45 |
+
if model_name in self.model_settings:
|
46 |
+
return self.model_settings[model_name].get(setting, None)
|
47 |
+
return None
|
input_processing.py
ADDED
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import json
|
3 |
+
|
4 |
+
class InputProcessor:
|
5 |
+
def __init__(self):
|
6 |
+
self.settings = {
|
7 |
+
"text_processing": True,
|
8 |
+
"file_processing": True,
|
9 |
+
"real_time_processing": True,
|
10 |
+
"custom_settings": {}
|
11 |
+
}
|
12 |
+
|
13 |
+
def process_text(self, text):
|
14 |
+
if self.settings["text_processing"]:
|
15 |
+
# Implement text processing logic here
|
16 |
+
return text
|
17 |
+
else:
|
18 |
+
return "Text processing is disabled."
|
19 |
+
|
20 |
+
def process_file(self, file_path):
|
21 |
+
if self.settings["file_processing"]:
|
22 |
+
with open(file_path, 'r') as file:
|
23 |
+
content = file.read()
|
24 |
+
# Implement file processing logic here
|
25 |
+
return content
|
26 |
+
else:
|
27 |
+
return "File processing is disabled."
|
28 |
+
|
29 |
+
def process_real_time_data(self, data_stream):
|
30 |
+
if self.settings["real_time_processing"]:
|
31 |
+
# Implement real-time data processing logic here
|
32 |
+
return data_stream
|
33 |
+
else:
|
34 |
+
return "Real-time data processing is disabled."
|
35 |
+
|
36 |
+
def load_custom_settings(self, settings_file):
|
37 |
+
if os.path.exists(settings_file):
|
38 |
+
with open(settings_file, 'r') as file:
|
39 |
+
self.settings["custom_settings"] = json.load(file)
|
40 |
+
else:
|
41 |
+
return "Settings file not found."
|
42 |
+
|
43 |
+
def apply_custom_settings(self):
|
44 |
+
# Apply custom settings logic here
|
45 |
+
pass
|
46 |
+
|
47 |
+
def update_settings(self, new_settings):
|
48 |
+
self.settings.update(new_settings)
|
49 |
+
|
50 |
+
def get_settings(self):
|
51 |
+
return self.settings
|
models.py
ADDED
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
class AIModel:
|
2 |
+
def __init__(self, model_name, model):
|
3 |
+
self.model_name = model_name
|
4 |
+
self.model = model
|
5 |
+
|
6 |
+
def analyze(self, input_data):
|
7 |
+
return self.model(input_data)
|
8 |
+
|
9 |
+
class ModelManager:
|
10 |
+
def __init__(self):
|
11 |
+
self.models = {}
|
12 |
+
|
13 |
+
def load_model(self, model_name, model):
|
14 |
+
self.models[model_name] = AIModel(model_name, model)
|
15 |
+
|
16 |
+
def update_model(self, model_name, model):
|
17 |
+
if model_name in self.models:
|
18 |
+
self.models[model_name].model = model
|
19 |
+
|
20 |
+
def enable_model(self, model_name):
|
21 |
+
if model_name in self.models:
|
22 |
+
self.models[model_name].enabled = True
|
23 |
+
|
24 |
+
def disable_model(self, model_name):
|
25 |
+
if model_name in self.models:
|
26 |
+
self.models[model_name].enabled = False
|
27 |
+
|
28 |
+
def analyze_with_model(self, model_name, input_data):
|
29 |
+
if model_name in self.models and self.models[model_name].enabled:
|
30 |
+
return self.models[model_name].analyze(input_data)
|
31 |
+
else:
|
32 |
+
return "Model not found or not enabled."
|
33 |
+
|
34 |
+
def get_model_names(self):
|
35 |
+
return list(self.models.keys())
|
36 |
+
|
37 |
+
def is_model_enabled(self, model_name):
|
38 |
+
if model_name in self.models:
|
39 |
+
return self.models[model_name].enabled
|
40 |
+
else:
|
41 |
+
return False
|
requirements.txt
ADDED
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
gradio
|
2 |
+
transformers
|
3 |
+
torch
|
4 |
+
pandas
|
5 |
+
numpy
|
6 |
+
scikit-learn
|
7 |
+
requests
|
8 |
+
flask
|
threat_intelligence.py
ADDED
@@ -0,0 +1,72 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import requests
|
2 |
+
import json
|
3 |
+
|
4 |
+
class ThreatIntelligence:
|
5 |
+
def __init__(self):
|
6 |
+
self.api_keys = {}
|
7 |
+
self.endpoints = {}
|
8 |
+
self.threat_data = []
|
9 |
+
|
10 |
+
def add_api_key(self, provider, api_key):
|
11 |
+
self.api_keys[provider] = api_key
|
12 |
+
|
13 |
+
def set_endpoint(self, provider, endpoint):
|
14 |
+
self.endpoints[provider] = endpoint
|
15 |
+
|
16 |
+
def fetch_threat_data(self, provider):
|
17 |
+
if provider in self.api_keys and provider in self.endpoints:
|
18 |
+
headers = {"Authorization": f"Bearer {self.api_keys[provider]}"}
|
19 |
+
response = requests.get(self.endpoints[provider], headers=headers)
|
20 |
+
if response.status_code == 200:
|
21 |
+
self.threat_data.append(response.json())
|
22 |
+
else:
|
23 |
+
print(f"Failed to fetch data from {provider}: {response.status_code}")
|
24 |
+
else:
|
25 |
+
print(f"API key or endpoint for {provider} not set.")
|
26 |
+
|
27 |
+
def aggregate_threat_data(self):
|
28 |
+
aggregated_data = {}
|
29 |
+
for data in self.threat_data:
|
30 |
+
for item in data:
|
31 |
+
threat_id = item.get("id")
|
32 |
+
if threat_id not in aggregated_data:
|
33 |
+
aggregated_data[threat_id] = item
|
34 |
+
else:
|
35 |
+
aggregated_data[threat_id].update(item)
|
36 |
+
return aggregated_data
|
37 |
+
|
38 |
+
def normalize_threat_data(self, data):
|
39 |
+
normalized_data = []
|
40 |
+
for item in data.values():
|
41 |
+
normalized_item = {
|
42 |
+
"id": item.get("id"),
|
43 |
+
"type": item.get("type"),
|
44 |
+
"description": item.get("description"),
|
45 |
+
"severity": item.get("severity"),
|
46 |
+
"source": item.get("source"),
|
47 |
+
"timestamp": item.get("timestamp")
|
48 |
+
}
|
49 |
+
normalized_data.append(normalized_item)
|
50 |
+
return normalized_data
|
51 |
+
|
52 |
+
def integrate_with_misp(self, misp_url, misp_key):
|
53 |
+
headers = {"Authorization": f"Bearer {misp_key}"}
|
54 |
+
response = requests.get(misp_url, headers=headers)
|
55 |
+
if response.status_code == 200:
|
56 |
+
self.threat_data.append(response.json())
|
57 |
+
else:
|
58 |
+
print(f"Failed to integrate with MISP: {response.status_code}")
|
59 |
+
|
60 |
+
def integrate_with_opencti(self, opencti_url, opencti_key):
|
61 |
+
headers = {"Authorization": f"Bearer {opencti_key}"}
|
62 |
+
response = requests.get(opencti_url, headers=headers)
|
63 |
+
if response.status_code == 200:
|
64 |
+
self.threat_data.append(response.json())
|
65 |
+
else:
|
66 |
+
print(f"Failed to integrate with OpenCTI: {response.status_code}")
|
67 |
+
|
68 |
+
def get_threat_data(self):
|
69 |
+
return self.threat_data
|
70 |
+
|
71 |
+
def clear_threat_data(self):
|
72 |
+
self.threat_data = []
|