Skip to content

Commit 0dbafe6

Browse files
Enhance security platform with Operational Security role and AI tools
- Created `social_media_analyzer/operational_security.py` with AI modules for Cloud, IoT, and OpSec. - Added `/analyze/cloud`, `/analyze/iot`, and `/analyze/opsec` endpoints to Flask backend. - Integrated the new "Operational Security" role into the `OfficialAssistance.jsx` frontend. - Added interactive tool launching and results display for the new security tools. - Updated `Marketplace.jsx` to reflect the expanded support capabilities. - Added unit tests for the new backend modules. Co-authored-by: GYFX35 <134739293+GYFX35@users.noreply.github.com>
1 parent 249bfed commit 0dbafe6

5 files changed

Lines changed: 242 additions & 3 deletions

File tree

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
import re
2+
from sensitive_data_scanner.scanner import SENSITIVE_DATA_PATTERNS
3+
from supply_chain_platform.security_tools import InfrastructureProtectionAI
4+
5+
class CloudSecurityAI:
6+
"""AI for scanning cloud credentials and sensitive information."""
7+
8+
def scan_content(self, text_content):
9+
findings = {}
10+
for pattern_name, regex in SENSITIVE_DATA_PATTERNS.items():
11+
matches = regex.findall(text_content)
12+
if matches:
13+
findings[pattern_name] = matches
14+
return findings
15+
16+
class IoTSecurityAI:
17+
"""AI for monitoring IoT device telemetry and detecting anomalies."""
18+
19+
def __init__(self):
20+
self.infra_protection = InfrastructureProtectionAI()
21+
22+
def analyze_telemetry(self, device_data):
23+
"""
24+
Wraps the InfrastructureProtectionAI logic for IoT telemetry analysis.
25+
"""
26+
return self.infra_protection.detect_iot_tampering(device_data)
27+
28+
class OpSecAI:
29+
"""AI for Operational Security (OpSec) analysis of logs and procedures."""
30+
31+
SUSPICIOUS_OPSEC_PATTERNS = {
32+
"Unauthorized Login Attempt": re.compile(r"failed login|unauthorized access|invalid credentials", re.I),
33+
"Privilege Escalation": re.compile(r"sudo usage|root access granted|privilege elevation", re.I),
34+
"Data Exfiltration Pattern": re.compile(r"large outbound transfer|data dump|exfiltrating", re.I),
35+
"Internal Scan Activity": re.compile(r"nmap scan|port sweep|internal reconnaissance", re.I),
36+
"Insecure Communication": re.compile(r"http transfer|unencrypted channel|plaintext password", re.I)
37+
}
38+
39+
def analyze_logs(self, log_entries):
40+
"""
41+
Analyzes a list of log strings for operational security risks.
42+
"""
43+
risk_score = 0
44+
findings = []
45+
46+
log_blob = "\n".join(log_entries)
47+
48+
for threat_name, regex in self.SUSPICIOUS_OPSEC_PATTERNS.items():
49+
matches = regex.findall(log_blob)
50+
if matches:
51+
findings.append(f"{threat_name} detected: {len(matches)} occurrences.")
52+
risk_score += len(matches) * 2
53+
54+
if not findings:
55+
return {"status": "SECURE", "score": 0, "findings": ["No operational security threats detected."]}
56+
else:
57+
status = "CRITICAL" if risk_score > 10 else "WARNING"
58+
return {
59+
"status": status,
60+
"score": min(risk_score, 100),
61+
"findings": findings
62+
}
63+
64+
def analyze_cloud_security(content):
65+
scanner = CloudSecurityAI()
66+
return scanner.scan_content(content)
67+
68+
def analyze_iot_security(device_data):
69+
scanner = IoTSecurityAI()
70+
return scanner.analyze_telemetry(device_data)
71+
72+
def analyze_opsec_security(logs):
73+
scanner = OpSecAI()
74+
return scanner.analyze_logs(logs)
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import unittest
2+
from social_media_analyzer.operational_security import CloudSecurityAI, IoTSecurityAI, OpSecAI
3+
4+
class TestOperationalSecurity(unittest.TestCase):
5+
def test_cloud_security_scan(self):
6+
ai = CloudSecurityAI()
7+
content = "My AWS Key is AKIA1234567890ABCDEF"
8+
findings = ai.scan_content(content)
9+
self.assertIn("AWS Access Key ID", findings)
10+
self.assertEqual(findings["AWS Access Key ID"], ["AKIA1234567890ABCDEF"])
11+
12+
def test_iot_security_analyze(self):
13+
ai = IoTSecurityAI()
14+
# Test warning case
15+
device_data = {'voltage': 2.5, 'temperature': 80, 'rssi': -95}
16+
result = ai.analyze_telemetry(device_data)
17+
self.assertEqual(result["status"], "WARNING")
18+
self.assertTrue(len(result["findings"]) > 0)
19+
20+
# Test secure case
21+
secure_data = {'voltage': 3.3, 'temperature': 25, 'rssi': -50}
22+
result = ai.analyze_telemetry(secure_data)
23+
self.assertEqual(result["status"], "SECURE")
24+
25+
def test_opsec_analyze(self):
26+
ai = OpSecAI()
27+
logs = ["unauthorized access attempt", "nmap scan detected"]
28+
result = ai.analyze_logs(logs)
29+
self.assertEqual(result["status"], "WARNING")
30+
self.assertTrue(any("Unauthorized Login Attempt" in f for f in result["findings"]))
31+
self.assertTrue(any("Internal Scan Activity" in f for f in result["findings"]))
32+
33+
if __name__ == "__main__":
34+
unittest.main()

src/Marketplace.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ const tools = [
4040
{
4141
id: 'assistance',
4242
name: 'Official Assistance',
43-
description: 'Integrated support tools for Police, Military, and Gendarmerie.',
43+
description: 'Integrated support tools for Police, Military, Gendarmerie, and Operational Security.',
4444
icon: '🛡️'
4545
}
4646
];

src/OfficialAssistance.jsx

Lines changed: 96 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,63 @@ const assistanceRoles = {
3030
{ id: 'traffic', name: 'Traffic Management', icon: '🚦', desc: 'Coordination of road safety and major transit routes.' },
3131
{ id: 'response', name: 'Specialized Response', icon: '🚨', desc: 'Elite units for counter-terrorism and high-risk interventions.' }
3232
]
33+
},
34+
opsec: {
35+
title: 'Operational Security',
36+
icon: '🔐',
37+
description: 'Cloud, IoT, and AI-driven security operations for modern infrastructure.',
38+
tools: [
39+
{ id: 'cloud_guard', name: 'Cloud Guard', icon: '☁️', desc: 'AI scanner for leaked credentials and sensitive cloud data.' },
40+
{ id: 'iot_shield', name: 'IoT Shield', icon: '🌐', desc: 'Real-time anomaly detection for industrial IoT networks.' },
41+
{ id: 'opsec_analyzer', name: 'OpSec Analyzer', icon: '🕵️', desc: 'AI-driven analysis of operational logs for procedural threats.' }
42+
]
3343
}
3444
};
3545

3646
export default function OfficialAssistance() {
3747
const [activeRole, setActiveRole] = useState('police');
48+
const [analysisResult, setAnalysisResult] = useState(null);
49+
const [loading, setLoading] = useState(false);
50+
51+
const handleLaunch = async (toolId, toolName) => {
52+
if (!['cloud_guard', 'iot_shield', 'opsec_analyzer'].includes(toolId)) {
53+
alert(`Launching ${toolName}... (Simulation mode)`);
54+
return;
55+
}
56+
57+
setLoading(true);
58+
setAnalysisResult(null);
59+
60+
try {
61+
let endpoint = '';
62+
let body = {};
63+
64+
if (toolId === 'cloud_guard') {
65+
endpoint = '/analyze/cloud';
66+
body = { content: "Sample content with simulated AWS key: AKIA1234567890ABCDEF and Google API Key: AIzaSyA12345678901234567890123456789012" };
67+
} else if (toolId === 'iot_shield') {
68+
endpoint = '/analyze/iot';
69+
body = { device_data: { voltage: 2.6, temperature: 82, rssi: -95 } };
70+
} else if (toolId === 'opsec_analyzer') {
71+
endpoint = '/analyze/opsec';
72+
body = { logs: ["unauthorized access attempt", "nmap scan detected", "large outbound transfer", "sudo usage"] };
73+
}
74+
75+
const response = await fetch(endpoint, {
76+
method: 'POST',
77+
headers: { 'Content-Type': 'application/json' },
78+
body: JSON.stringify(body)
79+
});
80+
81+
const data = await response.json();
82+
setAnalysisResult({ title: toolName, data });
83+
} catch (error) {
84+
console.error("Error launching tool:", error);
85+
alert("Failed to connect to security backend. Make sure the Flask server is running.");
86+
} finally {
87+
setLoading(false);
88+
}
89+
};
3890

3991
return (
4092
<div className="assistance-container">
@@ -63,10 +115,24 @@ export default function OfficialAssistance() {
63115
<h3>{tool.name}</h3>
64116
<p>{tool.desc}</p>
65117
</div>
66-
<button className="action-btn" onClick={() => alert(`Launching ${tool.name}...`)}>Launch</button>
118+
<button
119+
className="action-btn"
120+
onClick={() => handleLaunch(tool.id, tool.name)}
121+
disabled={loading}
122+
>
123+
{loading ? 'Processing...' : 'Launch'}
124+
</button>
67125
</div>
68126
))}
69127
</div>
128+
129+
{analysisResult && (
130+
<div className="analysis-result">
131+
<h3>{analysisResult.title} - AI Analysis Output</h3>
132+
<pre>{JSON.stringify(analysisResult.data, null, 2)}</pre>
133+
<button className="close-result" onClick={() => setAnalysisResult(null)}>Close Results</button>
134+
</div>
135+
)}
70136
</div>
71137

72138
<style jsx>{`
@@ -150,6 +216,35 @@ export default function OfficialAssistance() {
150216
font-weight: bold;
151217
cursor: pointer;
152218
}
219+
.action-btn:disabled {
220+
background: #555;
221+
cursor: not-allowed;
222+
}
223+
.analysis-result {
224+
margin-top: 30px;
225+
background: #1e2127;
226+
padding: 20px;
227+
border-radius: 8px;
228+
border: 1px solid #61dafb;
229+
}
230+
.analysis-result pre {
231+
background: #000;
232+
padding: 15px;
233+
border-radius: 5px;
234+
overflow-x: auto;
235+
color: #00ff00;
236+
font-family: 'Courier New', Courier, monospace;
237+
font-size: 0.85rem;
238+
}
239+
.close-result {
240+
background: transparent;
241+
color: #61dafb;
242+
border: 1px solid #61dafb;
243+
padding: 5px 15px;
244+
border-radius: 4px;
245+
cursor: pointer;
246+
margin-top: 10px;
247+
}
153248
`}</style>
154249
</div>
155250
);

text_message_analyzer/app.py

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
from flask import Flask, request, jsonify
2-
from social_media_analyzer import scam_detector, fake_news_detector, ai_content_detector, fake_content_verifier
2+
from social_media_analyzer import (
3+
scam_detector,
4+
fake_news_detector,
5+
ai_content_detector,
6+
fake_content_verifier,
7+
operational_security
8+
)
39
import os
410

511
app = Flask(__name__)
@@ -51,6 +57,36 @@ def analyze_fake_content():
5157
result = fake_content_verifier.analyze_text_for_fake_content(text_to_analyze)
5258
return jsonify(result)
5359

60+
@app.route('/analyze/cloud', methods=['POST'])
61+
def analyze_cloud():
62+
data = request.get_json()
63+
if not data or 'content' not in data:
64+
return jsonify({"error": "Missing 'content' in request body"}), 400
65+
66+
content = data['content']
67+
result = operational_security.analyze_cloud_security(content)
68+
return jsonify(result)
69+
70+
@app.route('/analyze/iot', methods=['POST'])
71+
def analyze_iot():
72+
data = request.get_json()
73+
if not data or 'device_data' not in data:
74+
return jsonify({"error": "Missing 'device_data' in request body"}), 400
75+
76+
device_data = data['device_data']
77+
result = operational_security.analyze_iot_security(device_data)
78+
return jsonify(result)
79+
80+
@app.route('/analyze/opsec', methods=['POST'])
81+
def analyze_opsec():
82+
data = request.get_json()
83+
if not data or 'logs' not in data:
84+
return jsonify({"error": "Missing 'logs' in request body"}), 400
85+
86+
logs = data['logs']
87+
result = operational_security.analyze_opsec_security(logs)
88+
return jsonify(result)
89+
5490

5591
if __name__ == '__main__':
5692
app.run(debug=True)

0 commit comments

Comments
 (0)