-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgui.py
More file actions
3646 lines (3144 loc) · 139 KB
/
Copy pathgui.py
File metadata and controls
3646 lines (3144 loc) · 139 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
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import os
import sys
import json
import platform
import psutil
import threading
from exploit import ExploitThread, ExploitResultsDialog
from PyQt5.QtWidgets import (QApplication, QMainWindow, QWidget, QVBoxLayout, QHBoxLayout, QPushButton,
QTextEdit, QLabel, QGroupBox, QCheckBox, QComboBox, QTabWidget, QTableWidget,
QTableWidgetItem, QHeaderView, QProgressBar, QFileDialog, QMessageBox, QInputDialog,
QLineEdit, QSplitter, QFrame, QDialog, QFormLayout, QGridLayout, QScrollArea,
QGraphicsDropShadowEffect, QSizePolicy)
from PyQt5.QtCore import Qt, QThread, pyqtSignal, QTimer, QSize, QPropertyAnimation, QEasingCurve, QRect
from PyQt5.QtGui import QFont, QColor, QIcon, QPalette, QPainter, QLinearGradient, QBrush, QPen, QPixmap
from scanner import ScanThread
from utils import get_system_info, get_current_time, get_cvss_score
from translations import get_translation, get_cve_details
from source_analysis_gui import SourceCodeAnalysisTab
# 导入增强的翻译功能
from translations import (get_translation, get_cve_details, format_vulnerability_details,
get_vulnerability_summary, translate_vulnerability_info, analyze_mitigation_status)
# 修复:Ubuntu编码问题
if platform.system() == "Linux":
import locale
# 设置系统编码
try:
locale.setlocale(locale.LC_ALL, 'zh_CN.UTF-8')
except:
try:
locale.setlocale(locale.LC_ALL, 'C.UTF-8')
except:
pass
def show_quick_start_guide(parent):
"""显示快速入门指南 - 增强版本,支持"不再显示"选项"""
# 修复:在函数开头正确导入所需组件
from PyQt5.QtWidgets import (QDialog, QVBoxLayout, QHBoxLayout, QLabel,
QPushButton, QTextEdit, QCheckBox, QWidget)
from PyQt5.QtCore import Qt
dialog = QDialog(parent)
dialog.setWindowTitle("🚀 快速入门指南")
dialog.setMinimumSize(650, 550)
dialog.setFixedSize(700, 600) # 固定窗口大小,防止内容溢出
dialog.setStyleSheet("""
QDialog {
background-color: #f8f9fa;
}
""")
# 设置窗口居中显示
if parent:
parent_geometry = parent.geometry()
x = parent_geometry.x() + (parent_geometry.width() - 700) // 2
y = parent_geometry.y() + (parent_geometry.height() - 600) // 2
dialog.move(max(0, x), max(0, y))
layout = QVBoxLayout(dialog)
layout.setContentsMargins(25, 25, 25, 25)
layout.setSpacing(20)
# 标题区域
title_container = QWidget()
title_layout = QVBoxLayout(title_container)
title_layout.setContentsMargins(0, 0, 0, 0)
title_layout.setSpacing(8)
title_label = QLabel("🚀 欢迎使用CPU漏洞检测工具")
title_label.setStyleSheet("""
QLabel {
font-family: 'Segoe UI', 'Microsoft YaHei', 'Arial';
font-size: 24px;
font-weight: 700;
color: #2c3e50;
text-align: center;
}
""")
title_label.setAlignment(Qt.AlignCenter)
subtitle_label = QLabel("SpecProbe v3.0.0 - 现代化CPU安全检测平台")
subtitle_label.setStyleSheet("""
QLabel {
font-family: 'Segoe UI', 'Microsoft YaHei', 'Arial';
font-size: 14px;
color: #667eea;
text-align: center;
font-weight: 500;
}
""")
subtitle_label.setAlignment(Qt.AlignCenter)
title_layout.addWidget(title_label)
title_layout.addWidget(subtitle_label)
layout.addWidget(title_container)
# 内容区域 - 使用滚动文本框
content = QTextEdit()
content.setReadOnly(True)
content.setStyleSheet("""
QTextEdit {
font-family: 'Segoe UI', 'Microsoft YaHei', 'Arial';
font-size: 13px;
border: 2px solid #e9ecef;
border-radius: 12px;
padding: 20px;
background-color: white;
color: #495057;
line-height: 1.8;
}
QScrollBar:vertical {
background-color: #f8f9fa;
width: 12px;
border-radius: 6px;
}
QScrollBar::handle:vertical {
background-color: #667eea;
border-radius: 6px;
min-height: 20px;
}
QScrollBar::handle:vertical:hover {
background-color: #764ba2;
}
""")
guide_text = """
🎯 欢迎使用CPU漏洞检测工具!
本工具是一个现代化的CPU安全检测平台,集成了静态分析和动态PoC验证功能,帮助您全面了解系统的安全状况。
📋 主要功能模块:
🔍 1. 硬件漏洞扫描
• 在"扫描设置"标签页中配置扫描选项
• 支持检测20多种CPU漏洞:Spectre、Meltdown、EntryBleed等
• 提供静态检测和动态PoC验证两种模式
• 点击"开始扫描"执行检测(首次使用需要sudo权限)
• 在"漏洞结果"标签页查看详细检测结果
🧬 2. 源代码安全分析
• 在"源代码分析"标签页中添加源代码文件
• 支持拖拽上传:直接将.c、.cpp、.java、.py等文件拖到文件列表
• 支持多种编程语言的安全漏洞分析
• 可选择内置或自定义QL检测脚本
• 提供详细的代码安全评估报告
📊 3. 结果导出与报告
• 支持导出JSON、CSV、TXT格式的原始结果
• 可生成精美的可视化HTML报告
• 包含详细的漏洞描述、影响分析和缓解建议
• 支持风险评估和安全趋势分析
💡 使用技巧与注意事项:
🔧 环境准备:
• 首次扫描时需要输入sudo密码(用于访问系统硬件信息)
• 动态PoC分析需要运行setup_pocs.sh脚本编译测试程序
• 源代码分析功能需要安装CodeQL工具(可选,不影响基本功能)
🎯 最佳实践:
• 建议先运行"全部扫描"了解系统整体安全状况
• 点击"详情"按钮查看每个漏洞的完整技术信息
• 定期扫描以确保系统安全状态
• 及时更新系统补丁和微码
📱 界面导航:
• "扫描设置" - 配置检测参数和启动扫描
• "漏洞结果" - 查看检测结果和统计信息
• "详细输出" - 查看原始扫描日志和调试信息
• "源代码分析" - 上传和分析源代码文件
• "系统信息" - 查看当前系统和CPU详细信息
🛡️ 安全提醒:
• 本工具仅用于安全研究和系统评估
• 动态PoC测试是安全的,不会对系统造成损害
• 所有检测结果包含详细的技术解释和缓解建议
• 如发现高危漏洞,请及时采取相应的安全措施
❓ 需要帮助?
• 查看"系统信息"标签了解当前运行环境
• 点击各功能区域的"帮助"按钮获取详细说明
• 所有检测结果都包含相关的CVE编号和参考链接
🚀 现在开始你的安全检测之旅吧!
温馨提示:如果您是首次使用,建议从"全部扫描"开始,这样可以快速了解系统的整体安全状况。
"""
content.setPlainText(guide_text)
layout.addWidget(content)
# 选项区域 - 添加"不再显示"选项
options_container = QWidget()
options_layout = QHBoxLayout(options_container)
options_layout.setContentsMargins(10, 10, 10, 10)
# "不再显示"复选框
dont_show_checkbox = QCheckBox("下次启动时不再显示此指南")
dont_show_checkbox.setStyleSheet("""
QCheckBox {
font-family: 'Segoe UI', 'Microsoft YaHei', 'Arial';
font-size: 12px;
color: #6c757d;
spacing: 8px;
}
QCheckBox::indicator {
width: 16px;
height: 16px;
border-radius: 3px;
border: 2px solid #bdc3c7;
background-color: white;
}
QCheckBox::indicator:checked {
background-color: #667eea;
border-color: #667eea;
image: url(data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMTIiIGhlaWdodD0iOSIgdmlld0JveD0iMCAwIDEyIDkiIGZpbGw9Im5vbmUiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+CjxwYXRoIGQ9Ik0xIDQuNUw0LjUgOEwxMSAxLjUiIHN0cm9rZT0iI0ZGRkZGRiIgc3Ryb2tlLXdpZHRoPSIyIiBzdHJva2UtbGluZWNhcD0icm91bmQiIHN0cm9rZS1saW5lam9pbj0icm91bmQiLz4KPC9zdmc+);
}
QCheckBox::indicator:hover {
border-color: #667eea;
background-color: rgba(102, 126, 234, 0.05);
}
""")
options_layout.addWidget(dont_show_checkbox)
options_layout.addStretch()
layout.addWidget(options_container)
# 按钮区域
button_container = QWidget()
button_layout = QHBoxLayout(button_container)
button_layout.setContentsMargins(0, 10, 0, 0)
button_layout.setSpacing(15)
# 查看更多帮助按钮
help_button = QPushButton("📖 查看更多帮助")
help_button.setFixedSize(120, 40)
help_button.setStyleSheet("""
QPushButton {
font-family: 'Segoe UI', 'Microsoft YaHei', 'Arial';
background-color: #17a2b8;
color: white;
border: none;
border-radius: 8px;
padding: 8px 16px;
font-weight: 500;
font-size: 12px;
}
QPushButton:hover {
background-color: #138496;
}
QPushButton:pressed {
background-color: #117a8b;
}
""")
def show_more_help():
"""显示更多帮助信息"""
help_dialog = QDialog(dialog)
help_dialog.setWindowTitle("📖 详细帮助")
help_dialog.setMinimumSize(600, 400)
help_dialog.setStyleSheet("QDialog { background-color: #f8f9fa; }")
help_layout = QVBoxLayout(help_dialog)
help_layout.setContentsMargins(20, 20, 20, 20)
help_content = QTextEdit()
help_content.setReadOnly(True)
help_content.setStyleSheet(content.styleSheet())
help_content.setPlainText("""
🔧 环境配置详细说明:
1. 动态PoC环境设置:
• 运行 sudo ./setup_pocs.sh 下载和编译PoC
• 编译成功后可在"扫描设置"中启用动态分析
• 动态分析提供更准确的漏洞验证
2. CodeQL源代码分析环境:
• 下载CodeQL CLI工具
• 配置环境变量或在工具中指定路径
• 支持C/C++/Java/Python等多种语言
📋 常见问题解答:
Q: 为什么需要sudo权限?
A: 漏洞检测需要读取CPU特性和内核信息,需要管理员权限。
Q: 动态分析安全吗?
A: 是的,所有PoC都是只读测试,不会修改系统或造成损害。
Q: 检测结果准确吗?
A: 工具基于官方spectre-meltdown-checker,结果高度可信。
Q: 如何解读检测结果?
A: 每个结果都有详细说明,包括CVE编号、影响描述和缓解建议。
🔗 相关资源:
• CVE官方数据库:https://cve.mitre.org/
• Intel安全公告:https://www.intel.com/content/www/us/en/security-center/
• AMD安全公告:https://www.amd.com/en/corporate/product-security
""")
help_layout.addWidget(help_content)
close_help_btn = QPushButton("关闭")
close_help_btn.clicked.connect(help_dialog.accept)
help_layout.addWidget(close_help_btn)
help_dialog.exec_()
help_button.clicked.connect(show_more_help)
# 开始使用按钮
start_button = QPushButton("🚀 开始使用")
start_button.setFixedSize(120, 40)
start_button.setStyleSheet("""
QPushButton {
font-family: 'Segoe UI', 'Microsoft YaHei', 'Arial';
background: qlineargradient(x1:0, y1:0, x2:1, y2:0,
stop:0 #667eea, stop:1 #764ba2);
color: white;
border: none;
border-radius: 8px;
padding: 8px 16px;
font-weight: 600;
font-size: 12px;
}
QPushButton:hover {
background: qlineargradient(x1:0, y1:0, x2:1, y2:0,
stop:0 #5a6fd8, stop:1 #6a4190);
}
QPushButton:pressed {
background: qlineargradient(x1:0, y1:0, x2:1, y2:0,
stop:0 #4e5bc4, stop:1 #5e3785);
}
""")
def start_application():
"""开始使用应用程序"""
# 检查用户是否选择了"不再显示"
if dont_show_checkbox.isChecked():
try:
# 创建"不再显示"标记文件
dont_show_file = os.path.expanduser('~/.cpu-vuln-scanner-dont-show')
with open(dont_show_file, 'w', encoding='utf-8') as f:
import datetime
f.write(f"用户选择不再显示快速入门指南\n")
f.write(f"时间: {datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')}\n")
f.write(f"版本: SpecProbe v3.0.0\n")
print("✅ 已保存用户偏好设置:不再显示快速入门指南")
except Exception as e:
print(f"⚠️ 保存用户偏好设置失败: {e}")
dialog.accept()
start_button.clicked.connect(start_application)
button_layout.addWidget(help_button)
button_layout.addStretch()
button_layout.addWidget(start_button)
layout.addWidget(button_container)
# 设置默认按钮和焦点
start_button.setDefault(True)
start_button.setFocus()
# 执行对话框
dialog.exec_()
def get_system_fonts():
"""获取系统适用的字体"""
system = platform.system()
if system == "Windows":
return {
'ui': ['Segoe UI', 'Microsoft YaHei', 'SimHei', 'Arial', 'sans-serif'],
'mono': ['Consolas', 'Courier New', 'monospace']
}
elif system == "Darwin": # macOS
return {
'ui': ['SF Pro Display', 'PingFang SC', 'Helvetica Neue', 'Arial', 'sans-serif'],
'mono': ['SF Mono', 'Monaco', 'Menlo', 'monospace']
}
else: # Linux/Unix
return {
'ui': ['DejaVu Sans', 'Liberation Sans', 'Noto Sans CJK SC', 'WenQuanYi Micro Hei', 'Ubuntu', 'Arial', 'sans-serif'],
'mono': ['DejaVu Sans Mono', 'Liberation Mono', 'Ubuntu Mono', 'Courier New', 'monospace']
}
class ModernCard(QFrame):
"""现代化卡片组件 - 修复高度控制问题"""
def __init__(self, title="", parent=None):
super().__init__(parent)
self.setFrameShape(QFrame.StyledPanel)
# 修复:默认使用preferred大小策略,允许固定高度
self.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Preferred)
# 修复:确保卡片有明确的边界约束
self.setStyleSheet("""
QFrame {
background-color: white;
border-radius: 12px;
border: 1px solid #e8e9ea;
margin: 2px;
}
""")
# 添加阴影效果
shadow = QGraphicsDropShadowEffect()
shadow.setBlurRadius(10)
shadow.setColor(QColor(0, 0, 0, 20))
shadow.setOffset(0, 2)
self.setGraphicsEffect(shadow)
self.layout = QVBoxLayout(self)
# 修复:调整内边距,为固定高度的内容留出空间
self.layout.setContentsMargins(20, 15, 20, 15)
self.layout.setSpacing(10)
if title:
fonts = get_system_fonts()
self.title_label = QLabel(title)
self.title_label.setFixedHeight(25) # 固定标题高度
self.title_label.setStyleSheet(f"""
QLabel {{
font-family: {', '.join(fonts['ui'])};
font-size: 16px;
font-weight: 600;
color: #2c3e50;
margin-bottom: 5px;
border: none;
padding: 0px;
}}
""")
self.layout.addWidget(self.title_label)
# 在ReportExporter类中也添加增强功能
class ReportExporter:
"""可视化报告导出器 - 增强版本"""
def __init__(self, scan_results, system_info):
self.scan_results = scan_results
self.system_info = system_info
def export_html_report(self, file_path):
"""导出HTML格式的可视化报告"""
html_content = self._generate_enhanced_html_report()
try:
with open(file_path, 'w', encoding='utf-8') as f:
f.write(html_content)
return True, "HTML报告导出成功"
except Exception as e:
return False, f"HTML报告导出失败: {str(e)}"
def _generate_enhanced_html_report(self):
"""生成增强的HTML报告内容"""
# 使用增强的汇总功能
try:
from translations import get_vulnerability_summary
summary = get_vulnerability_summary(self.scan_results, "zh")
total_vulns = summary['total']
affected_count = summary['vulnerable']
safe_count = summary['safe']
high_risk_count = summary['high_risk']
medium_risk_count = summary['medium_risk']
risk_percentage = summary['risk_percentage']
except:
# 回退到基本统计
total_vulns = len(self.scan_results)
affected_count = sum(1 for result in self.scan_results if result.get("VULNERABLE", False))
safe_count = total_vulns - affected_count
high_risk_count = affected_count // 2 # 估算
medium_risk_count = affected_count - high_risk_count
risk_percentage = round((affected_count / total_vulns * 100) if total_vulns > 0 else 0, 1)
# 获取当前时间
import datetime
current_time = datetime.datetime.now().strftime("%Y年%m月%d日 %H:%M:%S")
html_content = f"""
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>CPU漏洞检测报告</title>
<style>
body {{
font-family: 'Microsoft YaHei', 'Segoe UI', 'Arial', sans-serif;
line-height: 1.6;
margin: 0;
padding: 20px;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
min-height: 100vh;
}}
.container {{
max-width: 1200px;
margin: 0 auto;
background: white;
border-radius: 15px;
box-shadow: 0 10px 30px rgba(0,0,0,0.2);
overflow: hidden;
}}
.header {{
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
color: white;
padding: 30px;
text-align: center;
}}
.header h1 {{
margin: 0;
font-size: 2.5em;
font-weight: 300;
}}
.header .subtitle {{
margin-top: 10px;
opacity: 0.9;
font-size: 1.1em;
}}
.content {{
padding: 30px;
}}
.summary-grid {{
display: grid;
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
gap: 20px;
margin-bottom: 30px;
}}
.summary-card {{
background: #f8f9fa;
border-radius: 10px;
padding: 20px;
text-align: center;
border-left: 4px solid;
position: relative;
overflow: hidden;
}}
.summary-card.total {{ border-left-color: #3498db; }}
.summary-card.vulnerable {{ border-left-color: #e74c3c; }}
.summary-card.safe {{ border-left-color: #2ecc71; }}
.summary-card.high-risk {{ border-left-color: #c0392b; }}
.summary-card.medium-risk {{ border-left-color: #f39c12; }}
.summary-card.risk-percentage {{ border-left-color: #9b59b6; }}
.summary-number {{
font-size: 2.5em;
font-weight: bold;
margin-bottom: 5px;
}}
.summary-label {{
color: #666;
font-size: 0.9em;
text-transform: uppercase;
letter-spacing: 1px;
}}
.section {{
margin-bottom: 40px;
}}
.section h2 {{
color: #2c3e50;
border-bottom: 2px solid #667eea;
padding-bottom: 10px;
margin-bottom: 20px;
}}
.vulnerability-grid {{
display: grid;
gap: 20px;
}}
.vuln-card {{
background: white;
border: 1px solid #e0e0e0;
border-radius: 10px;
padding: 20px;
box-shadow: 0 2px 10px rgba(0,0,0,0.1);
transition: transform 0.2s;
}}
.vuln-card:hover {{
transform: translateY(-2px);
box-shadow: 0 4px 15px rgba(0,0,0,0.15);
}}
.vuln-card.vulnerable {{
border-left: 4px solid #e74c3c;
background: #fdf2f2;
}}
.vuln-card.safe {{
border-left: 4px solid #2ecc71;
background: #f0f9f0;
}}
.vuln-card.unknown {{
border-left: 4px solid #f39c12;
background: #fff9f0;
}}
.vuln-header {{
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 15px;
}}
.vuln-title {{
font-size: 1.2em;
font-weight: bold;
color: #2c3e50;
}}
.vuln-status {{
padding: 5px 15px;
border-radius: 20px;
font-size: 0.9em;
font-weight: bold;
}}
.status-vulnerable {{
background: #e74c3c;
color: white;
}}
.status-safe {{
background: #2ecc71;
color: white;
}}
.status-unknown {{
background: #f39c12;
color: white;
}}
.vuln-description {{
color: #666;
margin-bottom: 10px;
}}
.vuln-details {{
display: grid;
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
gap: 15px;
margin-top: 15px;
}}
.detail-item {{
background: #f8f9fa;
padding: 10px;
border-radius: 5px;
}}
.detail-label {{
font-weight: bold;
color: #667eea;
font-size: 0.9em;
margin-bottom: 5px;
}}
.detail-value {{
color: #2c3e50;
font-size: 0.9em;
}}
.system-info {{
background: #f8f9fa;
border-radius: 10px;
padding: 20px;
margin-bottom: 20px;
}}
.system-grid {{
display: grid;
grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
gap: 15px;
}}
.footer {{
background: #2c3e50;
color: white;
text-align: center;
padding: 20px;
font-size: 0.9em;
}}
.chart-container {{
background: white;
border-radius: 10px;
padding: 20px;
margin: 20px 0;
text-align: center;
}}
.progress-bar {{
width: 100%;
height: 20px;
background-color: #e9ecef;
border-radius: 10px;
overflow: hidden;
margin: 10px 0;
}}
.progress-fill {{
height: 100%;
background: linear-gradient(90deg, #2ecc71, #27ae60);
transition: width 0.3s ease;
}}
</style>
</head>
<body>
<div class="container">
<div class="header">
<h1>🛡️ CPU漏洞检测报告</h1>
<div class="subtitle">生成时间: {current_time}</div>
</div>
<div class="content">
<!-- 增强的统计概览 -->
<div class="section">
<h2>📊 检测概览</h2>
<div class="summary-grid">
<div class="summary-card total">
<div class="summary-number" style="color: #3498db;">{total_vulns}</div>
<div class="summary-label">总检测项目</div>
</div>
<div class="summary-card vulnerable">
<div class="summary-number" style="color: #e74c3c;">{affected_count}</div>
<div class="summary-label">受影响项目</div>
</div>
<div class="summary-card safe">
<div class="summary-number" style="color: #2ecc71;">{safe_count}</div>
<div class="summary-label">安全项目</div>
</div>
<div class="summary-card high-risk">
<div class="summary-number" style="color: #c0392b;">{high_risk_count}</div>
<div class="summary-label">高危漏洞</div>
</div>
<div class="summary-card medium-risk">
<div class="summary-number" style="color: #f39c12;">{medium_risk_count}</div>
<div class="summary-label">中危漏洞</div>
</div>
<div class="summary-card risk-percentage">
<div class="summary-number" style="color: #9b59b6;">{risk_percentage}%</div>
<div class="summary-label">风险比例</div>
</div>
</div>
</div>
<!-- 系统信息 -->
<div class="section">
<h2>🖥️ 系统信息</h2>
<div class="system-info">
<div class="system-grid">
<div class="detail-item">
<div class="detail-label">操作系统</div>
<div class="detail-value">{self.system_info.get('os', '未知')}</div>
</div>
<div class="detail-item">
<div class="detail-label">CPU型号</div>
<div class="detail-value">{self.system_info.get('cpu', '未知')}</div>
</div>
<div class="detail-item">
<div class="detail-label">内核版本</div>
<div class="detail-value">{self.system_info.get('kernel', '未知')}</div>
</div>
<div class="detail-item">
<div class="detail-label">可用内存</div>
<div class="detail-value">{self.system_info.get('memory', '未知')}</div>
</div>
</div>
</div>
</div>
<!-- 漏洞详情 -->
<div class="section">
<h2>🔍 漏洞检测详情</h2>
<div class="vulnerability-grid">
"""
# 添加每个漏洞的详细信息 - 增强版本
for result in self.scan_results:
vulnerable = result.get("VULNERABLE", False)
if vulnerable:
card_class = "vulnerable"
status_class = "status-vulnerable"
status_text = "受影响"
elif vulnerable is None:
card_class = "unknown"
status_class = "status-unknown"
status_text = "未知"
else:
card_class = "safe"
status_class = "status-safe"
status_text = "安全"
cve_id = result.get("CVE", "")
name = result.get("NAME", "")
description = result.get("DESCRIPTION", "暂无描述")
impact = result.get("IMPACT", "暂无影响信息")
mitigation = result.get("MITIGATION", "暂无缓解措施")
infos = result.get("INFOS", "")
mitigation_status = result.get("MITIGATION_STATUS", "")
# 翻译检测信息
try:
from translations import translate_vulnerability_info
translated_infos = translate_vulnerability_info(infos, "zh")
except:
translated_infos = infos
html_content += f"""
<div class="vuln-card {card_class}">
<div class="vuln-header">
<div class="vuln-title">{cve_id} - {name}</div>
<div class="vuln-status {status_class}">{status_text}</div>
</div>
<div class="vuln-description">{description}</div>
<div class="vuln-details">
<div class="detail-item">
<div class="detail-label">检测信息</div>
<div class="detail-value">{translated_infos}</div>
</div>
<div class="detail-item">
<div class="detail-label">缓解状态</div>
<div class="detail-value">{mitigation_status}</div>
</div>
<div class="detail-item">
<div class="detail-label">影响</div>
<div class="detail-value">{impact}</div>
</div>
<div class="detail-item">
<div class="detail-label">缓解措施</div>
<div class="detail-value">{mitigation}</div>
</div>
</div>
</div>
"""
html_content += f"""
</div>
</div>
</div>
<div class="footer">
<p>📋 本报告由CPU漏洞检测工具自动生成 | 🛡️ 建议定期进行安全检测 | ⚡ 及时更新系统补丁</p>
<p>风险评估:{risk_percentage}% | 如需技术支持,请参考相关CVE公告和厂商安全建议</p>
<p>生成时间:{current_time} | 检测项目:{total_vulns}个</p>
</div>
</div>
</body>
</html>
"""
return html_content
class GradientHeader(QLabel):
"""现代化渐变头部 - 修复字体问题"""
def __init__(self, text, parent=None):
super().__init__(text, parent)
self.setFixedHeight(80)
self.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed)
self.setAlignment(Qt.AlignCenter)
# 修复:使用系统兼容字体
fonts = get_system_fonts()
font = QFont()
font.setFamily(fonts['ui'][0]) # 使用第一个可用字体
font.setPointSize(24)
font.setBold(True)
self.setFont(font)
def paintEvent(self, event):
painter = QPainter(self)
painter.setRenderHint(QPainter.Antialiasing)
# 现代化渐变背景
gradient = QLinearGradient(0, 0, self.width(), 0)
gradient.setColorAt(0, QColor("#667eea"))
gradient.setColorAt(0.5, QColor("#764ba2"))
gradient.setColorAt(1, QColor("#f093fb"))
painter.fillRect(self.rect(), QBrush(gradient))
# 文字效果
pen = QPen(QColor("white"))
painter.setPen(pen)
painter.setFont(self.font())
painter.drawText(self.rect(), Qt.AlignCenter, self.text())
class ModernProgressBar(QProgressBar):
"""现代化进度条 - 支持自适应"""
def __init__(self, parent=None):
super().__init__(parent)
self.setFixedHeight(8)
self.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed)
self.setTextVisible(False)
self.setStyleSheet("""
QProgressBar {
border-radius: 4px;
background-color: #ecf0f1;
}
QProgressBar::chunk {
border-radius: 4px;
background: qlineargradient(x1:0, y1:0, x2:1, y2:0,
stop:0 #667eea, stop:0.5 #764ba2, stop:1 #f093fb);
}
""")
class AnimatedButton(QPushButton):
"""带动画效果的按钮 - 修复字体截断问题"""
def __init__(self, text, color_scheme="primary", parent=None):
super().__init__(text, parent)
self.color_scheme = color_scheme
self.setMinimumHeight(48) # 增加最小高度
self.setSizePolicy(QSizePolicy.Preferred, QSizePolicy.Fixed)
# 修复:使用系统兼容字体
fonts = get_system_fonts()
font = QFont()
font.setFamily(fonts['ui'][0])
font.setPointSize(11)
font.setWeight(QFont.Medium)
self.setFont(font)
self.setCursor(Qt.PointingHandCursor)
# 设置按钮样式
if color_scheme == "primary":
self.setStyleSheet(f"""
QPushButton {{
font-family: {', '.join(fonts['ui'])};
background: qlineargradient(x1:0, y1:0, x2:1, y2:0,
stop:0 #667eea, stop:1 #764ba2);
color: white;
border: none;
border-radius: 8px;
padding: 14px 24px;
font-weight: 500;
font-size: 13px;
min-height: 20px;
}}
QPushButton:hover {{
background: qlineargradient(x1:0, y1:0, x2:1, y2:0,
stop:0 #5a6fd8, stop:1 #6a4190);
border: 2px solid #4e5bc4;
padding: 12px 22px;
}}
QPushButton:pressed {{
background: qlineargradient(x1:0, y1:0, x2:1, y2:0,
stop:0 #4e5bc4, stop:1 #5e3785);
}}
QPushButton:disabled {{
background-color: #bdc3c7;
color: #7f8c8d;
}}
""")
elif color_scheme == "danger":
self.setStyleSheet(f"""
QPushButton {{
font-family: {', '.join(fonts['ui'])};
background: qlineargradient(x1:0, y1:0, x2:1, y2:0,
stop:0 #ff6b6b, stop:1 #ee5a52);
color: white;
border: none;
border-radius: 8px;
padding: 14px 24px;
font-weight: 500;
font-size: 13px;
min-height: 20px;
}}
QPushButton:hover {{
background: qlineargradient(x1:0, y1:0, x2:1, y2:0,
stop:0 #ff5757, stop:1 #dc4c47);
border: 2px solid #ff4757;
padding: 12px 22px;
}}
QPushButton:pressed {{
background: qlineargradient(x1:0, y1:0, x2:1, y2:0,
stop:0 #ff4757, stop:1 #c44242);
}}
""")
elif color_scheme == "success":
self.setStyleSheet(f"""
QPushButton {{
font-family: {', '.join(fonts['ui'])};
background: qlineargradient(x1:0, y1:0, x2:1, y2:0,
stop:0 #2ecc71, stop:1 #27ae60);
color: white;
border: none;
border-radius: 8px;
padding: 14px 24px;
font-weight: 500;
font-size: 13px;
min-height: 20px;
}}
QPushButton:hover {{
background: qlineargradient(x1:0, y1:0, x2:1, y2:0,
stop:0 #27c46e, stop:1 #239954);
border: 2px solid #1e8449;
padding: 12px 22px;
}}
""")
else: # secondary
self.setStyleSheet(f"""
QPushButton {{
font-family: {', '.join(fonts['ui'])};
background-color: #95a5a6;
color: white;
border: none;
border-radius: 8px;
padding: 14px 24px;
font-weight: 500;