Skip to content

Commit ded6c20

Browse files
authored
Merge pull request #30 from GYFX35/enhance-security-ai-roles-8222030255952741699
Enhance AI Security Roles and Data Protection
2 parents ed09756 + 9879698 commit ded6c20

4 files changed

Lines changed: 160 additions & 3 deletions

File tree

sensitive_data_scanner/scanner.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,11 @@
1313
"Credit Card (Mastercard)": re.compile(r"5[1-5][0-9]{14}"),
1414
"Credit Card (Amex)": re.compile(r"3[47][0-9]{13}"),
1515
"Credit Card (Discover)": re.compile(r"6(?:011|5[0-9]{2})[0-9]{12}"),
16-
"Social Security Number": re.compile(r"\d{3}-\d{2}-\d{4}")
16+
"Social Security Number": re.compile(r"\d{3}-\d{2}-\d{4}"),
17+
"Passport Number (US)": re.compile(r"[a-zA-Z0-9]{9}"),
18+
"GCP Service Account Key": re.compile(r"\"type\": \"service_account\""),
19+
"Azure Client Secret": re.compile(r"[a-zA-Z0-9-_~.]{34}"),
20+
"Health ID (HIPAA)": re.compile(r"H[0-9]{10}")
1721
}
1822

1923
def scan_file(filepath):

src/SupplyChainPlatform.jsx

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ export default function SupplyChainPlatform() {
102102
<button onClick={() => setActiveTab('twin')}>Digital Twin (3D)</button>
103103
<button onClick={() => setActiveTab('incoterms')}>Incoterms</button>
104104
<button onClick={() => setActiveTab('logistics')}>Logistics AI</button>
105+
<button onClick={() => setActiveTab('security')}>Security & Protection</button>
105106
</div>
106107

107108
{activeTab === 'twin' && (
@@ -150,6 +151,30 @@ export default function SupplyChainPlatform() {
150151
</div>
151152
)}
152153

154+
{activeTab === 'security' && (
155+
<div style={{ display: 'grid', gridTemplateColumns: '1fr 1fr', gap: '20px' }}>
156+
<div style={{ background: '#222', padding: '20px', borderRadius: '10px' }}>
157+
<h3>Infrastructure Protection</h3>
158+
<p>Monitoring critical IoT sensors for tampering or anomalies.</p>
159+
<div style={{ padding: '10px', border: '1px solid #444', borderRadius: '5px', marginBottom: '10px' }}>
160+
<strong>Device #842 Status:</strong> <span style={{ color: '#00ff00' }}>SECURE</span><br/>
161+
<small>Voltage: 3.3V | Temp: 24°C | RSSI: -42dBm</small>
162+
</div>
163+
<button onClick={() => logToBlockchain('Infrastructure Health Scan')}>Run AI Perimeter Scan</button>
164+
</div>
165+
166+
<div style={{ background: '#222', padding: '20px', borderRadius: '10px' }}>
167+
<h3>Antivirus Identification</h3>
168+
<p>AI-driven identification of malicious behavior and file patterns.</p>
169+
<div style={{ padding: '10px', border: '1px solid #444', borderRadius: '5px', marginBottom: '10px' }}>
170+
<strong>Latest Scan:</strong> No threats detected.<br/>
171+
<small>Last behavior scan: {new Date().toLocaleTimeString()}</small>
172+
</div>
173+
<button onClick={() => logToBlockchain('Malware Signature Update')}>Update AI Signatures</button>
174+
</div>
175+
</div>
176+
)}
177+
153178
{activeTab === 'logistics' && (
154179
<div style={{ display: 'grid', gridTemplateColumns: '1fr 1fr', gap: '20px' }}>
155180
<div style={{ background: '#222', padding: '20px', borderRadius: '10px' }}>
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
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"]))

supply_chain_platform/supply_chain_main.py

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import json
22
import os
33
from ai_logistics_engine import AILogisticsEngine
4+
from security_tools import InfrastructureProtectionAI, AntivirusIdentificationAI
45

56
def load_incoterms():
67
path = os.path.join(os.path.dirname(__file__), 'incoterms_data.json')
@@ -12,16 +13,19 @@ def display_menu():
1213
print("1. Incoterms Lookup")
1314
print("2. AI Delivery Delay Predictor")
1415
print("3. Inventory Risk Analysis")
15-
print("4. Exit")
16+
print("4. Security Analysis (Infrastructure & AV)")
17+
print("5. Exit")
1618
print("============================================")
1719

1820
def main():
1921
incoterms = load_incoterms()
2022
ai_engine = AILogisticsEngine()
23+
infra_ai = InfrastructureProtectionAI()
24+
av_ai = AntivirusIdentificationAI()
2125

2226
while True:
2327
display_menu()
24-
choice = input("Enter choice (1-4): ").strip()
28+
choice = input("Enter choice (1-5): ").strip()
2529

2630
if choice == '1':
2731
print("\nAvailable Incoterms:", ", ".join(incoterms.keys()))
@@ -53,6 +57,27 @@ def main():
5357
print("Invalid numbers.")
5458

5559
elif choice == '4':
60+
print("\n--- Security Analysis ---")
61+
print("1. IoT Tampering Detection")
62+
print("2. Antivirus Metadata Scan")
63+
sec_choice = input("Select sub-option (1-2): ").strip()
64+
65+
if sec_choice == '1':
66+
v = float(input("Enter device voltage: "))
67+
t = float(input("Enter device temperature: "))
68+
r = float(input("Enter signal RSSI: "))
69+
result = infra_ai.detect_iot_tampering({'voltage': v, 'temperature': t, 'rssi': r})
70+
print(f"\nResult: {result['status']} (Score: {result['score']})")
71+
for f in result['findings']:
72+
print(f" - {f}")
73+
elif sec_choice == '2':
74+
fname = input("Enter filename: ")
75+
fsize = float(input("Enter file size (KB): "))
76+
result = av_ai.scan_file_metadata(fname, fsize)
77+
print(f"\nRisk Level: {result['risk']}")
78+
print(f"Details: {result['details']}")
79+
80+
elif choice == '5':
5681
print("Exiting Supply Chain Platform.")
5782
break
5883
else:

0 commit comments

Comments
 (0)