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']}")