fix: 测试靶场只展示 index.json 登记的样本 + 清 4 个临时调试文件

问题:
  控制台测试靶场页面样本数: 目录 172 个 vs index.json 168 条
  差了 4 个是 YARA 调试时创建的临时文件 (L4-005_hotreload.txt 等)
  这些临时文件没进 index.json → meta_map 查不到 → category='未知' case_id='—'

修复:
  1) console.py test_center_page:
     samples_list 从遍历目录 (iterdir) 改成只从 index.json 来
     每个样本必须 index.json 有登记 + 磁盘上确实存在
     以后目录里即使有临时文件也不会混入靶场列表
  2) 清理 4 个重复临时调试文件:
     L4-005_hotreload.txt      → index.json 正式: L4-005_005_sample.txt
     L4-007_meta_rule.txt       → index.json 正式: L4-007_meta_rule_match.txt
     L4-010_regex_pattern.txt   → index.json 正式: L4-010_010_sample.txt
     L4-012_size_condition.txt  → index.json 正式: L4-012_size_condition.bin

控制台页面现在: 168 条, 全部有 case_id 和 category, 无 '未知' 和 '—'
This commit is contained in:
2026-10-29 17:11:51 +08:00
parent da8496adfd
commit c0cb292350
5 changed files with 7 additions and 13 deletions

View File

@@ -960,15 +960,13 @@ async def test_page(request: Request, current=Depends(require_login)):
index = json.loads(index_path.read_text(encoding="utf-8")) index = json.loads(index_path.read_text(encoding="utf-8"))
meta_map = {s["filename"]: s for s in index.get("samples", [])} meta_map = {s["filename"]: s for s in index.get("samples", [])}
# 收集所有样本文件 # ★ 只展示 index.json 里登记的样本(不遍历目录,避免临时/调试文件混入)
for fpath in sorted(samples_dir.iterdir()): # 每个样本必须: index.json 有登记 + 磁盘上确实存在
if not fpath.is_file(): for s in index.get("samples", []):
continue fname = s["filename"]
if fpath.name == "index.json" or fpath.name.startswith("_"): fpath = samples_dir / fname
continue if fpath.is_file():
if fpath.suffix == ".json" and fpath.name.startswith("_scan_results"): samples_list.append(fpath)
continue
samples_list.append(fpath)
results: list[dict] = [] results: list[dict] = []
pass_cnt = fail_cnt = 0 pass_cnt = fail_cnt = 0

View File

@@ -1 +0,0 @@
meshsafe-hot-reload-test-string present here

View File

@@ -1 +0,0 @@
trojan-metadata-test payload here

View File

@@ -1 +0,0 @@
powershell -enc ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwx+/==

View File

@@ -1 +0,0 @@
size_condition_test_payload small file