cti-verify-file-svm / predict.py
Kamlesh21's picture
CTI Verify file classifiers (SVM): models, scorer, feature code, model card
dcb3c82 verified
Raw History Blame Contribute Delete
597 Bytes
"""Score a file with the CTI Verify file classifiers.
pip install -r requirements.txt
python predict.py suspicious.exe # a Windows program, a Linux program or a PDF
"""
import json
import sys
from api import file_svm
MAGIC = {b"MZ": "exe", b"\x7fELF": "elf", b"%PDF": "pdf"}
data = open(sys.argv[1], "rb").read()
kind = next((k for m, k in MAGIC.items() if data.startswith(m)), None)
if not kind:
sys.exit("not a Windows program, a Linux program or a PDF: these models score only those")
print(json.dumps(file_svm.score(kind, data), indent=2, default=str))