|
| 1 | +import re |
| 2 | +import random |
| 3 | + |
| 4 | +class InfrastructureProtectionAI: |
| 5 | + """AI role for protecting critical infrastructure and IoT devices.""" |
| 6 | + |
| 7 | + def detect_iot_tampering(self, device_data): |
| 8 | + """ |
| 9 | + Analyzes IoT device telemetry for signs of physical or digital tampering. |
| 10 | +
|
| 11 | + Args: |
| 12 | + device_data (dict): Telemetry data including voltage, temperature, and signal strength. |
| 13 | + """ |
| 14 | + anomalies = [] |
| 15 | + |
| 16 | + # Heuristic: Rapid voltage drop might indicate a power-side attack or battery tampering |
| 17 | + if device_data.get('voltage', 3.3) < 2.8: |
| 18 | + anomalies.append("Low voltage detected - possible power source tampering.") |
| 19 | + |
| 20 | + # Heuristic: Temperature spikes outside industrial operating range |
| 21 | + if device_data.get('temperature', 25) > 75: |
| 22 | + anomalies.append("Extreme temperature spike - potential hardware stress or overheating attack.") |
| 23 | + |
| 24 | + # Heuristic: Signal RSSI fluctuations |
| 25 | + if device_data.get('rssi', -50) < -90: |
| 26 | + anomalies.append("Weak signal (low RSSI) - potential signal jamming or interference.") |
| 27 | + |
| 28 | + if not anomalies: |
| 29 | + return {"status": "SECURE", "score": 0, "findings": ["Normal operating parameters."]} |
| 30 | + else: |
| 31 | + return { |
| 32 | + "status": "WARNING", |
| 33 | + "score": len(anomalies) * 3, |
| 34 | + "findings": anomalies |
| 35 | + } |
| 36 | + |
| 37 | + def assess_facility_vulnerability(self, access_logs): |
| 38 | + """ |
| 39 | + AI assessment of facility security based on access logs. |
| 40 | + """ |
| 41 | + unauthorized_attempts = [log for log in access_logs if log.get('status') == 'DENIED'] |
| 42 | + |
| 43 | + if len(unauthorized_attempts) > 5: |
| 44 | + return "HIGH RISK: Multiple unauthorized access attempts detected at perimeter." |
| 45 | + elif len(unauthorized_attempts) > 0: |
| 46 | + return "MEDIUM RISK: Occasional unauthorized access attempts detected." |
| 47 | + else: |
| 48 | + return "LOW RISK: Perimeter security appears intact." |
| 49 | + |
| 50 | + |
| 51 | +class AntivirusIdentificationAI: |
| 52 | + """AI role for identifying malware signatures and suspicious file behaviors.""" |
| 53 | + |
| 54 | + SUSPICIOUS_EXTENSIONS = ['.exe', '.sh', '.bat', '.bin', '.scr'] |
| 55 | + |
| 56 | + def scan_file_metadata(self, filename, filesize_kb): |
| 57 | + """ |
| 58 | + Identifies potential threats based on file metadata heuristics. |
| 59 | + """ |
| 60 | + findings = [] |
| 61 | + ext = '.' + filename.split('.')[-1] if '.' in filename else '' |
| 62 | + |
| 63 | + if ext.lower() in self.SUSPICIOUS_EXTENSIONS: |
| 64 | + findings.append(f"Suspicious executable extension: {ext}") |
| 65 | + |
| 66 | + if filesize_kb < 1: |
| 67 | + findings.append("Unusually small file size - potential dropper or script.") |
| 68 | + |
| 69 | + if not findings: |
| 70 | + return {"risk": "LOW", "details": "File metadata appears standard."} |
| 71 | + else: |
| 72 | + return {"risk": "MEDIUM", "details": findings} |
| 73 | + |
| 74 | + def identify_malware_behavior_patterns(self, execution_logs): |
| 75 | + """ |
| 76 | + Scans execution logs for behavior patterns consistent with malware (e.g. ransomware, spyware). |
| 77 | + """ |
| 78 | + patterns = { |
| 79 | + "Ransomware": ["mass_file_rename", "encryption_started", "delete_shadow_copies"], |
| 80 | + "Spyware": ["unauthorized_camera_access", "keystroke_logging", "exfiltrating_data"], |
| 81 | + "Worm": ["rapid_network_scanning", "self_replication_attempt"] |
| 82 | + } |
| 83 | + |
| 84 | + detected_threats = [] |
| 85 | + logs_flat = " ".join(execution_logs).lower() |
| 86 | + |
| 87 | + for threat, indicators in patterns.items(): |
| 88 | + for indicator in indicators: |
| 89 | + if indicator in logs_flat: |
| 90 | + detected_threats.append(f"{threat} indicator: {indicator}") |
| 91 | + |
| 92 | + return detected_threats if detected_threats else ["No malicious behavior patterns detected."] |
| 93 | + |
| 94 | +if __name__ == "__main__": |
| 95 | + # Test Infrastructure Protection |
| 96 | + infra_ai = InfrastructureProtectionAI() |
| 97 | + test_device = {'voltage': 2.5, 'temperature': 80, 'rssi': -95} |
| 98 | + print("IoT Tampering Analysis:", infra_ai.detect_iot_tampering(test_device)) |
| 99 | + |
| 100 | + # Test Antivirus ID |
| 101 | + av_ai = AntivirusIdentificationAI() |
| 102 | + print("File Scan:", av_ai.scan_file_metadata("update.bat", 0.5)) |
| 103 | + print("Behavior Analysis:", av_ai.identify_malware_behavior_patterns(["encryption_started", "delete_shadow_copies"])) |
0 commit comments