Repository navigation
Expand file tree
/
Copy pathanalytics.py
More file actions
824 lines (721 loc) · 31 KB
/
Copy pathanalytics.py
File metadata and controls
824 lines (721 loc) · 31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
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
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
"""
Ethical Hacking Python - Analytics & Visualization Engine
Developed by issu321
https://github.com/issu321/Ethical-Hacking-Python
Advanced charts, heatmaps, node graphs, radar charts, benchmark analytics,
and reporting systems. All visualizations are educational and defensive.
"""
import json
import random
import math
from datetime import datetime
from typing import Dict, List, Any, Optional, Tuple, Union
import plotly.express as px
import plotly.graph_objects as go
from plotly.subplots import make_subplots
# Optional networkx
try:
import networkx as nx
NETWORKX_AVAILABLE = True
except ImportError:
NETWORKX_AVAILABLE = False
from utils import (
export_to_csv, export_to_json, export_to_txt,
generate_security_report, severity_color, format_bytes
)
# ═══════════════════════════════════════════════════════════
# COLOR UTILITIES
# ═══════════════════════════════════════════════════════════
def hex_to_rgba(hex_color: str, alpha: float = 1.0) -> str:
"""Convert 6-digit hex color to rgba string for Plotly compatibility."""
hex_color = hex_color.lstrip("#")
if len(hex_color) == 3:
hex_color = "".join([c * 2 for c in hex_color])
r = int(hex_color[0:2], 16)
g = int(hex_color[2:4], 16)
b = int(hex_color[4:6], 16)
return f"rgba({r},{g},{b},{alpha})"
# ═══════════════════════════════════════════════════════════
# COLOR PALETTES
# ═══════════════════════════════════════════════════════════
CYBER_COLORS = {
"primary": "#00f0ff",
"secondary": "#00ff41",
"accent": "#ff00ff",
"warning": "#ffaa00",
"danger": "#ff0040",
"dark": "#0a0a0a",
"panel": "#111111",
"text": "#e0e0e0",
"grid": "#222222"
}
CYBER_PALETTE = ["#00f0ff", "#00ff41", "#ff00ff", "#ffaa00", "#ff0040", "#7b2cbf", "#3a86ff", "#fb5607"]
# ═══════════════════════════════════════════════════════════
# RADAR CHARTS
# ═══════════════════════════════════════════════════════════
def create_radar_chart(
categories: List[str],
values: List[float],
title: str = "Security Radar",
fill_color: str = "#00f0ff"
) -> go.Figure:
"""Create a cyberpunk-styled radar chart."""
fig = go.Figure()
fig.add_trace(go.Scatterpolar(
r=values + [values[0]], # Close the shape
theta=categories + [categories[0]],
fill="toself",
fillcolor=hex_to_rgba(fill_color, 0.2),
line=dict(color=fill_color, width=2),
marker=dict(size=6, color=fill_color),
name="Score"
))
fig.update_layout(
polar=dict(
radialaxis=dict(
visible=True,
range=[0, 100],
tickfont=dict(color=CYBER_COLORS["text"], size=10),
gridcolor=CYBER_COLORS["grid"],
linecolor=CYBER_COLORS["grid"]
),
angularaxis=dict(
tickfont=dict(color=CYBER_COLORS["text"], size=11),
gridcolor=CYBER_COLORS["grid"],
linecolor=CYBER_COLORS["grid"]
),
bgcolor=CYBER_COLORS["panel"]
),
paper_bgcolor=CYBER_COLORS["dark"],
plot_bgcolor=CYBER_COLORS["dark"],
font=dict(color=CYBER_COLORS["text"], family="Courier New, monospace"),
title=dict(
text=title,
font=dict(color=CYBER_COLORS["primary"], size=16),
x=0.5
),
margin=dict(l=60, r=60, t=60, b=40),
showlegend=False
)
return fig
# ═══════════════════════════════════════════════════════════
# HEATMAPS
# ═══════════════════════════════════════════════════════════
def create_heatmap(
data: List[List[float]],
x_labels: List[str],
y_labels: List[str],
title: str = "Threat Heatmap",
colorscale: str = "Viridis"
) -> go.Figure:
"""Create a cyberpunk heatmap."""
fig = go.Figure(data=go.Heatmap(
z=data,
x=x_labels,
y=y_labels,
colorscale=colorscale,
hoverongaps=False,
colorbar=dict(
tickfont=dict(color=CYBER_COLORS["text"]),
title=dict(text="Intensity", font=dict(color=CYBER_COLORS["text"]))
)
))
fig.update_layout(
paper_bgcolor=CYBER_COLORS["dark"],
plot_bgcolor=CYBER_COLORS["dark"],
font=dict(color=CYBER_COLORS["text"], family="Courier New, monospace"),
title=dict(
text=title,
font=dict(color=CYBER_COLORS["primary"], size=16),
x=0.5
),
xaxis=dict(tickfont=dict(color=CYBER_COLORS["text"]), gridcolor=CYBER_COLORS["grid"]),
yaxis=dict(tickfont=dict(color=CYBER_COLORS["text"]), gridcolor=CYBER_COLORS["grid"]),
margin=dict(l=80, r=40, t=60, b=60)
)
return fig
def create_port_heatmap(scan_results: Dict[str, Any]) -> go.Figure:
"""Create a port scan heatmap from scan results."""
all_results = scan_results.get("all_results", [])
if not all_results:
return create_heatmap([[0]], ["N/A"], ["N/A"], "No Scan Data")
ports = [r["port"] for r in all_results]
states = [r["state"] for r in all_results]
severities = [r.get("severity", "info") for r in all_results]
state_map = {"open": 3, "filtered": 2, "closed": 1, "error": 0}
z = [[state_map.get(s, 0)] for s in states]
colors = [[severity_color(sev).replace("#", "") for sev in severities]]
fig = go.Figure(data=go.Heatmap(
z=z,
x=[str(p) for p in ports],
y=["Status"],
colorscale=[[0, "#333"], [0.5, "#ffaa00"], [1, "#ff0040"]],
showscale=False,
text=[[s.upper() for s in states]],
texttemplate="%{text}",
textfont=dict(size=10, color="white")
))
fig.update_layout(
paper_bgcolor=CYBER_COLORS["dark"],
plot_bgcolor=CYBER_COLORS["dark"],
font=dict(color=CYBER_COLORS["text"], family="Courier New, monospace"),
title=dict(
text="Port Status Heatmap",
font=dict(color=CYBER_COLORS["primary"], size=16),
x=0.5
),
xaxis=dict(tickfont=dict(color=CYBER_COLORS["text"], size=9), title="Port"),
yaxis=dict(showticklabels=False),
margin=dict(l=40, r=20, t=60, b=60),
height=250
)
return fig
# ═══════════════════════════════════════════════════════════
# NODE / NETWORK GRAPHS
# ═══════════════════════════════════════════════════════════
def create_network_topology_graph(scan_results: Dict[str, Any]) -> go.Figure:
"""Create a network topology node graph from scan results."""
all_results = scan_results.get("all_results", [])
open_ports = scan_results.get("open_ports", [])
if not all_results:
fig = go.Figure()
fig.add_annotation(
text="No scan data available",
xref="paper", yref="paper",
showarrow=False,
font=dict(size=16, color=CYBER_COLORS["warning"])
)
return fig
# Build graph
if NETWORKX_AVAILABLE:
G = nx.Graph()
target_ip = scan_results.get("ip", "Target")
G.add_node(target_ip, type="target")
for r in all_results:
port = r["port"]
service = r.get("service", "Unknown")
state = r["state"]
node_id = f"{port}:{service}"
G.add_node(node_id, type=state, port=port, service=service)
if state == "open":
G.add_edge(target_ip, node_id, weight=2)
else:
G.add_edge(target_ip, node_id, weight=0.5)
pos = nx.spring_layout(G, seed=42, k=2)
edge_x, edge_y = [], []
for edge in G.edges():
x0, y0 = pos[edge[0]]
x1, y1 = pos[edge[1]]
edge_x.extend([x0, x1, None])
edge_y.extend([y0, y1, None])
node_x, node_y, node_color, node_text, node_size = [], [], [], [], []
for node in G.nodes():
x, y = pos[node]
node_x.append(x)
node_y.append(y)
attrs = G.nodes[node]
if attrs.get("type") == "target":
node_color.append(CYBER_COLORS["primary"])
node_text.append(f"🎯 {node}")
node_size.append(30)
elif attrs.get("type") == "open":
node_color.append(CYBER_COLORS["danger"])
node_text.append(f"🔓 {node}")
node_size.append(20)
else:
node_color.append(CYBER_COLORS["grid"])
node_text.append(f"🔒 {node}")
node_size.append(12)
else:
# Fallback without networkx
node_x = [0]
node_y = [0]
node_color = [CYBER_COLORS["primary"]]
node_text = ["Target"]
node_size = [30]
edge_x, edge_y = [], []
angle_step = 2 * math.pi / max(len(all_results), 1)
for i, r in enumerate(all_results):
angle = i * angle_step
radius = 1.5
x = radius * math.cos(angle)
y = radius * math.sin(angle)
node_x.append(x)
node_y.append(y)
if r["state"] == "open":
node_color.append(CYBER_COLORS["danger"])
else:
node_color.append(CYBER_COLORS["grid"])
node_text.append(f"{r['port']}:{r.get('service', '?')}")
node_size.append(15 if r["state"] == "open" else 8)
edge_x.extend([0, x, None])
edge_y.extend([0, y, None])
fig = go.Figure()
fig.add_trace(go.Scatter(
x=edge_x, y=edge_y,
mode="lines",
line=dict(color=CYBER_COLORS["grid"], width=1),
hoverinfo="none",
showlegend=False
))
fig.add_trace(go.Scatter(
x=node_x, y=node_y,
mode="markers+text",
marker=dict(
size=node_size,
color=node_color,
line=dict(width=2, color=CYBER_COLORS["dark"])
),
text=node_text,
textposition="top center",
textfont=dict(size=9, color=CYBER_COLORS["text"]),
hoverinfo="text",
showlegend=False
))
fig.update_layout(
paper_bgcolor=CYBER_COLORS["dark"],
plot_bgcolor=CYBER_COLORS["dark"],
font=dict(color=CYBER_COLORS["text"], family="Courier New, monospace"),
title=dict(
text="Network Topology",
font=dict(color=CYBER_COLORS["primary"], size=16),
x=0.5
),
xaxis=dict(showgrid=False, zeroline=False, showticklabels=False),
yaxis=dict(showgrid=False, zeroline=False, showticklabels=False),
margin=dict(l=20, r=20, t=60, b=20),
height=500
)
return fig
def create_subdomain_graph(subdomain_data: Dict[str, Any]) -> go.Figure:
"""Create a subdomain relationship graph."""
subs = subdomain_data.get("subdomains", [])
domain = subdomain_data.get("domain", "domain")
if not subs:
fig = go.Figure()
fig.add_annotation(text="No subdomains found", xref="paper", yref="paper", showarrow=False,
font=dict(size=16, color=CYBER_COLORS["warning"]))
return fig
if NETWORKX_AVAILABLE:
G = nx.Graph()
G.add_node(domain, type="root")
for s in subs:
sub = s.get("subdomain", "")
ip = s.get("ip", "")
G.add_node(sub, type="sub", ip=ip)
G.add_edge(domain, sub)
pos = nx.spring_layout(G, seed=42, k=1.5)
edge_x, edge_y = [], []
for edge in G.edges():
x0, y0 = pos[edge[0]]
x1, y1 = pos[edge[1]]
edge_x.extend([x0, x1, None])
edge_y.extend([y0, y1, None])
node_x, node_y, node_color, node_text, node_size = [], [], [], [], []
for node in G.nodes():
x, y = pos[node]
node_x.append(x)
node_y.append(y)
if node == domain:
node_color.append(CYBER_COLORS["primary"])
node_text.append(f"🌐 {node}")
node_size.append(25)
else:
node_color.append(CYBER_COLORS["secondary"])
ip = G.nodes[node].get("ip", "")
node_text.append(f"📡 {node}\n{ip}")
node_size.append(15)
else:
node_x, node_y = [0], [0]
node_color = [CYBER_COLORS["primary"]]
node_text = [domain]
node_size = [25]
edge_x, edge_y = [], []
angle_step = 2 * math.pi / max(len(subs), 1)
for i, s in enumerate(subs):
angle = i * angle_step
radius = 1.5
x = radius * math.cos(angle)
y = radius * math.sin(angle)
node_x.append(x)
node_y.append(y)
node_color.append(CYBER_COLORS["secondary"])
node_text.append(f"{s.get('subdomain', '')}\n{s.get('ip', '')}")
node_size.append(12)
edge_x.extend([0, x, None])
edge_y.extend([0, y, None])
fig = go.Figure()
fig.add_trace(go.Scatter(
x=edge_x, y=edge_y,
mode="lines",
line=dict(color=CYBER_COLORS["grid"], width=1),
hoverinfo="none", showlegend=False
))
fig.add_trace(go.Scatter(
x=node_x, y=node_y,
mode="markers+text",
marker=dict(size=node_size, color=node_color,
line=dict(width=2, color=CYBER_COLORS["dark"])),
text=node_text,
textposition="top center",
textfont=dict(size=9, color=CYBER_COLORS["text"]),
hoverinfo="text", showlegend=False
))
fig.update_layout(
paper_bgcolor=CYBER_COLORS["dark"],
plot_bgcolor=CYBER_COLORS["dark"],
font=dict(color=CYBER_COLORS["text"], family="Courier New, monospace"),
title=dict(text="Subdomain Map", font=dict(color=CYBER_COLORS["primary"], size=16), x=0.5),
xaxis=dict(showgrid=False, zeroline=False, showticklabels=False),
yaxis=dict(showgrid=False, zeroline=False, showticklabels=False),
margin=dict(l=20, r=20, t=60, b=20),
height=500
)
return fig
# ═══════════════════════════════════════════════════════════
# GAUGE / INDICATOR CHARTS
# ═══════════════════════════════════════════════════════════
def create_risk_gauge(value: float, title: str = "Risk Score") -> go.Figure:
"""Create a cyberpunk risk gauge."""
color = CYBER_COLORS["secondary"] if value < 30 else CYBER_COLORS["warning"] if value < 70 else CYBER_COLORS["danger"]
fig = go.Figure(go.Indicator(
mode="gauge+number+delta",
value=value,
number=dict(font=dict(size=28, color=CYBER_COLORS["text"]), suffix="%"),
title=dict(text=title, font=dict(size=14, color=CYBER_COLORS["primary"])),
gauge=dict(
axis=dict(range=[0, 100], tickfont=dict(color=CYBER_COLORS["text"]),
tickcolor=CYBER_COLORS["grid"]),
bar=dict(color=color, thickness=0.6),
bgcolor=CYBER_COLORS["panel"],
borderwidth=2,
bordercolor=CYBER_COLORS["grid"],
steps=[
dict(range=[0, 30], color=hex_to_rgba(CYBER_COLORS["secondary"], 0.13)),
dict(range=[30, 70], color=hex_to_rgba(CYBER_COLORS["warning"], 0.13)),
dict(range=[70, 100], color=hex_to_rgba(CYBER_COLORS["danger"], 0.13))
],
threshold=dict(
line=dict(color=CYBER_COLORS["danger"], width=3),
thickness=0.8,
value=70
)
)
))
fig.update_layout(
paper_bgcolor=CYBER_COLORS["dark"],
font=dict(color=CYBER_COLORS["text"], family="Courier New, monospace"),
margin=dict(l=30, r=30, t=50, b=20),
height=280
)
return fig
def create_entropy_gauge(entropy: float, max_entropy: float = 128) -> go.Figure:
"""Create entropy gauge for password analysis."""
pct = min(100, (entropy / max_entropy) * 100)
return create_risk_gauge(pct, "Entropy Score")
# ═══════════════════════════════════════════════════════════
# BAR / PIE / LINE CHARTS
# ═══════════════════════════════════════════════════════════
def create_bar_chart(
data: Dict[str, Any],
x_key: str,
y_key: str,
title: str = "Bar Chart",
color_key: str = None
) -> go.Figure:
"""Create a cyberpunk bar chart."""
df_data = data if isinstance(data, list) else data.get("data", [])
if not df_data:
fig = go.Figure()
fig.add_annotation(text="No data", xref="paper", yref="paper", showarrow=False)
return fig
x_vals = [d.get(x_key, "") for d in df_data]
y_vals = [d.get(y_key, 0) for d in df_data]
colors = [d.get(color_key, CYBER_COLORS["primary"]) for d in df_data] if color_key else [CYBER_COLORS["primary"]] * len(df_data)
fig = go.Figure(data=[go.Bar(
x=x_vals,
y=y_vals,
marker=dict(
color=colors,
line=dict(color=CYBER_COLORS["dark"], width=1)
),
text=y_vals,
textposition="outside",
textfont=dict(color=CYBER_COLORS["text"], size=10)
)])
fig.update_layout(
paper_bgcolor=CYBER_COLORS["dark"],
plot_bgcolor=CYBER_COLORS["panel"],
font=dict(color=CYBER_COLORS["text"], family="Courier New, monospace"),
title=dict(text=title, font=dict(color=CYBER_COLORS["primary"], size=16), x=0.5),
xaxis=dict(tickfont=dict(color=CYBER_COLORS["text"]), gridcolor=CYBER_COLORS["grid"]),
yaxis=dict(tickfont=dict(color=CYBER_COLORS["text"]), gridcolor=CYBER_COLORS["grid"]),
margin=dict(l=50, r=20, t=60, b=60)
)
return fig
def create_pie_chart(
labels: List[str],
values: List[float],
title: str = "Distribution",
hole: float = 0.4
) -> go.Figure:
"""Create a cyberpunk pie/donut chart."""
fig = go.Figure(data=[go.Pie(
labels=labels,
values=values,
hole=hole,
marker=dict(
colors=CYBER_PALETTE[:len(labels)],
line=dict(color=CYBER_COLORS["dark"], width=2)
),
textfont=dict(color=CYBER_COLORS["text"], size=11),
hovertemplate="%{label}: %{value} (%{percent})<<extra></extra>"
)])
fig.update_layout(
paper_bgcolor=CYBER_COLORS["dark"],
font=dict(color=CYBER_COLORS["text"], family="Courier New, monospace"),
title=dict(text=title, font=dict(color=CYBER_COLORS["primary"], size=16), x=0.5),
margin=dict(l=20, r=20, t=60, b=20),
showlegend=True,
legend=dict(font=dict(color=CYBER_COLORS["text"]), bgcolor=CYBER_COLORS["panel"])
)
return fig
def create_line_chart(
x: List[Any],
y: List[float],
title: str = "Trend",
line_color: str = CYBER_COLORS["primary"]
) -> go.Figure:
"""Create a cyberpunk line chart."""
fig = go.Figure(data=[go.Scatter(
x=x,
y=y,
mode="lines+markers",
line=dict(color=line_color, width=2),
marker=dict(size=6, color=line_color, line=dict(color=CYBER_COLORS["dark"], width=1)),
fill="tozeroy",
fillcolor=hex_to_rgba(line_color, 0.08)
)])
fig.update_layout(
paper_bgcolor=CYBER_COLORS["dark"],
plot_bgcolor=CYBER_COLORS["panel"],
font=dict(color=CYBER_COLORS["text"], family="Courier New, monospace"),
title=dict(text=title, font=dict(color=CYBER_COLORS["primary"], size=16), x=0.5),
xaxis=dict(tickfont=dict(color=CYBER_COLORS["text"]), gridcolor=CYBER_COLORS["grid"]),
yaxis=dict(tickfont=dict(color=CYBER_COLORS["text"]), gridcolor=CYBER_COLORS["grid"]),
margin=dict(l=50, r=20, t=60, b=60)
)
return fig
# ═══════════════════════════════════════════════════════════
# THREAT INTELLIGENCE VISUALIZATIONS
# ═══════════════════════════════════════════════════════════
def create_threat_radar(threat_data: Dict[str, Any]) -> go.Figure:
"""Create threat intelligence radar chart."""
categories = ["Malware", "Phishing", "DDoS", "Intrusion", "Data Exfil", "Insider"]
values = [
threat_data.get("malware", random.randint(10, 80)),
threat_data.get("phishing", random.randint(10, 80)),
threat_data.get("ddos", random.randint(10, 80)),
threat_data.get("intrusion", random.randint(10, 80)),
threat_data.get("exfil", random.randint(10, 80)),
threat_data.get("insider", random.randint(10, 80)),
]
return create_radar_chart(categories, values, "Threat Vector Analysis", CYBER_COLORS["danger"])
def create_attack_chain_graph() -> go.Figure:
"""Create a simulated attack chain flow diagram."""
stages = ["Recon", "Weaponize", "Deliver", "Exploit", "Install", "C2", "Action"]
colors = [CYBER_COLORS["primary"], CYBER_COLORS["warning"], CYBER_COLORS["warning"],
CYBER_COLORS["danger"], CYBER_COLORS["danger"], CYBER_COLORS["accent"], CYBER_COLORS["accent"]]
fig = go.Figure()
for i, (stage, color) in enumerate(zip(stages, colors)):
fig.add_trace(go.Scatter(
x=[i],
y=[0],
mode="markers+text",
marker=dict(size=30, color=color, line=dict(width=2, color=CYBER_COLORS["dark"])),
text=[stage],
textposition="bottom center",
textfont=dict(size=11, color=CYBER_COLORS["text"]),
hoverinfo="text",
showlegend=False
))
# Add arrows
for i in range(len(stages) - 1):
fig.add_annotation(
x=i, y=0,
ax=i+1, ay=0,
xref="x", yref="y", axref="x", ayref="y",
showarrow=True,
arrowhead=2,
arrowsize=1,
arrowwidth=2,
arrowcolor=CYBER_COLORS["grid"]
)
fig.update_layout(
paper_bgcolor=CYBER_COLORS["dark"],
plot_bgcolor=CYBER_COLORS["dark"],
font=dict(color=CYBER_COLORS["text"], family="Courier New, monospace"),
title=dict(text="Cyber Kill Chain", font=dict(color=CYBER_COLORS["primary"], size=16), x=0.5),
xaxis=dict(showgrid=False, zeroline=False, showticklabels=False, range=[-0.5, len(stages)-0.5]),
yaxis=dict(showgrid=False, zeroline=False, showticklabels=False, range=[-1, 1]),
margin=dict(l=20, r=20, t=60, b=80),
height=250
)
return fig
def create_protocol_distribution(protocol_data: Dict[str, int]) -> go.Figure:
"""Create protocol distribution pie chart."""
labels = list(protocol_data.keys())
values = list(protocol_data.values())
return create_pie_chart(labels, values, "Protocol Distribution", hole=0.35)
# ═══════════════════════════════════════════════════════════
# SYSTEM MONITOR CHARTS
# ═══════════════════════════════════════════════════════════
def create_system_gauges(cpu: float, memory: float, disk: float) -> go.Figure:
"""Create system resource gauges."""
fig = make_subplots(
rows=1, cols=3,
specs=[[{"type": "indicator"}, {"type": "indicator"}, {"type": "indicator"}]]
)
fig.add_trace(go.Indicator(
mode="gauge+number",
value=cpu,
title=dict(text="CPU", font=dict(color=CYBER_COLORS["primary"])),
number=dict(suffix="%", font=dict(color=CYBER_COLORS["text"])),
gauge=dict(
axis=dict(range=[0, 100], tickfont=dict(color=CYBER_COLORS["text"])),
bar=dict(color=CYBER_COLORS["primary"]),
bgcolor=CYBER_COLORS["panel"],
steps=[
dict(range=[0, 50], color=hex_to_rgba(CYBER_COLORS["secondary"], 0.13)),
dict(range=[50, 80], color=hex_to_rgba(CYBER_COLORS["warning"], 0.13)),
dict(range=[80, 100], color=hex_to_rgba(CYBER_COLORS["danger"], 0.13))
]
)
), row=1, col=1)
fig.add_trace(go.Indicator(
mode="gauge+number",
value=memory,
title=dict(text="RAM", font=dict(color=CYBER_COLORS["accent"])),
number=dict(suffix="%", font=dict(color=CYBER_COLORS["text"])),
gauge=dict(
axis=dict(range=[0, 100], tickfont=dict(color=CYBER_COLORS["text"])),
bar=dict(color=CYBER_COLORS["accent"]),
bgcolor=CYBER_COLORS["panel"],
steps=[
dict(range=[0, 50], color=hex_to_rgba(CYBER_COLORS["secondary"], 0.13)),
dict(range=[50, 80], color=hex_to_rgba(CYBER_COLORS["warning"], 0.13)),
dict(range=[80, 100], color=hex_to_rgba(CYBER_COLORS["danger"], 0.13))
]
)
), row=1, col=2)
fig.add_trace(go.Indicator(
mode="gauge+number",
value=disk,
title=dict(text="Disk", font=dict(color=CYBER_COLORS["warning"])),
number=dict(suffix="%", font=dict(color=CYBER_COLORS["text"])),
gauge=dict(
axis=dict(range=[0, 100], tickfont=dict(color=CYBER_COLORS["text"])),
bar=dict(color=CYBER_COLORS["warning"]),
bgcolor=CYBER_COLORS["panel"],
steps=[
dict(range=[0, 50], color=hex_to_rgba(CYBER_COLORS["secondary"], 0.13)),
dict(range=[50, 80], color=hex_to_rgba(CYBER_COLORS["warning"], 0.13)),
dict(range=[80, 100], color=hex_to_rgba(CYBER_COLORS["danger"], 0.13))
]
)
), row=1, col=3)
fig.update_layout(
paper_bgcolor=CYBER_COLORS["dark"],
font=dict(color=CYBER_COLORS["text"], family="Courier New, monospace"),
margin=dict(l=20, r=20, t=50, b=20),
height=250
)
return fig
# ═══════════════════════════════════════════════════════════
# REPORTING SYSTEMS
# ═══════════════════════════════════════════════════════════
def generate_csv_report(data: List[Dict[str, Any]]) -> bytes:
"""Generate CSV report bytes."""
return export_to_csv(data)
def generate_json_report(data: Any) -> bytes:
"""Generate JSON report bytes."""
return export_to_json(data)
def generate_txt_report(content: str) -> bytes:
"""Generate TXT report bytes."""
return export_to_txt(content)
def create_vulnerability_summary_table(vulns: List[Dict[str, Any]]) -> go.Figure:
"""Create an interactive vulnerability table."""
if not vulns:
fig = go.Figure()
fig.add_annotation(text="No vulnerabilities to display", xref="paper", yref="paper", showarrow=False)
return fig
severities = [v.get("severity", "info").upper() for v in vulns]
colors = [severity_color(s) for s in severities]
fig = go.Figure(data=[go.Table(
header=dict(
values=["ID", "Name", "Severity", "CVSS", "Port", "Recommendation"],
fill_color=CYBER_COLORS["panel"],
align="left",
font=dict(color=CYBER_COLORS["primary"], size=12),
line=dict(color=CYBER_COLORS["grid"], width=1)
),
cells=dict(
values=[
[v.get("id", "") for v in vulns],
[v.get("name", "") for v in vulns],
severities,
[str(v.get("cvss_simulated", "N/A")) for v in vulns],
[str(v.get("port", "N/A")) for v in vulns],
[v.get("recommendation", "") for v in vulns]
],
fill_color=[CYBER_COLORS["dark"]] * len(vulns),
align="left",
font=dict(color=CYBER_COLORS["text"], size=10),
line=dict(color=CYBER_COLORS["grid"], width=1),
height=30
)
)])
fig.update_layout(
paper_bgcolor=CYBER_COLORS["dark"],
font=dict(color=CYBER_COLORS["text"], family="Courier New, monospace"),
title=dict(text="Vulnerability Findings", font=dict(color=CYBER_COLORS["primary"], size=16), x=0.5),
margin=dict(l=10, r=10, t=50, b=10),
height=min(400, 100 + len(vulns) * 35)
)
return fig
def create_threat_timeline() -> go.Figure:
"""Create simulated threat timeline."""
hours = [f"{h:02d}:00" for h in range(24)]
threats = [random.randint(0, 20) for _ in range(24)]
mitigated = [random.randint(0, t) for t in threats]
fig = go.Figure()
fig.add_trace(go.Scatter(
x=hours, y=threats,
mode="lines+markers",
name="Detected",
line=dict(color=CYBER_COLORS["danger"], width=2),
marker=dict(size=5),
fill="tozeroy",
fillcolor=hex_to_rgba(CYBER_COLORS["danger"], 0.08)
))
fig.add_trace(go.Scatter(
x=hours, y=mitigated,
mode="lines+markers",
name="Mitigated",
line=dict(color=CYBER_COLORS["secondary"], width=2),
marker=dict(size=5),
fill="tozeroy",
fillcolor=hex_to_rgba(CYBER_COLORS["secondary"], 0.08)
))
fig.update_layout(
paper_bgcolor=CYBER_COLORS["dark"],
plot_bgcolor=CYBER_COLORS["panel"],
font=dict(color=CYBER_COLORS["text"], family="Courier New, monospace"),
title=dict(text="24h Threat Activity", font=dict(color=CYBER_COLORS["primary"], size=16), x=0.5),
xaxis=dict(tickfont=dict(color=CYBER_COLORS["text"]), gridcolor=CYBER_COLORS["grid"]),
yaxis=dict(tickfont=dict(color=CYBER_COLORS["text"]), gridcolor=CYBER_COLORS["grid"], title="Events"),
legend=dict(font=dict(color=CYBER_COLORS["text"]), bgcolor=CYBER_COLORS["panel"]),
margin=dict(l=50, r=20, t=60, b=60),
height=350
)
return fig