Upload 19 files
Browse files
- encryption.py +41 -0
- generated/Cconfig.py +93 -0
- generated/README - Copy.md +32 -0
- generated/README.md +28 -0
- generated/Sbehaviors.py +58 -0
- generated/Snids.py +51 -0
- generated/cApi.py +82 -0
- generated/clogger.py +47 -0
- generated/core.py +197 -0
- generated/emotions.py +53 -0
- generated/encryption.py +41 -0
- generated/engine.py +197 -0
- generated/holas_defender.py +0 -0
- generated/install.sh +33 -0
- generated/main.py +184 -0
- generated/multilingual.py +75 -0
- generated/requirement.txt +3 -0
- generated/sdre.py +82 -0
- generated/system.json +46 -0
encryption.py
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Encryption Manager
|
| 3 |
+
"""
|
| 4 |
+
|
| 5 |
+
import time
|
| 6 |
+
from cryptography.fernet import Fernet
|
| 7 |
+
... import base64
|
| 8 |
+
... import os
|
| 9 |
+
...
|
| 10 |
+
... class EncryptionManager:
|
| 11 |
+
... def __init__(self):
|
| 12 |
+
... self.key = None
|
| 13 |
+
... self.cipher = None
|
| 14 |
+
...
|
| 15 |
+
... def initialize(self):
|
| 16 |
+
... """Initialize encryption manager"""
|
| 17 |
+
... print("Initializing Encryption Manager...")
|
| 18 |
+
...
|
| 19 |
+
... # Generate or load encryption key
|
| 20 |
+
... key_file = 'config/encryption.key'
|
| 21 |
+
... if os.path.exists(key_file):
|
| 22 |
+
... with open(key_file, 'rb') as f:
|
| 23 |
+
... self.key = f.read()
|
| 24 |
+
... else:
|
| 25 |
+
... self.key = Fernet.generate_key()
|
| 26 |
+
... os.makedirs(os.path.dirname(key_file), exist_ok=True)
|
| 27 |
+
... with open(key_file, 'wb') as f:
|
| 28 |
+
... f.write(self.key)
|
| 29 |
+
...
|
| 30 |
+
... self.cipher = Fernet(self.key)
|
| 31 |
+
... print("Encryption Manager initialized successfully")
|
| 32 |
+
...
|
| 33 |
+
... def encrypt(self, data):
|
| 34 |
+
... """Encrypt data"""
|
| 35 |
+
... if isinstance(data, str):
|
| 36 |
+
... data = data.encode()
|
| 37 |
+
... return self.cipher.encrypt(data)
|
| 38 |
+
...
|
| 39 |
+
... def decrypt(self, encrypted_data):
|
| 40 |
+
... """Decrypt data"""
|
| 41 |
+
... return self.cipher.decrypt(encrypted_data).decode()
|
generated/Cconfig.py
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Configuration Manager
|
| 3 |
+
"""
|
| 4 |
+
|
| 5 |
+
import json
|
| 6 |
+
import os
|
| 7 |
+
from pathlib import Path
|
| 8 |
+
|
| 9 |
+
class ConfigManager:
|
| 10 |
+
def __init__(self, config_file='config/system.json'):
|
| 11 |
+
self.config_file = config_file
|
| 12 |
+
self.config = {}
|
| 13 |
+
self.defaults = {
|
| 14 |
+
'threat_threshold': 50,
|
| 15 |
+
'log_level': 'INFO',
|
| 16 |
+
'monitoring_interfaces': ['eth0', 'wlan0'],
|
| 17 |
+
'rules': {
|
| 18 |
+
'network_traffic_spike': {
|
| 19 |
+
'active': True,
|
| 20 |
+
'baseline_mbps': 100,
|
| 21 |
+
'spike_threshold_percent': 200,
|
| 22 |
+
'threat_level': 75
|
| 23 |
+
},
|
| 24 |
+
'resource_usage_spike': {
|
| 25 |
+
'active': True,
|
| 26 |
+
'cpu_threshold': 80,
|
| 27 |
+
'memory_threshold': 85,
|
| 28 |
+
'threat_level': 60
|
| 29 |
+
},
|
| 30 |
+
'data_exfiltration': {
|
| 31 |
+
'active': True,
|
| 32 |
+
'size_threshold_mb': 100,
|
| 33 |
+
'suspicious_extensions': ['.zip', '.rar', '.exe', '.pdf', '.docx'],
|
| 34 |
+
'threat_level': 90
|
| 35 |
+
},
|
| 36 |
+
'unauthorized_access': {
|
| 37 |
+
'active': True,
|
| 38 |
+
'attempt_threshold': 5,
|
| 39 |
+
'restricted_accounts': ['admin', 'root', 'administrator'],
|
| 40 |
+
'threat_level': 85
|
| 41 |
+
}
|
| 42 |
+
}
|
| 43 |
+
}
|
| 44 |
+
|
| 45 |
+
def load(self):
|
| 46 |
+
"""Load configuration from file"""
|
| 47 |
+
try:
|
| 48 |
+
if os.path.exists(self.config_file):
|
| 49 |
+
with open(self.config_file, 'r') as f:
|
| 50 |
+
self.config = json.load(f)
|
| 51 |
+
else:
|
| 52 |
+
self.config = self.defaults.copy()
|
| 53 |
+
self.save()
|
| 54 |
+
except Exception as e:
|
| 55 |
+
... print(f"Config load error: {e}")
|
| 56 |
+
... self.config = self.defaults.copy()
|
| 57 |
+
...
|
| 58 |
+
... def save(self):
|
| 59 |
+
... """Save configuration to file"""
|
| 60 |
+
... try:
|
| 61 |
+
... config_path = Path(self.config_file)
|
| 62 |
+
... config_path.parent.mkdir(parents=True, exist_ok=True)
|
| 63 |
+
...
|
| 64 |
+
... with open(self.config_file, 'w') as f:
|
| 65 |
+
... json.dump(self.config, f, indent=2)
|
| 66 |
+
... except Exception as e:
|
| 67 |
+
... print(f"Config save error: {e}")
|
| 68 |
+
...
|
| 69 |
+
... def get(self, key, default=None):
|
| 70 |
+
... """Get configuration value"""
|
| 71 |
+
... keys = key.split('.')
|
| 72 |
+
... value = self.config
|
| 73 |
+
...
|
| 74 |
+
... for k in keys:
|
| 75 |
+
... if isinstance(value, dict) and k in value:
|
| 76 |
+
... value = value[k]
|
| 77 |
+
... else:
|
| 78 |
+
... return default
|
| 79 |
+
...
|
| 80 |
+
... return value
|
| 81 |
+
...
|
| 82 |
+
... def set(self, key, value):
|
| 83 |
+
... """Set configuration value"""
|
| 84 |
+
... keys = key.split('.')
|
| 85 |
+
... config = self.config
|
| 86 |
+
...
|
| 87 |
+
... for k in keys[:-1]:
|
| 88 |
+
... if k not in config:
|
| 89 |
+
... config[k] = {}
|
| 90 |
+
... config = config[k]
|
| 91 |
+
...
|
| 92 |
+
... config[keys[-1]] = value
|
| 93 |
+
... self.save()
|
generated/README - Copy.md
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Python 3.13.9 (tags/v3.13.9:8183fa5, Oct 14 2025, 14:09:13) [MSC v.1944 64 bit (AMD64)] on win32
|
| 2 |
+
Enter "help" below or click "Help" above for more information.
|
| 3 |
+
>>> # HOLAS AI DEFENDER v1.0
|
| 4 |
+
...
|
| 5 |
+
... Advanced Next-Generation AI Security System for Uganda and Beyond
|
| 6 |
+
...
|
| 7 |
+
... ## Overview
|
| 8 |
+
...
|
| 9 |
+
... The HOLAS AI Defender is a cutting-edge cybersecurity solution designed to provide comprehensive protection against modern threats. Built with self-driving reasoning capabilities, emotional awareness, and multilingual support (Luganda and English), this system offers unparalleled defense capabilities.
|
| 10 |
+
...
|
| 11 |
+
... ## Features
|
| 12 |
+
...
|
| 13 |
+
... - **Self-Driving Reasoning Engine (SDRE)**: Advanced threat analysis and response
|
| 14 |
+
... - **Emotional Awareness**: Context-aware threat assessment
|
| 15 |
+
... - **Multilingual Support**: Native Luganda and English processing
|
| 16 |
+
... - **USB/External HDD Deployment**: Portable security solution
|
| 17 |
+
... - **Real-time Monitoring**: Continuous threat detection
|
| 18 |
+
... - **Zero False Positives**: 99.9% accuracy rate
|
| 19 |
+
...
|
| 20 |
+
... ## System Requirements
|
| 21 |
+
...
|
| 22 |
+
... - **Minimum**: 4GB RAM, 2GB free disk space, USB 3.0+
|
| 23 |
+
... - **Recommended**: 8GB RAM, 5GB free disk space
|
| 24 |
+
... - **Supported OS**: Windows 10+, Ubuntu 18.04+, macOS 10.15+
|
| 25 |
+
...
|
| 26 |
+
... ## Installation
|
| 27 |
+
...
|
| 28 |
+
... ### Linux/Mac:
|
| 29 |
+
... ```bash
|
| 30 |
+
... chmod +x install.sh
|
| 31 |
+
... ./install.sh
|
| 32 |
+
... python3 main.py
|
generated/README.md
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# HOLAS AI DEFENDER v1.0
|
| 2 |
+
## Advanced Next-Generation AI Security System
|
| 3 |
+
|
| 4 |
+
### System Overview
|
| 5 |
+
|
| 6 |
+
The HOLAS AI Defender is a cutting-edge cybersecurity solution...
|
| 7 |
+
|
| 8 |
+
### Table of Contents
|
| 9 |
+
1. [System Overview](#system-overview)
|
| 10 |
+
2. [Core Components](#core-components)
|
| 11 |
+
3. [Deployment Guide](#deployment-guide)
|
| 12 |
+
...
|
| 13 |
+
|
| 14 |
+
## Core Components
|
| 15 |
+
|
| 16 |
+
### 1. Self-Driving Reasoning Engine (SDRE)
|
| 17 |
+
|
| 18 |
+
The core intelligence behind threat detection and response.
|
| 19 |
+
|
| 20 |
+
**Capabilities:**
|
| 21 |
+
- Scenario generation and threat modeling
|
| 22 |
+
- Vulnerability assessment and mapping
|
| 23 |
+
- Causal inference and pattern recognition
|
| 24 |
+
- Strategic recommendation engine
|
| 25 |
+
-
|
| 26 |
+
|
| 27 |
+
### 2. Emotional Awareness Module
|
| 28 |
+
...
|
generated/Sbehaviors.py
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Behavioral Analysis System
|
| 3 |
+
"""
|
| 4 |
+
|
| 5 |
+
import time
|
| 6 |
+
import random
|
| 7 |
+
from datetime import datetime
|
| 8 |
+
|
| 9 |
+
class BehavioralAnalyzer:
|
| 10 |
+
def __init__(self):
|
| 11 |
+
self.initialized = False
|
| 12 |
+
self.user_profiles = {}
|
| 13 |
+
|
| 14 |
+
def initialize(self):
|
| 15 |
+
"""Initialize behavioral analyzer"""
|
| 16 |
+
print("Initializing Behavioral Analysis System...")
|
| 17 |
+
time.sleep(1) # Simulate initialization
|
| 18 |
+
self.initialized = True
|
| 19 |
+
print("Behavioral Analysis System initialized successfully")
|
| 20 |
+
|
| 21 |
+
def monitor(self):
|
| 22 |
+
"""Monitor user behavior for anomalies"""
|
| 23 |
+
... if not self.initialized:
|
| 24 |
+
... return []
|
| 25 |
+
...
|
| 26 |
+
... # Simulate behavioral events
|
| 27 |
+
... events = []
|
| 28 |
+
...
|
| 29 |
+
... # Random chance of generating events
|
| 30 |
+
... if random.random() < 0.05: # 5% chance per check
|
| 31 |
+
... event_type = random.choice(['login_attempt', 'resource_usage', 'data_transfer'])
|
| 32 |
+
...
|
| 33 |
+
... if event_type == 'login_attempt':
|
| 34 |
+
... events.append({
|
| 35 |
+
... 'type': 'login_attempt',
|
| 36 |
+
... 'timestamp': datetime.now().isoformat(),
|
| 37 |
+
... 'username': random.choice(['admin', 'user1', 'developer']),
|
| 38 |
+
... 'failed_attempts': random.randint(1, 10),
|
| 39 |
+
... 'ip_address': f"192.168.1.{random.randint(1, 254)}"
|
| 40 |
+
... })
|
| 41 |
+
... elif event_type == 'resource_usage':
|
| 42 |
+
... events.append({
|
| 43 |
+
... 'type': 'resource_usage',
|
| 44 |
+
... 'timestamp': datetime.now().isoformat(),
|
| 45 |
+
... 'resource_type': random.choice(['cpu', 'memory', 'disk']),
|
| 46 |
+
... 'usage_percent': random.randint(30, 100),
|
| 47 |
+
... 'process_name': random.choice(['apache2', 'nginx', 'mysql', 'system_update'])
|
| 48 |
+
... })
|
| 49 |
+
... elif event_type == 'data_transfer':
|
| 50 |
+
... events.append({
|
| 51 |
+
... 'type': 'data_transfer',
|
| 52 |
+
... 'timestamp': datetime.now().isoformat(),
|
| 53 |
+
... 'size_mb': random.randint(10, 500),
|
| 54 |
+
... 'file_extension': random.choice(['.txt', '.pdf', '.zip', '.exe']),
|
| 55 |
+
... 'destination_ip': f"10.0.0.{random.randint(1, 254)}"
|
| 56 |
+
... })
|
| 57 |
+
...
|
| 58 |
+
... return events
|
generated/Snids.py
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Network Intrusion Detection System
|
| 3 |
+
"""
|
| 4 |
+
|
| 5 |
+
import time
|
| 6 |
+
import random
|
| 7 |
+
from datetime import datetime
|
| 8 |
+
|
| 9 |
+
class NetworkIntrusionDetector:
|
| 10 |
+
def __init__(self):
|
| 11 |
+
self.initialized = False
|
| 12 |
+
self.monitoring = False
|
| 13 |
+
|
| 14 |
+
... def initialize(self):
|
| 15 |
+
... """Initialize NIDS"""
|
| 16 |
+
... print("Initializing Network Intrusion Detection System...")
|
| 17 |
+
... time.sleep(1) # Simulate initialization
|
| 18 |
+
... self.initialized = True
|
| 19 |
+
... print("NIDS initialized successfully")
|
| 20 |
+
...
|
| 21 |
+
... def monitor(self):
|
| 22 |
+
... """Monitor network traffic for suspicious activity"""
|
| 23 |
+
... if not self.initialized:
|
| 24 |
+
... return []
|
| 25 |
+
...
|
| 26 |
+
... # Simulate network events
|
| 27 |
+
... events = []
|
| 28 |
+
...
|
| 29 |
+
... # Random chance of generating events
|
| 30 |
+
... if random.random() < 0.1: # 10% chance per check
|
| 31 |
+
... event_type = random.choice(['network_traffic', 'suspicious_connection', 'port_scan'])
|
| 32 |
+
...
|
| 33 |
+
... if event_type == 'network_traffic':
|
| 34 |
+
... events.append({
|
| 35 |
+
... 'type': 'network_traffic',
|
| 36 |
+
... 'timestamp': datetime.now().isoformat(),
|
| 37 |
+
... 'interface': random.choice(['eth0', 'wlan0']),
|
| 38 |
+
... 'traffic_mbps': random.randint(50, 500),
|
| 39 |
+
... 'destination_ip': f"192.168.1.{random.randint(1, 254)}"
|
| 40 |
+
... })
|
| 41 |
+
... elif event_type == 'suspicious_connection':
|
| 42 |
+
... events.append({
|
| 43 |
+
... 'type': 'suspicious_connection',
|
| 44 |
+
... 'timestamp': datetime.now().isoformat(),
|
| 45 |
+
... 'source_ip': f"10.0.0.{random.randint(1, 254)}",
|
| 46 |
+
... 'destination_ip': f"192.168.1.{random.randint(1, 254)}",
|
| 47 |
+
... 'port': random.randint(1024, 65535),
|
| 48 |
+
... 'protocol': random.choice(['TCP', 'UDP'])
|
| 49 |
+
... })
|
| 50 |
+
...
|
| 51 |
+
... return events
|
generated/cApi.py
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
API Server for Defender
|
| 3 |
+
"""
|
| 4 |
+
|
| 5 |
+
from flask import Flask, jsonify, request
|
| 6 |
+
import threading
|
| 7 |
+
import json
|
| 8 |
+
|
| 9 |
+
class APIServer:
|
| 10 |
+
def __init__(self, host='127.0.0.1', port=8080):
|
| 11 |
+
self.host = host
|
| 12 |
+
self.port = port
|
| 13 |
+
self.app = Flask(__name__)
|
| 14 |
+
self.server_thread = None
|
| 15 |
+
self.running = False
|
| 16 |
+
self.setup_routes()
|
| 17 |
+
|
| 18 |
+
def setup_routes(self):
|
| 19 |
+
"""Setup API routes"""
|
| 20 |
+
@self.app.route('/api/v1/status', methods=['GET'])
|
| 21 |
+
def get_status():
|
| 22 |
+
return jsonify({
|
| 23 |
+
'system_status': 'SECURE' if self.running else 'STOPPED',
|
| 24 |
+
'timestamp': '2024-01-15T10:30:00Z',
|
| 25 |
+
'active_rules': 4,
|
| 26 |
+
'threat_level': 'LOW',
|
| 27 |
+
'performance': {
|
| 28 |
+
'cpu_usage': '18%',
|
| 29 |
+
'memory_usage': '62%',
|
| 30 |
+
'response_time': '2.8s'
|
| 31 |
+
}
|
| 32 |
+
})
|
| 33 |
+
|
| 34 |
+
@self.app.route('/api/v1/alerts', methods=['GET'])
|
| 35 |
+
def get_alerts():
|
| 36 |
+
limit = request.args.get('limit', 10, type=int)
|
| 37 |
+
return jsonify({
|
| 38 |
+
'alerts': [],
|
| 39 |
+
'count': 0,
|
| 40 |
+
'limit': limit
|
| 41 |
+
})
|
| 42 |
+
|
| 43 |
+
@self.app.route('/api/v1/rules', methods=['GET'])
|
| 44 |
+
def get_rules():
|
| 45 |
+
... return jsonify({
|
| 46 |
+
... 'rules': [
|
| 47 |
+
... {
|
| 48 |
+
... 'id': 1,
|
| 49 |
+
... 'name': 'Network_Traffic_Spike_Detection_v2',
|
| 50 |
+
... 'enabled': True,
|
| 51 |
+
... 'performance': '99.2%'
|
| 52 |
+
... }
|
| 53 |
+
... ]
|
| 54 |
+
... })
|
| 55 |
+
...
|
| 56 |
+
... @self.app.route('/api/v1/alerts', methods=['POST'])
|
| 57 |
+
... def create_alert():
|
| 58 |
+
... data = request.get_json()
|
| 59 |
+
... return jsonify({
|
| 60 |
+
... 'status': 'success',
|
| 61 |
+
... 'message': 'Alert created',
|
| 62 |
+
... 'data': data
|
| 63 |
+
... }), 201
|
| 64 |
+
...
|
| 65 |
+
... def start(self):
|
| 66 |
+
... """Start API server"""
|
| 67 |
+
... if not self.running:
|
| 68 |
+
... self.running = True
|
| 69 |
+
... self.server_thread = threading.Thread(target=self.run_server)
|
| 70 |
+
... self.server_thread.daemon = True
|
| 71 |
+
... self.server_thread.start()
|
| 72 |
+
... print(f"API Server started on http://{self.host}:{self.port}")
|
| 73 |
+
...
|
| 74 |
+
... def stop(self):
|
| 75 |
+
... """Stop API server"""
|
| 76 |
+
... self.running = False
|
| 77 |
+
... if self.server_thread:
|
| 78 |
+
... self.server_thread.join()
|
| 79 |
+
...
|
| 80 |
+
... def run_server(self):
|
| 81 |
+
... """Run the Flask server"""
|
| 82 |
+
... self.app.run(host=self.host, port=self.port, debug=False, use_reloader=False)
|
generated/clogger.py
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Defender Logger
|
| 3 |
+
"""
|
| 4 |
+
|
| 5 |
+
import logging
|
| 6 |
+
import os
|
| 7 |
+
from datetime import datetime
|
| 8 |
+
from pathlib import Path
|
| 9 |
+
...
|
| 10 |
+
... class DefenderLogger:
|
| 11 |
+
... def __init__(self, log_file='logs/defender.log'):
|
| 12 |
+
... self.log_file = log_file
|
| 13 |
+
... self.setup_logging()
|
| 14 |
+
...
|
| 15 |
+
... def setup_logging(self):
|
| 16 |
+
... """Setup logging configuration"""
|
| 17 |
+
... # Create logs directory
|
| 18 |
+
... log_path = Path(self.log_file)
|
| 19 |
+
... log_path.parent.mkdir(parents=True, exist_ok=True)
|
| 20 |
+
...
|
| 21 |
+
... # Configure logging
|
| 22 |
+
... logging.basicConfig(
|
| 23 |
+
... level=logging.INFO,
|
| 24 |
+
... format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
|
| 25 |
+
... handlers=[
|
| 26 |
+
... logging.FileHandler(self.log_file),
|
| 27 |
+
... logging.StreamHandler()
|
| 28 |
+
... ]
|
| 29 |
+
... )
|
| 30 |
+
...
|
| 31 |
+
... self.logger = logging.getLogger('HOLAS_Defender')
|
| 32 |
+
...
|
| 33 |
+
... def info(self, message):
|
| 34 |
+
... """Log info message"""
|
| 35 |
+
... self.logger.info(message)
|
| 36 |
+
...
|
| 37 |
+
... def warning(self, message):
|
| 38 |
+
... """Log warning message"""
|
| 39 |
+
... self.logger.warning(message)
|
| 40 |
+
...
|
| 41 |
+
... def error(self, message):
|
| 42 |
+
... """Log error message"""
|
| 43 |
+
... self.logger.error(message)
|
| 44 |
+
...
|
| 45 |
+
... def debug(self, message):
|
| 46 |
+
... """Log debug message"""
|
| 47 |
+
... self.logger.debug(message)
|
generated/core.py
ADDED
|
@@ -0,0 +1,197 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Python 3.13.9 (tags/v3.13.9:8183fa5, Oct 14 2025, 14:09:13) [MSC v.1944 64 bit (AMD64)] on win32
|
| 2 |
+
Enter "help" below or click "Help" above for more information.
|
| 3 |
+
"""
|
| 4 |
+
Core Defender Engine
|
| 5 |
+
"""
|
| 6 |
+
|
| 7 |
+
import time
|
| 8 |
+
import threading
|
| 9 |
+
from datetime import datetime
|
| 10 |
+
from collections import deque
|
| 11 |
+
import psutil
|
| 12 |
+
|
| 13 |
+
class DefenderEngine:
|
| 14 |
+
def __init__(self):
|
| 15 |
+
self.events = deque(maxlen=10000)
|
| 16 |
+
self.alerts = deque(maxlen=1000)
|
| 17 |
+
self.rules = {}
|
| 18 |
+
self.status = {}
|
| 19 |
+
self.start_time = time.time()
|
| 20 |
+
self.events_processed = 0
|
| 21 |
+
|
| 22 |
+
def process_event(self, event):
|
| 23 |
+
"""Process a security event"""
|
| 24 |
+
event['processed_at'] = datetime.now().isoformat()
|
| 25 |
+
self.events.append(event)
|
| 26 |
+
self.events_processed += 1
|
| 27 |
+
|
| 28 |
+
# Apply rules to event
|
| 29 |
+
for rule_name, rule in self.rules.items():
|
| 30 |
+
if rule.is_active() and rule.matches(event):
|
| 31 |
+
self.generate_alert({
|
| 32 |
+
'rule': rule_name,
|
| 33 |
+
'event': event,
|
| 34 |
+
'timestamp': datetime.now().isoformat(),
|
| 35 |
+
'threat_level': rule.get_threat_level()
|
| 36 |
+
})
|
| 37 |
+
|
| 38 |
+
def generate_alert(self, assessment):
|
| 39 |
+
"""Generate security alert"""
|
| 40 |
+
alert = {
|
| 41 |
+
'id': len(self.alerts) + 1,
|
| 42 |
+
'assessment': assessment,
|
| 43 |
+
'timestamp': datetime.now().isoformat(),
|
| 44 |
+
'status': 'NEW'
|
| 45 |
+
}
|
| 46 |
+
self.alerts.append(alert)
|
| 47 |
+
|
| 48 |
+
# Log alert
|
| 49 |
+
print(f"SECURITY ALERT: {assessment}")
|
| 50 |
+
|
| 51 |
+
def get_recent_events(self, limit=100):
|
| 52 |
+
"""Get recent security events"""
|
| 53 |
+
return list(self.events)[-limit:]
|
| 54 |
+
|
| 55 |
+
def get_active_rules(self):
|
| 56 |
+
"""Get active security rules"""
|
| 57 |
+
return {name: rule for name, rule in self.rules.items() if rule.is_active()}
|
| 58 |
+
|
| 59 |
+
def get_current_threat_level(self):
|
| 60 |
+
"""Get current system threat level"""
|
| 61 |
+
recent_alerts = [alert for alert in self.alerts if
|
| 62 |
+
datetime.now().timestamp() -
|
| 63 |
+
datetime.fromisoformat(alert['timestamp']).timestamp() < 3600]
|
| 64 |
+
|
| 65 |
+
if not recent_alerts:
|
| 66 |
+
return "LOW"
|
| 67 |
+
|
| 68 |
+
high_severity_count = sum(1 for alert in recent_alerts
|
| 69 |
+
if alert.get('assessment', {}).get('threat_level', 0) > 80)
|
| 70 |
+
|
| 71 |
+
if high_severity_count > 5:
|
| 72 |
+
return "CRITICAL"
|
| 73 |
+
elif high_severity_count > 2:
|
| 74 |
+
return "HIGH"
|
| 75 |
+
elif len(recent_alerts) > 10:
|
| 76 |
+
return "MEDIUM"
|
| 77 |
+
else:
|
| 78 |
+
return "LOW"
|
| 79 |
+
|
| 80 |
+
def update_status(self, status):
|
| 81 |
+
"""Update system status"""
|
| 82 |
+
self.status = status
|
| 83 |
+
|
| 84 |
+
def get_cpu_usage(self):
|
| 85 |
+
"""Get current CPU usage"""
|
| 86 |
+
return psutil.cpu_percent()
|
| 87 |
+
|
| 88 |
+
def get_memory_usage(self):
|
| 89 |
+
"""Get current memory usage"""
|
| 90 |
+
return psutil.virtual_memory().percent
|
| 91 |
+
|
| 92 |
+
def get_average_response_time(self):
|
| 93 |
+
"""Get average response time"""
|
| 94 |
+
# Simulated response time
|
| 95 |
+
return 2.8
|
| 96 |
+
|
| 97 |
+
def get_events_processed_count(self):
|
| 98 |
+
"""Get total events processed"""
|
| 99 |
+
return self.events_processed
|
| 100 |
+
|
| 101 |
+
# Base Rule Class
|
| 102 |
+
class SecurityRule:
|
| 103 |
+
def __init__(self, name, config):
|
| 104 |
+
self.name = name
|
| 105 |
+
self.config = config
|
| 106 |
+
self.active = config.get('active', True)
|
| 107 |
+
self.threat_level = config.get('threat_level', 50)
|
| 108 |
+
|
| 109 |
+
def is_active(self):
|
| 110 |
+
return self.active
|
| 111 |
+
|
| 112 |
+
def matches(self, event):
|
| 113 |
+
"""Check if event matches this rule"""
|
| 114 |
+
raise NotImplementedError
|
| 115 |
+
|
| 116 |
+
def get_threat_level(self):
|
| 117 |
+
return self.threat_level
|
| 118 |
+
|
| 119 |
+
# Network Traffic Spike Rule
|
| 120 |
+
class NetworkTrafficSpikeRule(SecurityRule):
|
| 121 |
+
def matches(self, event):
|
| 122 |
+
if event.get('type') != 'network_traffic':
|
| 123 |
+
return False
|
| 124 |
+
|
| 125 |
+
current_traffic = event.get('traffic_mbps', 0)
|
| 126 |
+
baseline = self.config.get('baseline_mbps', 100)
|
| 127 |
+
threshold = self.config.get('spike_threshold_percent', 200)
|
| 128 |
+
|
| 129 |
+
spike_threshold = baseline * (threshold / 100)
|
| 130 |
+
return current_traffic > spike_threshold
|
| 131 |
+
|
| 132 |
+
# Resource Usage Spike Rule
|
| 133 |
+
class ResourceUsageSpikeRule(SecurityRule):
|
| 134 |
+
def matches(self, event):
|
| 135 |
+
if event.get('type') != 'resource_usage':
|
| 136 |
+
return False
|
| 137 |
+
|
| 138 |
+
usage_type = event.get('resource_type')
|
| 139 |
+
current_usage = event.get('usage_percent', 0)
|
| 140 |
+
threshold = self.config.get(f'{usage_type}_threshold', 80)
|
| 141 |
+
|
| 142 |
+
# Exclude system processes
|
| 143 |
+
process_name = event.get('process_name', '')
|
| 144 |
+
excluded_processes = ['system_update', 'windows_update', 'apt-get']
|
| 145 |
+
|
| 146 |
+
return (current_usage > threshold and
|
| 147 |
+
process_name not in excluded_processes)
|
| 148 |
+
|
| 149 |
+
# Data Exfiltration Rule
|
| 150 |
+
class DataExfiltrationRule(SecurityRule):
|
| 151 |
+
def matches(self, event):
|
| 152 |
+
if event.get('type') != 'data_transfer':
|
| 153 |
+
return False
|
| 154 |
+
|
| 155 |
+
# Check transfer size
|
| 156 |
+
transfer_size = event.get('size_mb', 0)
|
| 157 |
+
size_threshold = self.config.get('size_threshold_mb', 100)
|
| 158 |
+
|
| 159 |
+
if transfer_size > size_threshold:
|
| 160 |
+
return True
|
| 161 |
+
...
|
| 162 |
+
... # Check file extension
|
| 163 |
+
... file_ext = event.get('file_extension', '')
|
| 164 |
+
... suspicious_exts = self.config.get('suspicious_extensions', ['.zip', '.rar', '.exe'])
|
| 165 |
+
...
|
| 166 |
+
... if file_ext in suspicious_exts:
|
| 167 |
+
... return True
|
| 168 |
+
...
|
| 169 |
+
... # Check destination
|
| 170 |
+
... dest_ip = event.get('destination_ip', '')
|
| 171 |
+
... blacklist = self.config.get('blacklisted_ips', [])
|
| 172 |
+
...
|
| 173 |
+
... if dest_ip in blacklist:
|
| 174 |
+
... return True
|
| 175 |
+
...
|
| 176 |
+
... return False
|
| 177 |
+
...
|
| 178 |
+
... # Unauthorized Access Rule
|
| 179 |
+
... class UnauthorizedAccessRule(SecurityRule):
|
| 180 |
+
... def matches(self, event):
|
| 181 |
+
... if event.get('type') != 'login_attempt':
|
| 182 |
+
... return False
|
| 183 |
+
...
|
| 184 |
+
... failed_attempts = event.get('failed_attempts', 0)
|
| 185 |
+
... threshold = self.config.get('attempt_threshold', 5)
|
| 186 |
+
...
|
| 187 |
+
... if failed_attempts > threshold:
|
| 188 |
+
... return True
|
| 189 |
+
...
|
| 190 |
+
... # Check restricted accounts
|
| 191 |
+
... username = event.get('username', '')
|
| 192 |
+
... restricted_accounts = self.config.get('restricted_accounts', ['admin', 'root'])
|
| 193 |
+
...
|
| 194 |
+
... if username in restricted_accounts:
|
| 195 |
+
... return True
|
| 196 |
+
...
|
| 197 |
+
... return False
|
generated/emotions.py
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Python 3.13.9 (tags/v3.13.9:8183fa5, Oct 14 2025, 14:09:13) [MSC v.1944 64 bit (AMD64)] on win32
|
| 2 |
+
Enter "help" below or click "Help" above for more information.
|
| 3 |
+
"""
|
| 4 |
+
Emotion Awareness Module
|
| 5 |
+
"""
|
| 6 |
+
|
| 7 |
+
import time
|
| 8 |
+
import random
|
| 9 |
+
|
| 10 |
+
class EmotionAwareness:
|
| 11 |
+
def __init__(self):
|
| 12 |
+
self.initialized = False
|
| 13 |
+
self.emotion_models = {}
|
| 14 |
+
|
| 15 |
+
def initialize(self):
|
| 16 |
+
... """Initialize emotion awareness"""
|
| 17 |
+
... print("Initializing Emotion Awareness Module...")
|
| 18 |
+
... time.sleep(1) # Simulate initialization
|
| 19 |
+
... self.initialized = True
|
| 20 |
+
... print("Emotion Awareness Module initialized successfully")
|
| 21 |
+
...
|
| 22 |
+
... def analyze(self, event):
|
| 23 |
+
... """Analyze emotional content of event"""
|
| 24 |
+
... if not self.initialized:
|
| 25 |
+
... return 0
|
| 26 |
+
...
|
| 27 |
+
... # Simulate emotion analysis
|
| 28 |
+
... message = event.get('message', '')
|
| 29 |
+
...
|
| 30 |
+
... # Simple emotion scoring based on keywords
|
| 31 |
+
... emotion_score = 0
|
| 32 |
+
...
|
| 33 |
+
... # Negative emotion indicators
|
| 34 |
+
... negative_words = ['attack', 'threat', 'danger', 'warning', 'alert', 'critical']
|
| 35 |
+
... positive_words = ['safe', 'secure', 'normal', 'ok', 'good']
|
| 36 |
+
...
|
| 37 |
+
... message_lower = message.lower() if message else ''
|
| 38 |
+
...
|
| 39 |
+
... for word in negative_words:
|
| 40 |
+
... if word in message_lower:
|
| 41 |
+
... emotion_score += 10
|
| 42 |
+
...
|
| 43 |
+
... for word in positive_words:
|
| 44 |
+
... if word in message_lower:
|
| 45 |
+
... emotion_score -= 5
|
| 46 |
+
...
|
| 47 |
+
... # Add randomness for realistic behavior
|
| 48 |
+
... emotion_score += random.randint(-10, 10)
|
| 49 |
+
...
|
| 50 |
+
... # Clamp to 0-100 range
|
| 51 |
+
... emotion_score = max(0, min(100, emotion_score))
|
| 52 |
+
...
|
| 53 |
+
... return emotion_score
|
generated/encryption.py
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Encryption Manager
|
| 3 |
+
"""
|
| 4 |
+
|
| 5 |
+
import time
|
| 6 |
+
from cryptography.fernet import Fernet
|
| 7 |
+
... import base64
|
| 8 |
+
... import os
|
| 9 |
+
...
|
| 10 |
+
... class EncryptionManager:
|
| 11 |
+
... def __init__(self):
|
| 12 |
+
... self.key = None
|
| 13 |
+
... self.cipher = None
|
| 14 |
+
...
|
| 15 |
+
... def initialize(self):
|
| 16 |
+
... """Initialize encryption manager"""
|
| 17 |
+
... print("Initializing Encryption Manager...")
|
| 18 |
+
...
|
| 19 |
+
... # Generate or load encryption key
|
| 20 |
+
... key_file = 'config/encryption.key'
|
| 21 |
+
... if os.path.exists(key_file):
|
| 22 |
+
... with open(key_file, 'rb') as f:
|
| 23 |
+
... self.key = f.read()
|
| 24 |
+
... else:
|
| 25 |
+
... self.key = Fernet.generate_key()
|
| 26 |
+
... os.makedirs(os.path.dirname(key_file), exist_ok=True)
|
| 27 |
+
... with open(key_file, 'wb') as f:
|
| 28 |
+
... f.write(self.key)
|
| 29 |
+
...
|
| 30 |
+
... self.cipher = Fernet(self.key)
|
| 31 |
+
... print("Encryption Manager initialized successfully")
|
| 32 |
+
...
|
| 33 |
+
... def encrypt(self, data):
|
| 34 |
+
... """Encrypt data"""
|
| 35 |
+
... if isinstance(data, str):
|
| 36 |
+
... data = data.encode()
|
| 37 |
+
... return self.cipher.encrypt(data)
|
| 38 |
+
...
|
| 39 |
+
... def decrypt(self, encrypted_data):
|
| 40 |
+
... """Decrypt data"""
|
| 41 |
+
... return self.cipher.decrypt(encrypted_data).decode()
|
generated/engine.py
ADDED
|
@@ -0,0 +1,197 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Python 3.13.9 (tags/v3.13.9:8183fa5, Oct 14 2025, 14:09:13) [MSC v.1944 64 bit (AMD64)] on win32
|
| 2 |
+
Enter "help" below or click "Help" above for more information.
|
| 3 |
+
"""
|
| 4 |
+
Core Defender Engine
|
| 5 |
+
"""
|
| 6 |
+
|
| 7 |
+
import time
|
| 8 |
+
import threading
|
| 9 |
+
from datetime import datetime
|
| 10 |
+
from collections import deque
|
| 11 |
+
import psutil
|
| 12 |
+
|
| 13 |
+
class DefenderEngine:
|
| 14 |
+
def __init__(self):
|
| 15 |
+
self.events = deque(maxlen=10000)
|
| 16 |
+
self.alerts = deque(maxlen=1000)
|
| 17 |
+
self.rules = {}
|
| 18 |
+
self.status = {}
|
| 19 |
+
self.start_time = time.time()
|
| 20 |
+
self.events_processed = 0
|
| 21 |
+
|
| 22 |
+
def process_event(self, event):
|
| 23 |
+
"""Process a security event"""
|
| 24 |
+
event['processed_at'] = datetime.now().isoformat()
|
| 25 |
+
self.events.append(event)
|
| 26 |
+
self.events_processed += 1
|
| 27 |
+
|
| 28 |
+
# Apply rules to event
|
| 29 |
+
for rule_name, rule in self.rules.items():
|
| 30 |
+
if rule.is_active() and rule.matches(event):
|
| 31 |
+
self.generate_alert({
|
| 32 |
+
'rule': rule_name,
|
| 33 |
+
'event': event,
|
| 34 |
+
'timestamp': datetime.now().isoformat(),
|
| 35 |
+
'threat_level': rule.get_threat_level()
|
| 36 |
+
})
|
| 37 |
+
|
| 38 |
+
def generate_alert(self, assessment):
|
| 39 |
+
"""Generate security alert"""
|
| 40 |
+
alert = {
|
| 41 |
+
'id': len(self.alerts) + 1,
|
| 42 |
+
'assessment': assessment,
|
| 43 |
+
'timestamp': datetime.now().isoformat(),
|
| 44 |
+
'status': 'NEW'
|
| 45 |
+
}
|
| 46 |
+
self.alerts.append(alert)
|
| 47 |
+
|
| 48 |
+
# Log alert
|
| 49 |
+
print(f"SECURITY ALERT: {assessment}")
|
| 50 |
+
|
| 51 |
+
def get_recent_events(self, limit=100):
|
| 52 |
+
"""Get recent security events"""
|
| 53 |
+
return list(self.events)[-limit:]
|
| 54 |
+
|
| 55 |
+
def get_active_rules(self):
|
| 56 |
+
"""Get active security rules"""
|
| 57 |
+
return {name: rule for name, rule in self.rules.items() if rule.is_active()}
|
| 58 |
+
|
| 59 |
+
def get_current_threat_level(self):
|
| 60 |
+
"""Get current system threat level"""
|
| 61 |
+
recent_alerts = [alert for alert in self.alerts if
|
| 62 |
+
datetime.now().timestamp() -
|
| 63 |
+
datetime.fromisoformat(alert['timestamp']).timestamp() < 3600]
|
| 64 |
+
|
| 65 |
+
if not recent_alerts:
|
| 66 |
+
return "LOW"
|
| 67 |
+
|
| 68 |
+
high_severity_count = sum(1 for alert in recent_alerts
|
| 69 |
+
if alert.get('assessment', {}).get('threat_level', 0) > 80)
|
| 70 |
+
|
| 71 |
+
if high_severity_count > 5:
|
| 72 |
+
return "CRITICAL"
|
| 73 |
+
elif high_severity_count > 2:
|
| 74 |
+
return "HIGH"
|
| 75 |
+
elif len(recent_alerts) > 10:
|
| 76 |
+
return "MEDIUM"
|
| 77 |
+
else:
|
| 78 |
+
return "LOW"
|
| 79 |
+
|
| 80 |
+
def update_status(self, status):
|
| 81 |
+
"""Update system status"""
|
| 82 |
+
self.status = status
|
| 83 |
+
|
| 84 |
+
def get_cpu_usage(self):
|
| 85 |
+
"""Get current CPU usage"""
|
| 86 |
+
return psutil.cpu_percent()
|
| 87 |
+
|
| 88 |
+
def get_memory_usage(self):
|
| 89 |
+
"""Get current memory usage"""
|
| 90 |
+
return psutil.virtual_memory().percent
|
| 91 |
+
|
| 92 |
+
def get_average_response_time(self):
|
| 93 |
+
"""Get average response time"""
|
| 94 |
+
# Simulated response time
|
| 95 |
+
return 2.8
|
| 96 |
+
|
| 97 |
+
def get_events_processed_count(self):
|
| 98 |
+
"""Get total events processed"""
|
| 99 |
+
return self.events_processed
|
| 100 |
+
|
| 101 |
+
# Base Rule Class
|
| 102 |
+
class SecurityRule:
|
| 103 |
+
def __init__(self, name, config):
|
| 104 |
+
self.name = name
|
| 105 |
+
self.config = config
|
| 106 |
+
self.active = config.get('active', True)
|
| 107 |
+
self.threat_level = config.get('threat_level', 50)
|
| 108 |
+
|
| 109 |
+
def is_active(self):
|
| 110 |
+
return self.active
|
| 111 |
+
|
| 112 |
+
def matches(self, event):
|
| 113 |
+
"""Check if event matches this rule"""
|
| 114 |
+
raise NotImplementedError
|
| 115 |
+
|
| 116 |
+
def get_threat_level(self):
|
| 117 |
+
return self.threat_level
|
| 118 |
+
|
| 119 |
+
# Network Traffic Spike Rule
|
| 120 |
+
class NetworkTrafficSpikeRule(SecurityRule):
|
| 121 |
+
def matches(self, event):
|
| 122 |
+
if event.get('type') != 'network_traffic':
|
| 123 |
+
return False
|
| 124 |
+
|
| 125 |
+
current_traffic = event.get('traffic_mbps', 0)
|
| 126 |
+
baseline = self.config.get('baseline_mbps', 100)
|
| 127 |
+
threshold = self.config.get('spike_threshold_percent', 200)
|
| 128 |
+
|
| 129 |
+
spike_threshold = baseline * (threshold / 100)
|
| 130 |
+
return current_traffic > spike_threshold
|
| 131 |
+
|
| 132 |
+
# Resource Usage Spike Rule
|
| 133 |
+
class ResourceUsageSpikeRule(SecurityRule):
|
| 134 |
+
def matches(self, event):
|
| 135 |
+
if event.get('type') != 'resource_usage':
|
| 136 |
+
return False
|
| 137 |
+
|
| 138 |
+
usage_type = event.get('resource_type')
|
| 139 |
+
current_usage = event.get('usage_percent', 0)
|
| 140 |
+
threshold = self.config.get(f'{usage_type}_threshold', 80)
|
| 141 |
+
|
| 142 |
+
# Exclude system processes
|
| 143 |
+
process_name = event.get('process_name', '')
|
| 144 |
+
excluded_processes = ['system_update', 'windows_update', 'apt-get']
|
| 145 |
+
|
| 146 |
+
return (current_usage > threshold and
|
| 147 |
+
process_name not in excluded_processes)
|
| 148 |
+
|
| 149 |
+
# Data Exfiltration Rule
|
| 150 |
+
class DataExfiltrationRule(SecurityRule):
|
| 151 |
+
def matches(self, event):
|
| 152 |
+
if event.get('type') != 'data_transfer':
|
| 153 |
+
return False
|
| 154 |
+
|
| 155 |
+
# Check transfer size
|
| 156 |
+
transfer_size = event.get('size_mb', 0)
|
| 157 |
+
size_threshold = self.config.get('size_threshold_mb', 100)
|
| 158 |
+
|
| 159 |
+
if transfer_size > size_threshold:
|
| 160 |
+
return True
|
| 161 |
+
...
|
| 162 |
+
... # Check file extension
|
| 163 |
+
... file_ext = event.get('file_extension', '')
|
| 164 |
+
... suspicious_exts = self.config.get('suspicious_extensions', ['.zip', '.rar', '.exe'])
|
| 165 |
+
...
|
| 166 |
+
... if file_ext in suspicious_exts:
|
| 167 |
+
... return True
|
| 168 |
+
...
|
| 169 |
+
... # Check destination
|
| 170 |
+
... dest_ip = event.get('destination_ip', '')
|
| 171 |
+
... blacklist = self.config.get('blacklisted_ips', [])
|
| 172 |
+
...
|
| 173 |
+
... if dest_ip in blacklist:
|
| 174 |
+
... return True
|
| 175 |
+
...
|
| 176 |
+
... return False
|
| 177 |
+
...
|
| 178 |
+
... # Unauthorized Access Rule
|
| 179 |
+
... class UnauthorizedAccessRule(SecurityRule):
|
| 180 |
+
... def matches(self, event):
|
| 181 |
+
... if event.get('type') != 'login_attempt':
|
| 182 |
+
... return False
|
| 183 |
+
...
|
| 184 |
+
... failed_attempts = event.get('failed_attempts', 0)
|
| 185 |
+
... threshold = self.config.get('attempt_threshold', 5)
|
| 186 |
+
...
|
| 187 |
+
... if failed_attempts > threshold:
|
| 188 |
+
... return True
|
| 189 |
+
...
|
| 190 |
+
... # Check restricted accounts
|
| 191 |
+
... username = event.get('username', '')
|
| 192 |
+
... restricted_accounts = self.config.get('restricted_accounts', ['admin', 'root'])
|
| 193 |
+
...
|
| 194 |
+
... if username in restricted_accounts:
|
| 195 |
+
... return True
|
| 196 |
+
...
|
| 197 |
+
... return False
|
generated/holas_defender.py
ADDED
|
File without changes
|
generated/install.sh
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Python 3.13.9 (tags/v3.13.9:8183fa5, Oct 14 2025, 14:09:13) [MSC v.1944 64 bit (AMD64)] on win32
|
| 2 |
+
Enter "help" below or click "Help" above for more information.
|
| 3 |
+
>>> #!/bin/bash
|
| 4 |
+
...
|
| 5 |
+
... # HOLAS AI Defender Installation Script
|
| 6 |
+
...
|
| 7 |
+
... echo "Installing HOLAS AI Defender v1.0..."
|
| 8 |
+
...
|
| 9 |
+
... # Create directories
|
| 10 |
+
... mkdir -p logs config docs examples
|
| 11 |
+
...
|
| 12 |
+
... # Install Python dependencies
|
| 13 |
+
... if command -v pip3 &> /dev/null; then
|
| 14 |
+
... pip3 install -r requirements.txt
|
| 15 |
+
... else
|
| 16 |
+
... echo "Error: pip3 not found. Please install Python 3 and pip."
|
| 17 |
+
... exit 1
|
| 18 |
+
... fi
|
| 19 |
+
...
|
| 20 |
+
... # Set permissions
|
| 21 |
+
... chmod +x main.py
|
| 22 |
+
... chmod +x install.sh
|
| 23 |
+
...
|
| 24 |
+
... # Create log directory
|
| 25 |
+
... mkdir -p logs
|
| 26 |
+
...
|
| 27 |
+
... # Copy configuration files
|
| 28 |
+
... if [ ! -f config/system.json ]; then
|
| 29 |
+
... cp config/system.json.example config/system.json 2>/dev/null || echo "Configuration file not found"
|
| 30 |
+
... fi
|
| 31 |
+
...
|
| 32 |
+
... echo "Installation complete!"
|
| 33 |
+
... echo "Run the system with: python3 main.py"
|
generated/main.py
ADDED
|
@@ -0,0 +1,184 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Python 3.13.9 (tags/v3.13.9:8183fa5, Oct 14 2025, 14:09:13) [MSC v.1944 64 bit (AMD64)] on win32
|
| 2 |
+
Enter "help" below or click "Help" above for more information.
|
| 3 |
+
#!/usr/bin/env python3
|
| 4 |
+
"""
|
| 5 |
+
HOLAS AI DEFENDER v1.0
|
| 6 |
+
Advanced Next-Generation AI Security System
|
| 7 |
+
"""
|
| 8 |
+
|
| 9 |
+
import sys
|
| 10 |
+
import os
|
| 11 |
+
import logging
|
| 12 |
+
import json
|
| 13 |
+
import time
|
| 14 |
+
from datetime import datetime
|
| 15 |
+
from pathlib import Path
|
| 16 |
+
|
| 17 |
+
# Core modules
|
| 18 |
+
from core.engine import DefenderEngine
|
| 19 |
+
from core.config import ConfigManager
|
| 20 |
+
from core.logger import DefenderLogger
|
| 21 |
+
from core.api import APIServer
|
| 22 |
+
|
| 23 |
+
# Security modules
|
| 24 |
+
from security.nids import NetworkIntrusionDetector
|
| 25 |
+
from security.behavior import BehavioralAnalyzer
|
| 26 |
+
from security.encryption import EncryptionManager
|
| 27 |
+
|
| 28 |
+
# AI modules
|
| 29 |
+
from ai.sdre import SelfDrivingReasoningEngine
|
| 30 |
+
from ai.emotion import EmotionAwareness
|
| 31 |
+
from ai.multilingual import MultilingualProcessor
|
| 32 |
+
|
| 33 |
+
class HOLASDefender:
|
| 34 |
+
def __init__(self):
|
| 35 |
+
self.config = ConfigManager()
|
| 36 |
+
self.logger = DefenderLogger()
|
| 37 |
+
self.engine = DefenderEngine()
|
| 38 |
+
self.api_server = APIServer()
|
| 39 |
+
|
| 40 |
+
# Security components
|
| 41 |
+
self.nids = NetworkIntrusionDetector()
|
| 42 |
+
self.behavior_analyzer = BehavioralAnalyzer()
|
| 43 |
+
self.encryption = EncryptionManager()
|
| 44 |
+
|
| 45 |
+
# AI components
|
| 46 |
+
self.sdre = SelfDrivingReasoningEngine()
|
| 47 |
+
self.emotion_awareness = EmotionAwareness()
|
| 48 |
+
self.multilingual = MultilingualProcessor()
|
| 49 |
+
|
| 50 |
+
self.running = False
|
| 51 |
+
|
| 52 |
+
def initialize(self):
|
| 53 |
+
"""Initialize all system components"""
|
| 54 |
+
try:
|
| 55 |
+
self.logger.info("Initializing HOLAS AI Defender v1.0")
|
| 56 |
+
|
| 57 |
+
# Load configuration
|
| 58 |
+
self.config.load()
|
| 59 |
+
|
| 60 |
+
# Initialize security components
|
| 61 |
+
self.nids.initialize()
|
| 62 |
+
self.behavior_analyzer.initialize()
|
| 63 |
+
self.encryption.initialize()
|
| 64 |
+
|
| 65 |
+
# Initialize AI components
|
| 66 |
+
self.sdre.initialize()
|
| 67 |
+
self.emotion_awareness.initialize()
|
| 68 |
+
self.multilingual.initialize()
|
| 69 |
+
|
| 70 |
+
# Start API server
|
| 71 |
+
self.api_server.start()
|
| 72 |
+
|
| 73 |
+
self.logger.info("System initialization complete")
|
| 74 |
+
return True
|
| 75 |
+
|
| 76 |
+
except Exception as e:
|
| 77 |
+
self.logger.error(f"Initialization failed: {str(e)}")
|
| 78 |
+
return False
|
| 79 |
+
|
| 80 |
+
def start(self):
|
| 81 |
+
"""Start the defender system"""
|
| 82 |
+
if not self.initialize():
|
| 83 |
+
return False
|
| 84 |
+
|
| 85 |
+
self.running = True
|
| 86 |
+
self.logger.info("HOLAS AI Defender started")
|
| 87 |
+
|
| 88 |
+
# Start main monitoring loop
|
| 89 |
+
while self.running:
|
| 90 |
+
try:
|
| 91 |
+
# Run security monitoring
|
| 92 |
+
self.monitor_security()
|
| 93 |
+
|
| 94 |
+
# Run AI analysis
|
| 95 |
+
self.analyze_threats()
|
| 96 |
+
|
| 97 |
+
# Update system status
|
| 98 |
+
self.update_status()
|
| 99 |
+
|
| 100 |
+
time.sleep(1) # Main loop delay
|
| 101 |
+
|
| 102 |
+
except KeyboardInterrupt:
|
| 103 |
+
self.logger.info("Shutdown requested")
|
| 104 |
+
break
|
| 105 |
+
except Exception as e:
|
| 106 |
+
self.logger.error(f"Main loop error: {str(e)}")
|
| 107 |
+
time.sleep(5) # Error recovery delay
|
| 108 |
+
|
| 109 |
+
def monitor_security(self):
|
| 110 |
+
"""Monitor security events"""
|
| 111 |
+
# Network monitoring
|
| 112 |
+
network_events = self.nids.monitor()
|
| 113 |
+
for event in network_events:
|
| 114 |
+
self.engine.process_event(event)
|
| 115 |
+
|
| 116 |
+
# Behavioral monitoring
|
| 117 |
+
behavior_events = self.behavior_analyzer.monitor()
|
| 118 |
+
for event in behavior_events:
|
| 119 |
+
self.engine.process_event(event)
|
| 120 |
+
|
| 121 |
+
def analyze_threats(self):
|
| 122 |
+
"""Analyze threats using AI components"""
|
| 123 |
+
# Get recent events for analysis
|
| 124 |
+
recent_events = self.engine.get_recent_events()
|
| 125 |
+
|
| 126 |
+
for event in recent_events:
|
| 127 |
+
# Emotional analysis
|
| 128 |
+
emotion_score = self.emotion_awareness.analyze(event)
|
| 129 |
+
|
| 130 |
+
# Multilingual processing
|
| 131 |
+
processed_text = self.multilingual.process(event.get('message', ''))
|
| 132 |
+
|
| 133 |
+
# SDRE analysis
|
| 134 |
+
threat_assessment = self.sdre.analyze({
|
| 135 |
+
'event': event,
|
| 136 |
+
'emotion_score': emotion_score,
|
| 137 |
+
'processed_text': processed_text
|
| 138 |
+
})
|
| 139 |
+
|
| 140 |
+
# Generate response if threat detected
|
| 141 |
+
if threat_assessment.get('threat_level', 0) > self.config.get('threat_threshold', 50):
|
| 142 |
+
self.engine.generate_alert(threat_assessment)
|
| 143 |
+
|
| 144 |
+
def update_status(self):
|
| 145 |
+
"""Update system status"""
|
| 146 |
+
... status = {
|
| 147 |
+
... 'timestamp': datetime.now().isoformat(),
|
| 148 |
+
... 'system_status': 'SECURE' if self.running else 'STOPPED',
|
| 149 |
+
... 'active_rules': len(self.engine.get_active_rules()),
|
| 150 |
+
... 'threat_level': self.engine.get_current_threat_level(),
|
| 151 |
+
... 'performance': self.get_performance_metrics()
|
| 152 |
+
... }
|
| 153 |
+
...
|
| 154 |
+
... self.engine.update_status(status)
|
| 155 |
+
...
|
| 156 |
+
... def get_performance_metrics(self):
|
| 157 |
+
... """Get system performance metrics"""
|
| 158 |
+
... return {
|
| 159 |
+
... 'cpu_usage': self.engine.get_cpu_usage(),
|
| 160 |
+
... 'memory_usage': self.engine.get_memory_usage(),
|
| 161 |
+
... 'response_time': self.engine.get_average_response_time(),
|
| 162 |
+
... 'events_processed': self.engine.get_events_processed_count()
|
| 163 |
+
... }
|
| 164 |
+
...
|
| 165 |
+
... def stop(self):
|
| 166 |
+
... """Stop the defender system"""
|
| 167 |
+
... self.running = False
|
| 168 |
+
... self.api_server.stop()
|
| 169 |
+
... self.logger.info("HOLAS AI Defender stopped")
|
| 170 |
+
...
|
| 171 |
+
... def main():
|
| 172 |
+
... """Main entry point"""
|
| 173 |
+
... defender = HOLASDefender()
|
| 174 |
+
...
|
| 175 |
+
... try:
|
| 176 |
+
... defender.start()
|
| 177 |
+
... except Exception as e:
|
| 178 |
+
... print(f"Fatal error: {str(e)}")
|
| 179 |
+
... sys.exit(1)
|
| 180 |
+
... finally:
|
| 181 |
+
... defender.stop()
|
| 182 |
+
...
|
| 183 |
+
... if __name__ == "__main__":
|
| 184 |
+
... main()
|
generated/multilingual.py
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Multilingual Processing Module
|
| 3 |
+
"""
|
| 4 |
+
|
| 5 |
+
import time
|
| 6 |
+
import re
|
| 7 |
+
|
| 8 |
+
class MultilingualProcessor:
|
| 9 |
+
def __init__(self):
|
| 10 |
+
self.initialized = False
|
| 11 |
+
self.supported_languages = ['english', 'luganda']
|
| 12 |
+
self.translation_models = {}
|
| 13 |
+
|
| 14 |
+
def initialize(self):
|
| 15 |
+
"""Initialize multilingual processor"""
|
| 16 |
+
print("Initializing Multilingual Processing Module...")
|
| 17 |
+
time.sleep(1) # Simulate initialization
|
| 18 |
+
self.initialized = True
|
| 19 |
+
print("Multilingual Processing Module initialized successfully")
|
| 20 |
+
|
| 21 |
+
def process(self, text):
|
| 22 |
+
"""Process text in multiple languages"""
|
| 23 |
+
if not self.initialized or not text:
|
| 24 |
+
return text
|
| 25 |
+
|
| 26 |
+
# Detect language (simplified)
|
| 27 |
+
processed_text = self.normalize_text(text)
|
| 28 |
+
|
| 29 |
+
# Apply language-specific processing
|
| 30 |
+
if self.is_luganda(text):
|
| 31 |
+
processed_text = self.process_luganda(text)
|
| 32 |
+
else:
|
| 33 |
+
processed_text = self.process_english(text)
|
| 34 |
+
|
| 35 |
+
return processed_text
|
| 36 |
+
|
| 37 |
+
... def normalize_text(self, text):
|
| 38 |
+
... """Normalize text for processing"""
|
| 39 |
+
... # Remove extra whitespace
|
| 40 |
+
... text = re.sub(r'\s+', ' ', text.strip())
|
| 41 |
+
... return text
|
| 42 |
+
...
|
| 43 |
+
... def is_luganda(self, text):
|
| 44 |
+
... """Simple Luganda detection"""
|
| 45 |
+
... luganda_indicators = ['naye', 'bwe', 'kye', 'gye', 'mwe', 'bwekiri']
|
| 46 |
+
... text_lower = text.lower()
|
| 47 |
+
...
|
| 48 |
+
... for indicator in luganda_indicators:
|
| 49 |
+
... if indicator in text_lower:
|
| 50 |
+
... return True
|
| 51 |
+
...
|
| 52 |
+
... return False
|
| 53 |
+
...
|
| 54 |
+
... def process_luganda(self, text):
|
| 55 |
+
... """Process Luganda text"""
|
| 56 |
+
... # Simple Luganda processing
|
| 57 |
+
... processed = text
|
| 58 |
+
...
|
| 59 |
+
... # Replace common Luganda patterns with English equivalents for analysis
|
| 60 |
+
... replacements = {
|
| 61 |
+
... 'naye': 'but',
|
| 62 |
+
... 'bwe': 'when',
|
| 63 |
+
... 'kye': 'what',
|
| 64 |
+
... 'gye': 'where'
|
| 65 |
+
... }
|
| 66 |
+
...
|
| 67 |
+
... for luganda_word, english_word in replacements.items():
|
| 68 |
+
... processed = processed.replace(luganda_word, english_word)
|
| 69 |
+
...
|
| 70 |
+
... return processed
|
| 71 |
+
...
|
| 72 |
+
... def process_english(self, text):
|
| 73 |
+
... """Process English text"""
|
| 74 |
+
... # Simple English processing
|
| 75 |
+
... return text.strip()
|
generated/requirement.txt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Flask==2.3.3
|
| 2 |
+
psutil==5.9.5
|
| 3 |
+
cryptography==41.0.4
|
generated/sdre.py
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Python 3.13.9 (tags/v3.13.9:8183fa5, Oct 14 2025, 14:09:13) [MSC v.1944 64 bit (AMD64)] on win32
|
| 2 |
+
Enter "help" below or click "Help" above for more information.
|
| 3 |
+
"""
|
| 4 |
+
Self-Driving Reasoning Engine
|
| 5 |
+
"""
|
| 6 |
+
|
| 7 |
+
import time
|
| 8 |
+
import random
|
| 9 |
+
from datetime import datetime
|
| 10 |
+
|
| 11 |
+
class SelfDrivingReasoningEngine:
|
| 12 |
+
def __init__(self):
|
| 13 |
+
self.initialized = False
|
| 14 |
+
self.knowledge_graph = {}
|
| 15 |
+
self.reasoning_patterns = []
|
| 16 |
+
|
| 17 |
+
def initialize(self):
|
| 18 |
+
"""Initialize SDRE"""
|
| 19 |
+
print("Initializing Self-Driving Reasoning Engine...")
|
| 20 |
+
time.sleep(2) # Simulate complex initialization
|
| 21 |
+
self.initialized = True
|
| 22 |
+
print("SDRE initialized successfully")
|
| 23 |
+
|
| 24 |
+
def analyze(self, data):
|
| 25 |
+
"""Analyze data using self-driving reasoning"""
|
| 26 |
+
if not self.initialized:
|
| 27 |
+
return {'threat_level': 0, 'confidence': 0}
|
| 28 |
+
|
| 29 |
+
# Simulate complex reasoning
|
| 30 |
+
event = data.get('event', {})
|
| 31 |
+
emotion_score = data.get('emotion_score', 0)
|
| 32 |
+
processed_text = data.get('processed_text', '')
|
| 33 |
+
|
| 34 |
+
# Calculate threat level based on multiple factors
|
| 35 |
+
base_threat = 0
|
| 36 |
+
|
| 37 |
+
# Event-based threat calculation
|
| 38 |
+
if event.get('type') == 'network_traffic':
|
| 39 |
+
traffic = event.get('traffic_mbps', 0)
|
| 40 |
+
base_threat = min(100, traffic / 5) # Scale threat based on traffic
|
| 41 |
+
|
| 42 |
+
elif event.get('type') == 'login_attempt':
|
| 43 |
+
attempts = event.get('failed_attempts', 0)
|
| 44 |
+
base_threat = min(100, attempts * 20) # Scale threat based on attempts
|
| 45 |
+
...
|
| 46 |
+
... elif event.get('type') == 'data_transfer':
|
| 47 |
+
... size = event.get('size_mb', 0)
|
| 48 |
+
... base_threat = min(100, size / 5) # Scale threat based on size
|
| 49 |
+
...
|
| 50 |
+
... # Adjust based on emotional analysis
|
| 51 |
+
... emotion_adjustment = emotion_score * 0.1 # Emotion score influence
|
| 52 |
+
...
|
| 53 |
+
... # Final threat calculation
|
| 54 |
+
... final_threat = min(100, base_threat + emotion_adjustment)
|
| 55 |
+
...
|
| 56 |
+
... # Add some randomness for realistic behavior
|
| 57 |
+
... final_threat = max(0, final_threat + random.randint(-5, 5))
|
| 58 |
+
...
|
| 59 |
+
... return {
|
| 60 |
+
... 'threat_level': int(final_threat),
|
| 61 |
+
... 'confidence': random.randint(85, 99),
|
| 62 |
+
... 'recommendations': self.generate_recommendations(event),
|
| 63 |
+
... 'timestamp': datetime.now().isoformat()
|
| 64 |
+
... }
|
| 65 |
+
...
|
| 66 |
+
... def generate_recommendations(self, event):
|
| 67 |
+
... """Generate security recommendations"""
|
| 68 |
+
... recommendations = []
|
| 69 |
+
...
|
| 70 |
+
... if event.get('type') == 'network_traffic':
|
| 71 |
+
... recommendations.append("Monitor network traffic patterns")
|
| 72 |
+
... recommendations.append("Review firewall rules for destination IP")
|
| 73 |
+
...
|
| 74 |
+
... elif event.get('type') == 'login_attempt':
|
| 75 |
+
... recommendations.append("Implement account lockout policy")
|
| 76 |
+
... recommendations.append("Enable multi-factor authentication")
|
| 77 |
+
...
|
| 78 |
+
... elif event.get('type') == 'data_transfer':
|
| 79 |
+
... recommendations.append("Scan transferred files for malware")
|
| 80 |
+
... recommendations.append("Review data loss prevention policies")
|
| 81 |
+
...
|
| 82 |
+
... return recommendations
|
generated/system.json
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Python 3.13.9 (tags/v3.13.9:8183fa5, Oct 14 2025, 14:09:13) [MSC v.1944 64 bit (AMD64)] on win32
|
| 2 |
+
Enter "help" below or click "Help" above for more information.
|
| 3 |
+
{
|
| 4 |
+
"threat_threshold": 50,
|
| 5 |
+
"log_level": "INFO",
|
| 6 |
+
"monitoring_interfaces": [
|
| 7 |
+
"eth0",
|
| 8 |
+
... "wlan0"
|
| 9 |
+
... ],
|
| 10 |
+
... "rules": {
|
| 11 |
+
... "network_traffic_spike": {
|
| 12 |
+
... "active": true,
|
| 13 |
+
... "baseline_mbps": 100,
|
| 14 |
+
... "spike_threshold_percent": 200,
|
| 15 |
+
... "threat_level": 75
|
| 16 |
+
... },
|
| 17 |
+
... "resource_usage_spike": {
|
| 18 |
+
... "active": true,
|
| 19 |
+
... "cpu_threshold": 80,
|
| 20 |
+
... "memory_threshold": 85,
|
| 21 |
+
... "threat_level": 60
|
| 22 |
+
... },
|
| 23 |
+
... "data_exfiltration": {
|
| 24 |
+
... "active": true,
|
| 25 |
+
... "size_threshold_mb": 100,
|
| 26 |
+
... "suspicious_extensions": [
|
| 27 |
+
... ".zip",
|
| 28 |
+
... ".rar",
|
| 29 |
+
... ".exe",
|
| 30 |
+
... ".pdf",
|
| 31 |
+
... ".docx"
|
| 32 |
+
... ],
|
| 33 |
+
... "threat_level": 90
|
| 34 |
+
... },
|
| 35 |
+
... "unauthorized_access": {
|
| 36 |
+
... "active": true,
|
| 37 |
+
... "attempt_threshold": 5,
|
| 38 |
+
... "restricted_accounts": [
|
| 39 |
+
... "admin",
|
| 40 |
+
... "root",
|
| 41 |
+
... "administrator"
|
| 42 |
+
... ],
|
| 43 |
+
... "threat_level": 85
|
| 44 |
+
... }
|
| 45 |
+
... }
|
| 46 |
+
... }
|