核心功能: - 6 层检测管线: L0 结构分析 → L1 ClamAV → L2 文档深度检测 → L3 关键词匹配 → L4 YARA → L5 PE/二进制 - FastAPI + PostgreSQL + Redis + Docker Compose 架构 - 客户端 HMAC-SHA256 签名鉴权 + 限流 + 幂等性 - 控制台 UI (登录/Dashboard/诊断中心/策略管理/任务列表/测试中心/产品介绍页) - 三层诊断定时器 (error_scan 30s / db_aggregate 30s / container_check 5min) 并发与稳定性修复: - 诊断定时器 Redis 时间槽位锁 (多 worker 同一槽位只有一个执行) - JSONL 存储 fcntl 跨进程排他锁 + 容错解码 + 原子重写 - 移除 SQLite fallback, 统一 PostgreSQL - API_CLIENTS 脱敏为环境变量, .env 已 .gitignore
33 lines
1.1 KiB
Python
33 lines
1.1 KiB
Python
import sys, os
|
|
sys.path.insert(0, '.')
|
|
os.chdir(r'd:\project\MeshSafe')
|
|
# DB_URL 由 .env 或 compose environment 提供
|
|
os.environ.setdefault('MESHSAFE_MASTER_KEY', 'Dt0ktRs8SjEH8VxWZJDX125NV1qiII88HoiXZPhWers=')
|
|
os.environ.setdefault('MESHSAFE_POLICY_FILE', 'config/policy.yaml')
|
|
|
|
from app.services.scanner import Scanner
|
|
from app.services.policy import PolicyStore
|
|
|
|
ps = PolicyStore(policy_file='config/policy.yaml')
|
|
scanner = Scanner(ps)
|
|
|
|
files = [
|
|
'tests/samples/shell_php_eval.php',
|
|
'tests/samples/pe_injection.exe',
|
|
'tests/samples/normal_readme.txt',
|
|
'tests/samples/normal_deploy.sh',
|
|
]
|
|
|
|
for f in files:
|
|
print(f"\n{'='*60}")
|
|
print(f"扫描: {f}")
|
|
outcome = scanner.scan_file(
|
|
file_path=f, original_filename=os.path.basename(f),
|
|
task_id=f"debug-{os.path.basename(f)}", channel='test', client_id='test',
|
|
)
|
|
print(f"verdict={outcome.verdict} action={outcome.action} score={outcome.score}")
|
|
for fi in outcome.findings:
|
|
print(f" [{fi.engine}] rule={fi.rule} sev={fi.severity} weight={fi.weight}")
|
|
if outcome.meta.get('engine_errors'):
|
|
print(f" engine_errors: {outcome.meta['engine_errors']}")
|