Skip to content

Python Examples

Practical scripts demonstrating rekit integration into defensive security pipelines and CI/CD gates.

Example 1: Automated Pre-commit Static Gate

import subprocess
import json
import sys

def audit_binary(filepath):
    # Run rekit triage with --json
    cmd = ["python3", "rekit.py", "triage", filepath, "--json"]
    proc = subprocess.run(cmd, capture_output=True, text=True)

    if proc.returncode != 0:
        print(f"Audit failed: {proc.stderr}")
        return False

    data = json.loads(proc.stdout)
    if data.get("packer"):
        print(f"ALERT: Binary is packed with {data['packer']}")
        return False

    print(f"Passed: {filepath} ({data.get('kind')})")
    return True

if __name__ == "__main__":
    if not audit_binary(sys.argv[1]):
        sys.exit(1)

Example 2: Batch IOC Hunting

# Scan all downloaded assets in a staging directory
find ./downloads -type f -exec python3 rekit.py iocs {} +