generated from github/codespaces-react
-
-
Notifications
You must be signed in to change notification settings - Fork 1
Enhance AI Security Roles and Data Protection #30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,103 @@ | ||
| import re | ||
| import random | ||
|
|
||
| class InfrastructureProtectionAI: | ||
| """AI role for protecting critical infrastructure and IoT devices.""" | ||
|
|
||
| def detect_iot_tampering(self, device_data): | ||
| """ | ||
| Analyzes IoT device telemetry for signs of physical or digital tampering. | ||
|
|
||
| Args: | ||
| device_data (dict): Telemetry data including voltage, temperature, and signal strength. | ||
| """ | ||
| anomalies = [] | ||
|
|
||
| # Heuristic: Rapid voltage drop might indicate a power-side attack or battery tampering | ||
| if device_data.get('voltage', 3.3) < 2.8: | ||
| anomalies.append("Low voltage detected - possible power source tampering.") | ||
|
|
||
| # Heuristic: Temperature spikes outside industrial operating range | ||
| if device_data.get('temperature', 25) > 75: | ||
| anomalies.append("Extreme temperature spike - potential hardware stress or overheating attack.") | ||
|
|
||
| # Heuristic: Signal RSSI fluctuations | ||
| if device_data.get('rssi', -50) < -90: | ||
| anomalies.append("Weak signal (low RSSI) - potential signal jamming or interference.") | ||
|
|
||
| if not anomalies: | ||
| return {"status": "SECURE", "score": 0, "findings": ["Normal operating parameters."]} | ||
| else: | ||
| return { | ||
| "status": "WARNING", | ||
| "score": len(anomalies) * 3, | ||
| "findings": anomalies | ||
| } | ||
|
|
||
| def assess_facility_vulnerability(self, access_logs): | ||
| """ | ||
| AI assessment of facility security based on access logs. | ||
| """ | ||
| unauthorized_attempts = [log for log in access_logs if log.get('status') == 'DENIED'] | ||
|
|
||
| if len(unauthorized_attempts) > 5: | ||
| return "HIGH RISK: Multiple unauthorized access attempts detected at perimeter." | ||
| elif len(unauthorized_attempts) > 0: | ||
| return "MEDIUM RISK: Occasional unauthorized access attempts detected." | ||
| else: | ||
| return "LOW RISK: Perimeter security appears intact." | ||
|
|
||
|
|
||
| class AntivirusIdentificationAI: | ||
| """AI role for identifying malware signatures and suspicious file behaviors.""" | ||
|
|
||
| SUSPICIOUS_EXTENSIONS = ['.exe', '.sh', '.bat', '.bin', '.scr'] | ||
|
|
||
| def scan_file_metadata(self, filename, filesize_kb): | ||
| """ | ||
| Identifies potential threats based on file metadata heuristics. | ||
| """ | ||
| findings = [] | ||
| ext = '.' + filename.split('.')[-1] if '.' in filename else '' | ||
|
|
||
| if ext.lower() in self.SUSPICIOUS_EXTENSIONS: | ||
| findings.append(f"Suspicious executable extension: {ext}") | ||
|
|
||
| if filesize_kb < 1: | ||
| findings.append("Unusually small file size - potential dropper or script.") | ||
|
|
||
| if not findings: | ||
| return {"risk": "LOW", "details": "File metadata appears standard."} | ||
| else: | ||
| return {"risk": "MEDIUM", "details": findings} | ||
|
|
||
| def identify_malware_behavior_patterns(self, execution_logs): | ||
| """ | ||
| Scans execution logs for behavior patterns consistent with malware (e.g. ransomware, spyware). | ||
| """ | ||
| patterns = { | ||
| "Ransomware": ["mass_file_rename", "encryption_started", "delete_shadow_copies"], | ||
| "Spyware": ["unauthorized_camera_access", "keystroke_logging", "exfiltrating_data"], | ||
| "Worm": ["rapid_network_scanning", "self_replication_attempt"] | ||
| } | ||
|
|
||
| detected_threats = [] | ||
| logs_flat = " ".join(execution_logs).lower() | ||
|
|
||
| for threat, indicators in patterns.items(): | ||
| for indicator in indicators: | ||
| if indicator in logs_flat: | ||
| detected_threats.append(f"{threat} indicator: {indicator}") | ||
|
|
||
| return detected_threats if detected_threats else ["No malicious behavior patterns detected."] | ||
|
|
||
| if __name__ == "__main__": | ||
| # Test Infrastructure Protection | ||
| infra_ai = InfrastructureProtectionAI() | ||
| test_device = {'voltage': 2.5, 'temperature': 80, 'rssi': -95} | ||
| print("IoT Tampering Analysis:", infra_ai.detect_iot_tampering(test_device)) | ||
|
|
||
| # Test Antivirus ID | ||
| av_ai = AntivirusIdentificationAI() | ||
| print("File Scan:", av_ai.scan_file_metadata("update.bat", 0.5)) | ||
| print("Behavior Analysis:", av_ai.identify_malware_behavior_patterns(["encryption_started", "delete_shadow_copies"])) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
issue (bug_risk): Security submenu input handling can raise unhandled exceptions and silently ignore invalid choices.
User inputs for voltage/temperature/RSSI and file size are cast directly to numeric types; non-numeric values will raise
ValueErrorand terminate the program. Also, unsupportedsec_choicevalues fall through with no message, unlike the main menu. Please wrap these conversions intry/exceptand add anelsebranch for invalidsec_choiceto align robustness and user feedback with the main menu behavior.