Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -3,34 +3,57 @@ import spaces
|
|
3 |
from transformers import pipeline
|
4 |
import torch
|
5 |
import time
|
|
|
|
|
6 |
|
7 |
-
#
|
8 |
-
|
9 |
.gradio-container {
|
10 |
-
max-width:
|
11 |
margin: 0 auto !important;
|
12 |
font-family: 'Arial', sans-serif;
|
13 |
}
|
14 |
|
15 |
-
.
|
|
|
|
|
16 |
border-radius: 8px !important;
|
17 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
18 |
padding: 15px !important;
|
19 |
-
font-
|
|
|
|
|
20 |
}
|
21 |
|
22 |
-
.
|
23 |
-
border-
|
|
|
|
|
24 |
}
|
25 |
|
26 |
-
.
|
27 |
-
background: #
|
28 |
-
|
|
|
29 |
border-radius: 8px !important;
|
30 |
-
|
31 |
-
font-size: 16px !important;
|
32 |
font-weight: 600 !important;
|
|
|
|
|
|
|
|
|
33 |
color: white !important;
|
|
|
|
|
|
|
|
|
34 |
}
|
35 |
|
36 |
.analysis-output {
|
@@ -41,13 +64,12 @@ simple_css = """
|
|
41 |
line-height: 1.6 !important;
|
42 |
}
|
43 |
|
44 |
-
.status-
|
45 |
background: #d4edda !important;
|
46 |
border: 1px solid #c3e6cb !important;
|
47 |
color: #155724 !important;
|
48 |
padding: 10px !important;
|
49 |
border-radius: 6px !important;
|
50 |
-
margin: 10px 0 !important;
|
51 |
}
|
52 |
"""
|
53 |
|
@@ -95,127 +117,341 @@ def load_model():
|
|
95 |
model_status = "⚠️ Using fallback mode"
|
96 |
return model_status
|
97 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
98 |
@spaces.GPU
|
99 |
def analyze_threat(threat_description, analyst_level):
|
100 |
-
"""
|
101 |
|
102 |
if not threat_description.strip():
|
103 |
return "Please enter a threat description first.", ""
|
104 |
|
105 |
start_time = time.time()
|
106 |
|
107 |
-
#
|
108 |
-
|
|
|
|
|
109 |
|
110 |
-
|
|
|
|
|
|
|
|
|
|
|
111 |
|
112 |
-
|
113 |
-
- Threat assessment
|
114 |
-
- Potential impact
|
115 |
-
- Recommended actions
|
116 |
|
117 |
ANALYSIS:"""
|
118 |
-
|
119 |
if pipe:
|
120 |
try:
|
121 |
result = pipe(
|
122 |
-
|
123 |
-
max_new_tokens=
|
124 |
do_sample=True,
|
125 |
temperature=0.3,
|
126 |
top_p=0.9,
|
127 |
repetition_penalty=1.1
|
128 |
)
|
129 |
|
130 |
-
analysis = result[0]['generated_text'][len(
|
131 |
|
132 |
if len(analysis) < 30:
|
133 |
-
analysis =
|
134 |
|
135 |
except Exception as e:
|
136 |
-
analysis = f"AI Error: {str(e)[:100]}\n\n{
|
137 |
else:
|
138 |
-
analysis =
|
139 |
|
140 |
processing_time = round(time.time() - start_time, 2)
|
141 |
-
status = f"✅
|
142 |
|
143 |
return analysis, status
|
144 |
|
145 |
-
def
|
146 |
-
"""
|
147 |
|
148 |
if analyst_level == "L1":
|
149 |
return f"""🚨 L1 TRIAGE ANALYSIS
|
150 |
|
151 |
-
|
152 |
{threat_description}
|
153 |
|
154 |
-
IMMEDIATE ACTIONS:
|
155 |
-
• Assess severity
|
156 |
-
•
|
157 |
-
•
|
158 |
-
•
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
159 |
|
160 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
161 |
|
162 |
elif analyst_level == "L2":
|
163 |
-
return f"""🔍 L2 INVESTIGATION
|
164 |
|
165 |
-
|
166 |
{threat_description}
|
167 |
|
168 |
-
INVESTIGATION
|
169 |
-
1.
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
|
|
174 |
|
175 |
-
|
176 |
-
•
|
177 |
-
•
|
178 |
-
•
|
179 |
-
•
|
180 |
|
181 |
-
|
182 |
-
•
|
183 |
-
•
|
184 |
-
•
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
185 |
|
186 |
else: # L3
|
187 |
-
return f"""🎯 L3
|
188 |
|
189 |
STRATEGIC THREAT ASSESSMENT:
|
190 |
{threat_description}
|
191 |
|
192 |
-
|
193 |
-
|
194 |
-
• Campaign analysis and TTPs
|
195 |
-
• Business impact evaluation
|
196 |
-
• Risk quantification
|
197 |
|
198 |
-
|
199 |
-
•
|
200 |
-
•
|
201 |
-
•
|
202 |
-
•
|
203 |
|
204 |
-
|
205 |
-
•
|
206 |
-
•
|
207 |
-
•
|
208 |
-
•
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
209 |
|
210 |
-
|
211 |
-
|
|
|
|
|
|
|
212 |
|
213 |
-
#
|
214 |
gr.Markdown("""
|
215 |
-
# 🛡️ SOC
|
216 |
-
**
|
217 |
|
218 |
-
|
219 |
""")
|
220 |
|
221 |
# Model status
|
@@ -223,82 +459,186 @@ with gr.Blocks(title="Simple SOC Analyzer", theme=gr.themes.Soft(), css=simple_c
|
|
223 |
value="🔄 Loading model...",
|
224 |
label="System Status",
|
225 |
interactive=False,
|
226 |
-
elem_classes=["status-
|
227 |
)
|
228 |
|
229 |
-
#
|
230 |
-
with gr.
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
threat_input = gr.Textbox(
|
235 |
-
label="🚨 Describe the Security Threat",
|
236 |
-
placeholder="Example: Suspicious PowerShell execution detected on user workstation with encoded commands...",
|
237 |
-
lines=5,
|
238 |
-
elem_classes=["threat-input"]
|
239 |
-
)
|
240 |
-
|
241 |
-
# Analysis level
|
242 |
-
analyst_level = gr.Radio(
|
243 |
-
choices=["L1", "L2", "L3"],
|
244 |
-
value="L2",
|
245 |
-
label="Analysis Level",
|
246 |
-
info="L1: Quick Triage • L2: Detailed Investigation • L3: Strategic Analysis"
|
247 |
-
)
|
248 |
-
|
249 |
-
# Analyze button
|
250 |
-
analyze_btn = gr.Button(
|
251 |
-
"🔍 Analyze Threat",
|
252 |
-
variant="primary",
|
253 |
-
size="lg",
|
254 |
-
elem_classes=["analyze-btn"]
|
255 |
-
)
|
256 |
-
|
257 |
-
# Quick examples
|
258 |
gr.Markdown("""
|
259 |
-
|
260 |
-
|
261 |
-
- Unusual network traffic to external IP
|
262 |
-
- User account showing signs of compromise
|
263 |
-
- Ransomware indicators detected on server
|
264 |
-
- Failed login attempts from multiple locations
|
265 |
""")
|
266 |
-
|
267 |
-
with gr.Column(scale=2):
|
268 |
|
269 |
-
|
270 |
-
|
271 |
-
|
272 |
-
|
273 |
-
|
274 |
-
|
275 |
-
|
276 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
277 |
|
278 |
-
|
279 |
-
|
280 |
-
|
281 |
-
|
282 |
-
|
283 |
-
|
284 |
-
|
285 |
-
|
286 |
-
|
287 |
-
|
288 |
-
|
289 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
290 |
|
291 |
-
#
|
292 |
gr.Markdown("""
|
293 |
---
|
294 |
-
|
|
|
|
|
|
|
|
|
|
|
295 |
""")
|
296 |
|
297 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
298 |
analyze_btn.click(
|
299 |
fn=analyze_threat,
|
300 |
inputs=[threat_input, analyst_level],
|
301 |
-
outputs=[analysis_output,
|
|
|
|
|
|
|
|
|
|
|
302 |
)
|
303 |
|
304 |
# Initialize model on startup
|
|
|
3 |
from transformers import pipeline
|
4 |
import torch
|
5 |
import time
|
6 |
+
import re
|
7 |
+
from datetime import datetime
|
8 |
|
9 |
+
# Enhanced CSS for both tasks
|
10 |
+
enhanced_css = """
|
11 |
.gradio-container {
|
12 |
+
max-width: 1200px !important;
|
13 |
margin: 0 auto !important;
|
14 |
font-family: 'Arial', sans-serif;
|
15 |
}
|
16 |
|
17 |
+
.task-tab {
|
18 |
+
background: linear-gradient(135deg, #667eea, #764ba2) !important;
|
19 |
+
color: white !important;
|
20 |
border-radius: 8px !important;
|
21 |
+
padding: 12px 20px !important;
|
22 |
+
font-weight: 600 !important;
|
23 |
+
margin: 5px !important;
|
24 |
+
}
|
25 |
+
|
26 |
+
.detection-input {
|
27 |
+
border-radius: 8px !important;
|
28 |
+
border: 2px solid #e74c3c !important;
|
29 |
padding: 15px !important;
|
30 |
+
font-family: 'Courier New', monospace !important;
|
31 |
+
background: #2d3436 !important;
|
32 |
+
color: #ddd !important;
|
33 |
}
|
34 |
|
35 |
+
.assistant-input {
|
36 |
+
border-radius: 8px !important;
|
37 |
+
border: 2px solid #667eea !important;
|
38 |
+
padding: 15px !important;
|
39 |
}
|
40 |
|
41 |
+
.threat-detected {
|
42 |
+
background: linear-gradient(135deg, #e74c3c, #c0392b) !important;
|
43 |
+
color: white !important;
|
44 |
+
padding: 15px !important;
|
45 |
border-radius: 8px !important;
|
46 |
+
margin: 10px 0 !important;
|
|
|
47 |
font-weight: 600 !important;
|
48 |
+
}
|
49 |
+
|
50 |
+
.threat-clear {
|
51 |
+
background: linear-gradient(135deg, #27ae60, #229954) !important;
|
52 |
color: white !important;
|
53 |
+
padding: 15px !important;
|
54 |
+
border-radius: 8px !important;
|
55 |
+
margin: 10px 0 !important;
|
56 |
+
font-weight: 600 !important;
|
57 |
}
|
58 |
|
59 |
.analysis-output {
|
|
|
64 |
line-height: 1.6 !important;
|
65 |
}
|
66 |
|
67 |
+
.status-success {
|
68 |
background: #d4edda !important;
|
69 |
border: 1px solid #c3e6cb !important;
|
70 |
color: #155724 !important;
|
71 |
padding: 10px !important;
|
72 |
border-radius: 6px !important;
|
|
|
73 |
}
|
74 |
"""
|
75 |
|
|
|
117 |
model_status = "⚠️ Using fallback mode"
|
118 |
return model_status
|
119 |
|
120 |
+
# ===================== TASK 1: DETECTION =====================
|
121 |
+
|
122 |
+
@spaces.GPU
|
123 |
+
def detect_threats_from_logs(log_data, detection_sensitivity):
|
124 |
+
"""Task 1: Detect threats from raw log data using LLM"""
|
125 |
+
|
126 |
+
if not log_data.strip():
|
127 |
+
return "Please provide log data for analysis.", ""
|
128 |
+
|
129 |
+
start_time = time.time()
|
130 |
+
|
131 |
+
# Enhanced detection prompt
|
132 |
+
detection_prompt = f"""You are a cybersecurity threat detection system. Analyze these security logs and detect any potential threats, anomalies, or suspicious activities.
|
133 |
+
|
134 |
+
DETECTION SENSITIVITY: {detection_sensitivity}
|
135 |
+
|
136 |
+
RAW LOG DATA:
|
137 |
+
{log_data}
|
138 |
+
|
139 |
+
Analyze for:
|
140 |
+
- Failed authentication attempts
|
141 |
+
- Unusual network connections
|
142 |
+
- Suspicious process executions
|
143 |
+
- Privilege escalations
|
144 |
+
- Malware indicators
|
145 |
+
- Data exfiltration attempts
|
146 |
+
- System anomalies
|
147 |
+
|
148 |
+
Output format:
|
149 |
+
THREAT DETECTED: [Yes/No]
|
150 |
+
THREAT TYPE: [Type if detected]
|
151 |
+
SEVERITY: [Critical/High/Medium/Low]
|
152 |
+
CONFIDENCE: [Percentage]
|
153 |
+
DETAILS: [Explanation]
|
154 |
+
RECOMMENDATIONS: [Next steps]
|
155 |
+
|
156 |
+
DETECTION ANALYSIS:"""
|
157 |
+
|
158 |
+
if pipe:
|
159 |
+
try:
|
160 |
+
result = pipe(
|
161 |
+
detection_prompt,
|
162 |
+
max_new_tokens=400,
|
163 |
+
do_sample=True,
|
164 |
+
temperature=0.2, # Lower temperature for detection accuracy
|
165 |
+
top_p=0.9,
|
166 |
+
repetition_penalty=1.1
|
167 |
+
)
|
168 |
+
|
169 |
+
detection_result = result[0]['generated_text'][len(detection_prompt):].strip()
|
170 |
+
|
171 |
+
if len(detection_result) < 30:
|
172 |
+
detection_result = get_detection_fallback(log_data, detection_sensitivity)
|
173 |
+
|
174 |
+
except Exception as e:
|
175 |
+
detection_result = f"AI Detection Error: {str(e)[:100]}\n\n{get_detection_fallback(log_data, detection_sensitivity)}"
|
176 |
+
else:
|
177 |
+
detection_result = get_detection_fallback(log_data, detection_sensitivity)
|
178 |
+
|
179 |
+
# Determine if threat was detected for status display
|
180 |
+
threat_status = "🚨 THREAT DETECTED" if "THREAT DETECTED: Yes" in detection_result or "threat" in detection_result.lower() else "✅ NO THREATS DETECTED"
|
181 |
+
|
182 |
+
processing_time = round(time.time() - start_time, 2)
|
183 |
+
status = f"{threat_status} | Analysis completed in {processing_time}s | {model_status}"
|
184 |
+
|
185 |
+
return detection_result, status
|
186 |
+
|
187 |
+
def get_detection_fallback(log_data, sensitivity):
|
188 |
+
"""Fallback detection analysis using pattern matching"""
|
189 |
+
|
190 |
+
# Simple pattern-based detection
|
191 |
+
threats_found = []
|
192 |
+
confidence = 60
|
193 |
+
|
194 |
+
# Check for common threat indicators
|
195 |
+
if re.search(r'failed.*login|authentication.*failed|invalid.*password', log_data, re.IGNORECASE):
|
196 |
+
threats_found.append("Failed Authentication Attempts")
|
197 |
+
confidence += 20
|
198 |
+
|
199 |
+
if re.search(r'powershell|cmd\.exe|suspicious.*process', log_data, re.IGNORECASE):
|
200 |
+
threats_found.append("Suspicious Process Execution")
|
201 |
+
confidence += 15
|
202 |
+
|
203 |
+
if re.search(r'connection.*refused|unusual.*traffic|suspicious.*ip', log_data, re.IGNORECASE):
|
204 |
+
threats_found.append("Abnormal Network Activity")
|
205 |
+
confidence += 15
|
206 |
+
|
207 |
+
if re.search(r'privilege.*escalation|admin.*rights|elevated.*access', log_data, re.IGNORECASE):
|
208 |
+
threats_found.append("Privilege Escalation Attempt")
|
209 |
+
confidence += 25
|
210 |
+
|
211 |
+
if re.search(r'malware|virus|trojan|ransomware', log_data, re.IGNORECASE):
|
212 |
+
threats_found.append("Malware Indicators")
|
213 |
+
confidence += 30
|
214 |
+
|
215 |
+
if threats_found:
|
216 |
+
severity = "Critical" if confidence > 85 else "High" if confidence > 70 else "Medium"
|
217 |
+
return f"""🚨 THREAT DETECTION ANALYSIS
|
218 |
+
|
219 |
+
THREAT DETECTED: Yes
|
220 |
+
THREAT TYPES: {', '.join(threats_found)}
|
221 |
+
SEVERITY: {severity}
|
222 |
+
CONFIDENCE: {min(confidence, 95)}%
|
223 |
+
|
224 |
+
DETECTED INDICATORS:
|
225 |
+
{chr(10).join(f"• {threat}" for threat in threats_found)}
|
226 |
+
|
227 |
+
IMMEDIATE ACTIONS REQUIRED:
|
228 |
+
• Isolate affected systems immediately
|
229 |
+
• Preserve logs for forensic analysis
|
230 |
+
• Escalate to L2 analyst for investigation
|
231 |
+
• Implement containment measures
|
232 |
+
• Monitor for lateral movement
|
233 |
+
|
234 |
+
PATTERN ANALYSIS:
|
235 |
+
Based on log pattern analysis, multiple threat indicators suggest ongoing malicious activity requiring immediate response."""
|
236 |
+
|
237 |
+
else:
|
238 |
+
return f"""✅ THREAT DETECTION ANALYSIS
|
239 |
+
|
240 |
+
THREAT DETECTED: No
|
241 |
+
SEVERITY: Low
|
242 |
+
CONFIDENCE: {confidence}%
|
243 |
+
|
244 |
+
ANALYSIS SUMMARY:
|
245 |
+
No obvious threat indicators detected in the provided log data. However, this does not guarantee absence of sophisticated threats.
|
246 |
+
|
247 |
+
RECOMMENDATIONS:
|
248 |
+
• Continue monitoring for unusual patterns
|
249 |
+
• Implement additional logging if needed
|
250 |
+
• Consider advanced behavioral analysis
|
251 |
+
• Regular security baseline reviews
|
252 |
+
|
253 |
+
NOTE: Advanced persistent threats may use evasion techniques not detected by pattern analysis."""
|
254 |
+
|
255 |
+
# ===================== TASK 2: ASSISTANT =====================
|
256 |
+
|
257 |
@spaces.GPU
|
258 |
def analyze_threat(threat_description, analyst_level):
|
259 |
+
"""Task 2: Assist analysts with threat investigation"""
|
260 |
|
261 |
if not threat_description.strip():
|
262 |
return "Please enter a threat description first.", ""
|
263 |
|
264 |
start_time = time.time()
|
265 |
|
266 |
+
# Enhanced assistant prompt
|
267 |
+
assistant_prompt = f"""As a {analyst_level} cybersecurity analyst, provide detailed analysis for this security incident:
|
268 |
+
|
269 |
+
INCIDENT: {threat_description}
|
270 |
|
271 |
+
Provide a comprehensive {analyst_level} level analysis including:
|
272 |
+
- Threat assessment and classification
|
273 |
+
- Potential impact and business risk
|
274 |
+
- Investigation steps and evidence collection
|
275 |
+
- Containment and mitigation strategies
|
276 |
+
- Recommended actions and next steps
|
277 |
|
278 |
+
Focus on {analyst_level} specific responsibilities and deliver actionable insights.
|
|
|
|
|
|
|
279 |
|
280 |
ANALYSIS:"""
|
281 |
+
|
282 |
if pipe:
|
283 |
try:
|
284 |
result = pipe(
|
285 |
+
assistant_prompt,
|
286 |
+
max_new_tokens=400,
|
287 |
do_sample=True,
|
288 |
temperature=0.3,
|
289 |
top_p=0.9,
|
290 |
repetition_penalty=1.1
|
291 |
)
|
292 |
|
293 |
+
analysis = result[0]['generated_text'][len(assistant_prompt):].strip()
|
294 |
|
295 |
if len(analysis) < 30:
|
296 |
+
analysis = get_assistant_fallback(threat_description, analyst_level)
|
297 |
|
298 |
except Exception as e:
|
299 |
+
analysis = f"AI Analysis Error: {str(e)[:100]}\n\n{get_assistant_fallback(threat_description, analyst_level)}"
|
300 |
else:
|
301 |
+
analysis = get_assistant_fallback(threat_description, analyst_level)
|
302 |
|
303 |
processing_time = round(time.time() - start_time, 2)
|
304 |
+
status = f"✅ {analyst_level} analysis completed in {processing_time}s | {model_status}"
|
305 |
|
306 |
return analysis, status
|
307 |
|
308 |
+
def get_assistant_fallback(threat_description, analyst_level):
|
309 |
+
"""Fallback assistant analysis"""
|
310 |
|
311 |
if analyst_level == "L1":
|
312 |
return f"""🚨 L1 TRIAGE ANALYSIS
|
313 |
|
314 |
+
INCIDENT SUMMARY:
|
315 |
{threat_description}
|
316 |
|
317 |
+
IMMEDIATE TRIAGE ACTIONS:
|
318 |
+
• Assess severity: Determine if this requires immediate escalation
|
319 |
+
• Initial containment: Isolate affected systems if critical
|
320 |
+
• Evidence preservation: Secure logs and system state
|
321 |
+
• Documentation: Record all initial observations
|
322 |
+
• Communication: Notify L2 analyst if severity warrants
|
323 |
+
|
324 |
+
SEVERITY ASSESSMENT:
|
325 |
+
• Impact scope: Determine number of affected systems
|
326 |
+
• Data sensitivity: Assess if sensitive data is involved
|
327 |
+
• Business criticality: Evaluate affected business functions
|
328 |
+
• Time sensitivity: Determine urgency of response
|
329 |
|
330 |
+
ESCALATION CRITERIA:
|
331 |
+
• Critical/High severity incidents → Immediate L2 escalation
|
332 |
+
• Multiple system involvement → L2 investigation required
|
333 |
+
• Potential data breach → L2/L3 consultation needed
|
334 |
+
• Advanced threat indicators → Expert analysis required
|
335 |
+
|
336 |
+
NEXT STEPS:
|
337 |
+
1. Complete initial assessment checklist
|
338 |
+
2. Gather additional context if needed
|
339 |
+
3. Make escalation decision based on severity
|
340 |
+
4. Hand off to appropriate team with complete documentation"""
|
341 |
|
342 |
elif analyst_level == "L2":
|
343 |
+
return f"""🔍 L2 DETAILED INVESTIGATION
|
344 |
|
345 |
+
INCIDENT DETAILS:
|
346 |
{threat_description}
|
347 |
|
348 |
+
INVESTIGATION METHODOLOGY:
|
349 |
+
1. Evidence Collection:
|
350 |
+
• System logs and event data
|
351 |
+
• Network traffic analysis
|
352 |
+
• File system artifacts
|
353 |
+
• Memory dumps if needed
|
354 |
+
• User activity records
|
355 |
|
356 |
+
2. Timeline Analysis:
|
357 |
+
• Establish attack timeline
|
358 |
+
• Identify initial compromise vector
|
359 |
+
• Map lateral movement patterns
|
360 |
+
• Document persistence mechanisms
|
361 |
|
362 |
+
3. Technical Analysis:
|
363 |
+
• IOC identification and extraction
|
364 |
+
• Malware analysis if applicable
|
365 |
+
• Network communication analysis
|
366 |
+
• System configuration review
|
367 |
+
|
368 |
+
4. Scope Assessment:
|
369 |
+
• Affected systems inventory
|
370 |
+
• Data exposure evaluation
|
371 |
+
• Privilege escalation review
|
372 |
+
• Lateral movement detection
|
373 |
+
|
374 |
+
CONTAINMENT STRATEGY:
|
375 |
+
• Network segmentation to prevent spread
|
376 |
+
• Account restrictions for compromised users
|
377 |
+
• System isolation for infected machines
|
378 |
+
• Enhanced monitoring deployment
|
379 |
+
|
380 |
+
RECOMMENDATIONS:
|
381 |
+
• Deploy additional detection rules
|
382 |
+
• Implement temporary compensating controls
|
383 |
+
• Coordinate with infrastructure teams
|
384 |
+
• Prepare for potential L3 escalation"""
|
385 |
|
386 |
else: # L3
|
387 |
+
return f"""🎯 L3 STRATEGIC ANALYSIS
|
388 |
|
389 |
STRATEGIC THREAT ASSESSMENT:
|
390 |
{threat_description}
|
391 |
|
392 |
+
EXECUTIVE SUMMARY:
|
393 |
+
This incident requires senior-level analysis due to its complexity and potential business impact. Strategic coordination is needed for effective response.
|
|
|
|
|
|
|
394 |
|
395 |
+
THREAT LANDSCAPE ANALYSIS:
|
396 |
+
• Adversary attribution and capability assessment
|
397 |
+
• Campaign analysis and threat actor profiling
|
398 |
+
• Attack sophistication and TTPs evaluation
|
399 |
+
• Strategic intent and targeting analysis
|
400 |
|
401 |
+
BUSINESS IMPACT ASSESSMENT:
|
402 |
+
• Operational disruption evaluation
|
403 |
+
• Financial impact quantification
|
404 |
+
• Regulatory compliance implications
|
405 |
+
• Reputational risk assessment
|
406 |
+
|
407 |
+
STRATEGIC RESPONSE PLAN:
|
408 |
+
1. Crisis Management:
|
409 |
+
• Executive stakeholder notification
|
410 |
+
• Communication strategy development
|
411 |
+
• Resource allocation decisions
|
412 |
+
• External support engagement
|
413 |
+
|
414 |
+
2. Advanced Investigation:
|
415 |
+
• Threat hunting operations
|
416 |
+
• Advanced forensics deployment
|
417 |
+
• Third-party security consultation
|
418 |
+
• Law enforcement coordination if needed
|
419 |
+
|
420 |
+
3. Recovery Strategy:
|
421 |
+
• Business continuity planning
|
422 |
+
• System restoration priorities
|
423 |
+
• Security architecture review
|
424 |
+
• Lessons learned integration
|
425 |
+
|
426 |
+
LONG-TERM RECOMMENDATIONS:
|
427 |
+
• Security program enhancement
|
428 |
+
• Advanced threat detection investment
|
429 |
+
• Staff training and awareness programs
|
430 |
+
• Strategic security partnerships"""
|
431 |
+
|
432 |
+
# ===================== SAMPLE DATA =====================
|
433 |
+
|
434 |
+
SAMPLE_LOGS = """2025-08-12 14:30:15 [AUTH] Failed login attempt for user 'administrator' from 192.168.1.100
|
435 |
+
2025-08-12 14:30:18 [AUTH] Failed login attempt for user 'admin' from 192.168.1.100
|
436 |
+
2025-08-12 14:30:22 [AUTH] Failed login attempt for user 'root' from 192.168.1.100
|
437 |
+
2025-08-12 14:30:45 [PROC] powershell.exe -WindowStyle Hidden -enc ZXhlYyBjYWxjLmV4ZQ==
|
438 |
+
2025-08-12 14:31:12 [NET] Outbound connection to 45.33.22.11:443 from 192.168.1.100
|
439 |
+
2025-08-12 14:31:45 [FILE] Suspicious file created: C:\\temp\\update.exe
|
440 |
+
2025-08-12 14:32:10 [PROC] rundll32.exe comsvcs.dll MiniDump 1234 lsass.dmp full
|
441 |
+
2025-08-12 14:32:33 [NET] Large data transfer detected: 1.2GB to external IP"""
|
442 |
|
443 |
+
SAMPLE_THREAT = "Suspicious PowerShell execution detected on user workstation with encoded commands, followed by unusual network traffic to external IP addresses and potential credential dumping activity."
|
444 |
+
|
445 |
+
# ===================== GRADIO INTERFACE =====================
|
446 |
+
|
447 |
+
with gr.Blocks(title="Comprehensive SOC LLM Tool", theme=gr.themes.Soft(), css=enhanced_css) as demo:
|
448 |
|
449 |
+
# Header
|
450 |
gr.Markdown("""
|
451 |
+
# 🛡️ Comprehensive SOC LLM Assistant
|
452 |
+
**Task 1: Threat Detection** • **Task 2: Analyst Assistant**
|
453 |
|
454 |
+
Covering both core LLM applications in Security Operations Centers
|
455 |
""")
|
456 |
|
457 |
# Model status
|
|
|
459 |
value="🔄 Loading model...",
|
460 |
label="System Status",
|
461 |
interactive=False,
|
462 |
+
elem_classes=["status-success"]
|
463 |
)
|
464 |
|
465 |
+
# Tabbed interface for two tasks
|
466 |
+
with gr.Tabs():
|
467 |
+
|
468 |
+
# ===================== TAB 1: DETECTION =====================
|
469 |
+
with gr.Tab("🔍 Task 1: Threat Detection", elem_classes=["task-tab"]):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
470 |
gr.Markdown("""
|
471 |
+
## 🚨 Raw Log Analysis & Threat Detection
|
472 |
+
Upload or paste security logs to detect potential threats using LLM analysis.
|
|
|
|
|
|
|
|
|
473 |
""")
|
|
|
|
|
474 |
|
475 |
+
with gr.Row():
|
476 |
+
with gr.Column(scale=1):
|
477 |
+
|
478 |
+
# Detection controls
|
479 |
+
detection_sensitivity = gr.Radio(
|
480 |
+
choices=["High", "Medium", "Low"],
|
481 |
+
value="Medium",
|
482 |
+
label="🎯 Detection Sensitivity",
|
483 |
+
info="High: More alerts, Low: Only obvious threats"
|
484 |
+
)
|
485 |
+
|
486 |
+
# Sample data button
|
487 |
+
load_sample_btn = gr.Button(
|
488 |
+
"📝 Load Sample Logs",
|
489 |
+
variant="secondary"
|
490 |
+
)
|
491 |
+
|
492 |
+
detect_btn = gr.Button(
|
493 |
+
"🔍 Detect Threats",
|
494 |
+
variant="primary",
|
495 |
+
size="lg"
|
496 |
+
)
|
497 |
+
|
498 |
+
gr.Markdown("""
|
499 |
+
### 📊 Detection Capabilities:
|
500 |
+
- Failed authentication attempts
|
501 |
+
- Suspicious process execution
|
502 |
+
- Unusual network connections
|
503 |
+
- Privilege escalation
|
504 |
+
- Malware indicators
|
505 |
+
- Data exfiltration patterns
|
506 |
+
""")
|
507 |
+
|
508 |
+
with gr.Column(scale=2):
|
509 |
+
|
510 |
+
# Log input
|
511 |
+
log_input = gr.Textbox(
|
512 |
+
label="📋 Security Logs / System Events",
|
513 |
+
placeholder="Paste your security logs here...\n\nExample:\n2025-08-12 14:30:15 [AUTH] Failed login attempt...\n2025-08-12 14:30:45 [PROC] powershell.exe -enc ...",
|
514 |
+
lines=12,
|
515 |
+
elem_classes=["detection-input"]
|
516 |
+
)
|
517 |
+
|
518 |
+
# Detection results
|
519 |
+
detection_output = gr.Textbox(
|
520 |
+
label="🚨 Threat Detection Results",
|
521 |
+
lines=15,
|
522 |
+
interactive=False,
|
523 |
+
elem_classes=["analysis-output"],
|
524 |
+
placeholder="Detection results will appear here..."
|
525 |
+
)
|
526 |
+
|
527 |
+
detection_status = gr.Textbox(
|
528 |
+
label="Detection Status",
|
529 |
+
interactive=False,
|
530 |
+
lines=1
|
531 |
+
)
|
532 |
+
|
533 |
+
# ===================== TAB 2: ASSISTANT =====================
|
534 |
+
with gr.Tab("🤖 Task 2: Analyst Assistant", elem_classes=["task-tab"]):
|
535 |
+
gr.Markdown("""
|
536 |
+
## 👥 Multi-Level Analyst Support
|
537 |
+
Get AI-powered analysis tailored to your expertise level (L1/L2/L3).
|
538 |
+
""")
|
539 |
|
540 |
+
with gr.Row():
|
541 |
+
with gr.Column(scale=1):
|
542 |
+
|
543 |
+
# Assistant controls
|
544 |
+
analyst_level = gr.Radio(
|
545 |
+
choices=["L1", "L2", "L3"],
|
546 |
+
value="L2",
|
547 |
+
label="👤 Analyst Level",
|
548 |
+
info="L1: Triage • L2: Investigation • L3: Strategic"
|
549 |
+
)
|
550 |
+
|
551 |
+
# Sample threat button
|
552 |
+
load_threat_btn = gr.Button(
|
553 |
+
"📝 Load Sample Threat",
|
554 |
+
variant="secondary"
|
555 |
+
)
|
556 |
+
|
557 |
+
analyze_btn = gr.Button(
|
558 |
+
"🚀 Analyze Threat",
|
559 |
+
variant="primary",
|
560 |
+
size="lg"
|
561 |
+
)
|
562 |
+
|
563 |
+
gr.Markdown("""
|
564 |
+
### 🎯 Analysis Levels:
|
565 |
+
|
566 |
+
**L1 (Triage):**
|
567 |
+
- Initial assessment
|
568 |
+
- Containment actions
|
569 |
+
- Escalation decisions
|
570 |
+
|
571 |
+
**L2 (Investigation):**
|
572 |
+
- Detailed analysis
|
573 |
+
- Evidence collection
|
574 |
+
- Technical investigation
|
575 |
+
|
576 |
+
**L3 (Expert):**
|
577 |
+
- Strategic assessment
|
578 |
+
- Business impact
|
579 |
+
- Executive briefing
|
580 |
+
""")
|
581 |
+
|
582 |
+
with gr.Column(scale=2):
|
583 |
+
|
584 |
+
# Threat input
|
585 |
+
threat_input = gr.Textbox(
|
586 |
+
label="🚨 Threat Description",
|
587 |
+
placeholder="Describe the security incident or threat...\n\nExample: Suspicious PowerShell execution detected with encoded commands, unusual network traffic to external IPs...",
|
588 |
+
lines=8,
|
589 |
+
elem_classes=["assistant-input"]
|
590 |
+
)
|
591 |
+
|
592 |
+
# Analysis results
|
593 |
+
analysis_output = gr.Textbox(
|
594 |
+
label="🤖 AI Analysis & Recommendations",
|
595 |
+
lines=15,
|
596 |
+
interactive=False,
|
597 |
+
elem_classes=["analysis-output"],
|
598 |
+
placeholder="Analysis will appear here..."
|
599 |
+
)
|
600 |
+
|
601 |
+
analysis_status = gr.Textbox(
|
602 |
+
label="Analysis Status",
|
603 |
+
interactive=False,
|
604 |
+
lines=1
|
605 |
+
)
|
606 |
|
607 |
+
# Footer
|
608 |
gr.Markdown("""
|
609 |
---
|
610 |
+
## 📊 **Comprehensive LLM-SOC Integration**
|
611 |
+
|
612 |
+
**Task 1 (Detection):** Raw logs → Threat identification
|
613 |
+
**Task 2 (Assistant):** Threat description → Investigation guidance
|
614 |
+
|
615 |
+
*Demonstrating the full spectrum of LLM applications in Security Operations Centers*
|
616 |
""")
|
617 |
|
618 |
+
# ===================== EVENT HANDLERS =====================
|
619 |
+
|
620 |
+
# Detection tab handlers
|
621 |
+
detect_btn.click(
|
622 |
+
fn=detect_threats_from_logs,
|
623 |
+
inputs=[log_input, detection_sensitivity],
|
624 |
+
outputs=[detection_output, detection_status]
|
625 |
+
)
|
626 |
+
|
627 |
+
load_sample_btn.click(
|
628 |
+
fn=lambda: SAMPLE_LOGS,
|
629 |
+
outputs=[log_input]
|
630 |
+
)
|
631 |
+
|
632 |
+
# Assistant tab handlers
|
633 |
analyze_btn.click(
|
634 |
fn=analyze_threat,
|
635 |
inputs=[threat_input, analyst_level],
|
636 |
+
outputs=[analysis_output, analysis_status]
|
637 |
+
)
|
638 |
+
|
639 |
+
load_threat_btn.click(
|
640 |
+
fn=lambda: SAMPLE_THREAT,
|
641 |
+
outputs=[threat_input]
|
642 |
)
|
643 |
|
644 |
# Initialize model on startup
|